From 7fe4f1e60c84f9da020fd1236ff2a98f87231245 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 16 Dec 2008 11:24:05 +0000 Subject: [PATCH] experimental support for note panning in SF2 player (I'm not sure what m_maxChannels should be or how to find it out. I just picked what worked for my setup.) git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1941 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/note_play_handle.h | 16 ++++++++++++++-- plugins/sf2_player/sf2_player.cpp | 24 ++++++++++++++++++++---- plugins/sf2_player/sf2_player.h | 2 ++ src/core/note_play_handle.cpp | 1 + 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/include/note_play_handle.h b/include/note_play_handle.h index 903e409fd..e6560256c 100644 --- a/include/note_play_handle.h +++ b/include/note_play_handle.h @@ -56,7 +56,7 @@ public: virtual ~notePlayHandle(); virtual void setVolume( const volume _volume = DefaultVolume ); - + int getMidiVelocity( void ) const; const float & frequency( void ) const @@ -250,6 +250,15 @@ public: m_patternIndex = _i; } #endif + inline int channel( void ) const + { + return m_channel; + } + inline void setChannel( int _channel ) + { + m_channel = _channel; + } + private: @@ -274,7 +283,7 @@ private: float m_value; } ; - + instrumentTrack * m_instrumentTrack; // needed for calling // instrumentTrack::playNote @@ -300,6 +309,9 @@ private: #ifdef LMMS_SINGERBOT_SUPPORT int m_patternIndex; // position among relevant notes #endif + // which channel this note was played on + // needed for some plugins like SF2 + int m_channel; // tempo reaction bpm_t m_origTempo; // original tempo diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index 1589d24ab..2a34c2ce6 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -41,6 +41,7 @@ #include "patches_dialog.h" #include "tooltip.h" #include "lcd_spinbox.h" +#include "panning.h" #undef SINGLE_SOURCE_COMPILE #include "embed.cpp" @@ -79,6 +80,8 @@ sf2Instrument::sf2Instrument( instrumentTrack * _instrument_track ) : m_fontId( 0 ), 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" ) ), @@ -387,7 +390,7 @@ void sf2Instrument::updatePatch( void ) { if( m_bankNum.value() >= 0 && m_patchNum.value() >= 0 ) { - fluid_synth_program_select( m_synth, 1, m_fontId, + fluid_synth_program_select( m_synth, m_channel, m_fontId, m_bankNum.value(), m_patchNum.value() ); } } @@ -573,8 +576,21 @@ void sf2Instrument::playNote( notePlayHandle * _n, sampleFrame * ) _n->m_pluginData = new int( midiNote ); m_synthMutex.lock(); - fluid_synth_noteon( m_synth, 1, midiNote, + + short ctrl = 0x0A; // PAN_MSB + int pan = 0 + + ( (float)( _n->getPanning() - PanningLeft ) ) / + ( (float)( PanningRight - PanningLeft ) ) * + ( (float)( 127 - 0 ) ); + fluid_synth_cc( m_synth, m_channel, ctrl, pan ); + fluid_synth_noteon( m_synth, m_channel, midiNote, _n->getMidiVelocity() ); + _n->setChannel( m_channel ); + if( ++m_channel > m_maxChannels ) + { + m_channel = 1; + } + m_synthMutex.unlock(); m_notesRunningMutex.lock(); @@ -594,7 +610,7 @@ void sf2Instrument::play( sampleFrame * _working_buffer ) if( m_lastMidiPitch != getInstrumentTrack()->midiPitch() ) { m_lastMidiPitch = getInstrumentTrack()->midiPitch(); - fluid_synth_pitch_bend( m_synth, 1, m_lastMidiPitch ); + fluid_synth_pitch_bend( m_synth, m_channel, m_lastMidiPitch ); } if( m_internalSampleRate < engine::getMixer()->processingSampleRate() && @@ -648,7 +664,7 @@ void sf2Instrument::deleteNotePluginData( notePlayHandle * _n ) if( n <= 0 ) { m_synthMutex.lock(); - fluid_synth_noteoff( m_synth, 1, *midiNote ); + fluid_synth_noteoff( m_synth, _n->channel(), *midiNote ); m_synthMutex.unlock(); } diff --git a/plugins/sf2_player/sf2_player.h b/plugins/sf2_player/sf2_player.h index fa53cbbbb..1a277e377 100644 --- a/plugins/sf2_player/sf2_player.h +++ b/plugins/sf2_player/sf2_player.h @@ -127,6 +127,8 @@ private: int m_notesRunning[128]; sample_rate_t m_internalSampleRate; int m_lastMidiPitch; + int m_channel; + int m_maxChannels; lcdSpinBoxModel m_bankNum; lcdSpinBoxModel m_patchNum; diff --git a/src/core/note_play_handle.cpp b/src/core/note_play_handle.cpp index b29ce78d4..76cac6fc5 100644 --- a/src/core/note_play_handle.cpp +++ b/src/core/note_play_handle.cpp @@ -73,6 +73,7 @@ notePlayHandle::notePlayHandle( instrumentTrack * _it, #ifdef LMMS_SINGERBOT_SUPPORT m_patternIndex( 0 ), #endif + m_channel( 1 ), m_origTempo( engine::getSong()->getTempo() ) { if( m_baseNote )