BogaudioModules

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

Lag.cpp (2442B)


      1 
      2 #include "Lag.hpp"
      3 
      4 bool Lag::active() {
      5 	return inputs[IN_INPUT].isConnected() && outputs[OUT_OUTPUT].isConnected();
      6 }
      7 
      8 void Lag::modulate() {
      9 	float time = params[TIME_PARAM].getValue();
     10 	if (inputs[TIME_INPUT].isConnected()) {
     11 		time *= clamp(inputs[TIME_INPUT].getVoltage() / 10.0f, 0.0f, 1.0f);
     12 	}
     13 	switch ((int)roundf(params[TIME_SCALE_PARAM].getValue())) {
     14 		case 0: {
     15 			time /= 10.f;
     16 			break;
     17 		}
     18 		case 2: {
     19 			time *= 10.f;
     20 			break;
     21 		}
     22 	}
     23 	time *= 1000.0f;
     24 
     25 	float shape = params[SHAPE_PARAM].getValue();
     26 	if (inputs[SHAPE_INPUT].isConnected()) {
     27 		shape *= clamp(inputs[SHAPE_INPUT].getVoltage() / 5.0f, -1.0f, 1.0f);
     28 	}
     29 	if (shape < 0.0) {
     30 		shape = 1.0f + shape;
     31 		shape = _slew.minShape + shape * (1.0f - _slew.minShape);
     32 	}
     33 	else {
     34 		shape *= _slew.maxShape - 1.0f;
     35 		shape += 1.0f;
     36 	}
     37 
     38 	_slew.setParams(APP->engine->getSampleRate(), time, shape);
     39 }
     40 
     41 void Lag::processAll(const ProcessArgs& args) {
     42 	outputs[OUT_OUTPUT].setVoltage(_slew.next(inputs[IN_INPUT].getVoltageSum()));
     43 }
     44 
     45 struct LagWidget : BGModuleWidget {
     46 	static constexpr int hp = 3;
     47 
     48 	LagWidget(Lag* module) {
     49 		setModule(module);
     50 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     51 		setPanel(box.size, "Lag");
     52 		createScrews();
     53 
     54 		// generated by svg_widgets.rb
     55 		auto timeParamPosition = Vec(8.0, 36.0);
     56 		auto timeScaleParamPosition = Vec(14.5, 84.0);
     57 		auto shapeParamPosition = Vec(8.0, 176.0);
     58 
     59 		auto timeInputPosition = Vec(10.5, 107.0);
     60 		auto shapeInputPosition = Vec(10.5, 217.0);
     61 		auto inInputPosition = Vec(10.5, 267.0);
     62 
     63 		auto outOutputPosition = Vec(10.5, 305.0);
     64 		// end generated by svg_widgets.rb
     65 
     66 		addParam(createParam<Knob29>(timeParamPosition, module, Lag::TIME_PARAM));
     67 		{
     68 			auto w = createParam<Knob16>(timeScaleParamPosition, module, Lag::TIME_SCALE_PARAM);
     69 			auto k = dynamic_cast<SvgKnob*>(w);
     70 			k->minAngle = -M_PI / 4.0f;
     71 			k->maxAngle = M_PI / 4.0f;
     72 			k->speed = 3.0;
     73 			addParam(w);
     74 		}
     75 		addParam(createParam<Knob29>(shapeParamPosition, module, Lag::SHAPE_PARAM));
     76 
     77 		addInput(createInput<Port24>(timeInputPosition, module, Lag::TIME_INPUT));
     78 		addInput(createInput<Port24>(shapeInputPosition, module, Lag::SHAPE_INPUT));
     79 		addInput(createInput<Port24>(inInputPosition, module, Lag::IN_INPUT));
     80 
     81 		addOutput(createOutput<Port24>(outOutputPosition, module, Lag::OUT_OUTPUT));
     82 	}
     83 };
     84 
     85 Model* modelLag = bogaudio::createModel<Lag, LagWidget>("Bogaudio-Lag", "Lag", "Slew limiter / lag processor", "Slew limiter");