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.

1122 lines
42KB

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