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.

1138 lines
43KB

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