<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>that'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>
<br>
<div class="moz-cite-prefix">On 9/7/2016 7:44 PM, Spencer Salazar wrote:<br>
</div>
<blockquote cite="mid:CA+ezOE4X0ULiatzQ16=97OzRrO-3vPbhnav5Cvqi-+vfRZWpRQ@mail.gmail.com" 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>"<span style="font-size:12.8px">o4l8cdefg</span>" => string code;</div>
<div>string matches[0];</div>
<div>"((o)([0-9]+)|([abcdefg])(1|2|<wbr>4|8|16)?|(l)([0-9]+))" => string pattern;</div>
<div><br>
</div>
<div>for(0 => int i; i < code.length(); )</div>
<div>{</div>
<div> if(RegEx.match(pattern, code.substring(i), matches))</div>
<div> {</div>
<div> if(matches[2] == "o")</div>
<div> <<< "octave:", matches[3] >>>;</div>
<div> else if(matches[4] == "a")</div>
<div> <<< "a" >>>;</div>
<div> // etc.</div>
<div> </div>
<div> matches[0].length() +=> i;</div>
<div> }</div>
<div> else</div>
<div> {</div>
<div> <<< "invalid code" >>>;</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 => int i; i < code.length(); )</div>
<div>{</div>
</div>
<div> int c = code.charAt(i);</div>
<div> if(c == 'o')</div>
<div> {</div>
<div> // look for number</div>
<div> }</div>
<div> else if(c == 'a' || c == 'b' || ... )</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">
<<a moz-do-not-send="true" href="mailto:colton-hill2014@hotmail.com" target="_blank">colton-hill2014@hotmail.com</a>></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's the code I'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't work... So have a test.<br>
<div class="HOEnZb">
<div class="h5"><br>
<br>
On 9/6/2016 3:33 AM, Hans Åberg wrote:<br>
>> On 5 Sep 2016, at 23:16, Colton Hill <<a moz-do-not-send="true" href="mailto:colton-hill2014@hotmail.com">colton-hill2014@hotmail.com</a>> wrote:<br>
>><br>
>> I know regular expressions syntax, but I really don't know how I would<br>
>> manage to make an mml parser that actually works. Turn o4l8cdefg into<br>
>> octave 4, length 8, and c d e f g notes with an 8th note length since no<br>
>> length is specified. Then there's c4., which is c4^c8... Just bla…<br>
> There are free MML parsers in C out there. Linking to ChucK, which is written in C++, might be a way.<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> chuck-users mailing list<br>
> <a moz-do-not-send="true" href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.<wbr>princeton.edu</a><br>
> <a moz-do-not-send="true" 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>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a moz-do-not-send="true" href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.<wbr>princeton.edu</a><br>
<a moz-do-not-send="true" 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 moz-do-not-send="true" href="mailto:spencer@ccrma.stanford.edu" target="_blank">spencer@ccrma.stanford.edu</a></div>
<div>+1 831.277.4654<br>
</div>
<div><a moz-do-not-send="true" href="https://ccrma.stanford.edu/%7Espencer/" 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>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset> <br>
<pre wrap="">_______________________________________________
chuck-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a>
<a class="moz-txt-link-freetext" href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a>
</pre>
</blockquote>
<br>
</body>
</html>