BogaudioModules

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

Follow.cpp (2077B)


      1 
      2 #include "Follow.hpp"
      3 
      4 bool Follow::active() {
      5 	return inputs[IN_INPUT].isConnected() && outputs[OUT_OUTPUT].isConnected();
      6 }
      7 
      8 int Follow::channels() {
      9 	return inputs[IN_INPUT].getChannels();
     10 }
     11 
     12 void Follow::addChannel(int c) {
     13 	_engines[c] = new Engine;
     14 }
     15 
     16 void Follow::removeChannel(int c) {
     17 	delete _engines[c];
     18 	_engines[c] = NULL;
     19 }
     20 
     21 void Follow::modulateChannel(int c) {
     22 	Engine& e = *_engines[c];
     23 	e.follower.setParams(APP->engine->getSampleRate(), sensitivity(params[RESPONSE_PARAM], &inputs[RESPONSE_INPUT], c));
     24 	e.gain.setLevel(gain(params[GAIN_PARAM], &inputs[GAIN_INPUT], c));
     25 }
     26 
     27 void Follow::processChannel(const ProcessArgs& args, int c) {
     28 	Engine& e = *_engines[c];
     29 	outputs[OUT_OUTPUT].setChannels(_channels);
     30 	outputs[OUT_OUTPUT].setVoltage(_saturator.next(e.gain.next(e.follower.next(inputs[IN_INPUT].getVoltage(c)))), c);
     31 }
     32 
     33 struct FollowWidget : BGModuleWidget {
     34 	static constexpr int hp = 3;
     35 
     36 	FollowWidget(Follow* module) {
     37 		setModule(module);
     38 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     39 		setPanel(box.size, "Follow");
     40 		createScrews();
     41 
     42 		// generated by svg_widgets.rb
     43 		auto responseParamPosition = Vec(8.0, 36.0);
     44 		auto gainParamPosition = Vec(8.0, 142.0);
     45 
     46 		auto responseInputPosition = Vec(10.5, 77.0);
     47 		auto gainInputPosition = Vec(10.5, 183.0);
     48 		auto inInputPosition = Vec(10.5, 233.0);
     49 
     50 		auto outOutputPosition = Vec(10.5, 271.0);
     51 		// end generated by svg_widgets.rb
     52 
     53 		addParam(createParam<Knob29>(responseParamPosition, module, Follow::RESPONSE_PARAM));
     54 		addParam(createParam<Knob29>(gainParamPosition, module, Follow::GAIN_PARAM));
     55 
     56 		addInput(createInput<Port24>(responseInputPosition, module, Follow::RESPONSE_INPUT));
     57 		addInput(createInput<Port24>(gainInputPosition, module, Follow::GAIN_INPUT));
     58 		addInput(createInput<Port24>(inInputPosition, module, Follow::IN_INPUT));
     59 
     60 		addOutput(createOutput<Port24>(outOutputPosition, module, Follow::OUT_OUTPUT));
     61 	}
     62 };
     63 
     64 Model* modelFollow = bogaudio::createModel<Follow, FollowWidget>("Bogaudio-Follow", "FOLLOW", "Envelope follower", "Envelope follower", "Polyphonic");