BogaudioModules

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

Mix4.hpp (4957B)


      1 #pragma once
      2 
      3 #include "Mix4_shared.hpp"
      4 
      5 using namespace bogaudio::dsp;
      6 
      7 namespace bogaudio {
      8 
      9 struct Mix4 : ExpandableModule<Mix4ExpanderMessage, DimmableMixerModule> {
     10 	enum ParamsIds {
     11 		LEVEL1_PARAM,
     12 		PAN1_PARAM,
     13 		MUTE1_PARAM,
     14 		LEVEL2_PARAM,
     15 		PAN2_PARAM,
     16 		MUTE2_PARAM,
     17 		LEVEL3_PARAM,
     18 		PAN3_PARAM,
     19 		MUTE3_PARAM,
     20 		LEVEL4_PARAM,
     21 		PAN4_PARAM,
     22 		MUTE4_PARAM,
     23 		MIX_PARAM,
     24 		MIX_MUTE_PARAM,
     25 		MIX_DIM_PARAM,
     26 		NUM_PARAMS
     27 	};
     28 
     29 	enum InputsIds {
     30 		CV1_INPUT,
     31 		PAN1_INPUT,
     32 		IN1_INPUT,
     33 		CV2_INPUT,
     34 		PAN2_INPUT,
     35 		IN2_INPUT,
     36 		CV3_INPUT,
     37 		PAN3_INPUT,
     38 		IN3_INPUT,
     39 		CV4_INPUT,
     40 		PAN4_INPUT,
     41 		IN4_INPUT,
     42 		MIX_CV_INPUT,
     43 		NUM_INPUTS
     44 	};
     45 
     46 	enum OutputsIds {
     47 		L_OUTPUT,
     48 		R_OUTPUT,
     49 		NUM_OUTPUTS
     50 	};
     51 
     52 	int _polyChannelOffset = -1;
     53 	MixerChannel* _channels[4] {};
     54 	bool _channelActive[4] {};
     55 	Panner _panners[4];
     56 	bogaudio::dsp::SlewLimiter _panSLs[4];
     57 	Amplifier _amplifier;
     58 	bogaudio::dsp::SlewLimiter _slewLimiter;
     59 	Saturator _saturator;
     60 	RootMeanSquare _rms;
     61 	float _rmsLevel = 0.0f;
     62 	Mix4ExpanderMessage _dummyExpanderMessage;
     63 	int _wasActive = 0;
     64 	bogaudio::dsp::SlewLimiter _levelCVSL;
     65 
     66 	Mix4() {
     67 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     68 		float levelDefault = fabsf(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels);
     69 		configParam(LEVEL1_PARAM, 0.0f, 1.0f, levelDefault, "Channel 1 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     70 		configParam(PAN1_PARAM, -1.0f, 1.0f, 0.0f, "Channel 1 panning", "%", 0.0f, 100.0f);
     71 		configSwitch(MUTE1_PARAM, 0.0f, 3.0f, 0.0f, "Channel 1 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
     72 		configParam(LEVEL2_PARAM, 0.0f, 1.0f, levelDefault, "Channel 2 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     73 		configParam(PAN2_PARAM, -1.0f, 1.0f, 0.0f, "Channel 2 panning", "%", 0.0f, 100.0f);
     74 		configSwitch(MUTE2_PARAM, 0.0f, 3.0f, 0.0f, "Channel 2 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
     75 		configParam(LEVEL3_PARAM, 0.0f, 1.0f, levelDefault, "Channel 3 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     76 		configParam(PAN3_PARAM, -1.0f, 1.0f, 0.0f, "Channel 3 panning", "%", 0.0f, 100.0f);
     77 		configSwitch(MUTE3_PARAM, 0.0f, 3.0f, 0.0f, "Channel 3 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
     78 		configParam(LEVEL4_PARAM, 0.0f, 1.0f, levelDefault, "Channel 4 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     79 		configParam(PAN4_PARAM, -1.0f, 1.0f, 0.0f, "Channel 4 panning", "%", 0.0f, 100.0f);
     80 		configSwitch(MUTE4_PARAM, 0.0f, 3.0f, 0.0f, "Channel 4 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
     81 		configParam(MIX_PARAM, 0.0f, 1.0f, levelDefault, "Master level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     82 		configSwitch(MIX_MUTE_PARAM, 0.0f, 1.0f, 0.0f, "Master mute", {"Unmuted", "Muted"});
     83 		configSwitch<DimSwitchQuantity>(MIX_DIM_PARAM, 0.0f, 1.0f, 0.0f, "Master dim", {"Disabled", "Enabled"});
     84 		getParamQuantity(MUTE1_PARAM)->randomizeEnabled = false;
     85 		getParamQuantity(MUTE2_PARAM)->randomizeEnabled = false;
     86 		getParamQuantity(MUTE3_PARAM)->randomizeEnabled = false;
     87 		getParamQuantity(MUTE4_PARAM)->randomizeEnabled = false;
     88 		getParamQuantity(MIX_MUTE_PARAM)->randomizeEnabled = false;
     89 		getParamQuantity(MIX_DIM_PARAM)->randomizeEnabled = false;
     90 
     91 		configInput(CV1_INPUT, "Channel 1 level CV");
     92 		configInput(PAN1_INPUT, "Channel 1 pan CV");
     93 		configInput(IN1_INPUT, "Channel 1");
     94 		configInput(CV2_INPUT, "Channel 2 level CV");
     95 		configInput(PAN2_INPUT, "Channel 2 pan CV");
     96 		configInput(IN2_INPUT, "Channel 2");
     97 		configInput(CV3_INPUT, "Channel 3 level CV");
     98 		configInput(PAN3_INPUT, "Channel 3 pan CV");
     99 		configInput(IN3_INPUT, "Channel 3");
    100 		configInput(CV4_INPUT, "Channel 4 level CV");
    101 		configInput(PAN4_INPUT, "Channel 4 pan CV");
    102 		configInput(IN4_INPUT, "Channel 4");
    103 		configInput(MIX_CV_INPUT, "Mix level CV");
    104 
    105 		configOutput(L_OUTPUT, "Left signal");
    106 		configOutput(R_OUTPUT, "Right signal");
    107 
    108 		_channels[0] = new MixerChannel(params[LEVEL1_PARAM], params[MUTE1_PARAM], inputs[CV1_INPUT]);
    109 		_channels[1] = new MixerChannel(params[LEVEL2_PARAM], params[MUTE2_PARAM], inputs[CV2_INPUT]);
    110 		_channels[2] = new MixerChannel(params[LEVEL3_PARAM], params[MUTE3_PARAM], inputs[CV3_INPUT]);
    111 		_channels[3] = new MixerChannel(params[LEVEL4_PARAM], params[MUTE4_PARAM], inputs[CV4_INPUT]);
    112 
    113 		sampleRateChange();
    114 		_rms.setSensitivity(0.05f);
    115 		setExpanderModelPredicate([](Model* m) { return m == modelMix4x; });
    116 	}
    117 	virtual ~Mix4() {
    118 		for (int i = 0; i < 4; ++i) {
    119 			delete _channels[i];
    120 		}
    121 	}
    122 
    123 	void onRandomize(const RandomizeEvent& e) override;
    124 	json_t* saveToJson(json_t* root) override;
    125 	void loadFromJson(json_t* root) override;
    126 	void sampleRateChange() override;
    127 	void processAll(const ProcessArgs& args) override;
    128 };
    129 
    130 } // namespace bogaudio