It is currently Tue Mar 09, 2021 4:44 am


MIDI programming best practices

Building organ consoles for use with Hauptwerk, adding MIDI to existing consoles, obtaining parts, ...
  • Author
  • Message
Offline

EricJ

Member

  • Posts: 8
  • Joined: Tue Sep 12, 2017 12:27 pm

MIDI programming best practices

PostSat Jan 09, 2021 4:02 pm

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
Offline
User avatar

mdyde

Moderator

  • Posts: 13094
  • Joined: Fri Mar 14, 2003 1:19 pm
  • Location: UK

Re: MIDI programming best practices

PostSat Jan 09, 2021 4:25 pm

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.
Best regards, Martin.
Hauptwerk software designer/developer, Milan Digital Audio.
Offline

EricJ

Member

  • Posts: 8
  • Joined: Tue Sep 12, 2017 12:27 pm

Re: MIDI programming best practices

PostSat Jan 09, 2021 4:39 pm

Thankyou so much, that is very helpful!
Offline
User avatar

mdyde

Moderator

  • Posts: 13094
  • Joined: Fri Mar 14, 2003 1:19 pm
  • Location: UK

Re: MIDI programming best practices

PostSun Jan 10, 2021 4:39 am

Thanks, Eric. You're very welcome.
Best regards, Martin.
Hauptwerk software designer/developer, Milan Digital Audio.

Return to DIY organ consoles / MIDI

Who is online

Users browsing this forum: No registered users and 4 guests