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.

181 lines
4.6KB

  1. #include "Squinky.hpp"
  2. #include "WidgetComposite.h"
  3. #ifdef _GRAY
  4. #include "Gray.h"
  5. #include "ctrl/SqMenuItem.h"
  6. using Comp = Gray<WidgetComposite>;
  7. /**
  8. */
  9. struct GrayModule : Module
  10. {
  11. public:
  12. GrayModule();
  13. /**
  14. *
  15. *
  16. * Overrides of Module functions
  17. */
  18. void step() override;
  19. std::shared_ptr<Comp> gray;
  20. private:
  21. };
  22. #ifdef __V1
  23. GrayModule::GrayModule()
  24. {
  25. config(Comp::NUM_PARAMS, Comp::NUM_INPUTS, Comp::NUM_OUTPUTS, Comp::NUM_LIGHTS);
  26. //wait until after config to allocate this guy.
  27. gray = std::make_shared<Comp>(this);
  28. std::shared_ptr<IComposite> icomp = Comp::getDescription();
  29. SqHelper::setupParams(icomp, this);
  30. }
  31. #else
  32. GrayModule::GrayModule()
  33. : Module(Comp::NUM_PARAMS,
  34. Comp::NUM_INPUTS,
  35. Comp::NUM_OUTPUTS,
  36. Comp::NUM_LIGHTS),
  37. gray(std::make_shared<Comp>(this))
  38. {
  39. }
  40. #endif
  41. void GrayModule::step()
  42. {
  43. gray->step();
  44. }
  45. ////////////////////
  46. // module widget
  47. ////////////////////
  48. struct GrayWidget : ModuleWidget
  49. {
  50. GrayWidget(GrayModule *);
  51. #ifdef __V1
  52. void appendContextMenu(Menu *menu) override;
  53. #else
  54. Menu* createContextMenu() override;
  55. #endif
  56. /**
  57. * Helper to add a text label to this widget
  58. */
  59. Label* addLabel(const Vec& v, const char* str, const NVGcolor& color = SqHelper::COLOR_BLACK)
  60. {
  61. Label* label = new Label();
  62. label->box.pos = v;
  63. label->text = str;
  64. label->color = color;
  65. addChild(label);
  66. return label;
  67. }
  68. private:
  69. void addBits(GrayModule *module);
  70. };
  71. const float jackCol = 99.5;
  72. const float ledCol = 69;
  73. const float vertSpace = 31; // 31.4
  74. const float firstBitY = 64;
  75. inline void GrayWidget::addBits(GrayModule *module)
  76. {
  77. for (int i = 0; i < 8; ++i) {
  78. const Vec v(jackCol, firstBitY + i * vertSpace);
  79. addOutput(createOutputCentered<PJ301MPort>(
  80. v,
  81. module,
  82. Gray<WidgetComposite>::OUTPUT_0 + i));
  83. addChild(createLight<MediumLight<GreenLight>>(
  84. Vec(ledCol, firstBitY + i * vertSpace - 6),
  85. module,
  86. Gray<WidgetComposite>::LIGHT_0 + i));
  87. }
  88. }
  89. /**
  90. * Widget constructor will describe my implementation structure and
  91. * provide meta-data.
  92. * This is not shared by all modules in the DLL, just one
  93. */
  94. #ifdef __V1
  95. GrayWidget::GrayWidget(GrayModule *module)
  96. {
  97. setModule(module);
  98. #else
  99. GrayWidget::GrayWidget(GrayModule *module) :
  100. ModuleWidget(module)
  101. {
  102. #endif
  103. std::shared_ptr<IComposite> icomp = Comp::getDescription();
  104. box.size = Vec(8 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  105. {
  106. SVGPanel *panel = new SVGPanel();
  107. panel->box.size = box.size;
  108. panel->setBackground(SVG::load(SqHelper::assetPlugin(plugin, "res/gray.svg")));
  109. addChild(panel);
  110. }
  111. addBits(module);
  112. addInput(createInputCentered<PJ301MPort>(
  113. Vec(22, 339),
  114. module,
  115. Gray<WidgetComposite>::INPUT_CLOCK));
  116. addLabel(Vec(0, 310), "Clock");
  117. addParam(SqHelper::createParamCentered<CKSS>(
  118. icomp,
  119. Vec(71, 33),
  120. module,
  121. Gray<WidgetComposite>::PARAM_CODE));
  122. addLabel(Vec(2, 27), "Balanced");
  123. addOutput(createOutputCentered<PJ301MPort>(
  124. Vec(100, 339),
  125. module,
  126. Gray<WidgetComposite>::OUTPUT_MIXED));
  127. addLabel(Vec(82, 310), "Mix", SqHelper::COLOR_WHITE);
  128. // screws
  129. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, 0)));
  130. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  131. addChild(createWidget<ScrewSilver>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  132. addChild(createWidget<ScrewSilver>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  133. }
  134. #ifdef __V1
  135. void GrayWidget::appendContextMenu(Menu* theMenu)
  136. {
  137. ManualMenuItem* manual = new ManualMenuItem("https://github.com/squinkylabs/SquinkyVCV/blob/master/docs/gray-code.md");
  138. theMenu->addChild(manual);
  139. }
  140. #else
  141. inline Menu* GrayWidget::createContextMenu()
  142. {
  143. Menu* theMenu = ModuleWidget::createContextMenu();
  144. ManualMenuItem* manual = new ManualMenuItem(
  145. "https://github.com/squinkylabs/SquinkyVCV/blob/master/docs/gray-code.md");
  146. theMenu->addChild(manual);
  147. return theMenu;
  148. }
  149. #endif
  150. RACK_PLUGIN_MODEL_INIT(squinkylabs_plug1, Gray) {
  151. Model *modelGrayModule = Model::create<GrayModule,
  152. GrayWidget>("Squinky Labs",
  153. "squinkylabs-gry",
  154. "Gray Code: Eclectic clock divider", CLOCK_MODULATOR_TAG, RANDOM_TAG);
  155. return modelGrayModule;
  156. }
  157. #endif