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.

66 lines
1.9KB

  1. #include "NonLinearInstruments.hpp"
  2. struct LuciControlRND : Module {
  3. enum ParamIds {
  4. RANDOMIZE_PARAM,
  5. NUM_PARAMS
  6. };
  7. enum InputIds {
  8. RANDOMIZE_INPUT,
  9. NUM_INPUTS
  10. };
  11. enum OutputIds {
  12. RANDOMIZE_OUTPUT,
  13. NUM_OUTPUTS
  14. };
  15. enum LightIds {
  16. RANDOMIZE_LIGHT,
  17. NUM_LIGHTS
  18. };
  19. LuciControlRND() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  20. void step() override;
  21. // do the light thing
  22. float lightLambda = 0.075;
  23. float randomizeLight = 0.0;
  24. // hold randomize param value
  25. float gotRandomize = 0.f;
  26. // For more advanced Module features, read Rack's engine.hpp header file
  27. // - toJson, fromJson: serialization of internal data
  28. // - onSampleRateChange: event triggered by a change of sample rate
  29. // - reset, randomize: implements special behavior when user clicks these from the context menu
  30. };
  31. void LuciControlRND::step() {
  32. gotRandomize = params[RANDOMIZE_PARAM].value + params[RANDOMIZE_INPUT].value;
  33. outputs[RANDOMIZE_OUTPUT].value = gotRandomize;
  34. // Reset button light
  35. if ( gotRandomize > 0 ) {
  36. randomizeLight = 1.0;
  37. }
  38. randomizeLight -= randomizeLight / lightLambda / engineGetSampleRate();
  39. lights[RANDOMIZE_LIGHT].value = randomizeLight;
  40. }
  41. LuciControlRNDWidget::LuciControlRNDWidget() {
  42. LuciControlRND *module = new LuciControlRND();
  43. setModule(module);
  44. box.size = Vec(25 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  45. {
  46. SVGPanel *panel = new SVGPanel();
  47. panel->box.size = box.size;
  48. panel->setBackground(SVG::load(assetPlugin(plugin, "res/LuciControlRND.svg")));
  49. addChild(panel);
  50. }
  51. addParam(createParam<BigLuciButton>(Vec(35, 55), module, LuciControlRND::RANDOMIZE_PARAM, 0.0, 1.0, 0.0));
  52. addChild(createLight<luciLight<BlueLight>>(Vec(40, 60), module, LuciControlRND::RANDOMIZE_LIGHT));
  53. addOutput(createOutput<PJ301MPort>(Vec(344, 172), module, LuciControlRND::RANDOMIZE_OUTPUT));
  54. addInput(createInput<PJ3410Port>(Vec(2, 172), module, LuciControlRND::RANDOMIZE_INPUT));
  55. }