MIDI Reset

Hi

Well, i know this not an Audio question per se, but i thought this was anyway the right forum to post it on.

I am working on a MIDI Foot Controller.

In the past, with other midi instruments that had nothing to do with arduinos, it happend to me a couple of times that a note "got stuck".
I hope this won't happen with the foot controller, but, just to be on the safe side, i would like to include some kind of reset to it.

I have read a little bit about doing a "soft reset":

asm volatile ("  jmp 0");

for what i understand, this brings the sketch again to the beginning, so it's a kind of software reset.
But, as i don't understand that code, and i read several conflicting opinions about it, i am actually a little bit afraid of using it.
Any ideas and experiences with it?

the other idea i had, was to send an ALL NOTES OFF midi command:

0xFF

Would this do the trick?
It would not reset the Arduino, but it would Reset all the MIDI, right?
So any stuck notes would also be reseted?

Hmmm, one more question...
i am sending my midi like this:

Serial.write(cmd);
Serial.write(pitch);
Serial.write(vel);

What would be the correct way to send the 0xFF Reset message?
I assume the 0xFF is the command, so it would go on the "Serial.Write(cmd)", but what about the pitch and the vel, can i just leave them empty?

Any other ideas on how to achieve this reset effect?

Thank you!
=)

some things send all notes off command. other things send every note with a velocity of 0.

but what would be a good solution with an Arduino? Anyone ever made something similar?

I guess the easiest solution is just to unplug the usb cable and plug it again but well, that isn't so elegant! :wink:

If a note on an external device is tuck, you have send something to stop it. Resetting your arduino device won't change that.

so the all notes off command (0xFF) would be the way to go?

I'm not sure that's the correct all notes off command.

Try reading this MIDI tutorial for programmers

Quoting from the relevant bit in section 9:

1 - Using MIDI controller 123
If you send a MIDI controller 123 on one MIDI channel, the synthesizer will stop all notes playing on that channel. To reset all MIDI channels, send that message for each channel. Please note that some synthesizer do not respond to this message.

2 -MIDI Reset message
This is a one status byte message 0xFF, without data bytes. It should reset the synthesizer to its power-on default, so it also stops all notes playing. Use this message sparingly, as it reset the full synthesizer, not only the notes playing.

3 - MIDI NOTE OFF
You can also send, for each channel (0 to 15) and each note pitch (0 to 127) one MIDI NOTE OFF message. This is the total solution, but requires a lot of MIDI messages to be sent, which may have some reaction time according to the MIDI hardware system you use.

4 - MIDI NOTE OFF - Optimized
In this case, use a table to keep track of the NOTE ON and OFF messages you send for each channel. A buffer of 128 bytes for each channel, representing the number of NOTE ON messages sent to that note, should be incremented by a NOTE ON and decremented by a NOTE OFF. Then, when you want to reset every note, simply go through that table and send a NOTE OFF to each note that is still playing.

Thank you, that seems like a nice page to with information about MIDI.
i will read it through tomorrow when i have a little time!
=)

This works for me. Try both!

void MIDIhardreset()
{
Serial.write(0xFF);
}

void MIDIsoftreset()
{
 Serial.write(0xF0);
 Serial.write(0x7F);
 Serial.write(0x7F); //device id 7F = 127 all channels
 Serial.write(0x02);
 Serial.write(0x7F); // command format 7F = all devices
 Serial.write(0x0A); // action 0x0A= reset
 Serial.write(0xF7);
 }

Thanks, i will try it out! 8)

Have you used it in any project? Did it work well?

The problem is that 0xF0 is system exclusive message. It will only work on some systems.

System Exclusive.
This message makes up for all that MIDI doesn't support. (iiiiiii) is usually a seven-bit Manufacturer's I.D. code. If the synthesizer recognizes the I.D. code as its own, it will listen to the rest of the message (ddddddd). Otherwise, the message will be ignored. System Exclusive is used to send bulk dumps such as patch parameters and other non-spec data. (Note: Real-Time messages ONLY may be interleaved with a System Exclusive.) This message also is used for extensions called Universal Exclusive Messages.

This is a good place to look for such data:-
http://www.midi.org/aboutmidi/index.php

Both works perfectly.
The difference is with hardreset software like Ableton and PC needs restart, softreset don't .
I had problems with midi cable like this
http://www.ebay.it/itm/180943062588
NOT with this one
http://www.ebay.it/itm/161006079225
Look well the images, they are different and works different.
Now with softreset both works well

what about something like this:

void sendReset () {
  int n = 12;
  while (n < 108) {
    noteOn(0x80, n, 0x00);
    n++;
  }
} // end void sendReset

(12~107 are the notes available in my sketch)

Like this, in practical terms, if a note would get stuck by sending this notes off i would "unstuck" it (is this a word?! 8) )?
I think this would be a simple solution.
I tried it a couple of times and it seems to work, but i won't know for sure until i get a real stuck note!
:wink:

maxscorda:
The difference is with hardreset software like Ableton and PC needs restart, softreset don't .

Not having to restart any software would be great!

Yes that should work. It will take a time though.
Unstuck is a word.

I'm sure your code is good for stuck notes but not for me.
My problem was that every time I compile, MIDI stop to work and I had to disconnect MIDI e Arduino USB cable to work again.
It happened only with one kind of cable not the others (I've got two for both)
With *softreset * everything fine now

Grumpy_Mike:
Yes that should work. It will take a time though.

It could even take one or two seconds, i don't think in this case that would be something super serious.
Thanks!

Grumpy_Mike:
Unstuck is a word.

maxscorda:
I'm sure your code is good for stuck notes but not for me.
My problem was that every time I compile, MIDI stop to work and I had to disconnect MIDI e Arduino USB cable to work again.
It happened only with one kind of cable not the others (I've got two for both)
With *softreset * everything fine now

Ah, ok, that makes sense.
Well, i'm connecting the Arduino via serial, and then converting to midi with a Serial>MIDI Converter, so my problem is (eventually) stuck notes. I don't think it will happen often (or i hope!!), but it's always better to have some kind of solution prepared!

By the way, i finished yesterday the soldering of this project, a MIDI Footcontroller, so i think i will soon post it here in the Exibition / Gallery (would it be better here in the Audio?) Forum, so maybe someone has some neat ideas of new functions to add to it!

Thanks for the help!
=)