Audio plugin host https://kx.studio/carla
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.

1145 lines
43KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - 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. namespace MidiHelpers
  18. {
  19. inline uint8 initialByte (const int type, const int channel) noexcept
  20. {
  21. return (uint8) (type | jlimit (0, 15, channel - 1));
  22. }
  23. inline uint8 validVelocity (const int v) noexcept
  24. {
  25. return (uint8) jlimit (0, 127, v);
  26. }
  27. }
  28. //==============================================================================
  29. uint8 MidiMessage::floatValueToMidiByte (const float v) noexcept
  30. {
  31. return MidiHelpers::validVelocity (roundToInt (v * 127.0f));
  32. }
  33. uint16 MidiMessage::pitchbendToPitchwheelPos (const float pitchbend,
  34. const float pitchbendRange) noexcept
  35. {
  36. // can't translate a pitchbend value that is outside of the given range!
  37. jassert (std::abs (pitchbend) <= pitchbendRange);
  38. return static_cast<uint16> (pitchbend > 0.0f
  39. ? jmap (pitchbend, 0.0f, pitchbendRange, 8192.0f, 16383.0f)
  40. : jmap (pitchbend, -pitchbendRange, 0.0f, 0.0f, 8192.0f));
  41. }
  42. //==============================================================================
  43. int MidiMessage::readVariableLengthVal (const uint8* data, int& numBytesUsed) noexcept
  44. {
  45. numBytesUsed = 0;
  46. int v = 0, i;
  47. do
  48. {
  49. i = (int) *data++;
  50. if (++numBytesUsed > 6)
  51. break;
  52. v = (v << 7) + (i & 0x7f);
  53. } while (i & 0x80);
  54. return v;
  55. }
  56. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) noexcept
  57. {
  58. // this method only works for valid starting bytes of a short midi message
  59. jassert (firstByte >= 0x80 && firstByte != 0xf0 && firstByte != 0xf7);
  60. static const char messageLengths[] =
  61. {
  62. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  63. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  64. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  65. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  66. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  67. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  68. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  69. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  70. };
  71. return messageLengths [firstByte & 0x7f];
  72. }
  73. //==============================================================================
  74. MidiMessage::MidiMessage() noexcept
  75. : timeStamp (0), size (2)
  76. {
  77. packedData.asBytes[0] = 0xf0;
  78. packedData.asBytes[1] = 0xf7;
  79. }
  80. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  81. : timeStamp (t), size (dataSize)
  82. {
  83. jassert (dataSize > 0);
  84. // this checks that the length matches the data..
  85. jassert (dataSize > 3 || *(uint8*)d >= 0xf0 || getMessageLengthFromFirstByte (*(uint8*)d) == size);
  86. memcpy (allocateSpace (dataSize), d, (size_t) dataSize);
  87. }
  88. MidiMessage::MidiMessage (const int byte1, const double t) noexcept
  89. : timeStamp (t), size (1)
  90. {
  91. packedData.asBytes[0] = (uint8) byte1;
  92. // check that the length matches the data..
  93. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  94. }
  95. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) noexcept
  96. : timeStamp (t), size (2)
  97. {
  98. packedData.asBytes[0] = (uint8) byte1;
  99. packedData.asBytes[1] = (uint8) byte2;
  100. // check that the length matches the data..
  101. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  102. }
  103. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) noexcept
  104. : timeStamp (t), size (3)
  105. {
  106. packedData.asBytes[0] = (uint8) byte1;
  107. packedData.asBytes[1] = (uint8) byte2;
  108. packedData.asBytes[2] = (uint8) byte3;
  109. // check that the length matches the data..
  110. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  111. }
  112. MidiMessage::MidiMessage (const MidiMessage& other)
  113. : timeStamp (other.timeStamp), size (other.size)
  114. {
  115. if (isHeapAllocated())
  116. memcpy (allocateSpace (size), other.getData(), (size_t) size);
  117. else
  118. packedData.allocatedData = other.packedData.allocatedData;
  119. }
  120. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  121. : timeStamp (newTimeStamp), size (other.size)
  122. {
  123. if (isHeapAllocated())
  124. memcpy (allocateSpace (size), other.getData(), (size_t) size);
  125. else
  126. packedData.allocatedData = other.packedData.allocatedData;
  127. }
  128. MidiMessage::MidiMessage (const void* srcData, int sz, int& numBytesUsed, const uint8 lastStatusByte,
  129. double t, bool sysexHasEmbeddedLength)
  130. : timeStamp (t)
  131. {
  132. const uint8* src = static_cast<const uint8*> (srcData);
  133. unsigned int byte = (unsigned int) *src;
  134. if (byte < 0x80)
  135. {
  136. byte = (unsigned int) (uint8) lastStatusByte;
  137. numBytesUsed = -1;
  138. }
  139. else
  140. {
  141. numBytesUsed = 0;
  142. --sz;
  143. ++src;
  144. }
  145. if (byte >= 0x80)
  146. {
  147. if (byte == 0xf0)
  148. {
  149. const uint8* d = src;
  150. bool haveReadAllLengthBytes = ! sysexHasEmbeddedLength;
  151. int numVariableLengthSysexBytes = 0;
  152. while (d < src + sz)
  153. {
  154. if (*d >= 0x80)
  155. {
  156. if (*d == 0xf7)
  157. {
  158. ++d; // include the trailing 0xf7 when we hit it
  159. break;
  160. }
  161. if (haveReadAllLengthBytes) // if we see a 0x80 bit set after the initial data length
  162. break; // bytes, assume it's the end of the sysex
  163. ++numVariableLengthSysexBytes;
  164. }
  165. else if (! haveReadAllLengthBytes)
  166. {
  167. haveReadAllLengthBytes = true;
  168. ++numVariableLengthSysexBytes;
  169. }
  170. ++d;
  171. }
  172. src += numVariableLengthSysexBytes;
  173. size = 1 + (int) (d - src);
  174. uint8* dest = allocateSpace (size);
  175. *dest = (uint8) byte;
  176. memcpy (dest + 1, src, (size_t) (size - 1));
  177. numBytesUsed += numVariableLengthSysexBytes; // (these aren't counted in the size)
  178. }
  179. else if (byte == 0xff)
  180. {
  181. int n;
  182. const int bytesLeft = readVariableLengthVal (src + 1, n);
  183. size = jmin (sz + 1, n + 2 + bytesLeft);
  184. uint8* dest = allocateSpace (size);
  185. *dest = (uint8) byte;
  186. memcpy (dest + 1, src, (size_t) size - 1);
  187. }
  188. else
  189. {
  190. size = getMessageLengthFromFirstByte ((uint8) byte);
  191. packedData.asBytes[0] = (uint8) byte;
  192. if (size > 1)
  193. {
  194. packedData.asBytes[1] = src[0];
  195. if (size > 2)
  196. packedData.asBytes[2] = src[1];
  197. }
  198. }
  199. numBytesUsed += size;
  200. }
  201. else
  202. {
  203. packedData.allocatedData = nullptr;
  204. size = 0;
  205. }
  206. }
  207. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  208. {
  209. if (this != &other)
  210. {
  211. if (other.isHeapAllocated())
  212. {
  213. if (isHeapAllocated())
  214. packedData.allocatedData = static_cast<uint8*> (std::realloc (packedData.allocatedData, (size_t) other.size));
  215. else
  216. packedData.allocatedData = static_cast<uint8*> (std::malloc ((size_t) other.size));
  217. memcpy (packedData.allocatedData, other.packedData.allocatedData, (size_t) other.size);
  218. }
  219. else
  220. {
  221. if (isHeapAllocated())
  222. std::free (packedData.allocatedData);
  223. packedData.allocatedData = other.packedData.allocatedData;
  224. }
  225. timeStamp = other.timeStamp;
  226. size = other.size;
  227. }
  228. return *this;
  229. }
  230. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  231. MidiMessage::MidiMessage (MidiMessage&& other) noexcept
  232. : timeStamp (other.timeStamp), size (other.size)
  233. {
  234. packedData.allocatedData = other.packedData.allocatedData;
  235. other.size = 0;
  236. }
  237. MidiMessage& MidiMessage::operator= (MidiMessage&& other) noexcept
  238. {
  239. packedData.allocatedData = other.packedData.allocatedData;
  240. timeStamp = other.timeStamp;
  241. size = other.size;
  242. other.size = 0;
  243. return *this;
  244. }
  245. #endif
  246. MidiMessage::~MidiMessage() noexcept
  247. {
  248. if (isHeapAllocated())
  249. std::free (packedData.allocatedData);
  250. }
  251. uint8* MidiMessage::allocateSpace (int bytes)
  252. {
  253. if (bytes > (int) sizeof (packedData))
  254. {
  255. uint8* d = static_cast<uint8*> (std::malloc ((size_t) bytes));
  256. packedData.allocatedData = d;
  257. return d;
  258. }
  259. return packedData.asBytes;
  260. }
  261. String MidiMessage::getDescription() const
  262. {
  263. if (isNoteOn()) return "Note on " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel());
  264. if (isNoteOff()) return "Note off " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + " Velocity " + String (getVelocity()) + " Channel " + String (getChannel());
  265. if (isProgramChange()) return "Program change " + String (getProgramChangeNumber()) + " Channel " + String (getChannel());
  266. if (isPitchWheel()) return "Pitch wheel " + String (getPitchWheelValue()) + " Channel " + String (getChannel());
  267. if (isAftertouch()) return "Aftertouch " + MidiMessage::getMidiNoteName (getNoteNumber(), true, true, 3) + ": " + String (getAfterTouchValue()) + " Channel " + String (getChannel());
  268. if (isChannelPressure()) return "Channel pressure " + String (getChannelPressureValue()) + " Channel " + String (getChannel());
  269. if (isAllNotesOff()) return "All notes off Channel " + String (getChannel());
  270. if (isAllSoundOff()) return "All sound off Channel " + String (getChannel());
  271. if (isMetaEvent()) return "Meta event";
  272. if (isController())
  273. {
  274. String name (MidiMessage::getControllerName (getControllerNumber()));
  275. if (name.isEmpty())
  276. name = String (getControllerNumber());
  277. return "Controller " + name + ": " + String (getControllerValue()) + " Channel " + String (getChannel());
  278. }
  279. return String::toHexString (getRawData(), getRawDataSize());
  280. }
  281. int MidiMessage::getChannel() const noexcept
  282. {
  283. const uint8* const data = getRawData();
  284. if ((data[0] & 0xf0) != 0xf0)
  285. return (data[0] & 0xf) + 1;
  286. return 0;
  287. }
  288. bool MidiMessage::isForChannel (const int channel) const noexcept
  289. {
  290. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  291. const uint8* const data = getRawData();
  292. return ((data[0] & 0xf) == channel - 1)
  293. && ((data[0] & 0xf0) != 0xf0);
  294. }
  295. void MidiMessage::setChannel (const int channel) noexcept
  296. {
  297. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  298. uint8* const data = getData();
  299. if ((data[0] & 0xf0) != (uint8) 0xf0)
  300. data[0] = (uint8) ((data[0] & (uint8) 0xf0)
  301. | (uint8)(channel - 1));
  302. }
  303. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const noexcept
  304. {
  305. const uint8* const data = getRawData();
  306. return ((data[0] & 0xf0) == 0x90)
  307. && (returnTrueForVelocity0 || data[2] != 0);
  308. }
  309. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const noexcept
  310. {
  311. const uint8* const data = getRawData();
  312. return ((data[0] & 0xf0) == 0x80)
  313. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  314. }
  315. bool MidiMessage::isNoteOnOrOff() const noexcept
  316. {
  317. const uint8* const data = getRawData();
  318. const int d = data[0] & 0xf0;
  319. return (d == 0x90) || (d == 0x80);
  320. }
  321. int MidiMessage::getNoteNumber() const noexcept
  322. {
  323. return getRawData()[1];
  324. }
  325. void MidiMessage::setNoteNumber (const int newNoteNumber) noexcept
  326. {
  327. if (isNoteOnOrOff() || isAftertouch())
  328. getData()[1] = (uint8) (newNoteNumber & 127);
  329. }
  330. uint8 MidiMessage::getVelocity() const noexcept
  331. {
  332. if (isNoteOnOrOff())
  333. return getRawData()[2];
  334. return 0;
  335. }
  336. float MidiMessage::getFloatVelocity() const noexcept
  337. {
  338. return getVelocity() * (1.0f / 127.0f);
  339. }
  340. void MidiMessage::setVelocity (const float newVelocity) noexcept
  341. {
  342. if (isNoteOnOrOff())
  343. getData()[2] = floatValueToMidiByte (newVelocity);
  344. }
  345. void MidiMessage::multiplyVelocity (const float scaleFactor) noexcept
  346. {
  347. if (isNoteOnOrOff())
  348. {
  349. uint8* const data = getData();
  350. data[2] = MidiHelpers::validVelocity (roundToInt (scaleFactor * data[2]));
  351. }
  352. }
  353. bool MidiMessage::isAftertouch() const noexcept
  354. {
  355. return (getRawData()[0] & 0xf0) == 0xa0;
  356. }
  357. int MidiMessage::getAfterTouchValue() const noexcept
  358. {
  359. jassert (isAftertouch());
  360. return getRawData()[2];
  361. }
  362. MidiMessage MidiMessage::aftertouchChange (const int channel,
  363. const int noteNum,
  364. const int aftertouchValue) noexcept
  365. {
  366. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  367. jassert (isPositiveAndBelow (noteNum, (int) 128));
  368. jassert (isPositiveAndBelow (aftertouchValue, (int) 128));
  369. return MidiMessage (MidiHelpers::initialByte (0xa0, channel),
  370. noteNum & 0x7f,
  371. aftertouchValue & 0x7f);
  372. }
  373. bool MidiMessage::isChannelPressure() const noexcept
  374. {
  375. return (getRawData()[0] & 0xf0) == 0xd0;
  376. }
  377. int MidiMessage::getChannelPressureValue() const noexcept
  378. {
  379. jassert (isChannelPressure());
  380. return getRawData()[1];
  381. }
  382. MidiMessage MidiMessage::channelPressureChange (const int channel, const int pressure) noexcept
  383. {
  384. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  385. jassert (isPositiveAndBelow (pressure, (int) 128));
  386. return MidiMessage (MidiHelpers::initialByte (0xd0, channel), pressure & 0x7f);
  387. }
  388. bool MidiMessage::isSustainPedalOn() const noexcept { return isControllerOfType (0x40) && getRawData()[2] >= 64; }
  389. bool MidiMessage::isSustainPedalOff() const noexcept { return isControllerOfType (0x40) && getRawData()[2] < 64; }
  390. bool MidiMessage::isSostenutoPedalOn() const noexcept { return isControllerOfType (0x42) && getRawData()[2] >= 64; }
  391. bool MidiMessage::isSostenutoPedalOff() const noexcept { return isControllerOfType (0x42) && getRawData()[2] < 64; }
  392. bool MidiMessage::isSoftPedalOn() const noexcept { return isControllerOfType (0x43) && getRawData()[2] >= 64; }
  393. bool MidiMessage::isSoftPedalOff() const noexcept { return isControllerOfType (0x43) && getRawData()[2] < 64; }
  394. bool MidiMessage::isProgramChange() const noexcept
  395. {
  396. return (getRawData()[0] & 0xf0) == 0xc0;
  397. }
  398. int MidiMessage::getProgramChangeNumber() const noexcept
  399. {
  400. jassert (isProgramChange());
  401. return getRawData()[1];
  402. }
  403. MidiMessage MidiMessage::programChange (const int channel, const int programNumber) noexcept
  404. {
  405. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  406. return MidiMessage (MidiHelpers::initialByte (0xc0, channel), programNumber & 0x7f);
  407. }
  408. bool MidiMessage::isPitchWheel() const noexcept
  409. {
  410. return (getRawData()[0] & 0xf0) == 0xe0;
  411. }
  412. int MidiMessage::getPitchWheelValue() const noexcept
  413. {
  414. jassert (isPitchWheel());
  415. const uint8* const data = getRawData();
  416. return data[1] | (data[2] << 7);
  417. }
  418. MidiMessage MidiMessage::pitchWheel (const int channel, const int position) noexcept
  419. {
  420. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  421. jassert (isPositiveAndBelow (position, (int) 0x4000));
  422. return MidiMessage (MidiHelpers::initialByte (0xe0, channel),
  423. position & 127, (position >> 7) & 127);
  424. }
  425. bool MidiMessage::isController() const noexcept
  426. {
  427. return (getRawData()[0] & 0xf0) == 0xb0;
  428. }
  429. bool MidiMessage::isControllerOfType (const int controllerType) const noexcept
  430. {
  431. const uint8* const data = getRawData();
  432. return (data[0] & 0xf0) == 0xb0 && data[1] == controllerType;
  433. }
  434. int MidiMessage::getControllerNumber() const noexcept
  435. {
  436. jassert (isController());
  437. return getRawData()[1];
  438. }
  439. int MidiMessage::getControllerValue() const noexcept
  440. {
  441. jassert (isController());
  442. return getRawData()[2];
  443. }
  444. MidiMessage MidiMessage::controllerEvent (const int channel, const int controllerType, const int value) noexcept
  445. {
  446. // the channel must be between 1 and 16 inclusive
  447. jassert (channel > 0 && channel <= 16);
  448. return MidiMessage (MidiHelpers::initialByte (0xb0, channel),
  449. controllerType & 127, value & 127);
  450. }
  451. MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const uint8 velocity) noexcept
  452. {
  453. jassert (channel > 0 && channel <= 16);
  454. jassert (isPositiveAndBelow (noteNumber, (int) 128));
  455. return MidiMessage (MidiHelpers::initialByte (0x90, channel),
  456. noteNumber & 127, MidiHelpers::validVelocity (velocity));
  457. }
  458. MidiMessage MidiMessage::noteOn (const int channel, const int noteNumber, const float velocity) noexcept
  459. {
  460. return noteOn (channel, noteNumber, floatValueToMidiByte (velocity));
  461. }
  462. MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, uint8 velocity) noexcept
  463. {
  464. jassert (channel > 0 && channel <= 16);
  465. jassert (isPositiveAndBelow (noteNumber, (int) 128));
  466. return MidiMessage (MidiHelpers::initialByte (0x80, channel),
  467. noteNumber & 127, MidiHelpers::validVelocity (velocity));
  468. }
  469. MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber, float velocity) noexcept
  470. {
  471. return noteOff (channel, noteNumber, floatValueToMidiByte (velocity));
  472. }
  473. MidiMessage MidiMessage::noteOff (const int channel, const int noteNumber) noexcept
  474. {
  475. jassert (channel > 0 && channel <= 16);
  476. jassert (isPositiveAndBelow (noteNumber, (int) 128));
  477. return MidiMessage (MidiHelpers::initialByte (0x80, channel), noteNumber & 127, 0);
  478. }
  479. MidiMessage MidiMessage::allNotesOff (const int channel) noexcept
  480. {
  481. return controllerEvent (channel, 123, 0);
  482. }
  483. bool MidiMessage::isAllNotesOff() const noexcept
  484. {
  485. const uint8* const data = getRawData();
  486. return (data[0] & 0xf0) == 0xb0 && data[1] == 123;
  487. }
  488. MidiMessage MidiMessage::allSoundOff (const int channel) noexcept
  489. {
  490. return controllerEvent (channel, 120, 0);
  491. }
  492. bool MidiMessage::isAllSoundOff() const noexcept
  493. {
  494. const uint8* const data = getRawData();
  495. return (data[0] & 0xf0) == 0xb0 && data[1] == 120;
  496. }
  497. MidiMessage MidiMessage::allControllersOff (const int channel) noexcept
  498. {
  499. return controllerEvent (channel, 121, 0);
  500. }
  501. MidiMessage MidiMessage::masterVolume (const float volume)
  502. {
  503. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  504. const uint8 buf[] = { 0xf0, 0x7f, 0x7f, 0x04, 0x01,
  505. (uint8) (vol & 0x7f),
  506. (uint8) (vol >> 7),
  507. 0xf7 };
  508. return MidiMessage (buf, 8);
  509. }
  510. //==============================================================================
  511. bool MidiMessage::isSysEx() const noexcept
  512. {
  513. return *getRawData() == 0xf0;
  514. }
  515. MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize)
  516. {
  517. HeapBlock<uint8> m ((size_t) dataSize + 2);
  518. m[0] = 0xf0;
  519. memcpy (m + 1, sysexData, (size_t) dataSize);
  520. m[dataSize + 1] = 0xf7;
  521. return MidiMessage (m, dataSize + 2);
  522. }
  523. const uint8* MidiMessage::getSysExData() const noexcept
  524. {
  525. return isSysEx() ? getRawData() + 1 : nullptr;
  526. }
  527. int MidiMessage::getSysExDataSize() const noexcept
  528. {
  529. return isSysEx() ? size - 2 : 0;
  530. }
  531. //==============================================================================
  532. bool MidiMessage::isMetaEvent() const noexcept { return *getRawData() == 0xff; }
  533. bool MidiMessage::isActiveSense() const noexcept { return *getRawData() == 0xfe; }
  534. int MidiMessage::getMetaEventType() const noexcept
  535. {
  536. const uint8* const data = getRawData();
  537. return *data != 0xff ? -1 : data[1];
  538. }
  539. int MidiMessage::getMetaEventLength() const noexcept
  540. {
  541. const uint8* const data = getRawData();
  542. if (*data == 0xff)
  543. {
  544. int n;
  545. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  546. }
  547. return 0;
  548. }
  549. const uint8* MidiMessage::getMetaEventData() const noexcept
  550. {
  551. jassert (isMetaEvent());
  552. int n;
  553. const uint8* d = getRawData() + 2;
  554. readVariableLengthVal (d, n);
  555. return d + n;
  556. }
  557. bool MidiMessage::isTrackMetaEvent() const noexcept { return getMetaEventType() == 0; }
  558. bool MidiMessage::isEndOfTrackMetaEvent() const noexcept { return getMetaEventType() == 47; }
  559. bool MidiMessage::isTextMetaEvent() const noexcept
  560. {
  561. const int t = getMetaEventType();
  562. return t > 0 && t < 16;
  563. }
  564. String MidiMessage::getTextFromTextMetaEvent() const
  565. {
  566. const char* const textData = reinterpret_cast<const char*> (getMetaEventData());
  567. return String (CharPointer_UTF8 (textData),
  568. CharPointer_UTF8 (textData + getMetaEventLength()));
  569. }
  570. MidiMessage MidiMessage::textMetaEvent (int type, StringRef text)
  571. {
  572. jassert (type > 0 && type < 16);
  573. MidiMessage result;
  574. const size_t textSize = text.text.sizeInBytes() - 1;
  575. uint8 header[8];
  576. size_t n = sizeof (header);
  577. header[--n] = (uint8) (textSize & 0x7f);
  578. for (size_t i = textSize; (i >>= 7) != 0;)
  579. header[--n] = (uint8) ((i & 0x7f) | 0x80);
  580. header[--n] = (uint8) type;
  581. header[--n] = 0xff;
  582. const size_t headerLen = sizeof (header) - n;
  583. const int totalSize = (int) (headerLen + textSize);
  584. uint8* const dest = result.allocateSpace (totalSize);
  585. result.size = totalSize;
  586. memcpy (dest, header + n, headerLen);
  587. memcpy (dest + headerLen, text.text.getAddress(), textSize);
  588. return result;
  589. }
  590. bool MidiMessage::isTrackNameEvent() const noexcept { const uint8* data = getRawData(); return (data[1] == 3) && (*data == 0xff); }
  591. bool MidiMessage::isTempoMetaEvent() const noexcept { const uint8* data = getRawData(); return (data[1] == 81) && (*data == 0xff); }
  592. bool MidiMessage::isMidiChannelMetaEvent() const noexcept { const uint8* data = getRawData(); return (data[1] == 0x20) && (*data == 0xff) && (data[2] == 1); }
  593. int MidiMessage::getMidiChannelMetaEventChannel() const noexcept
  594. {
  595. jassert (isMidiChannelMetaEvent());
  596. return getRawData()[3] + 1;
  597. }
  598. double MidiMessage::getTempoSecondsPerQuarterNote() const noexcept
  599. {
  600. if (! isTempoMetaEvent())
  601. return 0.0;
  602. const uint8* const d = getMetaEventData();
  603. return (((unsigned int) d[0] << 16)
  604. | ((unsigned int) d[1] << 8)
  605. | d[2])
  606. / 1000000.0;
  607. }
  608. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const noexcept
  609. {
  610. if (timeFormat > 0)
  611. {
  612. if (! isTempoMetaEvent())
  613. return 0.5 / timeFormat;
  614. return getTempoSecondsPerQuarterNote() / timeFormat;
  615. }
  616. else
  617. {
  618. const int frameCode = (-timeFormat) >> 8;
  619. double framesPerSecond;
  620. switch (frameCode)
  621. {
  622. case 24: framesPerSecond = 24.0; break;
  623. case 25: framesPerSecond = 25.0; break;
  624. case 29: framesPerSecond = 29.97; break;
  625. case 30: framesPerSecond = 30.0; break;
  626. default: framesPerSecond = 30.0; break;
  627. }
  628. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  629. }
  630. }
  631. MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) noexcept
  632. {
  633. const uint8 d[] = { 0xff, 81, 3,
  634. (uint8) (microsecondsPerQuarterNote >> 16),
  635. (uint8) (microsecondsPerQuarterNote >> 8),
  636. (uint8) microsecondsPerQuarterNote };
  637. return MidiMessage (d, 6, 0.0);
  638. }
  639. bool MidiMessage::isTimeSignatureMetaEvent() const noexcept
  640. {
  641. const uint8* const data = getRawData();
  642. return (data[1] == 0x58) && (*data == (uint8) 0xff);
  643. }
  644. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const noexcept
  645. {
  646. if (isTimeSignatureMetaEvent())
  647. {
  648. const uint8* const d = getMetaEventData();
  649. numerator = d[0];
  650. denominator = 1 << d[1];
  651. }
  652. else
  653. {
  654. numerator = 4;
  655. denominator = 4;
  656. }
  657. }
  658. MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  659. {
  660. int n = 1;
  661. int powerOfTwo = 0;
  662. while (n < denominator)
  663. {
  664. n <<= 1;
  665. ++powerOfTwo;
  666. }
  667. const uint8 d[] = { 0xff, 0x58, 0x04, (uint8) numerator, (uint8) powerOfTwo, 1, 96 };
  668. return MidiMessage (d, 7, 0.0);
  669. }
  670. MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) noexcept
  671. {
  672. const uint8 d[] = { 0xff, 0x20, 0x01, (uint8) jlimit (0, 0xff, channel - 1) };
  673. return MidiMessage (d, 4, 0.0);
  674. }
  675. bool MidiMessage::isKeySignatureMetaEvent() const noexcept
  676. {
  677. return getMetaEventType() == 0x59;
  678. }
  679. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const noexcept
  680. {
  681. return (int) (int8) getMetaEventData()[0];
  682. }
  683. bool MidiMessage::isKeySignatureMajorKey() const noexcept
  684. {
  685. return getMetaEventData()[1] == 0;
  686. }
  687. MidiMessage MidiMessage::keySignatureMetaEvent (int numberOfSharpsOrFlats, bool isMinorKey)
  688. {
  689. jassert (numberOfSharpsOrFlats >= -7 && numberOfSharpsOrFlats <= 7);
  690. const uint8 d[] = { 0xff, 0x59, 0x02, (uint8) numberOfSharpsOrFlats, isMinorKey ? (uint8) 1 : (uint8) 0 };
  691. return MidiMessage (d, 5, 0.0);
  692. }
  693. MidiMessage MidiMessage::endOfTrack() noexcept
  694. {
  695. return MidiMessage (0xff, 0x2f, 0, 0.0);
  696. }
  697. //==============================================================================
  698. bool MidiMessage::isSongPositionPointer() const noexcept { return *getRawData() == 0xf2; }
  699. int MidiMessage::getSongPositionPointerMidiBeat() const noexcept { const uint8* data = getRawData(); return data[1] | (data[2] << 7); }
  700. MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) noexcept
  701. {
  702. return MidiMessage (0xf2,
  703. positionInMidiBeats & 127,
  704. (positionInMidiBeats >> 7) & 127);
  705. }
  706. bool MidiMessage::isMidiStart() const noexcept { return *getRawData() == 0xfa; }
  707. MidiMessage MidiMessage::midiStart() noexcept { return MidiMessage (0xfa); }
  708. bool MidiMessage::isMidiContinue() const noexcept { return *getRawData() == 0xfb; }
  709. MidiMessage MidiMessage::midiContinue() noexcept { return MidiMessage (0xfb); }
  710. bool MidiMessage::isMidiStop() const noexcept { return *getRawData() == 0xfc; }
  711. MidiMessage MidiMessage::midiStop() noexcept { return MidiMessage (0xfc); }
  712. bool MidiMessage::isMidiClock() const noexcept { return *getRawData() == 0xf8; }
  713. MidiMessage MidiMessage::midiClock() noexcept { return MidiMessage (0xf8); }
  714. bool MidiMessage::isQuarterFrame() const noexcept { return *getRawData() == 0xf1; }
  715. int MidiMessage::getQuarterFrameSequenceNumber() const noexcept { return ((int) getRawData()[1]) >> 4; }
  716. int MidiMessage::getQuarterFrameValue() const noexcept { return ((int) getRawData()[1]) & 0x0f; }
  717. MidiMessage MidiMessage::quarterFrame (const int sequenceNumber, const int value) noexcept
  718. {
  719. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  720. }
  721. bool MidiMessage::isFullFrame() const noexcept
  722. {
  723. const uint8* const data = getRawData();
  724. return data[0] == 0xf0
  725. && data[1] == 0x7f
  726. && size >= 10
  727. && data[3] == 0x01
  728. && data[4] == 0x01;
  729. }
  730. void MidiMessage::getFullFrameParameters (int& hours, int& minutes, int& seconds, int& frames,
  731. MidiMessage::SmpteTimecodeType& timecodeType) const noexcept
  732. {
  733. jassert (isFullFrame());
  734. const uint8* const data = getRawData();
  735. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  736. hours = data[5] & 0x1f;
  737. minutes = data[6];
  738. seconds = data[7];
  739. frames = data[8];
  740. }
  741. MidiMessage MidiMessage::fullFrame (const int hours, const int minutes,
  742. const int seconds, const int frames,
  743. MidiMessage::SmpteTimecodeType timecodeType)
  744. {
  745. const uint8 d[] = { 0xf0, 0x7f, 0x7f, 0x01, 0x01,
  746. (uint8) ((hours & 0x01f) | (timecodeType << 5)),
  747. (uint8) minutes,
  748. (uint8) seconds,
  749. (uint8) frames,
  750. 0xf7 };
  751. return MidiMessage (d, 10, 0.0);
  752. }
  753. bool MidiMessage::isMidiMachineControlMessage() const noexcept
  754. {
  755. const uint8* const data = getRawData();
  756. return data[0] == 0xf0
  757. && data[1] == 0x7f
  758. && data[3] == 0x06
  759. && size > 5;
  760. }
  761. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const noexcept
  762. {
  763. jassert (isMidiMachineControlMessage());
  764. return (MidiMachineControlCommand) getRawData()[4];
  765. }
  766. MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  767. {
  768. const uint8 d[] = { 0xf0, 0x7f, 0, 6, (uint8) command, 0xf7 };
  769. return MidiMessage (d, 6, 0.0);
  770. }
  771. //==============================================================================
  772. bool MidiMessage::isMidiMachineControlGoto (int& hours, int& minutes, int& seconds, int& frames) const noexcept
  773. {
  774. const uint8* const data = getRawData();
  775. if (size >= 12
  776. && data[0] == 0xf0
  777. && data[1] == 0x7f
  778. && data[3] == 0x06
  779. && data[4] == 0x44
  780. && data[5] == 0x06
  781. && data[6] == 0x01)
  782. {
  783. hours = data[7] % 24; // (that some machines send out hours > 24)
  784. minutes = data[8];
  785. seconds = data[9];
  786. frames = data[10];
  787. return true;
  788. }
  789. return false;
  790. }
  791. MidiMessage MidiMessage::midiMachineControlGoto (int hours, int minutes, int seconds, int frames)
  792. {
  793. const uint8 d[] = { 0xf0, 0x7f, 0, 6, 0x44, 6, 1,
  794. (uint8) hours,
  795. (uint8) minutes,
  796. (uint8) seconds,
  797. (uint8) frames,
  798. 0xf7 };
  799. return MidiMessage (d, 12, 0.0);
  800. }
  801. //==============================================================================
  802. String MidiMessage::getMidiNoteName (int note, bool useSharps, bool includeOctaveNumber, int octaveNumForMiddleC)
  803. {
  804. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
  805. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" };
  806. if (isPositiveAndBelow (note, (int) 128))
  807. {
  808. String s (useSharps ? sharpNoteNames [note % 12]
  809. : flatNoteNames [note % 12]);
  810. if (includeOctaveNumber)
  811. s << (note / 12 + (octaveNumForMiddleC - 5));
  812. return s;
  813. }
  814. return String();
  815. }
  816. double MidiMessage::getMidiNoteInHertz (const int noteNumber, const double frequencyOfA) noexcept
  817. {
  818. return frequencyOfA * pow (2.0, (noteNumber - 69) / 12.0);
  819. }
  820. bool MidiMessage::isMidiNoteBlack (int noteNumber) noexcept
  821. {
  822. return ((1 << (noteNumber % 12)) & 0x054a) != 0;
  823. }
  824. const char* MidiMessage::getGMInstrumentName (const int n)
  825. {
  826. static const char* names[] =
  827. {
  828. NEEDS_TRANS("Acoustic Grand Piano"), NEEDS_TRANS("Bright Acoustic Piano"), NEEDS_TRANS("Electric Grand Piano"), NEEDS_TRANS("Honky-tonk Piano"),
  829. NEEDS_TRANS("Electric Piano 1"), NEEDS_TRANS("Electric Piano 2"), NEEDS_TRANS("Harpsichord"), NEEDS_TRANS("Clavinet"),
  830. NEEDS_TRANS("Celesta"), NEEDS_TRANS("Glockenspiel"), NEEDS_TRANS("Music Box"), NEEDS_TRANS("Vibraphone"),
  831. NEEDS_TRANS("Marimba"), NEEDS_TRANS("Xylophone"), NEEDS_TRANS("Tubular Bells"), NEEDS_TRANS("Dulcimer"),
  832. NEEDS_TRANS("Drawbar Organ"), NEEDS_TRANS("Percussive Organ"), NEEDS_TRANS("Rock Organ"), NEEDS_TRANS("Church Organ"),
  833. NEEDS_TRANS("Reed Organ"), NEEDS_TRANS("Accordion"), NEEDS_TRANS("Harmonica"), NEEDS_TRANS("Tango Accordion"),
  834. NEEDS_TRANS("Acoustic Guitar (nylon)"), NEEDS_TRANS("Acoustic Guitar (steel)"), NEEDS_TRANS("Electric Guitar (jazz)"), NEEDS_TRANS("Electric Guitar (clean)"),
  835. NEEDS_TRANS("Electric Guitar (mute)"), NEEDS_TRANS("Overdriven Guitar"), NEEDS_TRANS("Distortion Guitar"), NEEDS_TRANS("Guitar Harmonics"),
  836. NEEDS_TRANS("Acoustic Bass"), NEEDS_TRANS("Electric Bass (finger)"), NEEDS_TRANS("Electric Bass (pick)"), NEEDS_TRANS("Fretless Bass"),
  837. NEEDS_TRANS("Slap Bass 1"), NEEDS_TRANS("Slap Bass 2"), NEEDS_TRANS("Synth Bass 1"), NEEDS_TRANS("Synth Bass 2"),
  838. NEEDS_TRANS("Violin"), NEEDS_TRANS("Viola"), NEEDS_TRANS("Cello"), NEEDS_TRANS("Contrabass"),
  839. NEEDS_TRANS("Tremolo Strings"), NEEDS_TRANS("Pizzicato Strings"), NEEDS_TRANS("Orchestral Harp"), NEEDS_TRANS("Timpani"),
  840. NEEDS_TRANS("String Ensemble 1"), NEEDS_TRANS("String Ensemble 2"), NEEDS_TRANS("SynthStrings 1"), NEEDS_TRANS("SynthStrings 2"),
  841. NEEDS_TRANS("Choir Aahs"), NEEDS_TRANS("Voice Oohs"), NEEDS_TRANS("Synth Voice"), NEEDS_TRANS("Orchestra Hit"),
  842. NEEDS_TRANS("Trumpet"), NEEDS_TRANS("Trombone"), NEEDS_TRANS("Tuba"), NEEDS_TRANS("Muted Trumpet"),
  843. NEEDS_TRANS("French Horn"), NEEDS_TRANS("Brass Section"), NEEDS_TRANS("SynthBrass 1"), NEEDS_TRANS("SynthBrass 2"),
  844. NEEDS_TRANS("Soprano Sax"), NEEDS_TRANS("Alto Sax"), NEEDS_TRANS("Tenor Sax"), NEEDS_TRANS("Baritone Sax"),
  845. NEEDS_TRANS("Oboe"), NEEDS_TRANS("English Horn"), NEEDS_TRANS("Bassoon"), NEEDS_TRANS("Clarinet"),
  846. NEEDS_TRANS("Piccolo"), NEEDS_TRANS("Flute"), NEEDS_TRANS("Recorder"), NEEDS_TRANS("Pan Flute"),
  847. NEEDS_TRANS("Blown Bottle"), NEEDS_TRANS("Shakuhachi"), NEEDS_TRANS("Whistle"), NEEDS_TRANS("Ocarina"),
  848. NEEDS_TRANS("Lead 1 (square)"), NEEDS_TRANS("Lead 2 (sawtooth)"), NEEDS_TRANS("Lead 3 (calliope)"), NEEDS_TRANS("Lead 4 (chiff)"),
  849. NEEDS_TRANS("Lead 5 (charang)"), NEEDS_TRANS("Lead 6 (voice)"), NEEDS_TRANS("Lead 7 (fifths)"), NEEDS_TRANS("Lead 8 (bass+lead)"),
  850. NEEDS_TRANS("Pad 1 (new age)"), NEEDS_TRANS("Pad 2 (warm)"), NEEDS_TRANS("Pad 3 (polysynth)"), NEEDS_TRANS("Pad 4 (choir)"),
  851. NEEDS_TRANS("Pad 5 (bowed)"), NEEDS_TRANS("Pad 6 (metallic)"), NEEDS_TRANS("Pad 7 (halo)"), NEEDS_TRANS("Pad 8 (sweep)"),
  852. NEEDS_TRANS("FX 1 (rain)"), NEEDS_TRANS("FX 2 (soundtrack)"), NEEDS_TRANS("FX 3 (crystal)"), NEEDS_TRANS("FX 4 (atmosphere)"),
  853. NEEDS_TRANS("FX 5 (brightness)"), NEEDS_TRANS("FX 6 (goblins)"), NEEDS_TRANS("FX 7 (echoes)"), NEEDS_TRANS("FX 8 (sci-fi)"),
  854. NEEDS_TRANS("Sitar"), NEEDS_TRANS("Banjo"), NEEDS_TRANS("Shamisen"), NEEDS_TRANS("Koto"),
  855. NEEDS_TRANS("Kalimba"), NEEDS_TRANS("Bag pipe"), NEEDS_TRANS("Fiddle"), NEEDS_TRANS("Shanai"),
  856. NEEDS_TRANS("Tinkle Bell"), NEEDS_TRANS("Agogo"), NEEDS_TRANS("Steel Drums"), NEEDS_TRANS("Woodblock"),
  857. NEEDS_TRANS("Taiko Drum"), NEEDS_TRANS("Melodic Tom"), NEEDS_TRANS("Synth Drum"), NEEDS_TRANS("Reverse Cymbal"),
  858. NEEDS_TRANS("Guitar Fret Noise"), NEEDS_TRANS("Breath Noise"), NEEDS_TRANS("Seashore"), NEEDS_TRANS("Bird Tweet"),
  859. NEEDS_TRANS("Telephone Ring"), NEEDS_TRANS("Helicopter"), NEEDS_TRANS("Applause"), NEEDS_TRANS("Gunshot")
  860. };
  861. return isPositiveAndBelow (n, numElementsInArray (names)) ? names[n] : nullptr;
  862. }
  863. const char* MidiMessage::getGMInstrumentBankName (const int n)
  864. {
  865. static const char* names[] =
  866. {
  867. NEEDS_TRANS("Piano"), NEEDS_TRANS("Chromatic Percussion"), NEEDS_TRANS("Organ"), NEEDS_TRANS("Guitar"),
  868. NEEDS_TRANS("Bass"), NEEDS_TRANS("Strings"), NEEDS_TRANS("Ensemble"), NEEDS_TRANS("Brass"),
  869. NEEDS_TRANS("Reed"), NEEDS_TRANS("Pipe"), NEEDS_TRANS("Synth Lead"), NEEDS_TRANS("Synth Pad"),
  870. NEEDS_TRANS("Synth Effects"), NEEDS_TRANS("Ethnic"), NEEDS_TRANS("Percussive"), NEEDS_TRANS("Sound Effects")
  871. };
  872. return isPositiveAndBelow (n, numElementsInArray (names)) ? names[n] : nullptr;
  873. }
  874. const char* MidiMessage::getRhythmInstrumentName (const int n)
  875. {
  876. static const char* names[] =
  877. {
  878. NEEDS_TRANS("Acoustic Bass Drum"), NEEDS_TRANS("Bass Drum 1"), NEEDS_TRANS("Side Stick"), NEEDS_TRANS("Acoustic Snare"),
  879. NEEDS_TRANS("Hand Clap"), NEEDS_TRANS("Electric Snare"), NEEDS_TRANS("Low Floor Tom"), NEEDS_TRANS("Closed Hi-Hat"),
  880. NEEDS_TRANS("High Floor Tom"), NEEDS_TRANS("Pedal Hi-Hat"), NEEDS_TRANS("Low Tom"), NEEDS_TRANS("Open Hi-Hat"),
  881. NEEDS_TRANS("Low-Mid Tom"), NEEDS_TRANS("Hi-Mid Tom"), NEEDS_TRANS("Crash Cymbal 1"), NEEDS_TRANS("High Tom"),
  882. NEEDS_TRANS("Ride Cymbal 1"), NEEDS_TRANS("Chinese Cymbal"), NEEDS_TRANS("Ride Bell"), NEEDS_TRANS("Tambourine"),
  883. NEEDS_TRANS("Splash Cymbal"), NEEDS_TRANS("Cowbell"), NEEDS_TRANS("Crash Cymbal 2"), NEEDS_TRANS("Vibraslap"),
  884. NEEDS_TRANS("Ride Cymbal 2"), NEEDS_TRANS("Hi Bongo"), NEEDS_TRANS("Low Bongo"), NEEDS_TRANS("Mute Hi Conga"),
  885. NEEDS_TRANS("Open Hi Conga"), NEEDS_TRANS("Low Conga"), NEEDS_TRANS("High Timbale"), NEEDS_TRANS("Low Timbale"),
  886. NEEDS_TRANS("High Agogo"), NEEDS_TRANS("Low Agogo"), NEEDS_TRANS("Cabasa"), NEEDS_TRANS("Maracas"),
  887. NEEDS_TRANS("Short Whistle"), NEEDS_TRANS("Long Whistle"), NEEDS_TRANS("Short Guiro"), NEEDS_TRANS("Long Guiro"),
  888. NEEDS_TRANS("Claves"), NEEDS_TRANS("Hi Wood Block"), NEEDS_TRANS("Low Wood Block"), NEEDS_TRANS("Mute Cuica"),
  889. NEEDS_TRANS("Open Cuica"), NEEDS_TRANS("Mute Triangle"), NEEDS_TRANS("Open Triangle")
  890. };
  891. return (n >= 35 && n <= 81) ? names [n - 35] : nullptr;
  892. }
  893. const char* MidiMessage::getControllerName (const int n)
  894. {
  895. static const char* names[] =
  896. {
  897. NEEDS_TRANS("Bank Select"), NEEDS_TRANS("Modulation Wheel (coarse)"), NEEDS_TRANS("Breath controller (coarse)"),
  898. nullptr,
  899. NEEDS_TRANS("Foot Pedal (coarse)"), NEEDS_TRANS("Portamento Time (coarse)"), NEEDS_TRANS("Data Entry (coarse)"),
  900. NEEDS_TRANS("Volume (coarse)"), NEEDS_TRANS("Balance (coarse)"),
  901. nullptr,
  902. NEEDS_TRANS("Pan position (coarse)"), NEEDS_TRANS("Expression (coarse)"), NEEDS_TRANS("Effect Control 1 (coarse)"),
  903. NEEDS_TRANS("Effect Control 2 (coarse)"),
  904. nullptr, nullptr,
  905. NEEDS_TRANS("General Purpose Slider 1"), NEEDS_TRANS("General Purpose Slider 2"),
  906. NEEDS_TRANS("General Purpose Slider 3"), NEEDS_TRANS("General Purpose Slider 4"),
  907. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  908. NEEDS_TRANS("Bank Select (fine)"), NEEDS_TRANS("Modulation Wheel (fine)"), NEEDS_TRANS("Breath controller (fine)"),
  909. nullptr,
  910. NEEDS_TRANS("Foot Pedal (fine)"), NEEDS_TRANS("Portamento Time (fine)"), NEEDS_TRANS("Data Entry (fine)"), NEEDS_TRANS("Volume (fine)"),
  911. NEEDS_TRANS("Balance (fine)"), nullptr, NEEDS_TRANS("Pan position (fine)"), NEEDS_TRANS("Expression (fine)"),
  912. NEEDS_TRANS("Effect Control 1 (fine)"), NEEDS_TRANS("Effect Control 2 (fine)"),
  913. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  914. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  915. NEEDS_TRANS("Hold Pedal (on/off)"), NEEDS_TRANS("Portamento (on/off)"), NEEDS_TRANS("Sustenuto Pedal (on/off)"), NEEDS_TRANS("Soft Pedal (on/off)"),
  916. NEEDS_TRANS("Legato Pedal (on/off)"), NEEDS_TRANS("Hold 2 Pedal (on/off)"), NEEDS_TRANS("Sound Variation"), NEEDS_TRANS("Sound Timbre"),
  917. NEEDS_TRANS("Sound Release Time"), NEEDS_TRANS("Sound Attack Time"), NEEDS_TRANS("Sound Brightness"), NEEDS_TRANS("Sound Control 6"),
  918. NEEDS_TRANS("Sound Control 7"), NEEDS_TRANS("Sound Control 8"), NEEDS_TRANS("Sound Control 9"), NEEDS_TRANS("Sound Control 10"),
  919. NEEDS_TRANS("General Purpose Button 1 (on/off)"), NEEDS_TRANS("General Purpose Button 2 (on/off)"),
  920. NEEDS_TRANS("General Purpose Button 3 (on/off)"), NEEDS_TRANS("General Purpose Button 4 (on/off)"),
  921. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  922. NEEDS_TRANS("Reverb Level"), NEEDS_TRANS("Tremolo Level"), NEEDS_TRANS("Chorus Level"), NEEDS_TRANS("Celeste Level"),
  923. NEEDS_TRANS("Phaser Level"), NEEDS_TRANS("Data Button increment"), NEEDS_TRANS("Data Button decrement"), NEEDS_TRANS("Non-registered Parameter (fine)"),
  924. NEEDS_TRANS("Non-registered Parameter (coarse)"), NEEDS_TRANS("Registered Parameter (fine)"), NEEDS_TRANS("Registered Parameter (coarse)"),
  925. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  926. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  927. NEEDS_TRANS("All Sound Off"), NEEDS_TRANS("All Controllers Off"), NEEDS_TRANS("Local Keyboard (on/off)"), NEEDS_TRANS("All Notes Off"),
  928. NEEDS_TRANS("Omni Mode Off"), NEEDS_TRANS("Omni Mode On"), NEEDS_TRANS("Mono Operation"), NEEDS_TRANS("Poly Operation")
  929. };
  930. return isPositiveAndBelow (n, numElementsInArray (names)) ? names[n] : nullptr;
  931. }