USBComposite Sysex

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

USBComposite Sysex

Post by Kprellz »

Hey all,

Been using the USBComposite library for a bunch of midi stuff, now I need to receive sysex messages and I'm not really sure how. I've done sysex using the 47effects midi library however I'd rather not convert everything I have over to that just to use sysex. I know there is some level of sysex in the USB comp library, wondering if anyone has any examples of using it.

Thanks,
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: USBComposite Sysex

Post by Bakisha »

From looking in "USBMIDI.h" in library folder, and from "midiin" example sketch, you can add two functions:

Code: Select all

class myMidi : public USBMIDI {

 virtual void handleSysExData(unsigned char ExData) {

      // do something with ExData

    }
    virtual void handleSysExEnd(void) {

      // do something

    }

}
I never used those ones, but i don't see no reason not to work.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USBComposite Sysex

Post by Kprellz »

Usually sysex messages are pretty long, so i'm confused as to why its an unsigned char. Generally a sysex message is something like {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xf7} how is that supposed to be stored into an unsigned char, an unsigned char ARRAY would make sense.
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: USBComposite Sysex

Post by Bakisha »

I don't say i fully understand it, most of stuff i figure out by experiment.
I tested those functions in a "midiin.ino" example (now greatly expanded by adding stuff over last few months), and after adding

Code: Select all

    virtual void handleSysExData(unsigned char ExData) {
#ifdef USE_SERIAL1
      Serial1.print(" S:");
      Serial1.println(ExData, HEX);
#endif
    }
    virtual void handleSysExEnd(void) {
#ifdef USE_SERIAL1
      Serial1.println(" SysEx END");
#endif
    }
Here is output in serial monitor:

Code: Select all

 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:0
 S:7F
 S:0
 S:41
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:2
 S:0
 S:1
 S:3D
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:2
 S:1
 S:4C
 S:71
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:2
 S:2
 S:0
 S:3C
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:2
 S:3
 S:40
 S:7B
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:42
 S:20
 S:0
 S:5E
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:44
 S:20
 S:0
 S:5C
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:46
 S:20
 S:0
 S:5A
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:47
 S:20
 S:0
 S:59
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:48
 S:20
 S:0
 S:58
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:49
 S:20
 S:0
 S:57
 S:F7
 SysEx END
 S:F0
 S:41
 S:10
 S:42
 S:12
 S:40
 S:43
 S:20
 S:0
 S:5D
 S:F7
 SysEx END
