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
5.0KB

  1. //***********************************************************************************************
  2. //Impromptu Modular: Modules for VCV Rack by Marc Boulé
  3. //
  4. //Based on code from the Fundamental and AudibleInstruments plugins by Andrew Belt
  5. //and graphics from the Component Library by Wes Milholen
  6. //See ./LICENSE.txt for all licenses
  7. //See ./res/fonts/ for font licenses
  8. //***********************************************************************************************
  9. #include "ImpromptuModular.hpp"
  10. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, Tact);
  11. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, TwelveKey);
  12. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, Clocked);
  13. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, MidiFile);
  14. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, PhraseSeq16);
  15. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, PhraseSeq32);
  16. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, GateSeq64);
  17. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, WriteSeq32);
  18. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, WriteSeq64);
  19. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, BigButtonSeq);
  20. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, SemiModularSynth);
  21. RACK_PLUGIN_MODEL_DECLARE(ImpromptuModular, BlankPanel);
  22. RACK_PLUGIN_INIT(ImpromptuModular) {
  23. RACK_PLUGIN_INIT_ID();
  24. RACK_PLUGIN_INIT_WEBSITE("https://github.com/MarcBoule/ImpromptuModular");
  25. RACK_PLUGIN_INIT_MANUAL("https://github.com/MarcBoule/ImpromptuModular");
  26. RACK_PLUGIN_INIT_VERSION("0.6.11");
  27. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, Tact);
  28. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, TwelveKey);
  29. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, Clocked);
  30. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, MidiFile);
  31. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, PhraseSeq16);
  32. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, PhraseSeq32);
  33. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, GateSeq64);
  34. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, WriteSeq32);
  35. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, WriteSeq64);
  36. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, BigButtonSeq);
  37. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, SemiModularSynth);
  38. RACK_PLUGIN_MODEL_ADD(ImpromptuModular, BlankPanel);
  39. }
  40. LEDBezelBig::LEDBezelBig() {
  41. float ratio = 2.13f;
  42. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/LEDBezel.svg")));
  43. sw->box.size = sw->box.size.mult(ratio);
  44. box.size = sw->box.size;
  45. tw = new TransformWidget();
  46. removeChild(sw);
  47. tw->addChild(sw);
  48. addChild(tw);
  49. tw->box.size = sw->box.size;
  50. tw->scale(Vec(ratio, ratio));
  51. }
  52. void InvisibleKeySmall::onMouseDown(EventMouseDown &e) {
  53. if (e.button == 1) {// if right button (see events.hpp)
  54. maxValue = 2.0f;
  55. // Simulate MomentarySwitch::onDragStart() since not called for right clicks:
  56. setValue(maxValue);
  57. EventAction eAction;
  58. onAction(eAction);
  59. }
  60. else
  61. maxValue = 1.0f;
  62. //ParamWidget::onMouseDown(e);// don't want the reset() that is called in ParamWidget::onMouseDown(), so implement rest of that function here:
  63. e.consumed = true;
  64. e.target = this;
  65. }
  66. void InvisibleKeySmall::onMouseUp(EventMouseUp &e) {
  67. if (e.button == 1) {// if right button (see events.hpp)
  68. // Simulate MomentarySwitch::onDragEnd() since not called for right clicks:
  69. setValue(minValue);
  70. }
  71. ParamWidget::onMouseUp(e);
  72. }
  73. ScrewSilverRandomRot::ScrewSilverRandomRot() {
  74. float angle0_90 = randomUniform()*M_PI/2.0f;
  75. //float angle0_90 = randomUniform() > 0.5f ? M_PI/4.0f : 0.0f;// for testing
  76. tw = new TransformWidget();
  77. addChild(tw);
  78. sw = new SVGWidget();
  79. tw->addChild(sw);
  80. //sw->setSVG(SVG::load(assetPlugin(plugin, "res/Screw0.svg")));
  81. sw->setSVG(SVG::load(assetGlobal("res/ComponentLibrary/ScrewSilver.svg")));
  82. sc = new ScrewCircle(angle0_90);
  83. sc->box.size = sw->box.size;
  84. tw->addChild(sc);
  85. box.size = sw->box.size;
  86. tw->box.size = sw->box.size;
  87. tw->identity();
  88. // Rotate SVG
  89. Vec center = sw->box.getCenter();
  90. tw->translate(center);
  91. tw->rotate(angle0_90);
  92. tw->translate(center.neg());
  93. }
  94. ScrewHole::ScrewHole(Vec posGiven) {
  95. box.size = Vec(16, 7);
  96. box.pos = Vec(posGiven.x, posGiven.y + 4);// nudgeX for realism, 0 = no nudge
  97. }
  98. void ScrewHole::draw(NVGcontext *vg) {
  99. NVGcolor backgroundColor = nvgRGB(0x10, 0x10, 0x10);
  100. NVGcolor borderColor = nvgRGB(0x20, 0x20, 0x20);
  101. nvgBeginPath(vg);
  102. nvgRoundedRect(vg, 0.0, 0.0, box.size.x, box.size.y, 2.5f);
  103. nvgFillColor(vg, backgroundColor);
  104. nvgFill(vg);
  105. nvgStrokeWidth(vg, 1.0);
  106. nvgStrokeColor(vg, borderColor);
  107. nvgStroke(vg);
  108. }
  109. NVGcolor prepareDisplay(NVGcontext *vg, Rect *box) {
  110. NVGcolor backgroundColor = nvgRGB(0x38, 0x38, 0x38);
  111. NVGcolor borderColor = nvgRGB(0x10, 0x10, 0x10);
  112. nvgBeginPath(vg);
  113. nvgRoundedRect(vg, 0.0, 0.0, box->size.x, box->size.y, 5.0);
  114. nvgFillColor(vg, backgroundColor);
  115. nvgFill(vg);
  116. nvgStrokeWidth(vg, 1.0);
  117. nvgStrokeColor(vg, borderColor);
  118. nvgStroke(vg);
  119. nvgFontSize(vg, 18);
  120. NVGcolor textColor = nvgRGB(0xaf, 0xd2, 0x2c);
  121. return textColor;
  122. }
  123. bool calcWarningFlash(long count, long countInit) {
  124. bool warningFlashState = true;
  125. if (count > (countInit * 2l / 4l) && count < (countInit * 3l / 4l))
  126. warningFlashState = false;
  127. else if (count < (countInit * 1l / 4l))
  128. warningFlashState = false;
  129. return warningFlashState;
  130. }