BogaudioModules

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

Shaper.cpp (4725B)


      1 
      2 #include "Shaper.hpp"
      3 
      4 void Shaper::reset() {
      5 	for (int c = 0; c < _channels; ++c) {
      6 		_core[c]->reset();
      7 	}
      8 }
      9 
     10 int Shaper::channels() {
     11 	return inputs[TRIGGER_INPUT].getChannels();
     12 }
     13 
     14 void Shaper::addChannel(int c) {
     15 	_core[c] = new ShaperCore(
     16 		params[ATTACK_PARAM],
     17 		params[ON_PARAM],
     18 		params[DECAY_PARAM],
     19 		params[OFF_PARAM],
     20 		params[ENV_PARAM],
     21 		params[SIGNAL_PARAM],
     22 		params[TRIGGER_PARAM],
     23 		params[SPEED_PARAM],
     24 		params[LOOP_PARAM],
     25 
     26 		inputs[SIGNAL_INPUT],
     27 		inputs[TRIGGER_INPUT],
     28 		NULL,
     29 		NULL,
     30 		NULL,
     31 		NULL,
     32 		NULL,
     33 		NULL,
     34 
     35 		outputs[SIGNAL_OUTPUT],
     36 		outputs[ENV_OUTPUT],
     37 		outputs[INV_OUTPUT],
     38 		outputs[TRIGGER_OUTPUT],
     39 		NULL,
     40 		NULL,
     41 		NULL,
     42 		NULL,
     43 
     44 		_attackLights,
     45 		_onLights,
     46 		_decayLights,
     47 		_offLights,
     48 
     49 		_triggerOnLoad,
     50 		_shouldTriggerOnLoad
     51 	);
     52 }
     53 
     54 void Shaper::removeChannel(int c) {
     55 	delete _core[c];
     56 	_core[c] = NULL;
     57 }
     58 
     59 void Shaper::processChannel(const ProcessArgs& args, int c) {
     60 	_core[c]->step(c, _channels);
     61 }
     62 
     63 void Shaper::postProcess(const ProcessArgs& args) {
     64 	float attackSum = 0.0f;
     65 	float onSum = 0.0f;
     66 	float decaySum = 0.0f;
     67 	float offSum = 0.0f;
     68 	for (int c = 0; c < _channels; ++c) {
     69 		attackSum += _attackLights[c];
     70 		onSum += _onLights[c];
     71 		decaySum += _decayLights[c];
     72 		offSum += _offLights[c];
     73 	}
     74 	lights[ATTACK_LIGHT].value = attackSum * _inverseChannels;
     75 	lights[ON_LIGHT].value = onSum * _inverseChannels;
     76 	lights[DECAY_LIGHT].value = decaySum * _inverseChannels;
     77 	lights[OFF_LIGHT].value = offSum * _inverseChannels;
     78 }
     79 
     80 bool Shaper::shouldTriggerOnNextLoad() {
     81 	for (int c = 0; c < _channels; ++c) {
     82 		if (_core[c] && _core[c]->_stage != _core[c]->STOPPED_STAGE) {
     83 			return true;
     84 		}
     85 	}
     86 	return false;
     87 }
     88 
     89 struct ShaperWidget : TriggerOnLoadModuleWidget {
     90 	static constexpr int hp = 10;
     91 
     92 	ShaperWidget(Shaper* module) {
     93 		setModule(module);
     94 		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
     95 		setPanel(box.size, "Shaper");
     96 		createScrews();
     97 
     98 		// generated by svg_widgets.rb
     99 		auto attackParamPosition = Vec(29.0, 33.0);
    100 		auto triggerParamPosition = Vec(89.0, 43.0);
    101 		auto onParamPosition = Vec(29.0, 89.0);
    102 		auto speedParamPosition = Vec(118.5, 95.5);
    103 		auto decayParamPosition = Vec(29.0, 145.0);
    104 		auto loopParamPosition = Vec(118.5, 151.5);
    105 		auto offParamPosition = Vec(29.0, 201.0);
    106 		auto envParamPosition = Vec(82.3, 257.0);
    107 		auto signalParamPosition = Vec(82.3, 313.0);
    108 
    109 		auto triggerInputPosition = Vec(114.0, 40.0);
    110 		auto signalInputPosition = Vec(11.5, 320.0);
    111 
    112 		auto triggerOutputPosition = Vec(114.0, 208.0);
    113 		auto envOutputPosition = Vec(11.5, 264.0);
    114 		auto invOutputPosition = Vec(40.5, 264.0);
    115 		auto signalOutputPosition = Vec(40.5, 320.0);
    116 
    117 		auto attackLightPosition = Vec(12.0, 80.0);
    118 		auto onLightPosition = Vec(12.0, 121.0);
    119 		auto decayLightPosition = Vec(12.0, 189.0);
    120 		auto offLightPosition = Vec(12.0, 237.0);
    121 		// end generated by svg_widgets.rb
    122 
    123 		addParam(createParam<Knob38>(attackParamPosition, module, Shaper::ATTACK_PARAM));
    124 		addParam(createParam<Knob38>(onParamPosition, module, Shaper::ON_PARAM));
    125 		addParam(createParam<Knob38>(decayParamPosition, module, Shaper::DECAY_PARAM));
    126 		addParam(createParam<Knob38>(offParamPosition, module, Shaper::OFF_PARAM));
    127 		addParam(createParam<Knob38>(envParamPosition, module, Shaper::ENV_PARAM));
    128 		addParam(createParam<Knob38>(signalParamPosition, module, Shaper::SIGNAL_PARAM));
    129 
    130 		addParam(createParam<Button18>(triggerParamPosition, module, Shaper::TRIGGER_PARAM));
    131 		addInput(createInput<Port24>(triggerInputPosition, module, Shaper::TRIGGER_INPUT));
    132 
    133 		addParam(createParam<SliderSwitch2State14>(speedParamPosition, module, Shaper::SPEED_PARAM));
    134 		addParam(createParam<SliderSwitch2State14>(loopParamPosition, module, Shaper::LOOP_PARAM));
    135 		addOutput(createOutput<Port24>(triggerOutputPosition, module, Shaper::TRIGGER_OUTPUT));
    136 
    137 		addOutput(createOutput<Port24>(envOutputPosition, module, Shaper::ENV_OUTPUT));
    138 		addOutput(createOutput<Port24>(invOutputPosition, module, Shaper::INV_OUTPUT));
    139 
    140 		addInput(createInput<Port24>(signalInputPosition, module, Shaper::SIGNAL_INPUT));
    141 		addOutput(createOutput<Port24>(signalOutputPosition, module, Shaper::SIGNAL_OUTPUT));
    142 
    143 		addChild(createLight<BGTinyLight<GreenLight>>(attackLightPosition, module, Shaper::ATTACK_LIGHT));
    144 		addChild(createLight<BGTinyLight<GreenLight>>(onLightPosition, module, Shaper::ON_LIGHT));
    145 		addChild(createLight<BGTinyLight<GreenLight>>(decayLightPosition, module, Shaper::DECAY_LIGHT));
    146 		addChild(createLight<BGTinyLight<GreenLight>>(offLightPosition, module, Shaper::OFF_LIGHT));
    147 	}
    148 };
    149 
    150 Model* modelShaper = bogaudio::createModel<Shaper, ShaperWidget>("Bogaudio-Shaper", "SHAPER", "Retro-inspired envelope generator and amplifier", "Envelope generator", "VCA", "Polyphonic");