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.
This commit is contained in:
Garrett
2014-11-18 09:02:50 -08:00
parent 3f641c2c55
commit 76e182e586
2 changed files with 21 additions and 12 deletions

View File

@@ -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<GigNote>::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;

View File

@@ -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<GigSample> 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 )
{
}
} ;