Decoding MIDI messages (PIC)

Started by swinginguitar, October 26, 2011, 12:16:17 PM

Previous topic - Next topic

swinginguitar

When listening for MIDI messages, is there an elegant way to read, decode, and dispatch the message (in ASM), or do you typically brute force it (ie test in turn for each message you're interested in).

Arbitrary example - if I receive a range of CC messages at 0 or 127 to signal that I want to set a pin high/low to toggle a relay on. What would your code (or pseudo code) be to test for which channel/CC#/value has elapsed?

potul

I don't fully understand the question..... but I'll give it a try

You will need to parse all incoming messages at least the first bytes until you can tell if the midi channel is the one you are listening to or not, and if is a message meningful for your application or not....

In general, I would do it quite "brute force"

1-Read byte. Is it a CC message to the correct channel?  (1011nnnn)
2-If yes, read second byte (cc code). Is it one of the expected ones?
2.1-If yes, read third byte (value) and trigger whatever action
2.2-If not, go back to 1.
3-If not, go back to 1.

Mat

swinginguitar

You answered me perfectly...

That is basically how I would have intuitively done it. Just didn't know (within the realm of ASM) if there was a more elegant way - like a message pump or some sort of dispatcher like you could do in a higher level language.

egasimus

Depending on the device used, you could always go the C way for some convenience with not much of a performance drop ;)

swinginguitar

Another question (OT but in the same vein):

Is there a recommended way to sync up say a rackmounted switcher and a footcontroller? - in other words, they may each power up in some state (realays on or off or some combination) and be out of sync.

You could obviously have one or the other dump its state out to the other at bootup, but this assume the 2 are MIDI connected at startup. What if you powered them up, then connected them?

There are numerous ways I can think of to handle this, but none seem very elegant.

potul

How I would do it:

You need to choose who's going to be the owner of keeping the state. If the owner is the footwswitch, then I would transmit the full status of each relay every time you hit a button (not only the status change of one relay, but the target status of them all)

This way, you can program the footswitch to send updates when powering up, updates when a change occurs (pressing a button) and even updates at a regular timing and minimize the chances that they get out of sync.


Mat


swinginguitar


potul

 :icon_cool:

Me too. It's nice to find a place where you can both learn a lot and contribute to others as well.

swinginguitar

#8
Been digging around on the forum about expression and CCs and such -

what approach should I take to scaling 0-5v control voltage into MIDI CC values 0-127?

Also on the subjuct of expression - I've been reading here about the LED/LDR methods of remote volume control, particularly the Anderton circuit. Can you not just have an LDR to ground dumping your signal, or is the VCA/OTA a necessity (and why)? Does this need to be buffered as well?

EDIT: and what about tap - I would like to have tap on the footcontroller (i presume also a midi message) control everything in the rack....for devices that don't support midi tap, how do you scale that to a clock pulse or something in the analog domain?

G. Hoffman

Quote from: swinginguitar on October 28, 2011, 10:37:59 AM
what approach should I take to scaling 0-5v control voltage into MIDI CC values 0-127?

Your PIC has a 10 bit ADC, right?  You should be able to set it up to left justify the result, then you can ignore the least significant byte, and you just rotate the high byte right by one bit, and you're set.


Gabriel