BogaudioModules

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

Mix2.hpp (2107B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "mixer.hpp"
      5 #include "dsp/signal.hpp"
      6 
      7 using namespace bogaudio::dsp;
      8 
      9 extern Model* modelMix2;
     10 
     11 namespace bogaudio {
     12 
     13 struct Mix2 : LinearCVMixerModule {
     14 	enum ParamsIds {
     15 		LEVEL_PARAM,
     16 		MUTE_PARAM,
     17 		NUM_PARAMS
     18 	};
     19 
     20 	enum InputsIds {
     21 		LEVEL_INPUT,
     22 		MUTE_INPUT,
     23 		L_INPUT,
     24 		R_INPUT,
     25 		NUM_INPUTS
     26 	};
     27 
     28 	enum OutputsIds {
     29 		L_OUTPUT,
     30 		R_OUTPUT,
     31 		NUM_OUTPUTS
     32 	};
     33 
     34 	struct Engine {
     35 		MixerChannel left;
     36 		MixerChannel right;
     37 
     38 		Engine(
     39 			Param& levelParam,
     40 			Param& muteParam,
     41 			Input& levelInput,
     42 			Input& muteInput
     43 		)
     44 		: left(levelParam, muteParam, levelInput, 1000.0f, &muteInput)
     45 		, right(levelParam, muteParam, levelInput, 1000.0f, &muteInput)
     46 		{
     47 			float sr = APP->engine->getSampleRate();
     48 			left.setSampleRate(sr);
     49 			right.setSampleRate(sr);
     50 		}
     51 	};
     52 
     53 	Engine* _engines[maxChannels] {};
     54 	float _leftRmsSum = 0.0f;
     55 	float _leftRms = 0.0f;
     56 	float _rightRmsSum = 0.0f;
     57 	float _rightRms = 0.0f;
     58 	int _polyChannelOffset = -1;
     59 
     60 	Mix2() {
     61 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     62 		configParam(LEVEL_PARAM, 0.0f, 1.0f, fabsf(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels), "Level", "dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     63 		configSwitch(MUTE_PARAM, 0.0f, 1.0f, 0.0f, "Mute", {"Unmuted", "Muted"});
     64 
     65 		configInput(LEVEL_INPUT, "Level CV");
     66 		configInput(MUTE_INPUT, "Mute CV");
     67 		configInput(L_INPUT, "Left signal");
     68 		configInput(R_INPUT, "Right signal");
     69 
     70 		configOutput(L_OUTPUT, "Left signal");
     71 		configOutput(R_OUTPUT, "Right signal");
     72 	}
     73 
     74 	json_t* saveToJson(json_t* root) override;
     75 	void loadFromJson(json_t* root) override;
     76 	void sampleRateChange() override;
     77 	bool active() override;
     78 	int channels() override;
     79 	void addChannel(int c) override;
     80 	void removeChannel(int c) override;
     81 	void processAlways(const ProcessArgs& args) override;
     82 	void processChannel(const ProcessArgs& args, int c) override;
     83 	void postProcessAlways(const ProcessArgs& args) override;
     84 	void processBypass(const ProcessArgs& args) override;
     85 };
     86 
     87 } // namespace bogaudio