From 880c322cf619086857175e00d1ddf33acb7520fd Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 29 Sep 2008 19:29:04 +0000 Subject: [PATCH] * replaced instrument::notePlayHandleBased() with instrument::isMidiBased() * renamed bendable() to isBendable() * if the instrument is MIDI based and instrument-track's volume is below 100, adjust velocity of MIDI events and scaling factor when mixing sound git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1715 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/instrument.h | 12 +++++++----- include/note_play_handle.h | 5 +++-- plugins/sf2_player/sf2_player.h | 4 ++-- plugins/vestige/vestige.h | 4 ++-- plugins/vibed/vibed.h | 13 +++++++------ src/core/note_play_handle.cpp | 10 ++++++---- src/tracks/instrument_track.cpp | 12 ++++++++++-- 7 files changed, 37 insertions(+), 23 deletions(-) diff --git a/include/instrument.h b/include/instrument.h index 0dc1f5707..4e401bc6d 100644 --- a/include/instrument.h +++ b/include/instrument.h @@ -87,19 +87,21 @@ public: return( 0 ); } - // instrument-play-handle-based instruments should return FALSE - inline virtual bool notePlayHandleBased( void ) const + // return false if instrument is not bendable + inline virtual bool isBendable( void ) const { return( true ); } - inline virtual bool bendable( void ) const + // return true if instruments reacts to MIDI events passed to + // handleMidiEvent() rather than playNote() & Co + inline virtual bool isMidiBased( void ) const { - return( true ); + return( false ); } // sub-classes can re-implement this for receiving all incoming - // MIDI-events except NoteOn and NoteOff + // MIDI-events inline virtual bool handleMidiEvent( const midiEvent & _me, const midiTime & _time ) { diff --git a/include/note_play_handle.h b/include/note_play_handle.h index e4e2624bf..f180b605c 100644 --- a/include/note_play_handle.h +++ b/include/note_play_handle.h @@ -245,11 +245,12 @@ public: && // we must not parallelize note-play-handles, which // belong to instruments that are instrument-play- - // handle-driven, because then waitForWorkerThread() + // handle-driven (i.e. react to MIDI events), + // because then waitForWorkerThread() // would be additionally called for each // note-play-handle which results in hangups m_instrumentTrack->getInstrument()-> - notePlayHandleBased() ); + isMidiBased() ); } virtual void waitForWorkerThread( void ) diff --git a/plugins/sf2_player/sf2_player.h b/plugins/sf2_player/sf2_player.h index 518b492c5..626b89615 100644 --- a/plugins/sf2_player/sf2_player.h +++ b/plugins/sf2_player/sf2_player.h @@ -76,9 +76,9 @@ public: return( 0 ); } - virtual bool notePlayHandleBased( void ) const + virtual bool isMidiBased( void ) const { - return( FALSE ); + return( true ); } virtual pluginView * instantiateView( QWidget * _parent ); diff --git a/plugins/vestige/vestige.h b/plugins/vestige/vestige.h index f797692af..5cb905b12 100644 --- a/plugins/vestige/vestige.h +++ b/plugins/vestige/vestige.h @@ -67,9 +67,9 @@ public: virtual void waitForWorkerThread( void ); - virtual bool notePlayHandleBased( void ) const + virtual bool isMidiBased( void ) const { - return( FALSE ); + return( true ); } virtual bool handleMidiEvent( const midiEvent & _me, diff --git a/plugins/vibed/vibed.h b/plugins/vibed/vibed.h index c0c735a9c..4084daebd 100644 --- a/plugins/vibed/vibed.h +++ b/plugins/vibed/vibed.h @@ -21,8 +21,8 @@ * Boston, MA 02110-1301 USA. * */ -#ifndef _VIBED_STRINGS_H -#define _VIBED_STRINGS_H +#ifndef _VIBED_H +#define _VIBED_H #include "instrument.h" #include "instrument_view.h" @@ -53,13 +53,14 @@ public: virtual QString nodeName( void ) const; - inline virtual bool bendable( void ) const - { - return( false ); - } + inline virtual bool isBendable( void ) const + { + return( false ); + } virtual pluginView * instantiateView( QWidget * _parent ); + private: QList m_pickKnobs; QList m_pickupKnobs; diff --git a/src/core/note_play_handle.cpp b/src/core/note_play_handle.cpp index f5872027a..d76974ea1 100644 --- a/src/core/note_play_handle.cpp +++ b/src/core/note_play_handle.cpp @@ -163,10 +163,12 @@ void notePlayHandle::setVolume( const volume _volume ) int notePlayHandle::getMidiVelocity( void ) const { - return tLimit( (Uint16) ( ( getVolume() / 100.0f ) * - ( m_instrumentTrack->getVolume() / 100.0f ) * - MidiMaxVelocity ), - 0, MidiMaxVelocity ); + int vel = getVolume(); + if( m_instrumentTrack->getVolume() < DefaultVolume ) + { + vel = ( vel * m_instrumentTrack->getVolume() ) / DefaultVolume; + } + return( qMin( MidiMaxVelocity, vel * MidiMaxVelocity / DefaultVolume ) ); } diff --git a/src/tracks/instrument_track.cpp b/src/tracks/instrument_track.cpp index 5871cf002..6cc90b872 100644 --- a/src/tracks/instrument_track.cpp +++ b/src/tracks/instrument_track.cpp @@ -151,12 +151,13 @@ void instrumentTrack::processAudioBuffer( sampleFrame * _buf, { return; } - float v_scale = (float) getVolume() / DefaultVolume; // if effects "went to sleep" because there was no input, wake them up // now m_audioPort.getEffects()->startRunning(); + float v_scale = (float) getVolume() / DefaultVolume; + // instruments using instrument-play-handles will call this method // without any knowledge about notes, so they pass NULL for _n, which // is no problem for us since we just bypass the envelopes+LFOs @@ -165,6 +166,13 @@ void instrumentTrack::processAudioBuffer( sampleFrame * _buf, m_soundShaping.processAudioBuffer( _buf, _frames, _n ); v_scale *= ( (float) _n->getVolume() / DefaultVolume ); } + else + { + if( getVolume() < DefaultVolume ) + { + v_scale = 1; + } + } m_audioPort.setNextFxChannel( m_effectChannelModel.value() ); engine::getMixer()->bufferToPort( _buf, @@ -1262,7 +1270,7 @@ void instrumentTrackWindow::modelChanged( void ) m_effectChannelNumber->setModel( &m_track->m_effectChannelModel ); m_pianoView->setModel( &m_track->m_piano ); - if( m_track->getInstrument() && m_track->getInstrument()->bendable() ) + if( m_track->getInstrument() && m_track->getInstrument()->isBendable() ) { m_pitchKnob->setModel( &m_track->m_pitchModel ); m_pitchKnob->show();