[chuck-users] New to Chuck - Clases and Machine.add question

Oba Ozai obaozai at yahoo.com
Fri Nov 13 09:57:53 EST 2015


Hi, Im stuck with something simple, i cant figure out :)
This works fine =>// test score
// sound chain;
SinOsc s => dac;
// create class with a function to return midi values
//given and input string
class mymidivals { 
 int result;
 fun int midivals (string x){ 
 if (x == "c4") 60 => result;
 if (x == "d4") 62 => result;
 if (x == "e4") 64 => result;
 if (x == "f4") 65 => result;
 if (x == "g4") 67 => result;
 if (x == "a4") 69 => result;
 if (x == "b4") 71 => result;
 if (x == "c5") 72 => result;
 return result; 
 } // fun 
}// class
//define object
mymidivals midivals;// create array with the melody notes
["c4","d4","e4","f4","g4","a4","b4","c5" ] @=> string song[];
song.cap() => int songcap; 
for (0 => int i; i < songcap ; i++) { 
 0.2 =>s.gain;
 Std.mtof(midivals.midivals(song[i])) => s.freq;
 0.5::second => now; 
 ===================================But if i put the function mymidivals on a .ck file like this //midivaltest.ck
// create class with a function to return midi values
//given and input string
public class mymidivals { 
 int result;
 fun int midivals (string x){ 
 if (x == "c4") 60 => result;
 if (x == "d4") 62 => result;
 if (x == "e4") 64 => result;
 if (x == "f4") 65 => result;
 if (x == "g4") 67 => result;
 if (x == "a4") 69 => result;
 if (x == "b4") 71 => result;
 if (x == "c5") 72 => result;
 return result; 
 } // fun 
}// class
mymidivals midivals;=============================================and if call it this way, it does not work, error => undefined variable "midivals"
// test score// sound chain;
SinOsc s => dac;;// midivaltest.ck lives on same dir as this code
Machine.add(me.dir() + "midivaltest.ck");
// create array with the melody notes
["c4","d4","e4","f4","g4","a4","b4","c5" ] @=> string song[];
song.cap() => int songcap; 
for (0 => int i; i < songcap ; i++) {
 0.2 =>s.gain;
 Std.mtof(midivals.midivals(song[i])) => s.freq;
 0.5::second => now; 
} 
-------------------------------------------------------any ideas ? Thanks 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20151113/67eab17c/attachment.html>


More information about the chuck-users mailing list