OpenShot Library | libopenshot-audio
0.2.0
|
26 MidiKeyboardState::MidiKeyboardState()
28 zerostruct (noteStates);
31 MidiKeyboardState::~MidiKeyboardState()
39 zerostruct (noteStates);
45 jassert (midiChannel >= 0 && midiChannel <= 16);
47 return isPositiveAndBelow (n, 128)
48 && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
53 return isPositiveAndBelow (n, 128)
54 && (noteStates[n] & midiChannelMask) != 0;
59 jassert (midiChannel >= 0 && midiChannel <= 16);
60 jassert (isPositiveAndBelow (midiNoteNumber, 128));
64 if (isPositiveAndBelow (midiNoteNumber, 128))
68 eventsToAdd.
clear (0, timeNow - 500);
70 noteOnInternal (midiChannel, midiNoteNumber, velocity);
74 void MidiKeyboardState::noteOnInternal (
const int midiChannel,
const int midiNoteNumber,
const float velocity)
76 if (isPositiveAndBelow (midiNoteNumber, 128))
78 noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
80 for (
int i = listeners.size(); --i >= 0;)
81 listeners.getUnchecked(i)->handleNoteOn (
this, midiChannel, midiNoteNumber, velocity);
89 if (
isNoteOn (midiChannel, midiNoteNumber))
93 eventsToAdd.
clear (0, timeNow - 500);
95 noteOffInternal (midiChannel, midiNoteNumber, velocity);
99 void MidiKeyboardState::noteOffInternal (
const int midiChannel,
const int midiNoteNumber,
const float velocity)
101 if (
isNoteOn (midiChannel, midiNoteNumber))
103 noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
105 for (
int i = listeners.size(); --i >= 0;)
106 listeners.getUnchecked(i)->handleNoteOff (
this, midiChannel, midiNoteNumber, velocity);
114 if (midiChannel <= 0)
116 for (
int i = 1; i <= 16; ++i)
121 for (
int i = 0; i < 128; ++i)
122 noteOff (midiChannel, i, 0.0f);
138 for (
int i = 0; i < 128; ++i)
139 noteOffInternal (message.
getChannel(), i, 0.0f);
144 const int startSample,
145 const int numSamples,
146 const bool injectIndirectEvents)
157 if (injectIndirectEvents)
161 const double scaleFactor = numSamples / (double) (eventsToAdd.
getLastEventTime() + 1 - firstEventToAdd);
165 const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
166 buffer.
addEvent (message, startSample + pos);
177 listeners.addIfNotAlreadyThere (listener);
183 listeners.removeFirstMatchingValue (listener);
bool isNoteOn(bool returnTrueForVelocity0=false) const noexcept
Returns true if this message is a 'key-down' event.
int getLastEventTime() const noexcept
Returns the sample number of the last event in the buffer.
bool isNoteOnForChannels(int midiChannelMask, int midiNoteNumber) const noexcept
Returns true if the given midi key is currently held down on any of a set of midi channels.
Used to iterate through the events in a MidiBuffer.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
void reset()
Resets the state of the object.
void processNextMidiBuffer(MidiBuffer &buffer, int startSample, int numSamples, bool injectIndirectEvents)
Scans a midi stream for up/down events and adds its own events to it.
void processNextMidiEvent(const MidiMessage &message)
Looks at a key-up/down event and uses it to update the state of this object.
void clear() noexcept
Removes all events from the buffer.
Holds a sequence of time-stamped midi events.
void addEvent(const MidiMessage &midiMessage, int sampleNumber)
Adds an event to the buffer.
int getFirstEventTime() const noexcept
Returns the sample number of the first event in the buffer.
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
Retrieves a copy of the next event from the buffer.
void addListener(MidiKeyboardStateListener *listener)
Registers a listener for callbacks when keys go up or down.
bool isAllNotesOff() const noexcept
Checks whether this message is an all-notes-off message.
static MidiMessage noteOn(int channel, int noteNumber, float velocity) noexcept
Creates a key-down message (using a floating-point velocity).
bool isNoteOff(bool returnTrueForNoteOnVelocity0=true) const noexcept
Returns true if this message is a 'key-up' event.
Encapsulates a MIDI message.
Receives events from a MidiKeyboardState object.
void allNotesOff(int midiChannel)
This will turn off any currently-down notes for the given midi channel.
void noteOff(int midiChannel, int midiNoteNumber, float velocity)
Turns a specified note off.
Automatically locks and unlocks a mutex object.
void removeListener(MidiKeyboardStateListener *listener)
Deregisters a listener.
int getNoteNumber() const noexcept
Returns the midi note number for note-on and note-off messages.
void noteOn(int midiChannel, int midiNoteNumber, float velocity)
Turns a specified note on.
float getFloatVelocity() const noexcept
Returns the velocity of a note-on or note-off message.
bool isNoteOn(int midiChannel, int midiNoteNumber) const noexcept
Returns true if the given midi key is currently held down for the given midi channel.
int getChannel() const noexcept
Returns the midi channel associated with the message.
static MidiMessage noteOff(int channel, int noteNumber, float velocity) noexcept
Creates a key-up message.