JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::MidiMessageCollector Class Reference

Collects incoming realtime MIDI messages and turns them into blocks suitable for processing by a block-based audio callback. More...

#include <juce_MidiMessageCollector.h>

Inheritance diagram for juce::MidiMessageCollector:
Collaboration diagram for juce::MidiMessageCollector:

Public Member Functions

 MidiMessageCollector ()
 Creates a MidiMessageCollector. More...
 
 ~MidiMessageCollector () override
 Destructor. More...
 
void addMessageToQueue (const MidiMessage &message)
 Takes an incoming real-time message and adds it to the queue. More...
 
void handleIncomingMidiMessage (MidiInput *, const MidiMessage &) override
 
void handleNoteOff (MidiKeyboardState *, int midiChannel, int midiNoteNumber, float velocity) override
 
void handleNoteOn (MidiKeyboardState *, int midiChannel, int midiNoteNumber, float velocity) override
 
virtual void handlePartialSysexMessage (MidiInput *source, const uint8 *messageData, int numBytesSoFar, double timestamp)
 Notification sent each time a packet of a multi-packet sysex message arrives. More...
 
void removeNextBlockOfMessages (MidiBuffer &destBuffer, int numSamples)
 Removes all the pending messages from the queue as a buffer. More...
 
void reset (double sampleRate)
 Clears any messages from the queue. More...
 

Private Attributes

bool hasCalledReset = false
 
MidiBuffer incomingMessages
 
double lastCallbackTime = 0
 
CriticalSection midiCallbackLock
 
double sampleRate = 44100.0
 

Detailed Description

Collects incoming realtime MIDI messages and turns them into blocks suitable for processing by a block-based audio callback.

The class can also be used as either a MidiKeyboardStateListener or a MidiInputCallback so it can easily use a midi input or keyboard component as its source.

See also
MidiMessage, MidiInput

{Audio}

Constructor & Destructor Documentation

◆ MidiMessageCollector()

juce::MidiMessageCollector::MidiMessageCollector ( )

◆ ~MidiMessageCollector()

juce::MidiMessageCollector::~MidiMessageCollector ( )
override

Destructor.

Member Function Documentation

◆ addMessageToQueue()

void juce::MidiMessageCollector::addMessageToQueue ( const MidiMessage message)

Takes an incoming real-time message and adds it to the queue.

The message's timestamp is taken, and it will be ready for retrieval as part of the block returned by the next call to removeNextBlockOfMessages().

This method is fully thread-safe when overlapping calls are made with removeNextBlockOfMessages().

◆ handleIncomingMidiMessage()

void juce::MidiMessageCollector::handleIncomingMidiMessage ( MidiInput ,
const MidiMessage  
)
overridevirtual

◆ handleNoteOff()

void juce::MidiMessageCollector::handleNoteOff ( MidiKeyboardState ,
int  midiChannel,
int  midiNoteNumber,
float  velocity 
)
overridevirtual

◆ handleNoteOn()

void juce::MidiMessageCollector::handleNoteOn ( MidiKeyboardState ,
int  midiChannel,
int  midiNoteNumber,
float  velocity 
)
overridevirtual

◆ handlePartialSysexMessage()

virtual void juce::MidiInputCallback::handlePartialSysexMessage ( MidiInput source,
const uint8 messageData,
int  numBytesSoFar,
double  timestamp 
)
inlinevirtualinherited

Notification sent each time a packet of a multi-packet sysex message arrives.

If a long sysex message is broken up into multiple packets, this callback is made for each packet that arrives until the message is finished, at which point the normal handleIncomingMidiMessage() callback will be made with the entire message.

The message passed in will contain the start of a sysex, but won't be finished with the terminating 0xf7 byte.

References juce::ignoreUnused().

◆ removeNextBlockOfMessages()

void juce::MidiMessageCollector::removeNextBlockOfMessages ( MidiBuffer destBuffer,
int  numSamples 
)

Removes all the pending messages from the queue as a buffer.

This will also correct the messages' timestamps to make sure they're in the range 0 to numSamples - 1.

This call should be made regularly by something like an audio processing callback, because the time that it happens is used in calculating the midi event positions.

This method is fully thread-safe when overlapping calls are made with addMessageToQueue().

Precondition: numSamples must be greater than 0.

◆ reset()

void juce::MidiMessageCollector::reset ( double  sampleRate)

Clears any messages from the queue.

You need to call this method before starting to use the collector, so that it knows the correct sample rate to use.

Member Data Documentation

◆ hasCalledReset

bool juce::MidiMessageCollector::hasCalledReset = false
private

◆ incomingMessages

MidiBuffer juce::MidiMessageCollector::incomingMessages
private

◆ lastCallbackTime

double juce::MidiMessageCollector::lastCallbackTime = 0
private

◆ midiCallbackLock

CriticalSection juce::MidiMessageCollector::midiCallbackLock
private

◆ sampleRate

double juce::MidiMessageCollector::sampleRate = 44100.0
private

The documentation for this class was generated from the following file: