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.

96 lines
2.2KB

  1. #include "arjo_modules.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_arjo_modules {
  4. struct Seq : Module {
  5. enum ParamIds {
  6. ENUMS(VALUE_PARAM, 8),
  7. NUM_PARAMS
  8. };
  9. enum InputIds {
  10. CLK_INPUT,
  11. RST_INPUT,
  12. NUM_INPUTS
  13. };
  14. enum OutputIds {
  15. VALUE_OUTPUT,
  16. NUM_OUTPUTS
  17. };
  18. enum LightIds {
  19. ENUMS(LIGHTS, 8),
  20. NUM_LIGHTS
  21. };
  22. SchmittTrigger clock_trigger;
  23. SchmittTrigger reset_trigger;
  24. int current_input = 0;
  25. int max_input = 7;
  26. Seq() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  27. void step() override;
  28. };
  29. void Seq::step() {
  30. if (reset_trigger.process(inputs[RST_INPUT].value)) {
  31. current_input = 0;
  32. }
  33. if (clock_trigger.process(inputs[CLK_INPUT].value)) {
  34. current_input++;
  35. }
  36. if (current_input > max_input) {
  37. current_input = 0;
  38. }
  39. for (int i=0; i < 8; i++) {
  40. lights[LIGHTS + i].setBrightnessSmooth(0);
  41. }
  42. lights[LIGHTS + current_input].setBrightnessSmooth(1);
  43. outputs[VALUE_OUTPUT].value = params[VALUE_PARAM + current_input].value;
  44. }
  45. struct SeqWidget : ModuleWidget {
  46. SeqWidget(Seq *module) : ModuleWidget(module) {
  47. setPanel(SVG::load(assetPlugin(plugin, "res/seq.svg")));
  48. // Screws
  49. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  50. addChild(Widget::create<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  51. // Inputs
  52. addInput(Port::create<small_port>(Vec(4.5, 50.5), Port::INPUT, module, Seq::CLK_INPUT));
  53. addInput(Port::create<small_port>(Vec(23.5, 50.5), Port::INPUT, module, Seq::RST_INPUT));
  54. // Knobs
  55. static const float portY[8] = {83-4, 113-4, 142-4, 172-4, 202-4, 232-4, 262-4, 292-4};
  56. for (int i = 0; i < 8; i++) {
  57. addChild(ModuleLightWidget::create<TinyLight<GreenLight>>(Vec(31.5, portY[i]), module, Seq::LIGHTS + i));
  58. addParam(ParamWidget::create<RoundSmallBlackKnob>(Vec(10.5, portY[i]), module, Seq::VALUE_PARAM + i, 0.0f, 10.0f, 0.0f));
  59. }
  60. // Output
  61. addOutput(Port::create<PJ301MPort>(Vec(10.5, 321.5), Port::OUTPUT, module, Seq::VALUE_OUTPUT));
  62. }
  63. };
  64. } // namespace rack_plugin_arjo_modules
  65. using namespace rack_plugin_arjo_modules;
  66. RACK_PLUGIN_MODEL_INIT(arjo_modules, Seq) {
  67. Model *modelSeq = Model::create<Seq, SeqWidget>("arjo_modules", "seq", "seq", SEQUENCER_TAG);
  68. return modelSeq;
  69. }