From 205056621c353fe50316f963b479b6f824ca6246 Mon Sep 17 00:00:00 2001 From: Garrett Date: Sun, 23 Nov 2014 14:24:51 -0800 Subject: [PATCH] Fixed release samples never being deleted I removed code in a previous commit that deleted ended samples since that sometimes caused issues when the samples had loop points. However, removing the code caused issues with the release samples. Thus, now it removes ended samples only if they are release samples. Otherwise, the keyup event and ADSR handle ending the note. --- plugins/GigPlayer/GigPlayer.cpp | 11 ++++++++++- plugins/GigPlayer/GigPlayer.h | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/GigPlayer/GigPlayer.cpp b/plugins/GigPlayer/GigPlayer.cpp index c4f98ca2c..34e404420 100644 --- a/plugins/GigPlayer/GigPlayer.cpp +++ b/plugins/GigPlayer/GigPlayer.cpp @@ -371,7 +371,12 @@ void GigInstrument::play( sampleFrame * _working_buffer ) for( QList::iterator sample = it->samples.begin(); sample != it->samples.end(); ++sample ) { - if( sample->sample == NULL || sample->adsr.done() ) + // Delete if the ADSR for a sample is complete for normal + // notes, or if a release sample, then if we've reached + // the end of the sample + if( sample->sample == NULL || sample->adsr.done() || + ( it->isRelease == true && + sample->pos >= sample->sample->SamplesTotal - 1 ) ) { sample = it->samples.erase( sample ); @@ -729,6 +734,10 @@ void GigInstrument::addSamples( GigNote & gignote, bool wantReleaseSample ) gig::DimensionRegion * pDimRegion = pRegion->GetDimensionRegionByValue( dim.DimValues ); gig::Sample * pSample = pDimRegion->pSample; + // If this is a release sample, the note won't ever be + // released, so we handle it differently + gignote.isRelease = wantReleaseSample; + // Does this note have release samples? Set this only on the original // notes and not when we get the release samples. if( wantReleaseSample != true ) diff --git a/plugins/GigPlayer/GigPlayer.h b/plugins/GigPlayer/GigPlayer.h index 25600e166..f302df622 100644 --- a/plugins/GigPlayer/GigPlayer.h +++ b/plugins/GigPlayer/GigPlayer.h @@ -201,6 +201,7 @@ public: int midiNote; int velocity; bool release; // Whether to trigger a release sample on key up + bool isRelease; // Whether this is a release sample, changes when we delete it GigState state; float frequency; QList samples; @@ -213,7 +214,8 @@ public: GigNote( int midiNote, int velocity, float frequency, GIGPluginData * handle ) : midiNote( midiNote ), velocity( velocity ), - release( false ), state( KeyDown ), frequency( frequency ), handle( handle ) + release( false ), isRelease( false ), state( KeyDown ), + frequency( frequency ), handle( handle ) { } } ;