MidiInput used as GUI controller


#1

Hi There,
I’ve created a ApplicationCommandManager kind of class wich uses Midi messages as shortcuts. So in fact it is an MidiCommandManager.
When i receive messages from a MidiInputCallback i forward them to my MidiCommandManager, however i don’t think i’m doing it in a right way because now i am locking the messagemanager each time i receive a midi message wich i think is not how it should be done.
here is my code:

class ApplicationMidiCallback : public MidiInputCallback
{
public:
	OwnedArray<MidiInput> midiInputs;
	
	MidiCommandManager* mcm;

	ApplicationMidiCallback()
	{
	  apc = 0;

      StringArray mArray = MidiInput::getDevices();
      for (int i = 0; i < mArray.size(); ++i) {
		  midiInputs.add( MidiInput::openDevice(i, this) );
		  midiInputs[midiInputs.size()-1]->start();
      }

	  mcm =  MidiCommandManager::getInstance();

	}

	~ApplicationMidiCallback()
	{
		for (int i=0; i < midiInputs.size(); ++i) {
			midiInputs[i]->stop();			
		}
		midiInputs.clear();
		
	}

	void handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message)
	{		
		const MessageManagerLock mmLock;
		
		mcm->handleMidiMessage( message );
	}

};

Would i need to create a sort of buffer of midimessages and fill this with the new messages and let the MidiCommandManger check for new messages? Has anyone got suggestions on how to do this.

any help is appreciated,
Cheers,
Edwin[/code]


#2

I’d suggest putting the midi data into a Message object and posting it to the handler to deal with (make it a MessageListener).


#3

Thanx, For the GUI part this would indeed be nice solution.
But i also use the midimessages to control my render engine, and we need the lowest possible latency. I guess the messagemanager is controlled by the main message thread, so using messages will cause a big delay.

How should i send messages to my engine without stalling the midiInput thread.


#4

For that, you can just use a midibuffer and a criticalsection.


#5

So i need to fill the Midibuffer with the incoming messages.
And use an MidiBuffer::Iterator in another thread to read the messages from this buffer both using the same criticalsection ?


#6

yes, that’s the idea.


#7

Or use a MidiMessageCollector…


#8

Im trying to trigger commands from handleIncomingMidiMessage with invokeDirectly (is this i bad idea?), problem is that the command Flags then arent set (in perform()) like I did in getCommandInfo - so i cant use the isTicked flag e.g…

Building a new ApplicationCommandManager with Midi seems kind of a huge step, or would this be very easy??

greetz equinox


#9