C............... 0 7
C............... 20 2
P............... 62
C............... 7 78
C............... A 40
.C.............. 0 0
.C.............. 20 2
.P.............. 1A
.C.............. 7 7F
.C.............. A 40
..C............. 0 0
..C............. 20 2
..P............. 18
..C............. 7 7F
..C............. A 1D
...C............ 0 0
...C............ 20 2
...P............ 9
...C............ 7 7F
...C............ A 68
....C........... 0 0
....C........... 20 2
....P........... D
....C........... 7 7F
....C........... A 5E
.....C.......... 0 0
.....C.......... 20 2
.....P.......... 59
.....C.......... 7 78
.....C.......... A 31
......C......... 0 0
......C......... 20 2
......P......... 59
......C......... 7 7A
......C......... A 3B
.......C........ 0 0
.......C........ 20 2
.......P........ 59
.......C........ 7 7C
.......C........ A 45
........C....... 0 0
........C....... 20 2
........P....... 59
........C....... 7 7F
........C....... A 4F
..........C..... 0 5
..........C..... 20 2
..........P..... 62
..........C..... 7 78
..........C..... A 40
C............... 63 1
C............... 62 63
C............... 6 40
C............... 26 0
C............... 63 1
C............... 62 64
C............... 6 40
C............... 26 0
C............... 63 1
C............... 62 66
C............... 6 44
C............... 26 0
C............... 63 1
C............... 62 20
C............... 6 36
C............... 26 0
C............... 63 1
C............... 62 21
C............... 6 32
C............... 26 0
C............... 63 1
C............... 62 8
C............... 6 40
C............... 26 0
C............... 63 1
C............... 62 9
C............... 6 40
C............... 26 0
C............... 63 1
C............... 62 A
C............... 6 40
C............... 26 0
C............... 5B 64
C............... 5D 40
C............... 5E 0
C............... B 7F
.C.............. 63 1
.C.............. 62 63
.C.............. 6 40
.C.............. 26 0
.C.............. 63 1
.C.............. 62 64
.C.............. 6 40
.C.............. 26 0
.C.............. 63 1
.C.............. 62 66
.C.............. 6 40
.C.............. 26 0
.C.............. 63 1
.C.............. 62 20
.C.............. 6 7F
.C.............. 26 0
.C.............. 63 1
.C.............. 62 21
.C.............. 6 5A
.C.............. 26 0
.C.............. 63 1
.C.............. 62 8
.C.............. 6 40
.C.............. 26 0
.C.............. 63 1
.C.............. 62 9
.C.............. 6 40
.C.............. 26 0
.C.............. 63 1
.C.............. 62 A
.C.............. 6 40
.C.............. 26 0
.C.............. 5B 64
.C.............. 5D 0
.C.............. 5E 0
.C.............. B 7F
..C............. 63 1
..C............. 62 63
..C............. 6 40
..C............. 26 0
..C............. 63 1
..C............. 62 64
..C............. 6 40
..C............. 26 0
..C............. 63 1
..C............. 62 66
..C............. 6 40
..C............. 26 0
..C............. 63 1
..C............. 62 20
..C............. 6 30
..C............. 26 0
..C............. 63 1
..C............. 62 21
..C............. 6 40
..C............. 26 0
..C............. 63 1
..C............. 62 8
..C............. 6 40
..C............. 26 0
..C............. 63 1
..C............. 62 9
..C............. 6 40
..C............. 26 0
..C............. 63 1
..C............. 62 A
..C............. 6 40
..C............. 26 0
..C............. 5B 50
..C............. 5D 0
..C............. 5E 0
..C............. B 7F
...C............ 63 1
...C............ 62 63
...C............ 6 40
...C............ 26 0
...C............ 63 1
...C............ 62 64
...C............ 6 40
...C............ 26 0
...C............ 63 1
...C............ 62 66
...C............ 6 40
...C............ 26 0
...C............ 63 1
...C............ 62 20
...C............ 6 36
...C............ 26 0
...C............ 63 1
...C............ 62 21
...C............ 6 40
...C............ 26 0
...C............ 63 1
...C............ 62 8
...C............ 6 40
...C............ 26 0
...C............ 63 1
...C............ 62 9
...C............ 6 40
...C............ 26 0
...C............ 63 1
...C............ 62 A
...C............ 6 40
...C............ 26 0
...C............ 5B 7F
...C............ 5D 14
...C............ 5E 0
...C............ B 7F
....C........... 63 1
....C........... 62 63
....C........... 6 40
....C........... 26 0
....C........... 63 1
....C........... 62 64
....C........... 6 40
....C........... 26 0
....C........... 63 1
....C........... 62 66
....C........... 6 40
....C........... 26 0
....C........... 63 1
....C........... 62 20
....C........... 6 2C
....C........... 26 0
....C........... 63 1
....C........... 62 21
....C........... 6 40
....C........... 26 0
....C........... 63 1
....C........... 62 8
....C........... 6 40
....C........... 26 0
....C........... 63 1
....C........... 62 9
....C........... 6 40
....C........... 26 0
....C........... 63 1
....C........... 62 A
....C........... 6 40
....C........... 26 0
....C........... 5B 64
....C........... 5D 0
....C........... 5E 0
....C........... B 7F
.....C.......... 63 1
.....C.......... 62 63
.....C.......... 6 46
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 64
.....C.......... 6 40
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 66
.....C.......... 6 40
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 20
.....C.......... 6 50
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 21
.....C.......... 6 18
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 8
.....C.......... 6 40
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 9
.....C.......... 6 40
.....C.......... 26 0
.....C.......... 63 1
.....C.......... 62 A
.....C.......... 6 40
.....C.......... 26 0
.....C.......... 5B 50
.....C.......... 5D 28
.....C.......... 5E 0
.....C.......... B 7F
......C......... 63 1
......C......... 62 63
......C......... 6 46
......C......... 26 0
......C......... 63 1
......C......... 62 64
......C......... 6 40
......C......... 26 0
......C......... 63 1
......C......... 62 66
......C......... 6 40
......C......... 26 0
......C......... 63 1
......C......... 62 20
......C......... 6 50
......C......... 26 0
......C......... 63 1
......C......... 62 21
......C......... 6 18
......C......... 26 0
......C......... 63 1
......C......... 62 8
......C......... 6 40
......C......... 26 0
......C......... 63 1
......C......... 62 9
......C......... 6 40
......C......... 26 0
......C......... 63 1
......C......... 62 A
......C......... 6 40
......C......... 26 0
......C......... 5B 50
......C......... 5D 28
......C......... 5E 0
......C......... B 7F
.......C........ 63 1
.......C........ 62 63
.......C........ 6 46
.......C........ 26 0
.......C........ 63 1
.......C........ 62 64
.......C........ 6 40
.......C........ 26 0
.......C........ 63 1
.......C........ 62 66
.......C........ 6 40
.......C........ 26 0
.......C........ 63 1
.......C........ 62 20
.......C........ 6 50
.......C........ 26 0
.......C........ 63 1
.......C........ 62 21
.......C........ 6 18
.......C........ 26 0
.......C........ 63 1
.......C........ 62 8
.......C........ 6 40
.......C........ 26 0
.......C........ 63 1
.......C........ 62 9
.......C........ 6 40
.......C........ 26 0
.......C........ 63 1
.......C........ 62 A
.......C........ 6 40
.......C........ 26 0
.......C........ 5B 50
.......C........ 5D 28
.......C........ 5E 0
.......C........ B 7F
........C....... 63 1
........C....... 62 63
........C....... 6 46
........C....... 26 0
........C....... 63 1
........C....... 62 64
........C....... 6 40
........C....... 26 0
........C....... 63 1
........C....... 62 66
........C....... 6 40
........C....... 26 0
........C....... 63 1
........C....... 62 20
........C....... 6 50
........C....... 26 0
........C....... 63 1
........C....... 62 21
........C....... 6 18
........C....... 26 0
........C....... 63 1
........C....... 62 8
........C....... 6 40
........C....... 26 0
........C....... 63 1
........C....... 62 9
........C....... 6 40
........C....... 26 0
........C....... 63 1
........C....... 62 A
........C....... 6 40
........C....... 26 0
........C....... 5B 50
........C....... 5D 28
........C....... 5E 0
........C....... B 7F
..........C..... 63 1
..........C..... 62 63
..........C..... 6 40
..........C..... 26 0
..........C..... 63 1
..........C..... 62 64
..........C..... 6 40
..........C..... 26 0
..........C..... 63 1
..........C..... 62 66
..........C..... 6 44
..........C..... 26 0
..........C..... 63 1
..........C..... 62 20
..........C..... 6 E
..........C..... 26 0
..........C..... 63 1
..........C..... 62 21
..........C..... 6 40
..........C..... 26 0
..........C..... 63 1
..........C..... 62 8
..........C..... 6 40
..........C..... 26 0
..........C..... 63 1
..........C..... 62 9
..........C..... 6 40
..........C..... 26 0
..........C..... 63 1
..........C..... 62 A
..........C..... 6 40
..........C..... 26 0
..........C..... 5B 78
..........C..... 5D 28
..........C..... 5E 0
..........C..... B 7F
..+............. 2B 64 G 3
...+............ 43 64 G 5
....+........... 37 6E G 4
....-........... 37 7F
...-............ 43 7F
..-............. 2B 7F
..+............. 2A 64 F#-3
...+............ 42 64 F#-5
....+........... 36 6E F#-4
....-........... 36 7F
...-............ 42 7F
..-............. 2A 7F
..+............. 2D 64 A-3
...+............ 45 64 A-5
....+........... 39 6E A-4
....-........... 39 7F
...-............ 45 7F
..-............. 2D 7F
..+............. 23 64 B-2
...+............ 3B 64 B-4
....+........... 2F 6E B-3
.....+.......... 2F 5A B-3
......+......... 26 5A D-3
.......+........ 1F 5A G 2
....-........... 2F 7F
..-............. 23 7F
...-............ 3B 7F
.+.............. 1F 6E G 2
.-.............. 1F 7F
.+.............. 21 69 A-2
.-.............. 21 7F
.+.............. 23 6E B-2
.-.............. 23 7F
.+.............. 26 69 D-3
.-.............. 26 7F
.....-.......... 2F 7F
......-......... 26 7F
.+.............. 25 5A C#-3
.....+.......... 2D 5A A-3
......+......... 25 5A C#-3
.-.............. 25 7F
.+.............. 26 3C D-3
.-.............. 26 7F
.+.............. 25 50 C#-3
C............... 40 0
.C.............. 40 0
.-.............. 25 7F
..C............. 40 0
...C............ 40 0
....C........... 40 0
.....C.......... 40 0
.....-.......... 2D 7F
......C......... 40 0
......-......... 25 7F
.......C........ 40 0
.......-........ 1F 7F
........C....... 40 0
.........C...... 40 0
..........C..... 40 0
...........C.... 40 0
............C... 40 0
.............C.. 40 0
..............C. 40 0
...............C 40 0
C............... 40 0
.C.............. 40 0
.-.............. 25 7F
..C............. 40 0
...C............ 40 0
....C........... 40 0
.....C.......... 40 0
.....-.......... 2D 7F
......C......... 40 0
......-......... 25 7F
.......C........ 40 0
.......-........ 1F 7F
........C....... 40 0
.........C...... 40 0
..........C..... 40 0
...........C.... 40 0
............C... 40 0
.............C.. 40 0
..............C. 40 0
...............C 40 0
My setup: Bluepill with Roger core, ST-link upload, serial dongle on PA9/PA10.
Midi file played from Winamp (and maple as midi out in winamp's midi plugin settings) for few seconds.

What you see are bytes received as "sysex" messages. First is 0xF0 , as a mark of sysex commands start. Last is 0xF7. What those bytes in between represent, i have no idea, and i would rather not go into that rabbit hole.
It is up to you to make an array, and , depending on a device sending those sysex messages, make your code to deal with them.

For sending stuff (from bluepill), there are functions (again, from "USBMIDI.h file ):

Code: Select all

    void sendSysex(uint8_t b0, uint8_t b1, uint8_t b2);
    void sendSysexEndsIn1(uint8_t b0);
    void sendSysexEndsIn2(uint8_t b0, uint8_t b1);
    void sendSysexEndsIn3(uint8_t b0, uint8_t b1, uint8_t b2);
    void sendSysexPayload(uint8_t *payload, uint32 length);
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USBComposite Sysex

Post by Kprellz »

Ahhhhhh! I see. The 47 effects library does all the buffering of the Sysex message internally. I just need to read every byte of sysex and start storing it into an array if I get the start message and stop when I get the stop, then do what I need to do with the sysex array. Hopefully this doesn’t cause hangups while it iterates through messages.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USBComposite Sysex

Post by Kprellz »

So interestingly enough I actually cant get handleSysexData to detect my sysex messages. If I send a sysex message the function never gets called for some reason. currently sending a sysex Message from my DAW(pro tools) but the function never gets called to execute my code.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USBComposite Sysex

Post by Kprellz »

Code: Select all

virtual void handleSysExData(unsigned char ExData) {
      USBMIDI::sendNoteOn(0, 0, 0x7f);

    }
using the midiin example and just pasting that in. For whatever reason I never get that message back. using https://factotumo.com/web-midi-console/ to send/receive midi
User avatar
Bakisha
Posts: 139
Joined: Fri Dec 20, 2019 6:50 pm
Answers: 5
Contact:

Re: USBComposite Sysex

Post by Bakisha »

Sorry, that site is not compatible with my browser, so i cannot repeat your steps.
What i did is put code to send note when note off/on is received , and BP crashed after 30 seconds.
But once i put volatile flags in handleNoteOn/Off and used midi.sendNoteOn/Off in main loop, it worked ok.
Midi played in Winamp (sending to Maple-OUT), and in another program (some midi editor) i set Maple as MIDI-IN, and it played all notes that was send from BP.
Instead of

Code: Select all

USBMIDI::sendNoteOn(0, 0, 0x7f);
try to blink LED.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USBComposite Sysex

Post by Kprellz »

I figured it out. Apparently I had an older version of the library before sysex was actually implemented. just had to update now everything works fine. thank you!
peeddrroo
Posts: 2
Joined: Wed Feb 10, 2021 11:27 am

Re: USBComposite Sysex

Post by peeddrroo »

I'm facing the same problem.
I'm using the USBComposite_stm32f1 USBMIDI capabilities, but it doesn't handle sysex (either in or out).
Which library did you use ?
Post Reply

Return to “General discussion”