<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=FR-CA link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Looking at my code I remembered this note I put in <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>To be sure I won’t  forget it:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>/*<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Voice Message           Status Byte      Data Byte1          Data Byte2<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>-------------           -----------   -----------------   -----------------<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Note off                      8x      Key number          Note Off velocity<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Note on                       9x      Key number          Note on velocity<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Polyphonic Key Pressure       Ax      Key number          Amount of pressure<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Control Change                Bx      Controller number   Controller value<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Program Change                Cx      Program number      None<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Channel Pressure              Dx      Pressure value      None            <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Pitch Bend                    Ex      MSB                 LSB<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Channel mode messages are a special case of the Control Change message ( 0xBx or 1011nnnn). <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>The difference between a Control message and a Channel Mode message, <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>which share the same status byte value, is in the first data byte. <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Data byte values 121 through 127 have been reserved in the <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Control Change message for the channel mode messages. <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>Channel mode messages determine how an instrument will process MIDI voice messages. <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>1st Data Byte      Description                Meaning of 2nd Data Byte<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>-------------   ----------------------        ------------------------<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>     79        Reset all  controllers            None; set to 0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>     7A        Local control                     0 = off; 127  = on<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>---->7B        All notes off   <------           None; set to 0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>     7C        Omni mode off                     None; set to 0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>     7D        Omni mode on                      None; set to 0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>     7E        Mono mode on (Poly mode off)      **<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>     7F        Poly mode on (Mono mode off)      None; set to 0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Courier New"'>*/<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Synth-diy [mailto:synth-diy-bounces@synth-diy.org] <b>De la part de</b> Mikko Helin<br><b>Envoyé :</b> 20 mars 2020 01:39<br><b>À :</b> synth-diy@synth-diy.org List<br><b>Objet :</b> Re: [sdiy] MIDI I/O c code..<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>>Running status are ignored here</span><o:p></o:p></p><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So you are ignoring the data bytes that belong to next note on which is using running status, meaning the sender does not send the same status byte again but just skips it and just sends the key and velocity bytes?</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>pe 20. maalisk. 2020 klo 3.29 Jean-Pierre Desrochers <<a href="mailto:jpdesroc@oricom.ca">jpdesroc@oricom.ca</a>> kirjoitti:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>></span><span lang=EN-CA> Are you handling running status and note off sent as zero velocity note on?</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Yes I handle both.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Running status are ignored here,</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>And I consider both NOTE OFF and NOTE ON with zero velocity</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>As the end of a note.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-CA style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> dougall [mailto:<a href="mailto:dougalli@gmail.com" target="_blank">dougalli@gmail.com</a>] <br><b>Envoyé :</b> 19 mars 2020 21:06<br><b>À :</b> <a href="mailto:eidorian@aladan.net" target="_blank">eidorian@aladan.net</a><br><b>Cc :</b> Jean-Pierre Desrochers; <a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><b>Objet :</b> Re: [sdiy] MIDI I/O c code..</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Are you handling running status and note off sent as zero velocity note on?<o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p></div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>-d<o:p></o:p></p></div></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>On Fri, 20 Mar 2020 at 11:55, <<a href="mailto:eidorian@aladan.net" target="_blank">eidorian@aladan.net</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Sorry, I don't have example code for you, but here is some analysis that I hope might help point you in the right direction:</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>20MHz / 31,250Hz => ~640 instructions per MIDI data bit, or 6,400 instructions per MIDI data byte.  That's quite a lot of instruction execution time between notes, so I'd be checking the efficiency/optimisation of the code.</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>How long is it taking to update the analog outputs and do other processing?  If it's updating all 8 CVs via a "slow" protocol like I2C every time it loops then that might be taking a while, and maybe you need a different approach (i.e. only update a CV output when it changes).</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>How have you implemented the FIFO?  Do you have locking to ensure the interrupt isn't writing to it while the main loop is updating it?</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Create a debug version that has checks on the FIFO size in the interrupt, and sets an LED on if it overflows, so you can confirm for certainly whether or not that's the problem.</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>What I do (with 30+ years of programming experience) is pretend I'm the CPU, and "execute" the code in my head (or on paper if complex) in order to try to work out what unplanned or unexpected things might be happening to cause the problematic behaviour.</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Cheers,<br>A.</span><o:p></o:p></p><div id="m_-1322366504434334221gmail-m_5822220122528591338signature"><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>---</span><o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Courier New"'> </span><o:p></o:p></p></div></div><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p><p id="m_-1322366504434334221gmail-m_5822220122528591338reply-intro"><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>On 20-03-2020 11:14, Jean-Pierre Desrochers wrote:</span><o:p></o:p></p><blockquote style='border:none;border-left:solid #1010FF 1.5pt;padding:0cm 0cm 0cm 5.0pt;margin-left:0cm;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><blockquote style='border:none;border-left:solid #1010FF 1.5pt;padding:0cm 0cm 0cm 5.0pt;margin-left:0cm;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p></div></blockquote></blockquote><blockquote style='border:none;border-left:solid #1010FF 1.5pt;padding:0cm 0cm 0cm 5.0pt;margin-left:0cm;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div id="m_-1322366504434334221gmail-m_5822220122528591338replybody1"><div><div><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I’m working on a new polyphonic MIDI to CV module (8 voices).</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>So far I did my tests with an old PIC16F887 @ 20Mhz micro I had on hand.</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I use a USART interrupt driven c function to ‘catch’ all the incoming MIDI bytes.</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>My code is pretty fast, but still, since I only read one MIDI channel (1-16) at the time <br>when I play very fast chords on an external keyboard</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>all the notes are read in the incoming queue but sometimes</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>I get stuck notes or unread ones..</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Same thing happens when playing MIDI files on Cakewalk SONAR <br>feeding my prototype with  a MIDI cable.<br>The interrupt function grabs each incoming byte and put them</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>In a receive buffer of 32 bytes and the main () reads and treats them in a FIFO manner</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Later in the main loop.</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p><p><em><span style='font-family:"Verdana","sans-serif"'>-Would a 32Mhz micro do a difference in the USART interrupt reading speed ?</span></em><o:p></o:p></p><p><em><span style='font-family:"Verdana","sans-serif"'>-And is 32 bytes long enough for the RxBuffer to handle a 6 voices chords ?</span></em><o:p></o:p></p><p><em><span style='font-family:"Verdana","sans-serif"'>-And finaly I checked the web for a ‘decent’ C code examples</span></em><o:p></o:p></p><p><em><span style='font-family:"Verdana","sans-serif"'>  for MIDI reception (MIDI Tx is much easier to implement) with no success..</span></em><i><span style='font-family:"Verdana","sans-serif"'><br><em><span style='font-family:"Verdana","sans-serif"'>  ‘Obscure’ Arduino libraries all around with no explainations of its inner code.</span></em></span></i><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>Did anybody use good C code available ?</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'>JP</span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p><p><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a></span><o:p></o:p></p></div></div></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Verdana","sans-serif"'> </span><o:p></o:p></p><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Courier New"'>_______________________________________________<br>Synth-diy mailing list<br><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><a href="http://synth-diy.org/mailman/listinfo/synth-diy" target="_blank">http://synth-diy.org/mailman/listinfo/synth-diy</a></span><o:p></o:p></p></div></blockquote></div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>_______________________________________________<br>Synth-diy mailing list<br><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><a href="http://synth-diy.org/mailman/listinfo/synth-diy" target="_blank">http://synth-diy.org/mailman/listinfo/synth-diy</a><o:p></o:p></p></blockquote></div></div></div><p class=MsoNormal>_______________________________________________<br>Synth-diy mailing list<br><a href="mailto:Synth-diy@synth-diy.org" target="_blank">Synth-diy@synth-diy.org</a><br><a href="http://synth-diy.org/mailman/listinfo/synth-diy" target="_blank">http://synth-diy.org/mailman/listinfo/synth-diy</a><o:p></o:p></p></blockquote></div></div></body></html>