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