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.

juce_MidiMessage.cpp 40KB

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