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.

268 lines
9.5KB

  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 either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. // This file isn't part of the public API, it's where we encode the knowledge base
  18. // of all the different types of block we know about..
  19. struct BlockDataSheet
  20. {
  21. BlockDataSheet (const BlocksProtocol::BlockSerialNumber& serial) : serialNumber (serial)
  22. {
  23. if (serialNumber.isPadBlock()) initialiseForPadBlock2x2();
  24. if (serialNumber.isLiveBlock()) initialiseForControlBlockLive();
  25. if (serialNumber.isLoopBlock()) initialiseForControlBlockLoop();
  26. if (serialNumber.isDevCtrlBlock()) initialiseForControlBlockDeveloper();
  27. }
  28. Block::ConnectionPort convertPortIndexToConnectorPort (BlocksProtocol::ConnectorPort port) const noexcept
  29. {
  30. return ports[(int) port.get()];
  31. }
  32. const BlocksProtocol::BlockSerialNumber serialNumber;
  33. Block::Type apiType = Block::Type::unknown;
  34. const char* description = nullptr;
  35. int widthUnits = 0, heightUnits = 0;
  36. int lightGridWidth = 0, lightGridHeight = 0, lightGridStartIndex = 0;
  37. bool hasTouchSurface = false;
  38. int numKeywaves = 0;
  39. int numLEDRowLEDs = 0;
  40. uint32 programAndHeapSize = 0;
  41. struct ButtonInfo
  42. {
  43. ControlButton::ButtonFunction type;
  44. float x, y;
  45. };
  46. struct StatusLEDInfo
  47. {
  48. juce::String name;
  49. float x, y;
  50. };
  51. juce::Array<ButtonInfo> buttons;
  52. juce::Array<StatusLEDInfo> statusLEDs;
  53. juce::Array<Block::ConnectionPort> ports;
  54. juce::Array<const char*> dials;
  55. private:
  56. //==============================================================================
  57. void initialiseForPadBlock2x2()
  58. {
  59. apiType = Block::Type::lightPadBlock;
  60. description = "Pad BLOCK (2x2)";
  61. widthUnits = 2;
  62. heightUnits = 2;
  63. lightGridWidth = 15;
  64. lightGridHeight = 15;
  65. addPorts (2, 2, 2, 2);
  66. hasTouchSurface = true;
  67. programAndHeapSize = BlocksProtocol::padBlockProgramAndHeapSize;
  68. addModeButton();
  69. }
  70. void initialiseForControlBlockLoop()
  71. {
  72. initialiseControlBlock ("Loop BLOCK", Block::Type::loopBlock,
  73. ControlButton::ButtonFunction::mode,
  74. ControlButton::ButtonFunction::volume,
  75. ControlButton::ButtonFunction::click,
  76. ControlButton::ButtonFunction::snap,
  77. ControlButton::ButtonFunction::back,
  78. ControlButton::ButtonFunction::playOrPause,
  79. ControlButton::ButtonFunction::record,
  80. ControlButton::ButtonFunction::learn,
  81. ControlButton::ButtonFunction::down,
  82. ControlButton::ButtonFunction::up);
  83. }
  84. void initialiseForControlBlockLive()
  85. {
  86. initialiseControlBlock ("Live BLOCK", Block::Type::liveBlock,
  87. ControlButton::ButtonFunction::mode,
  88. ControlButton::ButtonFunction::volume,
  89. ControlButton::ButtonFunction::scale,
  90. ControlButton::ButtonFunction::chord,
  91. ControlButton::ButtonFunction::arp,
  92. ControlButton::ButtonFunction::sustain,
  93. ControlButton::ButtonFunction::octave,
  94. ControlButton::ButtonFunction::love,
  95. ControlButton::ButtonFunction::down,
  96. ControlButton::ButtonFunction::up);
  97. }
  98. void initialiseForControlBlockDeveloper()
  99. {
  100. initialiseControlBlock ("Dev Ctrl BLOCK", Block::Type::developerControlBlock,
  101. ControlButton::ButtonFunction::button0,
  102. ControlButton::ButtonFunction::button1,
  103. ControlButton::ButtonFunction::button2,
  104. ControlButton::ButtonFunction::button3,
  105. ControlButton::ButtonFunction::button4,
  106. ControlButton::ButtonFunction::button5,
  107. ControlButton::ButtonFunction::button6,
  108. ControlButton::ButtonFunction::button7,
  109. ControlButton::ButtonFunction::down,
  110. ControlButton::ButtonFunction::up);
  111. }
  112. void initialiseControlBlock (const char* name, Block::Type type,
  113. ControlButton::ButtonFunction b1, ControlButton::ButtonFunction b2,
  114. ControlButton::ButtonFunction b3, ControlButton::ButtonFunction b4,
  115. ControlButton::ButtonFunction b5, ControlButton::ButtonFunction b6,
  116. ControlButton::ButtonFunction b7, ControlButton::ButtonFunction b8,
  117. ControlButton::ButtonFunction b9, ControlButton::ButtonFunction b10)
  118. {
  119. apiType = type;
  120. description = name;
  121. widthUnits = 2;
  122. heightUnits = 1;
  123. programAndHeapSize = BlocksProtocol::controlBlockProgramAndHeapSize;
  124. addPorts (2, 1, 2, 1);
  125. float x1 = 0.2f;
  126. float x2 = 0.6f;
  127. float x3 = 1.0f;
  128. float x4 = 1.4f;
  129. float x5 = 1.8f;
  130. float y1 = 0.405f;
  131. float y2 = 0.798f;
  132. addButtons (b1, x1, y1,
  133. b2, x2, y1,
  134. b3, x3, y1,
  135. b4, x4, y1,
  136. b5, x5, y1,
  137. b6, x1, y2,
  138. b7, x2, y2,
  139. b8, x3, y2,
  140. b9, x4, y2,
  141. b10, x5, y2);
  142. numLEDRowLEDs = 15;
  143. }
  144. //==============================================================================
  145. void addStatusLED (const char* name, float x, float y)
  146. {
  147. statusLEDs.add ({ name, x, y });
  148. }
  149. template <typename... Args>
  150. void addButtons (ControlButton::ButtonFunction fn, float x, float y, Args... others)
  151. {
  152. addButtons (fn, x, y);
  153. addButtons (others...);
  154. }
  155. void addButtons (ControlButton::ButtonFunction fn, float x, float y)
  156. {
  157. buttons.add ({ fn, x, y });
  158. }
  159. void addModeButton()
  160. {
  161. addButtons (ControlButton::ButtonFunction::mode, -1.0f, -1.0f);
  162. }
  163. void addPorts (int numNorth, int numEast, int numSouth, int numWest)
  164. {
  165. addPortsNE (Block::ConnectionPort::DeviceEdge::north, numNorth);
  166. addPortsNE (Block::ConnectionPort::DeviceEdge::east, numEast);
  167. addPortsSW (Block::ConnectionPort::DeviceEdge::south, numSouth);
  168. addPortsSW (Block::ConnectionPort::DeviceEdge::west, numWest);
  169. }
  170. void addPortsNE (Block::ConnectionPort::DeviceEdge edge, int num)
  171. {
  172. for (int i = 0; i < num; ++i)
  173. ports.add ({ edge, i});
  174. }
  175. void addPortsSW (Block::ConnectionPort::DeviceEdge edge, int num)
  176. {
  177. for (int i = 0; i < num; ++i)
  178. ports.add ({ edge, num - i - 1});
  179. }
  180. };
  181. //==============================================================================
  182. static const char* getButtonNameForFunction (ControlButton::ButtonFunction fn) noexcept
  183. {
  184. using BF = ControlButton::ButtonFunction;
  185. switch (fn)
  186. {
  187. case BF::mode: return "Mode";
  188. case BF::volume: return "Volume";
  189. case BF::up: return "Up";
  190. case BF::down: return "Down";
  191. case BF::scale: return "Scale";
  192. case BF::chord: return "Chord";
  193. case BF::arp: return "Arp";
  194. case BF::sustain: return "Sustain";
  195. case BF::octave: return "Octave";
  196. case BF::love: return "Love";
  197. case BF::click: return "Click";
  198. case BF::snap: return "Snap";
  199. case BF::back: return "Back";
  200. case BF::playOrPause: return "Play/Pause";
  201. case BF::record: return "Record";
  202. case BF::learn: return "Learn";
  203. case BF::button0: return "0";
  204. case BF::button1: return "1";
  205. case BF::button2: return "2";
  206. case BF::button3: return "3";
  207. case BF::button4: return "4";
  208. case BF::button5: return "5";
  209. case BF::button6: return "6";
  210. case BF::button7: return "7";
  211. }
  212. jassertfalse;
  213. return nullptr;
  214. }