BogaudioModules

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

EQ.cpp (1960B)


      1 
      2 #include "EQ.hpp"
      3 
      4 bool EQ::active() {
      5 	return outputs[OUT_OUTPUT].isConnected();
      6 }
      7 
      8 int EQ::channels() {
      9 	return inputs[IN_INPUT].getChannels();
     10 }
     11 
     12 void EQ::addChannel(int c) {
     13 	_engines[c] = new Engine();
     14 }
     15 
     16 void EQ::removeChannel(int c) {
     17 	delete _engines[c];
     18 	_engines[c] = NULL;
     19 }
     20 
     21 float EQ::knobToDb(Param& p) {
     22 	float v = clamp(p.getValue(), -1.0f, 1.0f);
     23 	if (v < 0.0f) {
     24 		return -v * Engine::cutDb;
     25 	}
     26 	return v * Engine::gainDb;
     27 }
     28 
     29 void EQ::modulate() {
     30 	_lowDb = knobToDb(params[LOW_PARAM]);
     31 	_midDb = knobToDb(params[MID_PARAM]);
     32 	_highDb = knobToDb(params[HIGH_PARAM]);
     33 }
     34 
     35 void EQ::modulateChannel(int c) {
     36 	_engines[c]->setParams(
     37 		APP->engine->getSampleRate(),
     38 		_lowDb,
     39 		_midDb,
     40 		_highDb
     41 	);
     42 }
     43 
     44 void EQ::processAll(const ProcessArgs& args) {
     45 	outputs[OUT_OUTPUT].setChannels(_channels);
     46 }
     47 
     48 void EQ::processChannel(const ProcessArgs& args, int c) {
     49 	outputs[OUT_OUTPUT].setVoltage(_engines[c]->next(inputs[IN_INPUT].getVoltage(c)), c);
     50 }
     51 
     52 struct EQWidget : BGModuleWidget {
     53 	static constexpr int hp = 3;
     54 
     55 	EQWidget(EQ* module) {
     56 		setModule(module);
     57 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     58 		setPanel(box.size, "EQ");
     59 		createScrews();
     60 
     61 		// generated by svg_widgets.rb
     62 		auto lowParamPosition = Vec(8.0, 47.0);
     63 		auto midParamPosition = Vec(8.0, 125.0);
     64 		auto highParamPosition = Vec(8.0, 203.0);
     65 
     66 		auto inInputPosition = Vec(10.5, 267.0);
     67 
     68 		auto outOutputPosition = Vec(10.5, 305.0);
     69 		// end generated by svg_widgets.rb
     70 
     71 		addParam(createParam<Knob29>(lowParamPosition, module, EQ::LOW_PARAM));
     72 		addParam(createParam<Knob29>(midParamPosition, module, EQ::MID_PARAM));
     73 		addParam(createParam<Knob29>(highParamPosition, module, EQ::HIGH_PARAM));
     74 
     75 		addInput(createInput<Port24>(inInputPosition, module, EQ::IN_INPUT));
     76 
     77 		addOutput(createOutput<Port24>(outOutputPosition, module, EQ::OUT_OUTPUT));
     78 	}
     79 };
     80 
     81 Model* modelEQ = createModel<EQ, EQWidget>("Bogaudio-EQ", "EQ", "3-band equalizer", "Equalizer", "Polyphonic");