<div dir="ltr"><div><div><div>Hello Oba,<br><br></div>I think I've ran into this before, the instance of mymidivals you create at the bottom of <a href="http://midivaltest.ck">midivaltest.ck</a> goes out of scope at the end of the Machine.add call. When running the test score file you may notice that Machine.add creates a new shred.<br><br></div>To fix this you could either move the instance declaration to the test score file or make the midivals function static.<br><br>Or perhaps someone else might have better advice, because I still have problems with initializers and statics. For example, this package of classes is all sorts of broken<br><a href="https://github.com/heuermh/lick/tree/master/lick/tuning">https://github.com/heuermh/lick/tree/master/lick/tuning</a></div><div><br><div> michael<br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 13, 2015 at 8:57 AM, Oba Ozai <span dir="ltr"><<a href="mailto:obaozai@yahoo.com" target="_blank">obaozai@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div>Hi, </div><div>Im stuck with something simple, i cant figure out :)</div><div><br></div><div>This works fine =></div><div>// test score<br>// sound chain;<br>SinOsc s => dac;<br>// create class with a function to return midi values<br>//given and input string<br>class mymidivals { <br> int result;<br> fun int midivals (string x){ <br> if (x == "c4") 60 => result;<br> if (x == "d4") 62 => result;<br> if (x == "e4") 64 => result;<br> if (x == "f4") 65 => result;<br> if (x == "g4") 67 => result;<br> if (x == "a4") 69 => result;<br> if (x == "b4") 71 => result;<br> if (x == "c5") 72 => result;<br> return result; <br> } // fun <br>}// class</div><div><br>//define object<br>mymidivals midivals;</div><div>// create array with the melody notes<br>["c4","d4","e4","f4","g4","a4","b4","c5" ] @=> string song[];<br>song.cap() => int songcap; <br>for (0 => int i; i < songcap ; i++) { <br> 0.2 =>s.gain;<br> Std.mtof(midivals.midivals(song[i])) => s.freq;<br> 0.5::second => now; <br></div><div> ===================================</div><div>But if i put the function mymidivals on a .ck file like this </div><div>//<a href="http://midivaltest.ck" target="_blank">midivaltest.ck</a><br>// create class with a function to return midi values<br>//given and input string<br>public class mymidivals { <br> int result;<br> fun int midivals (string x){ <br> if (x == "c4") 60 => result;<br> if (x == "d4") 62 => result;<br> if (x == "e4") 64 => result;<br> if (x == "f4") 65 => result;<br> if (x == "g4") 67 => result;<br> if (x == "a4") 69 => result;<br> if (x == "b4") 71 => result;<br> if (x == "c5") 72 => result;<br> return result; <br> } // fun <br>}// class<br>mymidivals midivals;</div><div>=============================================</div><div>and if call it this way, it does not work, error => undefined variable "midivals"</div><div><br></div><div>// test score</div><div>// sound chain;<br>SinOsc s => dac;;</div><div>// <a href="http://midivaltest.ck" target="_blank">midivaltest.ck</a> lives on same dir as this code<br>Machine.add(me.dir() + "<a href="http://midivaltest.ck" target="_blank">midivaltest.ck</a>");<br>// create array with the melody notes<br>["c4","d4","e4","f4","g4","a4","b4","c5" ] @=> string song[];<br>song.cap() => int songcap; <br>for (0 => int i; i < songcap ; i++) {<br> 0.2 =>s.gain;<br> Std.mtof(midivals.midivals(song[i])) => s.freq;<br> 0.5::second => now; <br>} </div><div><br>-------------------------------------------------------</div><div dir="ltr">any ideas ? Thanks </div></div></div><br>_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br></div>