From 8b9ef85c80ed88fa1a3eb81845d947a257f5056d Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 13 Mar 2013 18:02:45 -0700 Subject: [PATCH] Mixer: Fix bypass for 1 IN 2 out modules. --- mixer/src/Chain.C | 5 +++-- mixer/src/Mono_Pan_Module.C | 13 +++++++++--- mixer/src/Plugin_Module.C | 40 ++++++++++++++++++++++++++++++++++--- mixer/src/Plugin_Module.H | 6 ++++-- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/mixer/src/Chain.C b/mixer/src/Chain.C index d160fb8..785b47f 100644 --- a/mixer/src/Chain.C +++ b/mixer/src/Chain.C @@ -686,7 +686,9 @@ Chain::build_process_queue ( void ) /* connect all the ports to the buffers */ for ( int i = 0; i < modules(); ++i ) { + Module *m = module( i ); + for ( unsigned int j = 0; j < m->audio_input.size(); ++j ) { m->audio_input[j].connect_to( &scratch_port[j] ); @@ -796,8 +798,7 @@ Chain::process ( nframes_t nframes ) { Module *m = *i; - if ( ! m->bypass() ) - m->process( nframes ); + m->process( nframes ); } } diff --git a/mixer/src/Mono_Pan_Module.C b/mixer/src/Mono_Pan_Module.C index 441f689..2108289 100644 --- a/mixer/src/Mono_Pan_Module.C +++ b/mixer/src/Mono_Pan_Module.C @@ -81,8 +81,15 @@ Mono_Pan_Module::process ( nframes_t nframes ) audio_output[0].connected() && audio_output[1].connected() ) { - buffer_copy_and_apply_gain( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes, rg ); - - buffer_apply_gain( (sample_t*)audio_output[0].buffer(), nframes, lg ); + if ( bypass() ) + { + buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes ); + } + else + { + buffer_copy_and_apply_gain( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes, rg ); + + buffer_apply_gain( (sample_t*)audio_output[0].buffer(), nframes, lg ); + } } } diff --git a/mixer/src/Plugin_Module.C b/mixer/src/Plugin_Module.C index aff05d8..47b29ad 100644 --- a/mixer/src/Plugin_Module.C +++ b/mixer/src/Plugin_Module.C @@ -40,8 +40,11 @@ #define HAVE_LIBLRDF 1 #include "LADSPAInfo.h" +#include "Chain.H" #include "Engine/Engine.H" +#include + static LADSPAInfo *ladspainfo; @@ -386,6 +389,18 @@ Plugin_Module::plugin_instances ( unsigned int n ) return true; } +void +Plugin_Module::bypass ( bool v ) +{ + if ( v != bypass() ) + { + if ( v ) + deactivate(); + else + activate(); + } +} + bool Plugin_Module::load ( unsigned long id ) { @@ -654,21 +669,29 @@ Plugin_Module::activate ( void ) if ( _active ) FATAL( "Attempt to activate already active plugin" ); + chain()->engine()->lock(); + if ( _idata->descriptor->activate ) for ( unsigned int i = 0; i < _idata->handle.size(); ++i ) _idata->descriptor->activate( _idata->handle[i] ); _active = true; + + chain()->engine()->unlock(); } void Plugin_Module::deactivate( void ) { - if ( _idata->descriptor->deactivate ) - for ( unsigned int i = 0; i < _idata->handle.size(); ++i ) - _idata->descriptor->activate( _idata->handle[i] ); + chain()->engine()->lock(); _active = false; + + if ( _idata->descriptor->deactivate ) + for ( unsigned int i = 0; i < _idata->handle.size(); ++i ) + _idata->descriptor->deactivate( _idata->handle[i] ); + + chain()->engine()->unlock(); } void @@ -703,8 +726,19 @@ Plugin_Module::process ( nframes_t nframes ) handle_port_connection_change(); if ( _active ) + { for ( unsigned int i = 0; i < _idata->handle.size(); ++i ) _idata->descriptor->run( _idata->handle[i], nframes ); + } + else + { + /* If this is a mono to stereo plugin, then duplicate the input channel... */ + /* There's not much we can do to automatically support other configurations. */ + if ( ninputs() == 1 && noutputs() == 2 ) + { + buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes ); + } + } } diff --git a/mixer/src/Plugin_Module.H b/mixer/src/Plugin_Module.H index e32cafc..2db3e42 100644 --- a/mixer/src/Plugin_Module.H +++ b/mixer/src/Plugin_Module.H @@ -81,7 +81,6 @@ private: void activate ( void ); void deactivate ( void ); void process ( unsigned long nframes ); - bool active ( void ) const { return _active; } bool plugin_instances ( unsigned int ); @@ -109,7 +108,10 @@ public: int can_support_inputs ( int ); bool configure_inputs ( int ); - void process ( nframes_t ); + virtual bool bypass ( void ) const { return !_active; } + virtual void bypass ( bool v ); + + virtual void process ( nframes_t ); void handle_port_connection_change ( void );