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.

87 lines
2.2KB

  1. #include "rcm.h"
  2. #include "GVerbWidget.hpp"
  3. #include "../include/BaseWidget.hpp"
  4. namespace rack_plugin_rcm {
  5. struct CV5to5Module : Module {
  6. enum ParamIds {
  7. AMOUNT_PARAM,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. NUM_INPUTS
  12. };
  13. enum OutputIds {
  14. CV_OUTPUT,
  15. NUM_OUTPUTS
  16. };
  17. enum LightIds {
  18. NUM_LIGHTS
  19. };
  20. CV5to5Module() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
  21. }
  22. void step() override;
  23. // For more advanced Module features, read Rack's engine.hpp header file
  24. // - toJson, fromJson: serialization of internal data
  25. // - onSampleRateChange: event triggered by a change of sample rate
  26. // - onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu
  27. };
  28. void CV5to5Module::step() {
  29. outputs[CV_OUTPUT].value = params[AMOUNT_PARAM].value;
  30. }
  31. struct CV5to5ModuleWidget : BaseWidget {
  32. TextField *textField;
  33. CV5to5ModuleWidget(CV5to5Module *module) : BaseWidget(module) {
  34. colourHotZone = Rect(Vec(10, 10), Vec(50, 13));
  35. backgroundHue = 0.754;
  36. backgroundSaturation = 1.f;
  37. backgroundLuminosity = 0.58f;
  38. setPanel(SVG::load(assetPlugin(plugin, "res/CV5to5.svg")));
  39. addParam(ParamWidget::create<Davies1900hLargeWhiteKnob>(Vec(10, 156.23), module, CV5to5Module::AMOUNT_PARAM, -5.0, 5.0, 0.0));
  40. addOutput(Port::create<PJ301MPort>(Vec(26, 331), Port::OUTPUT, module, CV5to5Module::CV_OUTPUT));
  41. textField = Widget::create<LedDisplayTextField>(Vec(7.5, 38.0));
  42. textField->box.size = Vec(60.0, 80.0);
  43. textField->multiline = true;
  44. ((LedDisplayTextField*)textField)->color = COLOR_WHITE;
  45. addChild(textField);
  46. }
  47. json_t *toJson() override {
  48. json_t *rootJ = BaseWidget::toJson();
  49. // text
  50. json_object_set_new(rootJ, "text", json_string(textField->text.c_str()));
  51. return rootJ;
  52. }
  53. void fromJson(json_t *rootJ) override {
  54. BaseWidget::fromJson(rootJ);
  55. // text
  56. json_t *textJ = json_object_get(rootJ, "text");
  57. if (textJ)
  58. textField->text = json_string_value(textJ);
  59. }
  60. };
  61. } // namespace rack_plugin_rcm
  62. using namespace rack_plugin_rcm;
  63. RACK_PLUGIN_MODEL_INIT(rcm, CV5to5Module) {
  64. Model *modelCV5to5Module = Model::create<CV5to5Module, CV5to5ModuleWidget>("rcm", "rcm-CV5to5", "CV5to5", ENVELOPE_FOLLOWER_TAG);
  65. return modelCV5to5Module;
  66. }