BlokasLabs / USBMIDI

USB MIDI library for Arduino.
Other
191 stars 14 forks source link

Added USB MIDI Synth example #5

Closed Harvie closed 5 years ago

Harvie commented 5 years ago

check this out :-)

gtrainavicius commented 5 years ago

Hey, thank you for the submission! This is a neat example!

Before merging this, I'd like to rename variable 'channel' to 'velocity' (the MIDI channel is in the command byte, it can be accessed by doing u8 channel = command & 0x0f), then in the if below, I think 'velocity' should be checked for 0 instead of pitch.

There is a possibility for note on / off messages to be missed when the incoming MIDI data contains other kinds of MIDI messages than 3-byte ones, (like program change or sysex) but after the buffer is exhausted, MIDI parsing will then continue to work. For the sake of simplicity, I think it's OK to keep it as is, but if you'd like to know more on why and how to solve it, let me know. :)

Harvie commented 5 years ago

I think it's OK to keep it as is, but if you'd like to know more on why and how to solve it, let me know

Yes, i've been reusing MIDI parsing code that i've written back in 2012. Yesterday i was trying to implement more complex polyphonic synth and i became aware of the problems. I can modify it. And maybe i will add pitch bend.

Harvie commented 5 years ago

What about now? I wasn't able to complete the pitchbend code, mainly because i don't have have any software to send PB messages at hand... But the parsing code should be cleaner now...

Harvie commented 5 years ago

BTW do you support sending and receiving SysEx? Haven't tried it yet, but i will need that soon...

gtrainavicius commented 5 years ago

BTW do you support sending and receiving SysEx? Haven't tried it yet, but i will need that soon...

Yes, SysEx is supported. Important thing to know is that during SysEx transfer, MIDI 'real time' messages such as tempo sync (0xf8) and start / stop, etc..., are allowed to be intermixed with the SysEx data.

Harvie commented 5 years ago

Important thing to know is that during SysEx transfer, MIDI 'real time' messages such as tempo sync (0xf8) and start / stop, etc..., are allowed to be intermixed with the SysEx data.

I guess, you can easily tell and filter them by 0b10000000 set

gtrainavicius commented 5 years ago

I guess, you can easily tell and filter them by 0b10000000 set

0x80 bit is always set for all MIDI command bytes. Real time command byte is always >= 0xf8.

gtrainavicius commented 5 years ago

Ok, thank you for fixing the issues :)