BogaudioModules

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

CVD.cpp (2793B)


      1 
      2 #include "CVD.hpp"
      3 
      4 void CVD::Engine::sampleRateChange() {
      5 	delay.setSampleRate(APP->engine->getSampleRate());
      6 }
      7 
      8 void CVD::sampleRateChange() {
      9 	for (int c = 0; c < _channels; ++c) {
     10 		_engines[c]->sampleRateChange();
     11 	}
     12 }
     13 
     14 int CVD::channels() {
     15 	return inputs[IN_INPUT].getChannels();
     16 }
     17 
     18 void CVD::addChannel(int c) {
     19 	_engines[c] = new Engine();
     20 	_engines[c]->sampleRateChange();
     21 }
     22 
     23 void CVD::removeChannel(int c) {
     24 	delete _engines[c];
     25 	_engines[c] = NULL;
     26 }
     27 
     28 void CVD::modulateChannel(int c) {
     29 	Engine& e = *_engines[c];
     30 
     31 	float time = params[TIME_PARAM].getValue();
     32 	if (inputs[TIME_INPUT].isConnected()) {
     33 		time *= clamp(inputs[TIME_INPUT].getPolyVoltage(c) / 10.0f, 0.0f, 1.0f);
     34 	}
     35 	switch ((int)roundf(params[TIME_SCALE_PARAM].getValue())) {
     36 		case 0: {
     37 			time /= 100.f;
     38 			break;
     39 		}
     40 		case 1: {
     41 			time /= 10.f;
     42 			break;
     43 		}
     44 	}
     45 	e.delay.setTime(time);
     46 
     47 	float mix = params[MIX_PARAM].getValue();
     48 	if (inputs[MIX_INPUT].isConnected()) {
     49 		mix = clamp(mix + inputs[MIX_INPUT].getPolyVoltage(c) / 5.0f, -1.0f, 1.0f);
     50 	}
     51 	e.mix.setParams(mix);
     52 }
     53 
     54 void CVD::processChannel(const ProcessArgs& args, int c) {
     55 	Engine& e = *_engines[c];
     56 
     57 	float in = inputs[IN_INPUT].getPolyVoltage(c);
     58 	float delayed = e.delay.next(in);
     59 	outputs[OUT_OUTPUT].setChannels(_channels);
     60 	outputs[OUT_OUTPUT].setVoltage(e.mix.next(in, delayed), c);
     61 }
     62 
     63 struct CVDWidget : BGModuleWidget {
     64 	static constexpr int hp = 3;
     65 
     66 	CVDWidget(CVD* module) {
     67 		setModule(module);
     68 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     69 		setPanel(box.size, "CVD");
     70 		createScrews();
     71 
     72 		// generated by svg_widgets.rb
     73 		auto timeParamPosition = Vec(8.0, 36.0);
     74 		auto timeScaleParamPosition = Vec(14.5, 84.0);
     75 		auto mixParamPosition = Vec(8.0, 176.0);
     76 
     77 		auto timeInputPosition = Vec(10.5, 107.0);
     78 		auto mixInputPosition = Vec(10.5, 217.0);
     79 		auto inInputPosition = Vec(10.5, 267.0);
     80 
     81 		auto outOutputPosition = Vec(10.5, 305.0);
     82 		// end generated by svg_widgets.rb
     83 
     84 		addParam(createParam<Knob29>(timeParamPosition, module, CVD::TIME_PARAM));
     85 		{
     86 			auto w = createParam<Knob16>(timeScaleParamPosition, module, CVD::TIME_SCALE_PARAM);
     87 			auto k = dynamic_cast<SvgKnob*>(w);
     88 			k->minAngle = -M_PI / 4.0f;
     89 			k->maxAngle = M_PI / 4.0f;
     90 			k->speed = 3.0;
     91 			addParam(w);
     92 		}
     93 		addParam(createParam<Knob29>(mixParamPosition, module, CVD::MIX_PARAM));
     94 
     95 		addInput(createInput<Port24>(timeInputPosition, module, CVD::TIME_INPUT));
     96 		addInput(createInput<Port24>(mixInputPosition, module, CVD::MIX_INPUT));
     97 		addInput(createInput<Port24>(inInputPosition, module, CVD::IN_INPUT));
     98 
     99 		addOutput(createOutput<Port24>(outOutputPosition, module, CVD::OUT_OUTPUT));
    100 	}
    101 };
    102 
    103 Model* modelCVD = bogaudio::createModel<CVD, CVDWidget>("Bogaudio-CVD", "CVD", "Simple delay designed for triggers and other CVs", "Delay", "Polyphonic");