.cc - week two.
This week I used a few new control structures like While, For and Case. Again, download the .rtf file for more legible formatting.
week2.rtf
// 1. evaluating a input
(
var freqIn = 5; // user input pitch
if (
440 >= freqIn,
{ freqIn+"Hz is below Concert A." },
{ freqIn+"Hz is above Concert A."}
);
)
// 2. more complicated
(
var freqIn = 490; // user input pitch
var concertA = 440; // concertA
a = freqIn - concertA;
b = concertA - freqIn;
if (
concertA >= freqIn,
{ (freqIn+"Hz is"+b+"Hz below 440 Hz (Concert A).").postln },
{ (freqIn+"Hz is"+a+"Hz above 440 Hz (Concert A).").postln }
);
)
// 3. harmonics of a fundamental
(
var inputFreq = 440; // user input frequency fundamental
j = 1; //count
while (
{ j <= 8 }, { (inputFreq * j).postln; j = j + 1; } ); )
// 4. harmonics of a fundamental in an array
(
var freqIn = 440; // user input frequency fundamental
e = {
arg freq, room;
var freqContent = Array.new(room);
for (
0, room,
{
arg i;
freqContent = freqContent.add((i+1) * freq);
}
);
freqContent;
};
f = e.value(freqIn,7);
)
// 5. harmonics of a fundamental in an array that are odd numbers
(
var freqIn = 445; // user input frequency fundamental
e = {
arg freq, room;
var freqContent = Array.new(room);
for (
0, room,
{
arg i;
freqContent = freqContent.add((i+1) * freq);
}
);
freqContent.takeThese({ arg item, index; item.even; }); //remove even numbers
};
f = e.value(freqIn,7);
)
// 6. drum name to MIDI note
(
var x, y;
x = "Crash"; // user input drum name
y = case
{ x == "kick" } { x+"is the MIDI note 36."}
{ x == "snare" } { x+"is the MIDI note 38." }
{ x == "hihat" } { x+"is the MIDI note 44." }
{ x == "crash" } { x+"is the MIDI note 49." }
{ x == "ride" } { x+"is the MIDI note 51." }
{ x == "tom" } { x+"is the MIDI note 45." };
)
// 7. MIDI note number to corresponding drum
(
var x, y, z, q;
x = "45"; // user input drum name
z = "text"; //pitch class
y = case
{ x == "36" } { z = "C1" }//determine pitch class
{ x == "38" } { z = "D1" }
{ x == "44" } { z = "G#1" }
{ x == "49" } { z = "C#2" }
{ x == "51" } { z = "D#2" }
{ x == "45" } { z = "A1" };
z = case //map pitch class to corresponding name
{ z == "C1" } { "The MIDI note"+x+"is the pitch class C1, Kick Drum." }
{ z == "D1" } { "The MIDI note"+x+"is the pitch class D1, Snare Drum." }
{ z == "G#1" } { "The MIDI note"+x+"is the pitch class G#1, HiHat Cymbal." }
{ z == "C#2" } { "The MIDI note"+x+"is the pitch class C#2, Crash Cymbal." }
{ z == "D#2" } { "The MIDI note"+x+"is the pitch class D#2, Ride Cymbal." }
{ z == "A1" } { "The MIDI note"+x+"is the pitch class A1, Tom Drum." };
)
.sources.
Haines, Christian, 13.3.08 "Introduction to SuperCollider (2)," Lecture of EMU, Adelaide University.
iieiwrmeieweeiimeemmwreiweremweireeemeimwieewwrwweereireeiimeewmiwwwemwiewimeeeremeiewmemweewieewerwemwiimiewmeiwireiiwrrewmwewree |
14.3.08
SuperCollider (2)
copywrite 1:49 pm
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment