Thursday, March 13, 2008

CC3 Week 2 - Introduction To SuperCollider II

This week's exercise was way too hard for only week two.



// ONE

(
z = { arg freq;
f = if (
freq == 440, // Set Concert A
{ "Frequency is Concert A" }, // If the input freq is equal to Concert A
{ g = if (
freq < 440, // If the input freq is less than 440
{ "below Concert A" }, // "below Concert A" is added to "Frequency is"
{ "above Concert A" } // or else "above Concert A" is added to it.
);
("Frequency is"+g) // Sentence beginning
}
);
}
)

(
a = z.value(440); // Input frequency
a.postln;
)



//TWO

(
z = { arg freq;
f = if (
freq == 440, // Set Concert A
{ "Frequency is Concert A, 440Hz." }, // If the input freq is equal to Concert A
{ i = freq - 440; // i = Frequency deviation
g = if (
freq < 440, // If the input freq is less than 440
{ "below Concert A," }, // "below Concert A" is added to "Frequency is"
{ "above Concert A, +" } // or else "above Concert A" is added to it.
);
("Frequency is"+g+i+"Hz.") // Sentence beginning +below/above +deviation
}
);
}
)

(
a = z.value(440); // Input frequency
a.postln;
)



//THREE

(
f = {
arg freq, list;
var i=1;
while (
{ i <= list }, // While i is less than list,
{
(freq*i).postln; // Multiply freq by i and
i = i + 1; // add 1 to i.
}
);
}
)

(
z = f.value(440, 10);
z.postln;
)



//FOUR

(
f = {
arg inputFreq, arraySize; // Defining inputs
var overTones = Array.new(arraySize); // Creating array
for (
0, // Start of array
arraySize, // End of array
{ arg i; overTones = overTones.add((i+1) * inputFreq);} // Add i+1*input frequency to array
);
overTones; // Set array
};
)

(
h = f.value(221, 6); // Input frequency and array size.
h.postln;
)



//FIVE

(
f = {
arg inputFreq, arraySize; // Defining inputs
var overTones = Array.new(arraySize); // Creating array
forBy (
1, // Start of array
arraySize*2, // End of array
2, // Step size
{ arg i; overTones = overTones.add((i+1) * inputFreq);} // Add i+1*input frequency to array
);
overTones; // Set array
};
)

(
h = f.value(221, 5); // Input frequency and array size.
h.postln;
)



//6IX

(
f = { arg drum;
var x=drum;
switch(x,
"kick", {"MIDI Note 1"}, // When a drum name is entered
"snare", {"MIDI Note 2"},// an associated number is printed.
"hihat", {"MIDI Note 3"},
"crash", {"MIDI Note 4"},
"ride", {"MIDI Note 5"},
"tom", {"MIDI Note 6"}
)
}
)

(
h = f.value("tom"); // Drum name
h.postln;
)



//SEVEN

(
f = { arg drum;
var x=drum%12; // MIDI note value pitch class is determined.
switch(x,
1, {"Kick"}, // Pitch class is converted into instrument.
2, {"Snare"},
3, {"Hihat"},
4, {"Crash"},
5, {"Ride"},
6, {"Tom"}
)
}
)

(
h = f.value(17); //MIDI note value
h.postln;
)




[1] Christian Haines. "Creative Computing: Semester 1 - Week 2 - Introduction To SuperCollider II". Lecture presented at the Electronic Music Unit, University of Adelaide, South Australia, 13th March 2008.

No comments: