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.

1095 lines
41KB

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