From 9cb4b82297891b25800db35c4e6a49cb5f888919 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Fri, 7 Mar 2008 10:24:58 +0000 Subject: [PATCH] added m_runningNotes-array to track overlapping or edge-to-edge notes and act accordingly git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@768 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 7 ++++ plugins/sf2_player/sf2_player.cpp | 60 ++++++++++++++++--------------- plugins/sf2_player/sf2_player.h | 8 +++-- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcc577ea7..d1d400f93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-03-06 Tobias Doerffel + + * plugins/sf2_player/sf2_player.h: + * plugins/sf2_player/sf2_player.cpp: + added m_runningNotes-array to track overlapping or edge-to-edge notes + and act accordingly + 2008-03-04 Tobias Doerffel * src/widgets/graph.cpp: diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index 9532ce31b..b09dda1ea 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -72,18 +72,21 @@ sf2Instrument::sf2Instrument( instrumentTrack * _instrument_track ) : m_bankNum( -1, -1, 999, 1, this ), m_patchNum( -1, -1, 127, 1, this ) { - - m_settings = new_fluid_settings(); + for( int i = 0; i < 128; ++i ) + { + m_notesRunning[i] = 0; + } + m_settings = new_fluid_settings(); - /* Set the synthesizer settings, if necessary */ + /* Set the synthesizer settings, if necessary */ - m_synth = new_fluid_synth( m_settings ); + m_synth = new_fluid_synth( m_settings ); - //fluid_settings_setstr(settings, "audio.driver", "jack"); + //fluid_settings_setstr(settings, "audio.driver", "jack"); - //adriver = new_fluid_audio_driver(settings, synth); + //adriver = new_fluid_audio_driver(settings, synth); instrumentPlayHandle * iph = new instrumentPlayHandle( this ); engine::getMixer()->addPlayHandle( iph ); @@ -167,18 +170,24 @@ void sf2Instrument::updatePatch( void ) void sf2Instrument::playNote( notePlayHandle * _n, bool ) { - const float LOG440 = 2.64345267649f; + const float LOG440 = 2.64345267649f; - const int defaultVelocity = 80; + const f_cnt_t tfp = _n->totalFramesPlayed(); - const f_cnt_t tfp = _n->totalFramesPlayed(); - - int midiNote = (int)floor( ( log2( _n->frequency() ) - LOG440 ) * 12 +69-58)+0.5; + int midiNote = (int)floor( ( log2( _n->frequency() ) - LOG440 ) * 12+69-58)+0.5; + // out of range? + if( midiNote <= 0 || midiNote >= 128 ) + { + return; + } if ( tfp == 0 ) { _n->m_pluginData = new int( midiNote ); - fluid_synth_noteon( m_synth, 1, midiNote, defaultVelocity ); + fluid_synth_noteon( m_synth, 1, midiNote, _n->getVolume() ); + m_notesRunningMutex.lock(); + ++m_notesRunning[midiNote]; + m_notesRunningMutex.unlock(); } else if( _n->released() ) { @@ -188,11 +197,6 @@ void sf2Instrument::playNote( notePlayHandle * _n, bool ) } -void sf2Instrument::waitForWorkerThread( void ) -{ - // No waiting required, at least not that I know of - return; -} void sf2Instrument::play( bool _try_parallelizing ) @@ -201,31 +205,29 @@ void sf2Instrument::play( bool _try_parallelizing ) sampleFrame * buf = new sampleFrame[frames]; - // Assumes stereo and float sample_t + // Assumes stereo and float sample_t - fluid_synth_write_float( m_synth, frames, buf, 0, 2, buf, 1, 2 ); + fluid_synth_write_float( m_synth, frames, buf, 0, 2, buf, 1, 2 ); getInstrumentTrack()->processAudioBuffer( buf, frames, NULL ); delete[] buf; - - if( !_try_parallelizing ) - { - waitForWorkerThread(); - } } void sf2Instrument::deleteNotePluginData( notePlayHandle * _n ) { - int * midiNote = static_cast( _n->m_pluginData ); - - fluid_synth_noteoff( m_synth, 1, *midiNote ); + int * midiNote = static_cast( _n->m_pluginData ); + m_notesRunningMutex.lock(); + const int n = --m_notesRunning[*midiNote]; + m_notesRunningMutex.unlock(); + if( n <= 0 ) + { + fluid_synth_noteoff( m_synth, 1, *midiNote ); + } delete midiNote; - - _n->noteOff(); } diff --git a/plugins/sf2_player/sf2_player.h b/plugins/sf2_player/sf2_player.h index 9a8ea6330..23d4bef69 100644 --- a/plugins/sf2_player/sf2_player.h +++ b/plugins/sf2_player/sf2_player.h @@ -26,6 +26,8 @@ #ifndef _SF2_PLAYER_H #define _SF2_PLAYER_H +#include + #include "instrument.h" #include "pixmap_button.h" #include "instrument_view.h" @@ -75,11 +77,10 @@ public: return( FALSE ); } - virtual void waitForWorkerThread( void ); - virtual pluginView * instantiateView( QWidget * _parent ); + public slots: void openFile( const QString & _sf2File ); void updatePatch( void ); @@ -93,7 +94,8 @@ private: fluid_audio_driver_t* m_adriver; int m_fontId; - + QMutex m_notesRunningMutex; + int m_notesRunning[128]; QString m_filename;