mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
MidiKeyboardComponent: Fix potential data race on shouldCheckState data member
This commit is contained in:
parent
ea250b3655
commit
ac3d1b7539
2 changed files with 12 additions and 14 deletions
|
|
@ -195,7 +195,7 @@ void MidiKeyboardComponent::setMidiChannel (int midiChannelNumber)
|
|||
void MidiKeyboardComponent::setMidiChannelsToDisplay (int midiChannelMask)
|
||||
{
|
||||
midiInChannelMask = midiChannelMask;
|
||||
shouldCheckState = true;
|
||||
noPendingUpdates.store (false);
|
||||
}
|
||||
|
||||
void MidiKeyboardComponent::setVelocity (float v, bool useMousePosition)
|
||||
|
|
@ -668,12 +668,12 @@ void MidiKeyboardComponent::resized()
|
|||
//==============================================================================
|
||||
void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
|
||||
{
|
||||
shouldCheckState = true; // (probably being called from the audio thread, so avoid blocking in here)
|
||||
noPendingUpdates.store (false);
|
||||
}
|
||||
|
||||
void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
|
||||
{
|
||||
shouldCheckState = true; // (probably being called from the audio thread, so avoid blocking in here)
|
||||
noPendingUpdates.store (false);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -809,19 +809,17 @@ void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, const MouseWheelD
|
|||
|
||||
void MidiKeyboardComponent::timerCallback()
|
||||
{
|
||||
if (shouldCheckState)
|
||||
if (noPendingUpdates.exchange (true))
|
||||
return;
|
||||
|
||||
for (int i = rangeStart; i <= rangeEnd; ++i)
|
||||
{
|
||||
shouldCheckState = false;
|
||||
bool isOn = state.isNoteOnForChannels (midiInChannelMask, i);
|
||||
|
||||
for (int i = rangeStart; i <= rangeEnd; ++i)
|
||||
if (keysCurrentlyDrawnDown[i] != isOn)
|
||||
{
|
||||
bool isOn = state.isNoteOnForChannels (midiInChannelMask, i);
|
||||
|
||||
if (keysCurrentlyDrawnDown[i] != isOn)
|
||||
{
|
||||
keysCurrentlyDrawnDown.setBit (i, isOn);
|
||||
repaintNote (i);
|
||||
}
|
||||
keysCurrentlyDrawnDown.setBit (i, isOn);
|
||||
repaintNote (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ private:
|
|||
|
||||
Array<int> mouseOverNotes, mouseDownNotes;
|
||||
BigInteger keysPressed, keysCurrentlyDrawnDown;
|
||||
bool shouldCheckState = false;
|
||||
std::atomic<bool> noPendingUpdates { true };
|
||||
|
||||
int rangeStart = 0, rangeEnd = 127;
|
||||
float firstKey = 12 * 4.0f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue