Page 1 of 1

MIDI programming best practices

PostPosted: Sat Jan 09, 2021 4:02 pm
by EricJ
I am adding MIDI to a pedalboard using the Arduino Leonardo because it has built-in USB communication and will be detected as a USB device by the computer.

What are the best practices for sending MIDI commands to HW?

For example. the simplest program would continuously scan the pedalboard and send a note-on command if the key is pressed and a note-off if the key is not pressed. This generates a constant stream of data, not a lot of bandwidth used but seems like over kill.

1. Should I check for the prior status of the note and only send commands when there is a change?

2. If I do #1 and no keys are pressed, then no commands are sent. How will the software detect the midi device? Is it sufficient to just send commands during the initial Midi input setup and HW will remember the midi device? Does it ever forget MIDI devices, i.e. when HW is restarted>

3. do I need to send a MIDI command periodically, (every x seconds) so that the MIDI device will be detected? I could send the All Notes Off command if no keys are pressed

Re: MIDI programming best practices

PostPosted: Sat Jan 09, 2021 4:25 pm
by mdyde
Hello Eric,

EricJ wrote:1. Should I check for the prior status of the note and only send commands when there is a change?


Yes.

EricJ wrote:2. If I do #1 and no keys are pressed, then no commands are sent. How will the software detect the midi device?


You don't need to worry about that within your hardware. When configuring Hauptwerk, you right-click on the relevant virtual keyboard, select 'Auto-detect MIDI settings', then follow the on-screen instructions to press and release the relevant keys on your keyboard so that Hauptwerk will hear the messages and thus know what settings to use.

EricJ wrote:and HW will remember the midi device?


Yes -- Hauptwerk will listen for the MIDI channel and MIDI port and remember them.

EricJ wrote:Does it ever forget MIDI devices, i.e. when HW is restarte


No -- it won't forget your settings. The only time you might need to auto-detect them again is if you change your MIDI device/hardware. (However, in Hauptwerk v6, you can remap MIDI port settings if you change your MIDI ports.)

EricJ wrote:3. do I need to send a MIDI command periodically, (every x seconds) so that the MIDI device will be detected? I could send the All Notes Off command if no keys are pressed


You don't need to send any messages periodically. However, some MIDI keyboards do send an 'all notes off' message every few seconds if no keys are pressed, just as a precautionary measure in case any preceding 'MIDI note-off' message were to be lost en route, thus avoiding the risk of a note 'sticking on'. That isn't a bad idea.

Re: MIDI programming best practices

PostPosted: Sat Jan 09, 2021 4:39 pm
by EricJ
Thankyou so much, that is very helpful!

Re: MIDI programming best practices

PostPosted: Sun Jan 10, 2021 4:39 am
by mdyde
Thanks, Eric. You're very welcome.