From f7da4a0f7e8d05b656aac77be2a5020d2da45938 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 15 Sep 2009 10:10:02 +0200 Subject: [PATCH] InstrumentPlayHandle: do not process if InstrumentTrack is muted While regular instruments were excluded from processing when muted this did not happen for InstrumentPlayHandle-based instruments. Muting for exampling tracks with VSTi's inside did not decrease CPU usage. Checking whether related InstrumentTrack is muted before calling Instrument::play() fixes this issue. Closes #2857426. (cherry picked from commit 6940d199693ba3b307445640de8e99979df0caad) --- include/Instrument.h | 2 ++ ...t_play_handle.h => InstrumentPlayHandle.h} | 12 ++++++----- plugins/lb302/lb302.cpp | 2 +- plugins/lb303/lb303.cpp | 2 +- plugins/sf2_player/sf2_player.cpp | 2 +- plugins/vestige/vestige.cpp | 13 +++++++----- plugins/zynaddsubfx/ZynAddSubFx.cpp | 21 +++++++++++-------- src/core/Instrument.cpp | 9 ++++++++ 8 files changed, 41 insertions(+), 22 deletions(-) rename include/{instrument_play_handle.h => InstrumentPlayHandle.h} (87%) diff --git a/include/Instrument.h b/include/Instrument.h index 74e47ac7e..97b23b0cf 100644 --- a/include/Instrument.h +++ b/include/Instrument.h @@ -117,6 +117,8 @@ public: virtual bool isFromTrack( const track * _track ) const; + bool isMuted() const; + protected: inline InstrumentTrack * instrumentTrack() const diff --git a/include/instrument_play_handle.h b/include/InstrumentPlayHandle.h similarity index 87% rename from include/instrument_play_handle.h rename to include/InstrumentPlayHandle.h index 252995363..ccb3e6f18 100644 --- a/include/instrument_play_handle.h +++ b/include/InstrumentPlayHandle.h @@ -1,8 +1,8 @@ /* - * instrument_play_handle.h - play-handle for playing an instrument + * InstrumentPlayHandle.h - play-handle for driving an instrument + * + * Copyright (c) 2005-2009 Tobias Doerffel * - * Copyright (c) 2005-2008 Tobias Doerffel - * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -22,7 +22,6 @@ * */ - #ifndef _INSTRUMENT_PLAY_HANDLE_H #define _INSTRUMENT_PLAY_HANDLE_H @@ -46,7 +45,10 @@ public: virtual void play( sampleFrame * _working_buffer ) { - m_instrument->play( _working_buffer ); + if( !m_instrument->isMuted() ) + { + m_instrument->play( _working_buffer ); + } } virtual bool done() const diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index 00f28353b..5e231413b 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -31,7 +31,7 @@ #include "lb302.h" #include "automatable_button.h" #include "engine.h" -#include "instrument_play_handle.h" +#include "InstrumentPlayHandle.h" #include "InstrumentTrack.h" #include "knob.h" #include "note_play_handle.h" diff --git a/plugins/lb303/lb303.cpp b/plugins/lb303/lb303.cpp index a41d67691..5c43aff37 100644 --- a/plugins/lb303/lb303.cpp +++ b/plugins/lb303/lb303.cpp @@ -33,7 +33,7 @@ #include "lb303.h" #include "engine.h" -#include "instrument_play_handle.h" +#include "InstrumentPlayHandle.h" #include "InstrumentTrack.h" #include "knob.h" #include "note_play_handle.h" diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index 6bbd5358f..383e3e131 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -33,7 +33,7 @@ #include "sf2_player.h" #include "engine.h" #include "InstrumentTrack.h" -#include "instrument_play_handle.h" +#include "InstrumentPlayHandle.h" #include "note_play_handle.h" #include "knob.h" #include "song.h" diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index e98db13a1..096d3c661 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -33,7 +33,7 @@ #include "engine.h" #include "gui_templates.h" -#include "instrument_play_handle.h" +#include "InstrumentPlayHandle.h" #include "InstrumentTrack.h" #include "VstPlugin.h" #include "pixmap_button.h" @@ -202,12 +202,15 @@ void vestigeInstrument::play( sampleFrame * _buf ) bool vestigeInstrument::handleMidiEvent( const midiEvent & _me, const midiTime & _time ) { - m_pluginMutex.lock(); - if( m_plugin != NULL ) + if( !isMuted() ) { - m_plugin->processMidiEvent( _me, _time ); + m_pluginMutex.lock(); + if( m_plugin != NULL ) + { + m_plugin->processMidiEvent( _me, _time ); + } + m_pluginMutex.unlock(); } - m_pluginMutex.unlock(); return true; } diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index bca946822..e2fa08e05 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -32,7 +32,7 @@ #include "ZynAddSubFx.h" #include "engine.h" #include "mmp.h" -#include "instrument_play_handle.h" +#include "InstrumentPlayHandle.h" #include "InstrumentTrack.h" #include "gui_templates.h" #include "string_pair_drag.h" @@ -232,16 +232,19 @@ void ZynAddSubFxInstrument::play( sampleFrame * _buf ) bool ZynAddSubFxInstrument::handleMidiEvent( const midiEvent & _me, const midiTime & _time ) { - m_pluginMutex.lock(); - if( m_remotePlugin ) + if( !isMuted() ) { - m_remotePlugin->processMidiEvent( _me, 0 ); + m_pluginMutex.lock(); + if( m_remotePlugin ) + { + m_remotePlugin->processMidiEvent( _me, 0 ); + } + else + { + m_plugin->processMidiEvent( _me ); + } + m_pluginMutex.unlock(); } - else - { - m_plugin->processMidiEvent( _me ); - } - m_pluginMutex.unlock(); return true; } diff --git a/src/core/Instrument.cpp b/src/core/Instrument.cpp index daaebb2f6..1f1ed5204 100644 --- a/src/core/Instrument.cpp +++ b/src/core/Instrument.cpp @@ -95,6 +95,15 @@ bool Instrument::isFromTrack( const track * _track ) const + +bool Instrument::isMuted() const +{ + return m_instrumentTrack->isMuted(); +} + + + + void Instrument::applyRelease( sampleFrame * buf, const notePlayHandle * _n ) { const fpp_t frames = _n->framesLeftForCurrentPeriod();