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.

322 lines
12KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. namespace BlocksProtocol
  20. {
  21. // This file isn't part of the public API, it's where we encode the knowledge base
  22. // of all the different types of block we know about..
  23. struct BlockDataSheet
  24. {
  25. BlockDataSheet (const BlocksProtocol::BlockSerialNumber& serial) : serialNumber (serial)
  26. {
  27. if (serialNumber.isPadBlock()) initialiseForPadBlock2x2();
  28. if (serialNumber.isLiveBlock()) initialiseForControlBlockLive();
  29. if (serialNumber.isLoopBlock()) initialiseForControlBlockLoop();
  30. if (serialNumber.isDevCtrlBlock()) initialiseForControlBlockDeveloper();
  31. if (serialNumber.isTouchBlock()) initialiseForControlBlockTouch();
  32. if (serialNumber.isSeaboardBlock()) initialiseForSeaboardBlock();
  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 initialiseForControlBlockTouch()
  119. {
  120. initialiseControlBlock ("Touch BLOCK", Block::Type::touchBlock,
  121. ControlButton::ButtonFunction::velocitySensitivity,
  122. ControlButton::ButtonFunction::glideSensitivity,
  123. ControlButton::ButtonFunction::slideSensitivity,
  124. ControlButton::ButtonFunction::pressSensitivity,
  125. ControlButton::ButtonFunction::liftSensitivity,
  126. ControlButton::ButtonFunction::fixedVelocity,
  127. ControlButton::ButtonFunction::glideLock,
  128. ControlButton::ButtonFunction::pianoMode,
  129. ControlButton::ButtonFunction::down,
  130. ControlButton::ButtonFunction::up);
  131. }
  132. void initialiseControlBlock (const char* name, Block::Type type,
  133. ControlButton::ButtonFunction b1, ControlButton::ButtonFunction b2,
  134. ControlButton::ButtonFunction b3, ControlButton::ButtonFunction b4,
  135. ControlButton::ButtonFunction b5, ControlButton::ButtonFunction b6,
  136. ControlButton::ButtonFunction b7, ControlButton::ButtonFunction b8,
  137. ControlButton::ButtonFunction b9, ControlButton::ButtonFunction b10)
  138. {
  139. apiType = type;
  140. description = name;
  141. widthUnits = 2;
  142. heightUnits = 1;
  143. programAndHeapSize = BlocksProtocol::controlBlockProgramAndHeapSize;
  144. addPorts (2, 1, 2, 1);
  145. float x1 = 0.2f;
  146. float x2 = 0.6f;
  147. float x3 = 1.0f;
  148. float x4 = 1.4f;
  149. float x5 = 1.8f;
  150. float y1 = 0.405f;
  151. float y2 = 0.798f;
  152. addButtons (b1, x1, y1,
  153. b2, x2, y1,
  154. b3, x3, y1,
  155. b4, x4, y1,
  156. b5, x5, y1,
  157. b6, x1, y2,
  158. b7, x2, y2,
  159. b8, x3, y2,
  160. b9, x4, y2,
  161. b10, x5, y2);
  162. numLEDRowLEDs = 15;
  163. }
  164. void initialiseForSeaboardBlock()
  165. {
  166. apiType = Block::Type::seaboardBlock;
  167. description = "Seaboard BLOCK (6x3)";
  168. widthUnits = 6;
  169. heightUnits = 3;
  170. lightGridWidth = 0;
  171. lightGridHeight = 0;
  172. numKeywaves = 24;
  173. addPortsSW (Block::ConnectionPort::DeviceEdge::west, 1);
  174. addPortsNE (Block::ConnectionPort::DeviceEdge::north, 2);
  175. addPortsNE (Block::ConnectionPort::DeviceEdge::east, 1);
  176. hasTouchSurface = true;
  177. programAndHeapSize = BlocksProtocol::padBlockProgramAndHeapSize;
  178. addModeButton();
  179. }
  180. //==============================================================================
  181. void addStatusLED (const char* name, float x, float y)
  182. {
  183. statusLEDs.add ({ name, x, y });
  184. }
  185. template <typename... Args>
  186. void addButtons (ControlButton::ButtonFunction fn, float x, float y, Args... others)
  187. {
  188. addButtons (fn, x, y);
  189. addButtons (others...);
  190. }
  191. void addButtons (ControlButton::ButtonFunction fn, float x, float y)
  192. {
  193. buttons.add ({ fn, x, y });
  194. }
  195. void addModeButton()
  196. {
  197. addButtons (ControlButton::ButtonFunction::mode, -1.0f, -1.0f);
  198. }
  199. void addPorts (int numNorth, int numEast, int numSouth, int numWest)
  200. {
  201. addPortsNE (Block::ConnectionPort::DeviceEdge::north, numNorth);
  202. addPortsNE (Block::ConnectionPort::DeviceEdge::east, numEast);
  203. addPortsSW (Block::ConnectionPort::DeviceEdge::south, numSouth);
  204. addPortsSW (Block::ConnectionPort::DeviceEdge::west, numWest);
  205. }
  206. void addPortsNE (Block::ConnectionPort::DeviceEdge edge, int num)
  207. {
  208. for (int i = 0; i < num; ++i)
  209. ports.add ({ edge, i});
  210. }
  211. void addPortsSW (Block::ConnectionPort::DeviceEdge edge, int num)
  212. {
  213. for (int i = 0; i < num; ++i)
  214. ports.add ({ edge, num - i - 1});
  215. }
  216. };
  217. //==============================================================================
  218. static const char* getButtonNameForFunction (ControlButton::ButtonFunction fn) noexcept
  219. {
  220. using BF = ControlButton::ButtonFunction;
  221. switch (fn)
  222. {
  223. case BF::mode: return "Mode";
  224. case BF::volume: return "Volume";
  225. case BF::up: return "Up";
  226. case BF::down: return "Down";
  227. case BF::scale: return "Scale";
  228. case BF::chord: return "Chord";
  229. case BF::arp: return "Arp";
  230. case BF::sustain: return "Sustain";
  231. case BF::octave: return "Octave";
  232. case BF::love: return "Love";
  233. case BF::click: return "Click";
  234. case BF::snap: return "Snap";
  235. case BF::back: return "Back";
  236. case BF::playOrPause: return "Play/Pause";
  237. case BF::record: return "Record";
  238. case BF::learn: return "Learn";
  239. case BF::button0: return "0";
  240. case BF::button1: return "1";
  241. case BF::button2: return "2";
  242. case BF::button3: return "3";
  243. case BF::button4: return "4";
  244. case BF::button5: return "5";
  245. case BF::button6: return "6";
  246. case BF::button7: return "7";
  247. case BF::velocitySensitivity: return "Velocity Sensitivity";
  248. case BF::glideSensitivity: return "Glide Sensitivity";
  249. case BF::slideSensitivity: return "Slide Sensitivity";
  250. case BF::pressSensitivity: return "Press Sensitivity";
  251. case BF::liftSensitivity: return "Lift Sensitivity";
  252. case BF::fixedVelocity: return "Fixed Velocity";
  253. case BF::glideLock: return "Glide Lock";
  254. case BF::pianoMode: return "Piano Mode";
  255. }
  256. jassertfalse;
  257. return nullptr;
  258. }
  259. } // namespace BlocksProtocol
  260. } // namespace juce