<div dir="ltr"><div><div><div>Hello Oba,<br><br></div>I think I&#39;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">&lt;<a href="mailto:obaozai@yahoo.com" target="_blank">obaozai@yahoo.com</a>&gt;</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 =&gt;</div><div>// test score<br>// sound chain;<br>SinOsc s =&gt; 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 == &quot;c4&quot;) 60 =&gt; result;<br>        if (x == &quot;d4&quot;) 62 =&gt; result;<br>        if (x == &quot;e4&quot;) 64 =&gt; result;<br>        if (x == &quot;f4&quot;) 65 =&gt; result;<br>        if (x == &quot;g4&quot;) 67 =&gt; result;<br>        if (x == &quot;a4&quot;) 69 =&gt; result;<br>        if (x == &quot;b4&quot;) 71 =&gt; result;<br>        if (x == &quot;c5&quot;) 72 =&gt; 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>[&quot;c4&quot;,&quot;d4&quot;,&quot;e4&quot;,&quot;f4&quot;,&quot;g4&quot;,&quot;a4&quot;,&quot;b4&quot;,&quot;c5&quot; ] @=&gt;  string song[];<br>song.cap() =&gt; int songcap; <br>for (0 =&gt; int i; i &lt; songcap ; i++) {   <br>  0.2 =&gt;s.gain;<br>  Std.mtof(midivals.midivals(song[i])) =&gt; s.freq;<br>  0.5::second =&gt; 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 == &quot;c4&quot;) 60 =&gt; result;<br>        if (x == &quot;d4&quot;) 62 =&gt; result;<br>        if (x == &quot;e4&quot;) 64 =&gt; result;<br>        if (x == &quot;f4&quot;) 65 =&gt; result;<br>        if (x == &quot;g4&quot;) 67 =&gt; result;<br>        if (x == &quot;a4&quot;) 69 =&gt; result;<br>        if (x == &quot;b4&quot;) 71 =&gt; result;<br>        if (x == &quot;c5&quot;) 72 =&gt; 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 =&gt; undefined variable &quot;midivals&quot;</div><div><br></div><div>// test score</div><div>// sound chain;<br>SinOsc s =&gt; 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() + &quot;<a href="http://midivaltest.ck" target="_blank">midivaltest.ck</a>&quot;);<br>// create array with the melody notes<br>[&quot;c4&quot;,&quot;d4&quot;,&quot;e4&quot;,&quot;f4&quot;,&quot;g4&quot;,&quot;a4&quot;,&quot;b4&quot;,&quot;c5&quot; ] @=&gt;  string song[];<br>song.cap() =&gt; int songcap; <br>for (0 =&gt; int i; i &lt; songcap ; i++) {<br>  0.2 =&gt;s.gain;<br>  Std.mtof(midivals.midivals(song[i])) =&gt; s.freq;<br>  0.5::second =&gt; 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>