From c1785f5a14bc7388618c979474adefdb06d3dd17 Mon Sep 17 00:00:00 2001 From: Martin Zuther Date: Fri, 10 Jul 2020 16:32:39 +0200 Subject: [PATCH] re-order functions in file --- src/ProtoFaust.cpp | 162 +++++++++++++++++++-------------------- src/ProtoFaustWidget.cpp | 4 +- 2 files changed, 80 insertions(+), 86 deletions(-) diff --git a/src/ProtoFaust.cpp b/src/ProtoFaust.cpp index 52a2d18..630c708 100644 --- a/src/ProtoFaust.cpp +++ b/src/ProtoFaust.cpp @@ -165,6 +165,77 @@ ProtoFaust::ProtoFaust() } +void ProtoFaust::onAdd() +{ + FaustDSP.buildUserInterface( &FaustUI ); + + // store GUI IDs to save time during processing + for ( auto& widget : activeWidgets ) { + attachFaustParameter( widget ); + } + + for ( auto& widget : passiveWidgets ) { + attachFaustParameter( widget ); + } + + FaustDSP.init( + APP->engine->getSampleRate() ); +} + + +void ProtoFaust::onSampleRateChange() +{ + FaustDSP.instanceConstants( + APP->engine->getSampleRate() ); +} + + +void ProtoFaust::process( const ProcessArgs& /* args (unused) */ ) +{ + std::vector temporaryInputs( numberOfChannels ); + std::vector temporaryOutputs( numberOfChannels ); + + // read from module's inputs; scale voltages from Rack to usual + // range in DSP processing (-1.0 to +1.0) so you don't have to + // adjust algorithms when porting them to VCV Rack + for ( auto channel = 0; channel < numberOfChannels; channel++ ) { + FAUSTFLOAT input = inputs[IN_1_INPUT + channel].getVoltage(); + temporaryInputs[channel] = input / voltageScaling; + + // protect your ears in case of misbehaviour + temporaryOutputs[channel] = 0.0; + } + + // get widget values and update Faust parameters + for ( auto& widget : activeWidgets ) { + updateParameter( widget ); + } + + // update Faust controls + int int_control[FaustDSP.getNumIntControls()]; + FAUSTFLOAT real_control[FaustDSP.getNumRealControls()]; + FaustDSP.control( int_control, real_control ); + + // process one sample in Faust + FaustDSP.compute( temporaryInputs.data(), + temporaryOutputs.data(), + int_control, + real_control ); + + // write to module's outputs; scale voltages from DSP processing + // back to Rack voltages (-5.0 to +5.0) + for ( auto channel = 0; channel < numberOfChannels; channel++ ) { + FAUSTFLOAT output = temporaryOutputs[channel]; + outputs[OUT_1_OUTPUT + channel].setVoltage( output * voltageScaling ); + } + + // get widget values and update Faust parameters + for ( auto& widget : passiveWidgets ) { + updateParameter( widget ); + } +} + + void ProtoFaust::addParameter( std::vector& widgets, int widgetType, int parameterId, @@ -239,90 +310,6 @@ void ProtoFaust::addParameterLed( std::vector& widgets, } -void ProtoFaust::onAdd() -{ - FaustDSP.buildUserInterface( &FaustUI ); - - // store GUI IDs to save time during processing - for ( auto& widget : activeWidgets ) { - attachFaustParameter( widget ); - } - - for ( auto& widget : passiveWidgets ) { - attachFaustParameter( widget ); - } - - FaustDSP.init( - APP->engine->getSampleRate() ); -} - - -void ProtoFaust::attachFaustParameter( WidgetAccess& widget ) -{ - widget.faustId = FaustUI.getParamIndex( - widget.faustStringId.c_str() ); -} - - -void ProtoFaust::onSampleRateChange() -{ - FaustDSP.instanceConstants( - APP->engine->getSampleRate() ); -} - - -void ProtoFaust::process( const ProcessArgs& /* args (unused) */ ) -{ - std::vector temporaryInputs( numberOfChannels ); - std::vector temporaryOutputs( numberOfChannels ); - - // read from module's inputs - for ( auto channel = 0; channel < numberOfChannels; channel++ ) { - FAUSTFLOAT input = inputs[IN_1_INPUT + channel].getVoltage(); - - // scale voltages from Rack to usual range in DSP processing - // (-1.0 to +1.0) so you don't have to adjust algorithms when - // porting them to VCV Rack - temporaryInputs[channel] = input / voltageScaling; - - // protect your ears in case of misbehaviour - temporaryOutputs[channel] = 0.0; - } - - // get widget values and update Faust parameters - for ( auto& widget : activeWidgets ) { - updateParameter( widget ); - } - - // update Faust controls - int int_control[FaustDSP.getNumIntControls()]; - FAUSTFLOAT real_control[FaustDSP.getNumRealControls()]; - - FaustDSP.control( int_control, real_control ); - - // process one sample in Faust - FaustDSP.compute( temporaryInputs.data(), - temporaryOutputs.data(), - int_control, - real_control ); - - // write to module's outputs - for ( auto channel = 0; channel < numberOfChannels; channel++ ) { - FAUSTFLOAT output = temporaryOutputs[channel]; - - // scale voltages from DSP processing back to Rack voltages - // (-5.0 to +5.0) - outputs[OUT_1_OUTPUT + channel].setVoltage( - output * voltageScaling ); - } - - // get widget values and update Faust parameters - for ( auto& widget : passiveWidgets ) { - updateParameter( widget ); - } -} - - void ProtoFaust::updateParameter( WidgetAccess& widget ) { switch ( widget.widgetType ) { @@ -359,5 +346,12 @@ void ProtoFaust::updateParameter( WidgetAccess& widget ) } +void ProtoFaust::attachFaustParameter( WidgetAccess& widget ) +{ + widget.faustId = FaustUI.getParamIndex( + widget.faustStringId.c_str() ); +} + + Model* modelProtoFaust = createModel( "ProtoFaust" ); diff --git a/src/ProtoFaustWidget.cpp b/src/ProtoFaustWidget.cpp index 8909f4d..a8f71b3 100644 --- a/src/ProtoFaustWidget.cpp +++ b/src/ProtoFaustWidget.cpp @@ -27,6 +27,8 @@ #include "Amalgamated.hpp" +// "repetitive" takes on a whole new meaning in this file ... + ProtoFaustWidget::ProtoFaustWidget( ProtoFaust* module ) : _module( module ) { @@ -34,8 +36,6 @@ ProtoFaustWidget::ProtoFaustWidget( ProtoFaust* module ) : setPanel( APP->window->loadSvg( asset::plugin( pluginInstance, "res/ProtoFaust.svg" ) ) ); - // "repetitive" takes on a whole new meaning here - // ------ screws ------ placeWidget( ProtoFaustWidget::SCREW,