The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

274 lines
10.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. // This file isn't part of the public API, it's where we encode the knowledge base
  24. // of all the different types of block we know about..
  25. struct BlockDataSheet
  26. {
  27. BlockDataSheet (const BlocksProtocol::BlockSerialNumber& serial) : serialNumber (serial)
  28. {
  29. if (serialNumber.isPadBlock()) initialiseForPadBlock2x2();
  30. if (serialNumber.isLiveBlock()) initialiseForControlBlockLive();
  31. if (serialNumber.isLoopBlock()) initialiseForControlBlockLoop();
  32. if (serialNumber.isDevCtrlBlock()) initialiseForControlBlockDeveloper();
  33. }
  34. Block::ConnectionPort convertPortIndexToConnectorPort (BlocksProtocol::ConnectorPort port) const noexcept
  35. {
  36. return ports[(int) port.get()];
  37. }
  38. const BlocksProtocol::BlockSerialNumber serialNumber;
  39. Block::Type apiType = Block::Type::unknown;
  40. const char* description = nullptr;
  41. int widthUnits = 0, heightUnits = 0;
  42. int lightGridWidth = 0, lightGridHeight = 0, lightGridStartIndex = 0;
  43. bool hasTouchSurface = false;
  44. int numKeywaves = 0;
  45. int numLEDRowLEDs = 0;
  46. uint32 programAndHeapSize = 0;
  47. struct ButtonInfo
  48. {
  49. ControlButton::ButtonFunction type;
  50. float x, y;
  51. };
  52. struct StatusLEDInfo
  53. {
  54. juce::String name;
  55. float x, y;
  56. };
  57. juce::Array<ButtonInfo> buttons;
  58. juce::Array<StatusLEDInfo> statusLEDs;
  59. juce::Array<Block::ConnectionPort> ports;
  60. juce::Array<const char*> dials;
  61. private:
  62. //==============================================================================
  63. void initialiseForPadBlock2x2()
  64. {
  65. apiType = Block::Type::lightPadBlock;
  66. description = "Pad BLOCK (2x2)";
  67. widthUnits = 2;
  68. heightUnits = 2;
  69. lightGridWidth = 15;
  70. lightGridHeight = 15;
  71. addPorts (2, 2, 2, 2);
  72. hasTouchSurface = true;
  73. programAndHeapSize = BlocksProtocol::padBlockProgramAndHeapSize;
  74. addModeButton();
  75. }
  76. void initialiseForControlBlockLoop()
  77. {
  78. initialiseControlBlock ("Loop BLOCK", Block::Type::loopBlock,
  79. ControlButton::ButtonFunction::mode,
  80. ControlButton::ButtonFunction::volume,
  81. ControlButton::ButtonFunction::click,
  82. ControlButton::ButtonFunction::snap,
  83. ControlButton::ButtonFunction::back,
  84. ControlButton::ButtonFunction::playOrPause,
  85. ControlButton::ButtonFunction::record,
  86. ControlButton::ButtonFunction::learn,
  87. ControlButton::ButtonFunction::down,
  88. ControlButton::ButtonFunction::up);
  89. }
  90. void initialiseForControlBlockLive()
  91. {
  92. initialiseControlBlock ("Live BLOCK", Block::Type::liveBlock,
  93. ControlButton::ButtonFunction::mode,
  94. ControlButton::ButtonFunction::volume,
  95. ControlButton::ButtonFunction::scale,
  96. ControlButton::ButtonFunction::chord,
  97. ControlButton::ButtonFunction::arp,
  98. ControlButton::ButtonFunction::sustain,
  99. ControlButton::ButtonFunction::octave,
  100. ControlButton::ButtonFunction::love,
  101. ControlButton::ButtonFunction::down,
  102. ControlButton::ButtonFunction::up);
  103. }
  104. void initialiseForControlBlockDeveloper()
  105. {
  106. initialiseControlBlock ("Dev Ctrl BLOCK", Block::Type::developerControlBlock,
  107. ControlButton::ButtonFunction::button0,
  108. ControlButton::ButtonFunction::button1,
  109. ControlButton::ButtonFunction::button2,
  110. ControlButton::ButtonFunction::button3,
  111. ControlButton::ButtonFunction::button4,
  112. ControlButton::ButtonFunction::button5,
  113. ControlButton::ButtonFunction::button6,
  114. ControlButton::ButtonFunction::button7,
  115. ControlButton::ButtonFunction::down,
  116. ControlButton::ButtonFunction::up);
  117. }
  118. void initialiseControlBlock (const char* name, Block::Type type,
  119. ControlButton::ButtonFunction b1, ControlButton::ButtonFunction b2,
  120. ControlButton::ButtonFunction b3, ControlButton::ButtonFunction b4,
  121. ControlButton::ButtonFunction b5, ControlButton::ButtonFunction b6,
  122. ControlButton::ButtonFunction b7, ControlButton::ButtonFunction b8,
  123. ControlButton::ButtonFunction b9, ControlButton::ButtonFunction b10)
  124. {
  125. apiType = type;
  126. description = name;
  127. widthUnits = 2;
  128. heightUnits = 1;
  129. programAndHeapSize = BlocksProtocol::controlBlockProgramAndHeapSize;
  130. addPorts (2, 1, 2, 1);
  131. float x1 = 0.2f;
  132. float x2 = 0.6f;
  133. float x3 = 1.0f;
  134. float x4 = 1.4f;
  135. float x5 = 1.8f;
  136. float y1 = 0.405f;
  137. float y2 = 0.798f;
  138. addButtons (b1, x1, y1,
  139. b2, x2, y1,
  140. b3, x3, y1,
  141. b4, x4, y1,
  142. b5, x5, y1,
  143. b6, x1, y2,
  144. b7, x2, y2,
  145. b8, x3, y2,
  146. b9, x4, y2,
  147. b10, x5, y2);
  148. numLEDRowLEDs = 15;
  149. }
  150. //==============================================================================
  151. void addStatusLED (const char* name, float x, float y)
  152. {
  153. statusLEDs.add ({ name, x, y });
  154. }
  155. template <typename... Args>
  156. void addButtons (ControlButton::ButtonFunction fn, float x, float y, Args... others)
  157. {
  158. addButtons (fn, x, y);
  159. addButtons (others...);
  160. }
  161. void addButtons (ControlButton::ButtonFunction fn, float x, float y)
  162. {
  163. buttons.add ({ fn, x, y });
  164. }
  165. void addModeButton()
  166. {
  167. addButtons (ControlButton::ButtonFunction::mode, -1.0f, -1.0f);
  168. }
  169. void addPorts (int numNorth, int numEast, int numSouth, int numWest)
  170. {
  171. addPortsNE (Block::ConnectionPort::DeviceEdge::north, numNorth);
  172. addPortsNE (Block::ConnectionPort::DeviceEdge::east, numEast);
  173. addPortsSW (Block::ConnectionPort::DeviceEdge::south, numSouth);
  174. addPortsSW (Block::ConnectionPort::DeviceEdge::west, numWest);
  175. }
  176. void addPortsNE (Block::ConnectionPort::DeviceEdge edge, int num)
  177. {
  178. for (int i = 0; i < num; ++i)
  179. ports.add ({ edge, i});
  180. }
  181. void addPortsSW (Block::ConnectionPort::DeviceEdge edge, int num)
  182. {
  183. for (int i = 0; i < num; ++i)
  184. ports.add ({ edge, num - i - 1});
  185. }
  186. };
  187. //==============================================================================
  188. static const char* getButtonNameForFunction (ControlButton::ButtonFunction fn) noexcept
  189. {
  190. using BF = ControlButton::ButtonFunction;
  191. switch (fn)
  192. {
  193. case BF::mode: return "Mode";
  194. case BF::volume: return "Volume";
  195. case BF::up: return "Up";
  196. case BF::down: return "Down";
  197. case BF::scale: return "Scale";
  198. case BF::chord: return "Chord";
  199. case BF::arp: return "Arp";
  200. case BF::sustain: return "Sustain";
  201. case BF::octave: return "Octave";
  202. case BF::love: return "Love";
  203. case BF::click: return "Click";
  204. case BF::snap: return "Snap";
  205. case BF::back: return "Back";
  206. case BF::playOrPause: return "Play/Pause";
  207. case BF::record: return "Record";
  208. case BF::learn: return "Learn";
  209. case BF::button0: return "0";
  210. case BF::button1: return "1";
  211. case BF::button2: return "2";
  212. case BF::button3: return "3";
  213. case BF::button4: return "4";
  214. case BF::button5: return "5";
  215. case BF::button6: return "6";
  216. case BF::button7: return "7";
  217. }
  218. jassertfalse;
  219. return nullptr;
  220. }