Help formating a Serial message into a MIDI noteout message


    Nov 30 2021 | 1:53 am
    I'm trying to convert a Serial message that comes from an Arduino, into a MIDI noteout message. Right now I have a message like this "42 127 1" and I need it to be like this 42, 127, 1 Been trying to mess with sprintf but no luck at all, if anyone can help me out solving this it will be much appreciated.

    • Nov 30 2021 | 3:03 am
    • Nov 30 2021 | 8:07 am
      fromsymbol is needed, but comma separation or itering not. But - 42 0 1 is not a valid midi message. Whatever you send from arduino, must be converted into something that uses midi specification, note, CC etc. read somewhere about raw midi data formatting. sending 42 0 1 will break midi communication, as midi objects would try to group midi flow into something usefull, and so scramble valid midi messages.
    • Nov 30 2021 | 8:51 am
      @Source Audio you're absolutely right, I was looking into the midiout object because it's the object that is on the M4L "MAX Midi Effect" template. Now after looking into the noteout object I saw that the Midi message is much simplier. Thanks for clarifiyng that out.
    • Nov 30 2021 | 3:18 pm
      you are welcome. You can ignore the 3rd list item as live is not clever enough to use midi channels in devices. I think your list is note - velocity - midi channel
      If you want to keep midiout just use 144 $1 $2. In case you need to filter messages by midi channel, which Live can't do for you because messages come from serial object, something like this could do
    • Nov 30 2021 | 4:33 pm
      That's lovelly, thanks again! I'm leaving the code here, and also the Arduino code I'm using. I know I'm re-inventing a squared/hammered wheel, but this might be usefull to someone, as it was for me.
    • Dec 01 2021 | 10:02 am
      You found your way through this jungle of Max - Arduino unknown waters, congrats. But ... there is a lot of potential to make it better. you use midi library, but don't use midi really, not over USB, not as midi over 5pol DIN (would need midi baud rate anyway), no midi at all. I understand that you push a single button to create random note, and in Max use makenote object with fixed velocity, and set note length from analog read. Actually only 2 values, note number and note length. No need for note Off, no need for velocity, no need for midi library at all. --- if you make note randomising in Max, with huge advantage to be able to change scales, ranges, even step through ostinatos on the fly etc even only 1 value - note length would do. ---------- int but; int EXbut; void setup() {Serial.begin(9600); pinMode(12, INPUT_PULLUP);} void loop() {int but = digitalRead(12); if (but == 1) {EXbut = 1;} if (but != EXbut and but == 0) {Serial.println(analogRead(A0));} EXbut = but; delay(10);} ------- That would be all it needs (beside that unneeded LED toggle stuff) complex debouncing is needed only if button you use is that bad. But for that you can use simpler code, or bounce library. ----- Then in Max
      You could also randomise velocity a bit ... But scaling length down to zero ??? stop message clears all hanging midi notes no need for flush or that counter 0 - 127, which anyway could also be done with uzi 128 0 P.S. another way to light a LED when button is pressed
    • Dec 02 2021 | 9:00 am
      Thanks for adding so much value to this post!