From 76e182e586e35746aef61427977f889bfe79cb46 Mon Sep 17 00:00:00 2001 From: Garrett Date: Tue, 18 Nov 2014 09:02:50 -0800 Subject: [PATCH] Release only one note on keyup Previously if you release a C4 then all C4 notes would be released. Now it stores the pointer to the plugin data which is unique for each key press and determines which to release based on the matching pointers. --- plugins/GigPlayer/GigPlayer.cpp | 13 +++---------- plugins/GigPlayer/GigPlayer.h | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/plugins/GigPlayer/GigPlayer.cpp b/plugins/GigPlayer/GigPlayer.cpp index 98c26e6d1..6cbf9da1a 100644 --- a/plugins/GigPlayer/GigPlayer.cpp +++ b/plugins/GigPlayer/GigPlayer.cpp @@ -74,14 +74,6 @@ Plugin::Descriptor PLUGIN_EXPORT gigplayer_plugin_descriptor = -struct GIGPluginData -{ - int midiNote; -} ; - - - - GigInstrument::GigInstrument( InstrumentTrack * _instrument_track ) : Instrument( _instrument_track, &gigplayer_plugin_descriptor ), m_instance( NULL ), @@ -313,7 +305,7 @@ void GigInstrument::playNote( NotePlayHandle * _n, sampleFrame * ) const uint velocity = _n->midiVelocity( baseVelocity ); QMutexLocker locker( &m_notesMutex ); - m_notes.push_back( GigNote( midiNote, velocity, _n->unpitchedFrequency() ) ); + m_notes.push_back( GigNote( midiNote, velocity, _n->unpitchedFrequency(), pluginData ) ); } } @@ -686,7 +678,8 @@ void GigInstrument::deleteNotePluginData( NotePlayHandle * _n ) // pressed (i.e., not if the key was already released) for( QList::iterator i = m_notes.begin(); i != m_notes.end(); ++i ) { - if( i->midiNote == pluginData->midiNote && + // Find the note by matching pointers to the plugin data + if( i->handle == pluginData && ( i->state == KeyDown || i->state == PlayingKeyDown ) ) { i->state = KeyUp; diff --git a/plugins/GigPlayer/GigPlayer.h b/plugins/GigPlayer/GigPlayer.h index aea3118e3..25600e166 100644 --- a/plugins/GigPlayer/GigPlayer.h +++ b/plugins/GigPlayer/GigPlayer.h @@ -48,6 +48,16 @@ class PatchesDialog; class QLabel; + + +struct GIGPluginData +{ + int midiNote; +} ; + + + + // Load a GIG file using libgig class GigInstance { @@ -195,9 +205,15 @@ public: float frequency; QList samples; - GigNote( int midiNote, int velocity, float frequency ) + // Used to determine which note should be released on key up + // + // Note: if accessing the data, be careful not to access it after the key + // has been released since that's when it is deleted + GIGPluginData * handle; + + GigNote( int midiNote, int velocity, float frequency, GIGPluginData * handle ) : midiNote( midiNote ), velocity( velocity ), - release( false ), state( KeyDown ), frequency( frequency ) + release( false ), state( KeyDown ), frequency( frequency ), handle( handle ) { } } ;