BogaudioModules

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

Mix8.hpp (7905B)


      1 #pragma once
      2 
      3 #include "Mix8_shared.hpp"
      4 
      5 using namespace bogaudio::dsp;
      6 
      7 namespace bogaudio {
      8 
      9 struct Mix8 : ExpandableModule<Mix8ExpanderMessage, DimmableMixerModule> {
     10 	enum ParamsIds {
     11 		LEVEL1_PARAM,
     12 		MUTE1_PARAM,
     13 		PAN1_PARAM,
     14 		LEVEL2_PARAM,
     15 		MUTE2_PARAM,
     16 		PAN2_PARAM,
     17 		LEVEL3_PARAM,
     18 		MUTE3_PARAM,
     19 		PAN3_PARAM,
     20 		LEVEL4_PARAM,
     21 		MUTE4_PARAM,
     22 		PAN4_PARAM,
     23 		LEVEL5_PARAM,
     24 		MUTE5_PARAM,
     25 		PAN5_PARAM,
     26 		LEVEL6_PARAM,
     27 		MUTE6_PARAM,
     28 		PAN6_PARAM,
     29 		LEVEL7_PARAM,
     30 		MUTE7_PARAM,
     31 		PAN7_PARAM,
     32 		LEVEL8_PARAM,
     33 		MUTE8_PARAM,
     34 		PAN8_PARAM,
     35 		MIX_PARAM,
     36 		MIX_MUTE_PARAM,
     37 		MIX_DIM_PARAM,
     38 		NUM_PARAMS
     39 	};
     40 
     41 	enum InputsIds {
     42 		CV1_INPUT,
     43 		PAN1_INPUT,
     44 		IN1_INPUT,
     45 		CV2_INPUT,
     46 		PAN2_INPUT,
     47 		IN2_INPUT,
     48 		CV3_INPUT,
     49 		PAN3_INPUT,
     50 		IN3_INPUT,
     51 		CV4_INPUT,
     52 		PAN4_INPUT,
     53 		IN4_INPUT,
     54 		CV5_INPUT,
     55 		PAN5_INPUT,
     56 		IN5_INPUT,
     57 		CV6_INPUT,
     58 		PAN6_INPUT,
     59 		IN6_INPUT,
     60 		CV7_INPUT,
     61 		PAN7_INPUT,
     62 		IN7_INPUT,
     63 		CV8_INPUT,
     64 		PAN8_INPUT,
     65 		IN8_INPUT,
     66 		MIX_CV_INPUT,
     67 		NUM_INPUTS
     68 	};
     69 
     70 	enum OutputsIds {
     71 		L_OUTPUT,
     72 		R_OUTPUT,
     73 		NUM_OUTPUTS
     74 	};
     75 
     76 	int _polyChannelOffset = -1;
     77 	MixerChannel* _channels[8] {};
     78 	bool _channelActive[8] {};
     79 	Panner _panners[8];
     80 	bogaudio::dsp::SlewLimiter _panSLs[8];
     81 	Amplifier _amplifier;
     82 	bogaudio::dsp::SlewLimiter _slewLimiter;
     83 	Saturator _saturator;
     84 	RootMeanSquare _rms;
     85 	float _rmsLevel = 0.0f;
     86 	Mix8ExpanderMessage _dummyExpanderMessage;
     87 	int _wasActive = 0;
     88 	bogaudio::dsp::SlewLimiter _levelCVSL;
     89 
     90 	Mix8() {
     91 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     92 		float levelDefault = fabsf(MixerChannel::minDecibels) / (MixerChannel::maxDecibels - MixerChannel::minDecibels);
     93 		configParam(LEVEL1_PARAM, 0.0f, 1.0f, levelDefault, "Channel 1 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     94 		configParam(PAN1_PARAM, -1.0f, 1.0f, 0.0f, "Channel 1 panning", "%", 0.0f, 100.0f);
     95 		configSwitch(MUTE1_PARAM, 0.0f, 3.0f, 0.0f, "Channel 1 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
     96 		configParam(LEVEL2_PARAM, 0.0f, 1.0f, levelDefault, "Channel 2 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
     97 		configParam(PAN2_PARAM, -1.0f, 1.0f, 0.0f, "Channel 2 panning", "%", 0.0f, 100.0f);
     98 		configSwitch(MUTE2_PARAM, 0.0f, 3.0f, 0.0f, "Channel 2 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
     99 		configParam(LEVEL3_PARAM, 0.0f, 1.0f, levelDefault, "Channel 3 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    100 		configParam(PAN3_PARAM, -1.0f, 1.0f, 0.0f, "Channel 3 panning", "%", 0.0f, 100.0f);
    101 		configSwitch(MUTE3_PARAM, 0.0f, 3.0f, 0.0f, "Channel 3 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
    102 		configParam(LEVEL4_PARAM, 0.0f, 1.0f, levelDefault, "Channel 4 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    103 		configParam(PAN4_PARAM, -1.0f, 1.0f, 0.0f, "Channel 4 panning", "%", 0.0f, 100.0f);
    104 		configSwitch(MUTE4_PARAM, 0.0f, 3.0f, 0.0f, "Channel 4 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
    105 		configParam(LEVEL5_PARAM, 0.0f, 1.0f, levelDefault, "Channel 5 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    106 		configParam(PAN5_PARAM, -1.0f, 1.0f, 0.0f, "Channel 5 panning", "%", 0.0f, 100.0f);
    107 		configSwitch(MUTE5_PARAM, 0.0f, 3.0f, 0.0f, "Channel 5 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
    108 		configParam(LEVEL6_PARAM, 0.0f, 1.0f, levelDefault, "Channel 6 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    109 		configParam(PAN6_PARAM, -1.0f, 1.0f, 0.0f, "Channel 6 panning", "%", 0.0f, 100.0f);
    110 		configSwitch(MUTE6_PARAM, 0.0f, 3.0f, 0.0f, "Channel 6 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
    111 		configParam(LEVEL7_PARAM, 0.0f, 1.0f, levelDefault, "Channel 7 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    112 		configParam(PAN7_PARAM, -1.0f, 1.0f, 0.0f, "Channel 7 panning", "%", 0.0f, 100.0f);
    113 		configSwitch(MUTE7_PARAM, 0.0f, 3.0f, 0.0f, "Channel 7 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
    114 		configParam(LEVEL8_PARAM, 0.0f, 1.0f, levelDefault, "Channel 8 level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    115 		configParam(PAN8_PARAM, -1.0f, 1.0f, 0.0f, "Channel 8 panning", "%", 0.0f, 100.0f);
    116 		configSwitch(MUTE8_PARAM, 0.0f, 3.0f, 0.0f, "Channel 8 mute", {"Unmuted", "Muted", "Soloed", "Soloed"});
    117 		configParam(MIX_PARAM, 0.0f, 1.0f, levelDefault, "Master level", " dB", 0.0f, MixerChannel::maxDecibels - MixerChannel::minDecibels, MixerChannel::minDecibels);
    118 		configSwitch(MIX_MUTE_PARAM, 0.0f, 1.0f, 0.0f, "Master mute", {"Unmuted", "Muted"});
    119 		configSwitch<DimSwitchQuantity>(MIX_DIM_PARAM, 0.0f, 1.0f, 0.0f, "Master dim", {"Disabled", "Enabled"});
    120 		getParamQuantity(MUTE1_PARAM)->randomizeEnabled = false;
    121 		getParamQuantity(MUTE2_PARAM)->randomizeEnabled = false;
    122 		getParamQuantity(MUTE3_PARAM)->randomizeEnabled = false;
    123 		getParamQuantity(MUTE4_PARAM)->randomizeEnabled = false;
    124 		getParamQuantity(MUTE5_PARAM)->randomizeEnabled = false;
    125 		getParamQuantity(MUTE6_PARAM)->randomizeEnabled = false;
    126 		getParamQuantity(MUTE7_PARAM)->randomizeEnabled = false;
    127 		getParamQuantity(MUTE8_PARAM)->randomizeEnabled = false;
    128 		getParamQuantity(MIX_MUTE_PARAM)->randomizeEnabled = false;
    129 		getParamQuantity(MIX_DIM_PARAM)->randomizeEnabled = false;
    130 
    131 		configInput(CV1_INPUT, "Channel 1 level CV");
    132 		configInput(PAN1_INPUT, "Channel 1 pan CV");
    133 		configInput(IN1_INPUT, "Channel 1");
    134 		configInput(CV2_INPUT, "Channel 2 level CV");
    135 		configInput(PAN2_INPUT, "Channel 2 pan CV");
    136 		configInput(IN2_INPUT, "Channel 2");
    137 		configInput(CV3_INPUT, "Channel 3 level CV");
    138 		configInput(PAN3_INPUT, "Channel 3 pan CV");
    139 		configInput(IN3_INPUT, "Channel 3");
    140 		configInput(CV4_INPUT, "Channel 4 level CV");
    141 		configInput(PAN4_INPUT, "Channel 4 pan CV");
    142 		configInput(IN4_INPUT, "Channel 4");
    143 		configInput(CV5_INPUT, "Channel 5 level CV");
    144 		configInput(PAN5_INPUT, "Channel 5 pan CV");
    145 		configInput(IN5_INPUT, "Channel 5");
    146 		configInput(CV6_INPUT, "Channel 6 level CV");
    147 		configInput(PAN6_INPUT, "Channel 6 pan CV");
    148 		configInput(IN6_INPUT, "Channel 6");
    149 		configInput(CV7_INPUT, "Channel 7 level CV");
    150 		configInput(PAN7_INPUT, "Channel 7 pan CV");
    151 		configInput(IN7_INPUT, "Channel 7");
    152 		configInput(CV8_INPUT, "Channel 8 level CV");
    153 		configInput(PAN8_INPUT, "Channel 8 pan CV");
    154 		configInput(IN8_INPUT, "Channel 8");
    155 		configInput(MIX_CV_INPUT, "Mix level CV");
    156 
    157 		configOutput(L_OUTPUT, "Left signal");
    158 		configOutput(R_OUTPUT, "Right signal");
    159 
    160 		_channels[0] = new MixerChannel(params[LEVEL1_PARAM], params[MUTE1_PARAM], inputs[CV1_INPUT]);
    161 		_channels[1] = new MixerChannel(params[LEVEL2_PARAM], params[MUTE2_PARAM], inputs[CV2_INPUT]);
    162 		_channels[2] = new MixerChannel(params[LEVEL3_PARAM], params[MUTE3_PARAM], inputs[CV3_INPUT]);
    163 		_channels[3] = new MixerChannel(params[LEVEL4_PARAM], params[MUTE4_PARAM], inputs[CV4_INPUT]);
    164 		_channels[4] = new MixerChannel(params[LEVEL5_PARAM], params[MUTE5_PARAM], inputs[CV5_INPUT]);
    165 		_channels[5] = new MixerChannel(params[LEVEL6_PARAM], params[MUTE6_PARAM], inputs[CV6_INPUT]);
    166 		_channels[6] = new MixerChannel(params[LEVEL7_PARAM], params[MUTE7_PARAM], inputs[CV7_INPUT]);
    167 		_channels[7] = new MixerChannel(params[LEVEL8_PARAM], params[MUTE8_PARAM], inputs[CV8_INPUT]);
    168 
    169 		sampleRateChange();
    170 		_rms.setSensitivity(0.05f);
    171 		setExpanderModelPredicate([](Model* m) { return m == modelMix8x; });
    172 	}
    173 	virtual ~Mix8() {
    174 		for (int i = 0; i < 8; ++i) {
    175 			delete _channels[i];
    176 		}
    177 	}
    178 
    179 	void onRandomize(const RandomizeEvent& e) override;
    180 	json_t* saveToJson(json_t* root) override;
    181 	void loadFromJson(json_t* root) override;
    182 	void sampleRateChange() override;
    183 	void processAll(const ProcessArgs& args) override;
    184 };
    185 
    186 } // namespace bogaudio