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.

155 lines
3.0KB

  1. #include "ML_modules.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_ML_modules {
  4. struct OctaTrig : Module {
  5. enum ParamIds {
  6. RESET_PARAM,
  7. NUM_PARAMS
  8. };
  9. enum InputIds {
  10. IN1_INPUT,
  11. IN2_INPUT,
  12. IN3_INPUT,
  13. IN4_INPUT,
  14. IN5_INPUT,
  15. IN6_INPUT,
  16. IN7_INPUT,
  17. IN8_INPUT,
  18. NUM_INPUTS
  19. };
  20. enum OutputIds {
  21. UP1_OUTPUT,
  22. UP2_OUTPUT,
  23. UP3_OUTPUT,
  24. UP4_OUTPUT,
  25. UP5_OUTPUT,
  26. UP6_OUTPUT,
  27. UP7_OUTPUT,
  28. UP8_OUTPUT,
  29. DN1_OUTPUT,
  30. DN2_OUTPUT,
  31. DN3_OUTPUT,
  32. DN4_OUTPUT,
  33. DN5_OUTPUT,
  34. DN6_OUTPUT,
  35. DN7_OUTPUT,
  36. DN8_OUTPUT,
  37. SUM1_OUTPUT,
  38. SUM2_OUTPUT,
  39. SUM3_OUTPUT,
  40. SUM4_OUTPUT,
  41. SUM5_OUTPUT,
  42. SUM6_OUTPUT,
  43. SUM7_OUTPUT,
  44. SUM8_OUTPUT,
  45. NUM_OUTPUTS
  46. };
  47. enum LightIds {
  48. NUM_LIGHTS
  49. };
  50. PulseGenerator upPulse[8], dnPulse[8];
  51. bool state[8] = {};
  52. float out_up[8] = {};
  53. float out_dn[8] = {};
  54. float delta;
  55. OctaTrig() : Module( NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS ) {
  56. for(int i=0; i<8; i++) state[i]=false;
  57. onSampleRateChange();
  58. };
  59. void onSampleRateChange() override { delta = 1.0/engineGetSampleRate(); }
  60. void step() override;
  61. };
  62. void OctaTrig::step() {
  63. bool gate[8];
  64. for(int i=0; i<8; i++) {
  65. gate[i] = inputs[IN1_INPUT+i].normalize(0.0) > 1.0;
  66. if (gate[i]^state[i]) {
  67. if(gate[i]) upPulse[i].trigger(0.01);
  68. else dnPulse[i].trigger(0.01);
  69. }
  70. out_up[i] = upPulse[i].process(delta)?10.0:0.0;
  71. out_dn[i] = dnPulse[i].process(delta)?10.0:0.0;
  72. state[i] = gate[i];
  73. }
  74. for(int i=0; i<8; i++) {
  75. outputs[UP1_OUTPUT+i].value = out_up[i];
  76. outputs[DN1_OUTPUT+i].value = out_dn[i];
  77. outputs[SUM1_OUTPUT+i].value = out_up[i] + out_dn[i];
  78. }
  79. };
  80. struct OctaTrigWidget : ModuleWidget {
  81. OctaTrigWidget(OctaTrig *module);
  82. };
  83. OctaTrigWidget::OctaTrigWidget(OctaTrig *module) : ModuleWidget(module) {
  84. box.size = Vec(15*10, 380);
  85. {
  86. SVGPanel *panel = new SVGPanel();
  87. panel->box.size = box.size;
  88. panel->setBackground(SVG::load(assetPlugin(plugin,"res/OctaTrig.svg")));
  89. addChild(panel);
  90. }
  91. addChild(Widget::create<MLScrew>(Vec(15, 0)));
  92. addChild(Widget::create<MLScrew>(Vec(box.size.x-30, 0)));
  93. addChild(Widget::create<MLScrew>(Vec(15, 365)));
  94. addChild(Widget::create<MLScrew>(Vec(box.size.x-30, 365)));
  95. const float offset_y = 60, delta_y = 32, row1=15, row2 = 50, row3 = 80, row4 = 110;
  96. for( int i=0; i<8; i++) {
  97. addInput(Port::create<MLPort>(Vec(row1, offset_y + i*delta_y ), Port::INPUT, module, OctaTrig::IN1_INPUT+i));
  98. addOutput(Port::create<MLPort>(Vec(row2, offset_y + i*delta_y ), Port::OUTPUT, module, OctaTrig::UP1_OUTPUT+i));
  99. addOutput(Port::create<MLPort>(Vec(row3, offset_y + i*delta_y ), Port::OUTPUT, module, OctaTrig::DN1_OUTPUT+i));
  100. addOutput(Port::create<MLPort>(Vec(row4, offset_y + i*delta_y ), Port::OUTPUT, module, OctaTrig::SUM1_OUTPUT+i));
  101. };
  102. }
  103. } // namespace rack_plugin_ML_modules
  104. using namespace rack_plugin_ML_modules;
  105. RACK_PLUGIN_MODEL_INIT(ML_modules, OctaTrig) {
  106. Model *modelOctaTrig = Model::create<OctaTrig, OctaTrigWidget>("ML modules", "OctaTrig", "OctaTrig", UTILITY_TAG );
  107. return modelOctaTrig;
  108. }