Beginners quest: retrieving midi input and prompting data

Hi,

Im trying to write a simple application that can prompt the midi-in data from my hardware synth; later I hope to succeed
in designing my own softsynth - when that time comes I think that Jules Demo application will help me but currently
I’m focused on prompting the midi data.

Right now, I have modified the juce application project (hello world window with a quit-button). I have added another button
that when pressed opens the sound manager window (sound configuration)…here I can see that my midi port has been found.
Also, I have included a text editor for prompting the midi values I hope to be able to recieve. So far so good!

Now, I have defined another class containing the following three variables:

MidiMessageCollector 	midiCollector;
Synthesiser 		synth;
MidiBuffer 		incomingMidi;

along with the following three member functions:

void prepareToPlay (int samplesPerBlockExpected,
double sampleRate)
{
midiCollector.reset (sampleRate);
synth.setCurrentPlaybackSampleRate (sampleRate);
}

void releaseResources()
{
}

void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
{
// the synth always adds its output to the audio buffer, so we have to clear it
// first…
bufferToFill.clearActiveBufferRegion();

	// fill a midi buffer with incoming messages from the midi input.
	midiCollector.removeNextBlockOfMessages (incomingMidi, bufferToFill.numSamples);

	// and now get the synth to process the midi events and generate its output.
	synth.renderNextBlock (*bufferToFill.buffer, incomingMidi, 0, bufferToFill.numSamples);
}

This class I have instantiated in the Main Component.h file but I can’t work out how to extract the midi data from the
midibuffer variable in the class described above and have data prompted in the text editor. I’m far from a skilled programmer
so please bare over with my primitive terminology and if this is trivial.

Can some one please describe what I need to do to get this done?

Thomas

You need the MidiBuffer::Iterator class - do a quick search through the code and you should find plenty of examples of it being used.

Thanks Jules…appriciate your help!

Will have a look for the iterator-clas!

Thomas

Hi,

I’m having difficulties with my simple midi data prompter and looking for some help. Hope someone will be reading this!

I have put in some code lines that should get me a little further but when running the program and pressing one of the keys on my external hardware synth (virus polar) I get an error at:

// you need to call reset() to set the correct sample rate before using this object jassert (sampleRate != 44100.0001);

The Juce demo works fine and to me it looks like I’m doing the exact same thing… :frowning:

Here is the code (shortened):

MainComponent:
AnAudioDeviceManager.initialise(1,2,0,true);
AnAudioDeviceManager.setAudioCallback(this);
AnAudioDeviceManager.addMidiInputCallback (String::empty, &mySynth.midiCollector);

mySynth Class:
class aSynth : public AudioSource
{
public:

MidiMessageCollector midiCollector;
Synthesiser synth;
MidiBuffer incomingMidi;

aSynth ()
{
}

~aSynth ()
{
}

void prepareToPlay (int samplesPerBlockExpected,
	double sampleRate)
{

midiCollector.reset(sampleRate); // isnt this the right way to reset???

synth.setCurrentPlaybackSampleRate (sampleRate);
}

void releaseResources()
{
}

void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
{
	// the synth always adds its output to the audio buffer, so we have to clear it
	// first..
	bufferToFill.clearActiveBufferRegion();

	// fill a midi buffer with incoming messages from the midi input.
	midiCollector.removeNextBlockOfMessages (incomingMidi, bufferToFill.numSamples);

	// and now get the synth to process the midi events and generate its output.
	//synth.renderNextBlock (*bufferToFill.buffer, incomingMidi, 0, bufferToFill.numSamples);
}

private:

};

Looks ok at first glance… Have you put in a breakpoint to what happens when it calls your prepareToPlay method?