I've been racking my brain trying to figure out how to get the MidiKeyboardComponent to display multiple colors for noteOn's simultaneously. the scenario:
You press down a key (midikeyboardstate.note = on )
you press down a sustain pedal
you release the key (midikeyboardstate.note = off )
the note turns off on the MidiKeyboardComponent, as expected.
Ideally, the note in the midikeyboardcomponent would stay lit, but maybe with a different color, until a sustainOff message arrived. Other note-on presses would be drawn with the normal keyDownOverlayColourId
I tried subclassing MidiKeyboardComponent, and exposing repaintNote() as a protected member:
class ExtraMidiKeyboardComponent : public MidiKeyboardComponent
{
public:
ExtraMidiKeyboardComponent( MidiKeyboardState& state, Orientation orientation) : MidiKeyboardComponent( state, orientation) {
sustainedColor = Colour( UInt32( 0xFF79E2FF) );
}
~ExtraMidiKeyboardComponent( ) {}
void drawSustainedNote (int note ) {
const MessageManagerLock mmLock;
state->noteOn(1, note, 1);
setColour( MidiKeyboardComponent::keyDownOverlayColourId, Colours::black );
repaintIndividualNote( note );
}
private:
SharedResourcePointer<MidiKeyboardState> state;
Colour sustainedColor;
};
and then in my class that uses the MidiKeyboardComponent, I had this:
void handleNoteOff( MidiKeyboardState* source, int, int ) {
if( sustain ) {
std::cout << "handleNoteOff \n";
std::vector<int> curNotes = detector->getCurrentOnNotes();
for( int i = 0; i < curNotes.size(); i++ )
keyboard->drawSustainedNote( curNotes[i] );
}
}
void setSustain( bool s, const MidiMessage &message ) {
sustain = s;
postMessageToList( message ); //triggers repaint()
if( sustain == false && detector->getCurrentOnNotes().size() == 0) {
//turn off everything that's still on
state->allNotesOff(0);
setKeyboardNoteOnColor(defaultNoteOnColor); //because drawSustainedNotes changes it
}
}
What i'm hoping to achieve is that any noteOns are drawn with the color they're always drawn with, and any notes that are sustained after a note-Off occurs, are drawn with a different color.
