BogaudioModules

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

Vish.cpp (4057B)


      1 
      2 #include "Vish.hpp"
      3 
      4 void Vish::Engine::reset() {
      5 	trigger.reset();
      6 	gatePulseGen.process(10.0);
      7 }
      8 
      9 void Vish::reset() {
     10 	for (int c = 0; c < _channels; ++c) {
     11 		_engines[c]->reset();
     12 	}
     13 }
     14 
     15 void Vish::sampleRateChange() {
     16 	_sampleRate = APP->engine->getSampleRate();
     17 	_sampleTime = APP->engine->getSampleTime();
     18 }
     19 
     20 bool Vish::active() {
     21 	return outputs[OUT_OUTPUT].isConnected();
     22 }
     23 
     24 int Vish::channels() {
     25 	return inputs[GATE_INPUT].getChannels();
     26 }
     27 
     28 void Vish::addChannel(int c) {
     29 	_engines[c] = new Engine();
     30 	_engines[c]->reset();
     31 }
     32 
     33 void Vish::removeChannel(int c) {
     34 	delete _engines[c];
     35 	_engines[c] = NULL;
     36 }
     37 
     38 void Vish::modulateChannel(int c) {
     39 	_engines[c]->slew.modulate(
     40 		_sampleRate,
     41 		params[RISE_PARAM],
     42 		&inputs[RISE_INPUT],
     43 		300.0f * _timeScale,
     44 		params[RISE_SHAPE_PARAM],
     45 		params[FALL_PARAM],
     46 		&inputs[FALL_INPUT],
     47 		1000.0f * _timeScale,
     48 		params[FALL_SHAPE_PARAM],
     49 		c,
     50 		false,
     51 		&inputs[SHAPE_INPUT],
     52 		_riseShapeMode,
     53 		_fallShapeMode
     54 	);
     55 }
     56 
     57 void Vish::processChannel(const ProcessArgs& args, int c) {
     58 	Engine& e = *_engines[c];
     59 
     60 	float in = inputs[GATE_INPUT].getPolyVoltage(c);
     61 	if (e.trigger.process(in)) {
     62 		float time = clamp(params[MINIMUM_GATE_PARAM].getValue(), 0.0f, 1.0f);
     63 		if (inputs[MINIMUM_GATE_INPUT].isConnected()) {
     64 			time *= clamp(inputs[MINIMUM_GATE_INPUT].getPolyVoltage(c) / 10.0f, 0.0f, 1.0f);
     65 		}
     66 		time *= time;
     67 		time *= _timeScale;
     68 		e.gateSeconds = time;
     69 
     70 		e.gateElapsedSeconds = 0.0f;
     71 		if (_gateToTrigger) {
     72 			e.gateSeconds = std::max(0.01f, time);
     73 		}
     74 		else {
     75 			e.gateSeconds = time;
     76 		}
     77 	}
     78 	else {
     79 		e.gateElapsedSeconds += _sampleTime;
     80 	}
     81 
     82 	float gate = 0.0f;
     83 	if (e.gateElapsedSeconds < e.gateSeconds) {
     84 		gate = 10.0f;
     85 	}
     86 	else if (!_gateToTrigger) {
     87 		gate = in;
     88 	}
     89 
     90 	outputs[OUT_OUTPUT].setChannels(_channels);
     91 	outputs[OUT_OUTPUT].setVoltage(e.slew.next(gate), c);
     92 }
     93 
     94 struct VishWidget : LPGEnvBaseWidget {
     95 	static constexpr int hp = 5;
     96 
     97 	VishWidget(Vish* module) {
     98 		setModule(module);
     99 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
    100 		setPanel(box.size, "Vish");
    101 		createScrews();
    102 
    103 		// generated by svg_widgets.rb
    104 		auto riseParamPosition = Vec(12.5, 47.0);
    105 		auto riseShapeParamPosition = Vec(52.0, 52.0);
    106 		auto fallParamPosition = Vec(12.5, 111.0);
    107 		auto fallShapeParamPosition = Vec(52.0, 116.0);
    108 		auto minimumGateParamPosition = Vec(23.0, 175.0);
    109 		auto gateToTriggerParamPosition = Vec(57.0, 220.0);
    110 		auto times10xParamPosition = Vec(55.0, 234.0);
    111 
    112 		auto riseInputPosition = Vec(10.5, 251.0);
    113 		auto minimumGateInputPosition = Vec(40.5, 251.0);
    114 		auto fallInputPosition = Vec(10.5, 288.0);
    115 		auto shapeInputPosition = Vec(40.5, 288.0);
    116 		auto gateInputPosition = Vec(10.5, 325.0);
    117 
    118 		auto outOutputPosition = Vec(40.5, 325.0);
    119 		// end generated by svg_widgets.rb
    120 
    121 		addParam(createParam<Knob26>(riseParamPosition, module, Vish::RISE_PARAM));
    122 		addParam(createParam<Knob16>(riseShapeParamPosition, module, Vish::RISE_SHAPE_PARAM));
    123 		addParam(createParam<Knob26>(fallParamPosition, module, Vish::FALL_PARAM));
    124 		addParam(createParam<Knob16>(fallShapeParamPosition, module, Vish::FALL_SHAPE_PARAM));
    125 		addParam(createParam<Knob29>(minimumGateParamPosition, module, Vish::MINIMUM_GATE_PARAM));
    126 		addParam(createParam<IndicatorButtonGreen9>(gateToTriggerParamPosition, module, Vish::GATE_TO_TRIGGER_PARAM));
    127 		addParam(createParam<IndicatorButtonGreen9>(times10xParamPosition, module, Vish::TIMES_10X_PARAM));
    128 
    129 		addInput(createInput<Port24>(riseInputPosition, module, Vish::RISE_INPUT));
    130 		addInput(createInput<Port24>(minimumGateInputPosition, module, Vish::MINIMUM_GATE_INPUT));
    131 		addInput(createInput<Port24>(fallInputPosition, module, Vish::FALL_INPUT));
    132 		addInput(createInput<Port24>(shapeInputPosition, module, Vish::SHAPE_INPUT));
    133 		addInput(createInput<Port24>(gateInputPosition, module, Vish::GATE_INPUT));
    134 
    135 		addOutput(createOutput<Port24>(outOutputPosition, module, Vish::OUT_OUTPUT));
    136 	}
    137 };
    138 
    139 Model* modelVish = createModel<Vish, VishWidget>("Bogaudio-Vish", "VISH", "Vactrol-ish envelope generator", "Envelope generator", "Slew Limiter", "Polyphonic");