From af60402078055cadd745869efd03a230cbc1c55b Mon Sep 17 00:00:00 2001 From: Vesa Date: Sun, 24 Aug 2014 20:29:43 +0300 Subject: [PATCH] Make it possible to use sample-exact controls in LADSPA plugins I don't think we currently have any that would support this functionality, but in case someone has a LADSPA plugin that has audiorate control ports, this allows them to be used with the new sample-exact models Again... not strictly related to memory management, but since I was in that part of the codebase already... --- include/LadspaControl.h | 2 ++ plugins/LadspaEffect/LadspaEffect.cpp | 29 ++++++++++++++++++--------- src/core/LadspaControl.cpp | 19 ++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/include/LadspaControl.h b/include/LadspaControl.h index 4e50379f7..e9fc424de 100644 --- a/include/LadspaControl.h +++ b/include/LadspaControl.h @@ -30,6 +30,7 @@ #include "AutomatableModel.h" #include "TempoSyncKnobModel.h" +#include "ValueBuffer.h" typedef struct PortDescription port_desc_t; @@ -44,6 +45,7 @@ public: ~LadspaControl(); LADSPA_Data value(); + ValueBuffer * valueBuffer(); void setValue( LADSPA_Data _value ); void setLink( bool _state ); diff --git a/plugins/LadspaEffect/LadspaEffect.cpp b/plugins/LadspaEffect/LadspaEffect.cpp index 9996d28b2..891a49438 100644 --- a/plugins/LadspaEffect/LadspaEffect.cpp +++ b/plugins/LadspaEffect/LadspaEffect.cpp @@ -38,6 +38,7 @@ #include "AutomationPattern.h" #include "ControllerConnection.h" #include "MemoryManager.h" +#include "ValueBuffer.h" #include "embed.cpp" @@ -175,18 +176,28 @@ bool LadspaEffect::processAudioBuffer( sampleFrame * _buf, ++channel; break; case AUDIO_RATE_INPUT: - pp->value = static_cast( - pp->control->value() / pp->scale ); - // This only supports control rate ports, so the audio rates are - // treated as though they were control rate by setting the - // port buffer to all the same value. - for( fpp_t frame = 0; - frame < frames; ++frame ) + { + ValueBuffer * vb = pp->control->valueBuffer(); + if( vb ) { - pp->buffer[frame] = - pp->value; + memcpy( pp->buffer, vb->values(), frames * sizeof(float) ); + } + else + { + pp->value = static_cast( + pp->control->value() / pp->scale ); + // This only supports control rate ports, so the audio rates are + // treated as though they were control rate by setting the + // port buffer to all the same value. + for( fpp_t frame = 0; + frame < frames; ++frame ) + { + pp->buffer[frame] = + pp->value; + } } break; + } case CONTROL_RATE_INPUT: if( pp->control == NULL ) { diff --git a/src/core/LadspaControl.cpp b/src/core/LadspaControl.cpp index 42e74141e..2559fe3d9 100644 --- a/src/core/LadspaControl.cpp +++ b/src/core/LadspaControl.cpp @@ -130,6 +130,25 @@ LADSPA_Data LadspaControl::value() } +ValueBuffer * LadspaControl::valueBuffer() +{ + switch( m_port->data_type ) + { + case TOGGLED: + case INTEGER: + return NULL; + case FLOATING: + return m_knobModel.valueBuffer(); + case TIME: + return m_tempoSyncKnobModel.valueBuffer(); + default: + qWarning( "LadspaControl::valueBuffer(): BAD BAD BAD\n" ); + break; + } + + return NULL; +} + void LadspaControl::setValue( LADSPA_Data _value )