BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

Velo.hpp (1778B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "dsp/signal.hpp"
      5 
      6 using namespace bogaudio::dsp;
      7 
      8 extern Model* modelVelo;
      9 
     10 namespace bogaudio {
     11 
     12 struct Velo : BGModule {
     13 	enum ParamsIds {
     14 		LEVEL_PARAM,
     15 		LEVEL_ATTENUATOR_PARAM,
     16 		VELOCITY_PARAM,
     17 		LINEAR_PARAM,
     18 		NUM_PARAMS
     19 	};
     20 
     21 	enum InputsIds {
     22 		LEVEL_INPUT,
     23 		CV_INPUT,
     24 		VELOCITY_INPUT,
     25 		IN_INPUT,
     26 		NUM_INPUTS
     27 	};
     28 
     29 	enum OutputsIds {
     30 		OUT_OUTPUT,
     31 		NUM_OUTPUTS
     32 	};
     33 
     34 	struct LevelParamQuantity : AmplifierParamQuantity {
     35 		bool isLinear() override;
     36 	};
     37 
     38 	Amplifier _amplifier[maxChannels];
     39 	bogaudio::dsp::SlewLimiter _levelSL[maxChannels];
     40 	Amplifier _velocity[maxChannels];
     41 	bogaudio::dsp::SlewLimiter _velocitySL[maxChannels];
     42 	Saturator _saturator[maxChannels];
     43 	float _velocityDb = 0.0f;
     44 	bool _levelScalesCV = true;
     45 
     46 	Velo() {
     47 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     48 		configParam<LevelParamQuantity>(LEVEL_PARAM, 0.0f, 1.0f, 0.8f, "level");
     49 		configParam(LEVEL_ATTENUATOR_PARAM, -1.0f, 1.0f, 0.0f, "Level CV");
     50 		configParam<ScaledSquaringParamQuantity<-60>>(VELOCITY_PARAM, 0.0f, 1.0f, SQUARE_ROOT_ONE_TENTH, "Velocity range", " dB");
     51 		configSwitch(LINEAR_PARAM, 0.0f, 1.0f, 0.0f, "Linear", {"Disabled", "Enabled"});
     52 		configBypass(IN_INPUT, OUT_OUTPUT);
     53 
     54 		configInput(LEVEL_INPUT, "Level unipolar CV");
     55 		configInput(CV_INPUT, "Level bipolar CV");
     56 		configInput(VELOCITY_INPUT, "Velocity CV");
     57 		configInput(IN_INPUT, "Signal");
     58 
     59 		configOutput(OUT_OUTPUT, "Signal");
     60 	}
     61 
     62 	inline bool isLinear() { return params[LINEAR_PARAM].getValue() > 0.5f; }
     63 	void sampleRateChange() override;
     64 	json_t* saveToJson(json_t* root) override;
     65 	void loadFromJson(json_t* root) override;
     66 	bool active() override;
     67 	void modulate() override;
     68 	void processAll(const ProcessArgs& args) override;
     69 };
     70 
     71 } // namespace bogaudio