<div dir="ltr">Store whatever the current command state is (e.g. character and number) and then keeping modifying that until you reach whatever is considered a new command, at which point the previous command is executed. E.g. <div><br></div><div><div>0 =&gt; int cmdc;</div><div>float cmdnum;</div><div><br></div><div>for(...)</div><div>{</div><div>    if(letter == &#39;a&#39;)</div><div>    {</div><div>        // dispatch previous command<br></div><div>        if(cmdc)</div><div>            doCmd(cmdc, cmdnum);</div><div>        // store new command<br></div><div>        letter =&gt; cmdc;</div><div>        0 =&gt; cmdnum;</div><div>    }</div><div>    // further down ...</div><div>    // if is number</div><div>    else if(letter &gt;= 48 &amp;&amp; letter &lt;= 57)</div><div>    {</div><div>        cmdnum*10 + (letter-48) =&gt; cmdnum;</div><div>    }</div><div>}</div></div><div><br></div><div>doCmd plays whatever the command is and needs to use the appropriate default if cmdnum is 0. Also this doesn&#39;t deal with octave/length or anything like that but I imagine thats straightforward to add on. Probably most of the letter if-statements could be folded into a single if. You may need to keep additional state variables for the command if there are other properties besides pitch class and duration, like octave (and intensity?). </div><div><br></div><div>spencer</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 7, 2016 at 5:52 PM, Colton Hill <span dir="ltr">&lt;<a href="mailto:colton-hill2014@hotmail.com" target="_blank">colton-hill2014@hotmail.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 bgcolor="#FFFFFF" text="#000000">
<p>that&#39;s the issue. I would slowly go through the string and parse down every command, if I knew how to grab numbers and things between one command and the next. For example, c8.c8<br>
</p><div><div class="h5">
<br>
<div>On 9/7/2016 7:44 PM, Spencer Salazar wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>I dont think you can use regex to match a whole expression like that but you can use it to pick off bits and pieces. Just make a regex that matches all of the possible commands + options and run that through, advancing the string position each time. Eg</div>
<div><br>
</div>
<div>
<div>&quot;<span style="font-size:12.8px">o4l8cdefg</span>&quot; =&gt; string code;</div>
<div>string matches[0];</div>
<div>&quot;((o)([0-9]+)|([abcdefg])(1|2|<wbr>4|8|16)?|(l)([0-9]+))&quot; =&gt; string pattern;</div>
<div><br>
</div>
<div>for(0 =&gt; int i; i &lt; code.length(); )</div>
<div>{</div>
<div>    if(RegEx.match(pattern, code.substring(i), matches))</div>
<div>    {</div>
<div>        if(matches[2] == &quot;o&quot;)</div>
<div>            &lt;&lt;&lt; &quot;octave:&quot;, matches[3] &gt;&gt;&gt;;</div>
<div>        else if(matches[4] == &quot;a&quot;)</div>
<div>            &lt;&lt;&lt; &quot;a&quot; &gt;&gt;&gt;;</div>
<div>        // etc.</div>
<div>        </div>
<div>        matches[0].length() +=&gt; i;</div>
<div>    }</div>
<div>    else</div>
<div>    {</div>
<div>        &lt;&lt;&lt; &quot;invalid code&quot; &gt;&gt;&gt;;</div>
<div>        break;</div>
<div>    }</div>
<div>}</div>
</div>
<div><br>
</div>
<div>I dont know anything about MML so I dont know what the final regex would look like. </div>
<div><br>
</div>
<div>Another option is to just go through the string iteratively and look at each character one at a time. If whitespace is undesirable StringTokenizer might be hurting more than helping here. </div>
<div><br>
</div>
<div>
<div>for(0 =&gt; int i; i &lt; code.length(); )</div>
<div>{</div>
</div>
<div>    int c = code.charAt(i);</div>
<div>    if(c == &#39;o&#39;)</div>
<div>    {</div>
<div>         // look for number</div>
<div>    }</div>
<div>    else if(c == &#39;a&#39; || c == &#39;b&#39; || ... )</div>
<div>    {</div>
<div>         // see if number follows</div>
<div>    }</div>
<div>}</div>
<div><br>
</div>
<div>spencer</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Sep 6, 2016 at 6:32 PM, Colton Hill <span dir="ltr">
&lt;<a href="mailto:colton-hill2014@hotmail.com" target="_blank">colton-hill2014@hotmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I also want to make sure I have a customizable play function that will<br>
handle my playing. Here&#39;s the code I&#39;ve been using for my current mml<br>
parser in chuck, actually does take a code string and a play function,<br>
and operates well. Only issue is including doesn&#39;t work... So have a test.<br>
<div>
<div><br>
<br>
On 9/6/2016 3:33 AM, Hans Åberg wrote:<br>
&gt;&gt; On 5 Sep 2016, at 23:16, Colton Hill &lt;<a href="mailto:colton-hill2014@hotmail.com" target="_blank">colton-hill2014@hotmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I know regular expressions syntax, but I really don&#39;t know how I would<br>
&gt;&gt; manage to make an mml parser that actually works. Turn o4l8cdefg into<br>
&gt;&gt; octave 4, length 8, and c d e f g notes with an 8th note length since no<br>
&gt;&gt; length is specified. Then there&#39;s c4., which is c4^c8... Just bla…<br>
&gt; There are free MML parsers in C out there. Linking to ChucK, which is written in C++, might be a way.<br>
&gt;<br>
&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; chuck-users mailing list<br>
&gt; <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton<wbr>.edu</a><br>
&gt; <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">
https://lists.cs.princeton.edu<wbr>/mailman/listinfo/chuck-users</a><br>
<br>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton<wbr>.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu<wbr>/mailman/listinfo/chuck-users</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div style="font-family:arial;font-size:small">
<div>Spencer Salazar<br>
</div>
<div>Doctoral Candidate</div>
<div>Center for Computer Research in Music and Acoustics</div>
<div>Stanford University</div>
<div><br>
</div>
<div><a href="mailto:spencer@ccrma.stanford.edu" target="_blank">spencer@ccrma.stanford.edu</a></div>
<div><a href="tel:%2B1%20831.277.4654" value="+18312774654" target="_blank">+1 831.277.4654</a><br>
</div>
<div><a href="https://ccrma.stanford.edu/%7Espencer/" style="color:rgb(17,85,204)" target="_blank">https://ccrma.stanford.edu/~<wbr>spencer/</a><br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset> <br>
<pre>______________________________<wbr>_________________
chuck-users mailing list
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.<wbr>princeton.edu</a>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.<wbr>edu/mailman/listinfo/chuck-<wbr>users</a>
</pre>
</blockquote>
<br>
</div></div></div>

<br>______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.<wbr>princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.<wbr>edu/mailman/listinfo/chuck-<wbr>users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="font-family:arial;font-size:small"><div>Spencer Salazar<br></div><div>Doctoral Candidate</div><div>Center for Computer Research in Music and Acoustics</div><div>Stanford University</div><div><br></div><div><a href="mailto:spencer@ccrma.stanford.edu" target="_blank">spencer@ccrma.stanford.edu</a></div><div></div><div>+1 831.277.4654<br></div><div><a href="https://ccrma.stanford.edu/~spencer/" style="color:rgb(17,85,204)" target="_blank">https://ccrma.stanford.edu/~spencer/</a><br></div><div><br></div></div></div></div></div></div></div></div></div></div>
</div>