JUCE: MidiMessageCollector Class Reference

JUCE

- Main Page
- Related Pages
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Member Functions | List of all members
MidiMessageCollector Class Reference
juce_audio_devices » midi_io

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 MidiMessageCollector:

## Public Member Functions
| MidiMessageCollector ()
| Creates a MidiMessageCollector.
| ~MidiMessageCollector () override
| Destructor.
void | reset (double sampleRate)
| Clears any messages from the queue.
void | addMessageToQueue (const MidiMessage &message)
| Takes an incoming real-time message and adds it to the queue.
void | removeNextBlockOfMessages (MidiBuffer &destBuffer, int numSamples)
| Removes all the pending messages from the queue as a buffer.
void | ensureStorageAllocated (size_t bytes)
| Preallocates storage for collected messages.
void | handleNoteOn (MidiKeyboardState *, int midiChannel, int midiNoteNumber, float velocity) override
void | handleNoteOff (MidiKeyboardState *, int midiChannel, int midiNoteNumber, float velocity) override
void | handleIncomingMidiMessage (MidiInput *, const MidiMessage &) override
Public Member Functions inherited from MidiKeyboardState::Listener
virtual | ~Listener ()=default
virtual void | handleNoteOn (MidiKeyboardState *source, int midiChannel, int midiNoteNumber, float velocity)=0
| Called when one of the MidiKeyboardState's keys is pressed.
virtual void | handleNoteOff (MidiKeyboardState *source, int midiChannel, int midiNoteNumber, float velocity)=0
| Called when one of the MidiKeyboardState's keys is released.
Public Member Functions inherited from MidiInputCallback
virtual | ~MidiInputCallback ()=default
| Destructor.
virtual void | handleIncomingMidiMessage (MidiInput *source, const MidiMessage &message)=0
| Receives an incoming message.
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.

## 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 MidiKeyboardState::Listener or a MidiInputCallback so it can easily use a midi input or keyboard component as its source.

See also
  MidiMessage, MidiInput

## Constructor & Destructor Documentation

## ◆ MidiMessageCollector()

MidiMessageCollector::MidiMessageCollector | ( |  | ) |

Creates a MidiMessageCollector.

## ◆ ~MidiMessageCollector()

MidiMessageCollector::~MidiMessageCollector | ( |  | ) |
| override

Destructor.

## Member Function Documentation

## ◆ reset()

void 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.

## ◆ addMessageToQueue()

void 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().

## ◆ removeNextBlockOfMessages()

void 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.

## ◆ ensureStorageAllocated()

void MidiMessageCollector::ensureStorageAllocated | ( | size_t | bytes | ) |

Preallocates storage for collected messages.

This can be called before audio processing begins to ensure that there is sufficient space for the expected MIDI messages, in order to avoid allocations within the audio callback.

## ◆ handleNoteOn()

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

Implements MidiKeyboardState::Listener.

## ◆ handleNoteOff()

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

Implements MidiKeyboardState::Listener.

## ◆ handleIncomingMidiMessage()

void MidiMessageCollector::handleIncomingMidiMessage | ( | MidiInput * | ,
|  | const MidiMessage & |
| ) |  |
| overridevirtual

Implements MidiInputCallback.

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

- juce_MidiMessageCollector.h