You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9KB

  1. #include "aepelzen.hpp"
  2. #include "dsp/digital.hpp"
  3. #define NUM_CHANNELS 4
  4. struct Werner : Module {
  5. enum ParamIds {
  6. TIME_PARAM,
  7. DELTA_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. CV_INPUT,
  12. NUM_INPUTS = NUM_CHANNELS
  13. };
  14. enum OutputIds {
  15. GATE_OUTPUT,
  16. NUM_OUTPUTS = NUM_CHANNELS
  17. };
  18. enum LightIds {
  19. NUM_LIGHTS
  20. };
  21. Werner() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  22. void step() override;
  23. PulseGenerator gatePulse[NUM_CHANNELS];
  24. float lastValue[NUM_CHANNELS];
  25. int res = 16;
  26. float minDelta = 0;
  27. int frame = 0;
  28. };
  29. void Werner::step() {
  30. //max time is about 100ms at 44kHz
  31. res = (int)clamp(params[TIME_PARAM].value * 4400.0f, 16.0f, 4400.0f);
  32. minDelta = params[DELTA_PARAM].value * 2.0f;
  33. if(++frame > res) {
  34. for(int i=0; i<NUM_CHANNELS;i++) {
  35. float value = inputs[CV_INPUT + i].value;
  36. if(abs(value - lastValue[i]) > minDelta) {
  37. gatePulse[i].trigger(0.01);
  38. }
  39. lastValue[i] = value;
  40. }
  41. frame = 0;
  42. }
  43. for(int i=0; i<NUM_CHANNELS;i++) {
  44. outputs[GATE_OUTPUT + i].value = gatePulse[i].process(1.0 / engineGetSampleRate()) ? 10.0 : 0.0;
  45. }
  46. }
  47. struct WernerWidget : ModuleWidget
  48. {
  49. WernerWidget(Werner *module);
  50. };
  51. WernerWidget::WernerWidget(Werner *module) : ModuleWidget(module) {
  52. setPanel(SVG::load(assetPlugin(plugin, "res/Werner.svg")));
  53. addParam(ParamWidget::create<Trimpot>(Vec(6, 30), module, Werner::TIME_PARAM, 0.0, 1.0, 0.0));
  54. addParam(ParamWidget::create<Trimpot>(Vec(6, 75), module, Werner::DELTA_PARAM, 0.0, 1.0, 0.0));
  55. for(int i=0;i<NUM_CHANNELS;i++) {
  56. addInput(Port::create<PJ301MPort>(Vec(3, 125 + i*30), Port::INPUT, module, Werner::CV_INPUT + i));
  57. addOutput(Port::create<PJ301MPort>(Vec(3, 250 + i*30), Port::OUTPUT, module, Werner::GATE_OUTPUT + i));
  58. }
  59. }
  60. Model *modelWerner = Model::create<Werner, WernerWidget>("Aepelzens Modules", "Werner", "CV-to-Trigger", UTILITY_TAG);