Arduino Forum

Forum 2005-2010 (read only) => Software => Syntax & Programs => Topic started by: warp on Mar 30, 2008, 05:50 pm

Title: MIDI Active Sensing
Post by: warp on Mar 30, 2008, 05:50 pm
hi all,

I'd like your suggestion/opinion in a specific technique regarding the active sensing.
Each 'Active sense' message is sent at least once every 300 ms.

in order to use the 'active sense' message to my system, I've done the following:

if(a MIDI msg is sent)
{
  send the message
}else (if nothing is sent)
{
  send 'ctive sense'
}

However, by doing this, the active sense is sent  almost 'continuously' to the receiving device (and not once every 300ms).

Then I've tried to use the delay function :

}else (if nothing is sent)
{
  send 'ctive sense'
  delay(300);
}

but this does not work, as the delay occurs to the whole system...
Is there any specific technique where i can send a 'active sense' message every 300ms without introduce any significant delay?

thanks,
warp
Title: Re: MIDI Active Sensing
Post by: simond on Mar 31, 2008, 01:41 pm
There are two approaches to this. The first is to use interrupts, and only send your message when a particular interrupt occurs. I'll not go into that approach here. The second is simpler for this application: count milliseconds, and only send your message if a timer expires. Something like:

Code: [Select]

0. Initialise timer to millis().
1. Do stuff.
2. If nothing is sent:
      if timer - millis() >= 300:
           send 'Active Sense'
           timer = millis()
3. Goto 1.


This approach will ensure that the active sense message is sent no more frequently than every 300 ms. Handling rollover is left as an exercise :)
Title: Re: MIDI Active Sensing
Post by: warp on Mar 31, 2008, 08:38 pm
thanks simond, sorted!

i had to use a second variable though, in order to store the value since the last message was sent..

thanks,
w
Title: Re: MIDI Active Sensing
Post by: simond on Mar 31, 2008, 11:33 pm
..and this is why I shouldn't post pre-caffeine:

Code: [Select]

if (timer - millis() >= 300)


should of course be:

Code: [Select]

if (millis() - timer >= 300)


Apologies for any confusion!
Title: Re: MIDI Active Sensing
Post by: usbmidi on Apr 02, 2008, 09:12 pm
Hi, warp -

Active sensing dates from a time when it was reasonable to fear that a synth would lose its mind and go off into the weeds. Nowadays, it's pretty pointless to send it, although you should include code to ignore incoming active sensing messages.

In fact, the high-end synth I help develop doesn't send active sensing messages and ignores received active sensing messages.

Also, think about this: If you're going to send these "not dead yet" bytes, what do you expect the recipient to do if it doesn't get one?