Loading...
Searching...
No Matches
juce_MidiKeyboardState.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API MidiKeyboardState
{
public:
//==============================================================================
MidiKeyboardState();
//==============================================================================
void reset();
bool isNoteOn (int midiChannel, int midiNoteNumber) const noexcept;
bool isNoteOnForChannels (int midiChannelMask, int midiNoteNumber) const noexcept;
void noteOn (int midiChannel, int midiNoteNumber, float velocity);
void noteOff (int midiChannel, int midiNoteNumber, float velocity);
void allNotesOff (int midiChannel);
//==============================================================================
void processNextMidiEvent (const MidiMessage& message);
void processNextMidiBuffer (MidiBuffer& buffer,
int startSample,
int numSamples,
bool injectIndirectEvents);
//==============================================================================
class JUCE_API Listener
{
public:
//==============================================================================
virtual ~Listener() = default;
//==============================================================================
virtual void handleNoteOn (MidiKeyboardState* source,
int midiChannel, int midiNoteNumber, float velocity) = 0;
virtual void handleNoteOff (MidiKeyboardState* source,
int midiChannel, int midiNoteNumber, float velocity) = 0;
};
void addListener (Listener* listener);
void removeListener (Listener* listener);
private:
//==============================================================================
CriticalSection lock;
std::atomic<uint16> noteStates[128];
MidiBuffer eventsToAdd;
ListenerList<Listener> listeners;
void noteOnInternal (int midiChannel, int midiNoteNumber, float velocity);
void noteOffInternal (int midiChannel, int midiNoteNumber, float velocity);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiKeyboardState)
};
using MidiKeyboardStateListener = MidiKeyboardState::Listener;
} // namespace juce
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::ListenerList
Definition juce_ListenerList.h:81
juce::MidiBuffer
Definition juce_MidiBuffer.h:145
juce::MidiKeyboardState::Listener
Definition juce_MidiKeyboardState.h:139
juce::MidiKeyboardState::Listener::handleNoteOff
virtual void handleNoteOff(MidiKeyboardState *source, int midiChannel, int midiNoteNumber, float velocity)=0
juce::MidiKeyboardState::Listener::handleNoteOn
virtual void handleNoteOn(MidiKeyboardState *source, int midiChannel, int midiNoteNumber, float velocity)=0
juce::MidiKeyboardState::processNextMidiBuffer
void processNextMidiBuffer(MidiBuffer &buffer, int startSample, int numSamples, bool injectIndirectEvents)
Definition juce_MidiKeyboardState.cpp:135
juce::MidiKeyboardState::addListener
void addListener(Listener *listener)
Definition juce_MidiKeyboardState.cpp:161
juce::MidiKeyboardState::noteOff
void noteOff(int midiChannel, int midiNoteNumber, float velocity)
Definition juce_MidiKeyboardState.cpp:79
juce::MidiKeyboardState::allNotesOff
void allNotesOff(int midiChannel)
Definition juce_MidiKeyboardState.cpp:102
juce::MidiKeyboardState::processNextMidiEvent
void processNextMidiEvent(const MidiMessage &message)
Definition juce_MidiKeyboardState.cpp:118
juce::MidiKeyboardState::removeListener
void removeListener(Listener *listener)
Definition juce_MidiKeyboardState.cpp:167
juce::MidiKeyboardState::isNoteOn
bool isNoteOn(int midiChannel, int midiNoteNumber) const noexcept
Definition juce_MidiKeyboardState.cpp:39
juce::MidiKeyboardState::noteOn
void noteOn(int midiChannel, int midiNoteNumber, float velocity)
Definition juce_MidiKeyboardState.cpp:53
juce::MidiKeyboardState::reset
void reset()
Definition juce_MidiKeyboardState.cpp:32
juce::MidiKeyboardState::isNoteOnForChannels
bool isNoteOnForChannels(int midiChannelMask, int midiNoteNumber) const noexcept
Definition juce_MidiKeyboardState.cpp:47
juce::MidiMessage
Definition juce_MidiMessage.h:35