Sf2Player: fixed hanging notes with enabled panning support

If SF2_PANNING_SUPPORT is set, overlapping notes of the same key played on
different MIDI channel caused some notes to hang. This commit fixes the issue.
This commit is contained in:
Tobias Doerffel
2009-03-16 16:51:35 +01:00
parent 12fd3206b4
commit b1fe2dcbdf
2 changed files with 16 additions and 9 deletions

View File

@@ -77,6 +77,7 @@ struct SF2PluginData
} ;
// Static map of current sfonts
QMap<QString, sf2Font*> sf2Instrument::s_fonts;
QMutex sf2Instrument::s_fontsMutex;
@@ -91,7 +92,6 @@ sf2Instrument::sf2Instrument( instrumentTrack * _instrument_track ) :
m_filename( "" ),
m_lastMidiPitch( 8192 ),
m_channel( 1 ),
m_maxChannels( 5 ),
m_bankNum( 0, 0, 999, this, tr("Bank") ),
m_patchNum( 0, 0, 127, this, tr("Patch") ),
m_gain( 1.0f, 0.0f, 5.0f, 0.01f, this, tr( "Gain" ) ),
@@ -116,7 +116,10 @@ sf2Instrument::sf2Instrument( instrumentTrack * _instrument_track ) :
{
for( int i = 0; i < 128; ++i )
{
m_notesRunning[i] = 0;
for( int j = 0; j < MaxFluidChannels; ++j )
{
m_notesRunning[i][j] = 0;
}
}
m_settings = new_fluid_settings();
@@ -602,7 +605,7 @@ void sf2Instrument::playNote( notePlayHandle * _n, sampleFrame * )
_n->getMidiVelocity() );
#ifdef SF2_PANNING_SUPPORT
if( ++m_channel > m_maxChannels )
if( ++m_channel > MaxFluidChannels )
{
m_channel = 1;
}
@@ -611,7 +614,7 @@ void sf2Instrument::playNote( notePlayHandle * _n, sampleFrame * )
m_synthMutex.unlock();
m_notesRunningMutex.lock();
++m_notesRunning[midiNote];
++m_notesRunning[midiNote][pluginData->midiChannel-1];
m_notesRunningMutex.unlock();
}
@@ -693,7 +696,8 @@ void sf2Instrument::deleteNotePluginData( notePlayHandle * _n )
SF2PluginData * pluginData = static_cast<SF2PluginData *>(
_n->m_pluginData );
m_notesRunningMutex.lock();
const int n = --m_notesRunning[pluginData->midiNote];
const int n = --m_notesRunning[pluginData->midiNote]
[pluginData->midiChannel-1];
m_notesRunningMutex.unlock();
if( n <= 0 )

View File

@@ -37,6 +37,7 @@
#include "fluidsynth.h"
#include "sample_buffer.h"
class sf2InstrumentView;
class sf2Font;
class notePlayHandle;
@@ -44,6 +45,9 @@ class notePlayHandle;
class patchesDialog;
class QLabel;
const int MaxFluidChannels = 5;
class sf2Instrument : public instrument
{
Q_OBJECT
@@ -72,12 +76,12 @@ public:
virtual f_cnt_t desiredReleaseFrames( void ) const
{
return( 0 );
return 0;
}
virtual bool isMidiBased( void ) const
{
return( true );
return true;
}
virtual pluginView * instantiateView( QWidget * _parent );
@@ -124,11 +128,10 @@ private:
QMutex m_synthMutex;
QMutex m_loadMutex;
int m_notesRunning[128];
int m_notesRunning[128][MaxFluidChannels];
sample_rate_t m_internalSampleRate;
int m_lastMidiPitch;
int m_channel;
int m_maxChannels;
lcdSpinBoxModel m_bankNum;
lcdSpinBoxModel m_patchNum;