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.

258 lines
7.2KB

  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. #ifndef IMPROMPU_MODULAR_HPP
  10. #define IMPROMPU_MODULAR_HPP
  11. #include "rack.hpp"
  12. #include "IMWidgets.hpp"
  13. using namespace rack;
  14. #define plugin "ImpromptuModular"
  15. // General constants
  16. static const float lightLambda = 0.075f;
  17. static const std::string lightPanelID = "Classic";
  18. static const std::string darkPanelID = "Dark-valor";
  19. static const std::string expansionMenuLabel = "Extra CVs (requires +4HP to the right!)";
  20. enum RunModeIds {MODE_FWD, MODE_REV, MODE_PPG, MODE_BRN, MODE_RND, MODE_FW2, MODE_FW3, MODE_FW4, NUM_MODES};
  21. static const std::string modeLabels[NUM_MODES]={"FWD","REV","PPG","BRN","RND","FW2","FW3","FW4"};
  22. enum GateModeIds {GATE_24, GATE_34, GATE_44, GATE_14, GATE_TRIG, GATE_DUO, GATE_DU1, GATE_DU2,
  23. GATE_TRIPLET, GATE_TRIP1, GATE_TRIP2, GATE_TRIP3, GATE_TRIP4, GATE_TRIP5, GATE_TRIP6, NUM_GATES};
  24. static const std::string gateLabels[NUM_GATES]={"2/4","3/4","4/4","1/4","TRG","DUO","DU1","DU2",
  25. "TRP","TR1","TR2","TR3","TR4","TR5","TR6"};
  26. // Constants for displaying notes
  27. static const char noteLettersSharp[12] = {'C', 'C', 'D', 'D', 'E', 'F', 'F', 'G', 'G', 'A', 'A', 'B'};
  28. static const char noteLettersFlat [12] = {'C', 'D', 'D', 'E', 'E', 'F', 'G', 'G', 'A', 'A', 'B', 'B'};
  29. static const char isBlackKey [12] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
  30. // Component offset constants
  31. static const int hOffsetCKSS = 5;
  32. static const int vOffsetCKSS = 2;
  33. static const int vOffsetCKSSThree = -2;
  34. static const int hOffsetCKSSH = 2;
  35. static const int vOffsetCKSSH = 5;
  36. static const int offsetCKD6 = -1;//does both h and v
  37. static const int offsetCKD6b = 0;//does both h and v
  38. static const int vOffsetDisplay = -2;
  39. static const int offsetIMBigKnob = -6;//does both h and v
  40. static const int offsetIMSmallKnob = 0;//does both h and v
  41. static const int offsetMediumLight = 9;
  42. static const float offsetLEDbutton = 3.0f;//does both h and v
  43. static const float offsetLEDbuttonLight = 4.4f;//does both h and v
  44. static const int offsetTL1105 = 4;//does both h and v
  45. static const int offsetLEDbezel = 1;//does both h and v
  46. static const float offsetLEDbezelLight = 2.2f;//does both h and v
  47. static const float offsetLEDbezelBig = -11;//does both h and v
  48. static const int offsetTrimpot = 3;//does both h and v
  49. // Variations on existing knobs, lights, etc
  50. // Screws
  51. struct IMScrew : DynamicSVGScrew {
  52. IMScrew() {
  53. addSVGalt(SVG::load(assetPlugin(plugin, "res/dark/comp/ScrewSilver.svg")));
  54. }
  55. };
  56. // Ports
  57. struct IMPort : DynamicSVGPort {
  58. IMPort() {
  59. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/PJ301M.svg")));
  60. addFrame(SVG::load(assetPlugin(plugin, "res/dark/comp/PJ301M.svg")));
  61. shadow->blurRadius = 10.0;
  62. shadow->opacity = 0.8;
  63. }
  64. };
  65. // Buttons and switches
  66. struct CKSSH : SVGSwitch, ToggleSwitch {
  67. CKSSH() {
  68. addFrame(SVG::load(assetPlugin(plugin, "res/comp/CKSSH_0.svg")));
  69. addFrame(SVG::load(assetPlugin(plugin, "res/comp/CKSSH_1.svg")));
  70. sw->wrap();
  71. box.size = sw->box.size;
  72. }
  73. };
  74. struct CKSSThreeInv : SVGSwitch, ToggleSwitch {
  75. CKSSThreeInv() {
  76. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKSSThree_2.svg")));
  77. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKSSThree_1.svg")));
  78. addFrame(SVG::load(assetGlobal("res/ComponentLibrary/CKSSThree_0.svg")));
  79. }
  80. };
  81. struct IMBigPushButton : DynamicSVGSwitch, MomentarySwitch {
  82. IMBigPushButton() {
  83. addFrameAll(SVG::load(assetPlugin(plugin, "res/light/comp/CKD6b_0.svg")));
  84. addFrameAll(SVG::load(assetPlugin(plugin, "res/light/comp/CKD6b_1.svg")));
  85. addFrameAll(SVG::load(assetPlugin(plugin, "res/dark/comp/CKD6b_0.svg")));
  86. addFrameAll(SVG::load(assetPlugin(plugin, "res/dark/comp/CKD6b_1.svg")));
  87. }
  88. };
  89. struct LEDBezelBig : SVGSwitch, MomentarySwitch {
  90. TransformWidget *tw;
  91. LEDBezelBig();
  92. };
  93. // Knobs
  94. struct IMKnob : DynamicSVGKnob {
  95. IMKnob() {
  96. minAngle = -0.83*M_PI;
  97. maxAngle = 0.83*M_PI;
  98. shadow->blurRadius = 10.0;
  99. shadow->opacity = 0.8;
  100. }
  101. };
  102. struct IMBigKnob : IMKnob {
  103. IMBigKnob() {
  104. addFrameAll(SVG::load(assetPlugin(plugin, "res/light/comp/BlackKnobLargeWithMark.svg")));
  105. addFrameAll(SVG::load(assetPlugin(plugin, "res/dark/comp/BlackKnobLargeWithMark.svg")));
  106. addEffect(SVG::load(assetPlugin(plugin, "res/dark/comp/BlackKnobLargeWithMarkEffects.svg")));
  107. }
  108. };
  109. struct IMBigSnapKnob : IMBigKnob {
  110. IMBigSnapKnob() {
  111. snap = true;
  112. smooth = false;
  113. }
  114. };
  115. struct IMBigKnobInf : IMKnob {
  116. IMBigKnobInf() {
  117. addFrameAll(SVG::load(assetPlugin(plugin, "res/light/comp/BlackKnobLarge.svg")));
  118. addFrameAll(SVG::load(assetPlugin(plugin, "res/dark/comp/BlackKnobLarge.svg")));
  119. addEffect(SVG::load(assetPlugin(plugin, "res/dark/comp/BlackKnobLargeEffects.svg")));
  120. speed = 0.9f;
  121. //smooth = false;
  122. }
  123. };
  124. struct IMSmallKnob : IMKnob {
  125. IMSmallKnob() {
  126. addFrameAll(SVG::load(assetPlugin(plugin, "res/light/comp/RoundSmallBlackKnob.svg")));
  127. addFrameAll(SVG::load(assetPlugin(plugin, "res/dark/comp/RoundSmallBlackKnob.svg")));
  128. addEffect(SVG::load(assetPlugin(plugin, "res/dark/comp/RoundSmallBlackKnobEffects.svg")));
  129. shadow->box.pos = Vec(0.0, box.size.y * 0.15);
  130. }
  131. };
  132. struct IMSmallSnapKnob : IMSmallKnob {
  133. IMSmallSnapKnob() {
  134. snap = true;
  135. smooth = false;
  136. }
  137. };
  138. struct IMFivePosSmallKnob : IMSmallSnapKnob {
  139. IMFivePosSmallKnob() {
  140. minAngle = -0.5*M_PI;
  141. maxAngle = 0.5*M_PI;
  142. }
  143. };
  144. struct IMSixPosBigKnob : IMBigSnapKnob {
  145. IMSixPosBigKnob() {
  146. minAngle = -0.4*M_PI;
  147. maxAngle = 0.4*M_PI;
  148. }
  149. };
  150. struct IMTactile : DynamicIMTactile {
  151. IMTactile() {
  152. smooth = false;// must be false or else DynamicIMTactile::changeValue() call from module will crash Rack
  153. }
  154. };
  155. // Lights
  156. struct OrangeLight : GrayModuleLightWidget {
  157. OrangeLight() {
  158. addBaseColor(COLOR_ORANGE);
  159. }
  160. };
  161. template <typename BASE>
  162. struct MuteLight : BASE {
  163. MuteLight() {
  164. this->box.size = mm2px(Vec(6.0f, 6.0f));
  165. }
  166. };
  167. template <typename BASE>
  168. struct GiantLight : BASE {
  169. GiantLight() {
  170. this->box.size = mm2px(Vec(19.0f, 19.0f));
  171. }
  172. };
  173. template <typename BASE>
  174. struct GiantLight2 : BASE {
  175. GiantLight2() {
  176. this->box.size = mm2px(Vec(12.8f, 12.8f));
  177. }
  178. };
  179. // Other
  180. struct InvisibleKey : MomentarySwitch {
  181. InvisibleKey() {
  182. box.size = Vec(34, 72);
  183. }
  184. };
  185. struct InvisibleKeySmall : MomentarySwitch {
  186. InvisibleKeySmall() {
  187. box.size = Vec(23, 50);
  188. }
  189. void onMouseDown(EventMouseDown &e) override;
  190. void onMouseUp(EventMouseUp &e) override;
  191. };
  192. struct ScrewSilverRandomRot : FramebufferWidget {// location: include/app.hpp and src/app/SVGScrew.cpp [some code also from src/app/SVGKnob.cpp]
  193. SVGWidget *sw;
  194. TransformWidget *tw;
  195. ScrewCircle *sc;
  196. ScrewSilverRandomRot();
  197. };
  198. struct ScrewHole : TransparentWidget {
  199. ScrewHole(Vec posGiven);
  200. void draw(NVGcontext *vg) override;
  201. };
  202. NVGcolor prepareDisplay(NVGcontext *vg, Rect *box);
  203. int moveIndex(int index, int indexNext, int numSteps);
  204. bool moveIndexRunMode(int* index, int numSteps, int runMode, int* history);
  205. bool calcWarningFlash(long count, long countInit);
  206. #endif