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.

941 lines
34KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_MIDIMESSAGE_JUCEHEADER__
  19. #define __JUCE_MIDIMESSAGE_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. Encapsulates a MIDI message.
  23. @see MidiMessageSequence, MidiOutput, MidiInput
  24. */
  25. class JUCE_API MidiMessage
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates a 3-byte short midi message.
  30. @param byte1 message byte 1
  31. @param byte2 message byte 2
  32. @param byte3 message byte 3
  33. @param timeStamp the time to give the midi message - this value doesn't
  34. use any particular units, so will be application-specific
  35. */
  36. MidiMessage (int byte1, int byte2, int byte3, double timeStamp = 0) noexcept;
  37. /** Creates a 2-byte short midi message.
  38. @param byte1 message byte 1
  39. @param byte2 message byte 2
  40. @param timeStamp the time to give the midi message - this value doesn't
  41. use any particular units, so will be application-specific
  42. */
  43. MidiMessage (int byte1, int byte2, double timeStamp = 0) noexcept;
  44. /** Creates a 1-byte short midi message.
  45. @param byte1 message byte 1
  46. @param timeStamp the time to give the midi message - this value doesn't
  47. use any particular units, so will be application-specific
  48. */
  49. MidiMessage (int byte1, double timeStamp = 0) noexcept;
  50. /** Creates a midi message from a block of data. */
  51. MidiMessage (const void* data, int numBytes, double timeStamp = 0);
  52. /** Reads the next midi message from some data.
  53. This will read as many bytes from a data stream as it needs to make a
  54. complete message, and will return the number of bytes it used. This lets
  55. you read a sequence of midi messages from a file or stream.
  56. @param data the data to read from
  57. @param maxBytesToUse the maximum number of bytes it's allowed to read
  58. @param numBytesUsed returns the number of bytes that were actually needed
  59. @param lastStatusByte in a sequence of midi messages, the initial byte
  60. can be dropped from a message if it's the same as the
  61. first byte of the previous message, so this lets you
  62. supply the byte to use if the first byte of the message
  63. has in fact been dropped.
  64. @param timeStamp the time to give the midi message - this value doesn't
  65. use any particular units, so will be application-specific
  66. */
  67. MidiMessage (const void* data, int maxBytesToUse,
  68. int& numBytesUsed, uint8 lastStatusByte,
  69. double timeStamp = 0);
  70. /** Creates an active-sense message.
  71. Since the MidiMessage has to contain a valid message, this default constructor
  72. just initialises it with an empty sysex message.
  73. */
  74. MidiMessage() noexcept;
  75. /** Creates a copy of another midi message. */
  76. MidiMessage (const MidiMessage& other);
  77. /** Creates a copy of another midi message, with a different timestamp. */
  78. MidiMessage (const MidiMessage& other, double newTimeStamp);
  79. /** Destructor. */
  80. ~MidiMessage();
  81. /** Copies this message from another one. */
  82. MidiMessage& operator= (const MidiMessage& other);
  83. #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
  84. MidiMessage (MidiMessage&& other) noexcept;
  85. MidiMessage& operator= (MidiMessage&& other) noexcept;
  86. #endif
  87. //==============================================================================
  88. /** Returns a pointer to the raw midi data.
  89. @see getRawDataSize
  90. */
  91. uint8* getRawData() const noexcept { return data; }
  92. /** Returns the number of bytes of data in the message.
  93. @see getRawData
  94. */
  95. int getRawDataSize() const noexcept { return size; }
  96. //==============================================================================
  97. /** Returns the timestamp associated with this message.
  98. The exact meaning of this time and its units will vary, as messages are used in
  99. a variety of different contexts.
  100. If you're getting the message from a midi file, this could be a time in seconds, or
  101. a number of ticks - see MidiFile::convertTimestampTicksToSeconds().
  102. If the message is being used in a MidiBuffer, it might indicate the number of
  103. audio samples from the start of the buffer.
  104. If the message was created by a MidiInput, see MidiInputCallback::handleIncomingMidiMessage()
  105. for details of the way that it initialises this value.
  106. @see setTimeStamp, addToTimeStamp
  107. */
  108. double getTimeStamp() const noexcept { return timeStamp; }
  109. /** Changes the message's associated timestamp.
  110. The units for the timestamp will be application-specific - see the notes for getTimeStamp().
  111. @see addToTimeStamp, getTimeStamp
  112. */
  113. void setTimeStamp (double newTimestamp) noexcept { timeStamp = newTimestamp; }
  114. /** Adds a value to the message's timestamp.
  115. The units for the timestamp will be application-specific.
  116. */
  117. void addToTimeStamp (double delta) noexcept { timeStamp += delta; }
  118. //==============================================================================
  119. /** Returns the midi channel associated with the message.
  120. @returns a value 1 to 16 if the message has a channel, or 0 if it hasn't (e.g.
  121. if it's a sysex)
  122. @see isForChannel, setChannel
  123. */
  124. int getChannel() const noexcept;
  125. /** Returns true if the message applies to the given midi channel.
  126. @param channelNumber the channel number to look for, in the range 1 to 16
  127. @see getChannel, setChannel
  128. */
  129. bool isForChannel (int channelNumber) const noexcept;
  130. /** Changes the message's midi channel.
  131. This won't do anything for non-channel messages like sysexes.
  132. @param newChannelNumber the channel number to change it to, in the range 1 to 16
  133. */
  134. void setChannel (int newChannelNumber) noexcept;
  135. //==============================================================================
  136. /** Returns true if this is a system-exclusive message.
  137. */
  138. bool isSysEx() const noexcept;
  139. /** Returns a pointer to the sysex data inside the message.
  140. If this event isn't a sysex event, it'll return 0.
  141. @see getSysExDataSize
  142. */
  143. const uint8* getSysExData() const noexcept;
  144. /** Returns the size of the sysex data.
  145. This value excludes the 0xf0 header byte and the 0xf7 at the end.
  146. @see getSysExData
  147. */
  148. int getSysExDataSize() const noexcept;
  149. //==============================================================================
  150. /** Returns true if this message is a 'key-down' event.
  151. @param returnTrueForVelocity0 if true, then if this event is a note-on with
  152. velocity 0, it will still be considered to be a note-on and the
  153. method will return true. If returnTrueForVelocity0 is false, then
  154. if this is a note-on event with velocity 0, it'll be regarded as
  155. a note-off, and the method will return false
  156. @see isNoteOff, getNoteNumber, getVelocity, noteOn
  157. */
  158. bool isNoteOn (bool returnTrueForVelocity0 = false) const noexcept;
  159. /** Creates a key-down message (using a floating-point velocity).
  160. @param channel the midi channel, in the range 1 to 16
  161. @param noteNumber the key number, 0 to 127
  162. @param velocity in the range 0 to 1.0
  163. @see isNoteOn
  164. */
  165. static MidiMessage noteOn (int channel, int noteNumber, float velocity) noexcept;
  166. /** Creates a key-down message (using an integer velocity).
  167. @param channel the midi channel, in the range 1 to 16
  168. @param noteNumber the key number, 0 to 127
  169. @param velocity in the range 0 to 127
  170. @see isNoteOn
  171. */
  172. static MidiMessage noteOn (int channel, int noteNumber, uint8 velocity) noexcept;
  173. /** Returns true if this message is a 'key-up' event.
  174. If returnTrueForNoteOnVelocity0 is true, then his will also return true
  175. for a note-on event with a velocity of 0.
  176. @see isNoteOn, getNoteNumber, getVelocity, noteOff
  177. */
  178. bool isNoteOff (bool returnTrueForNoteOnVelocity0 = true) const noexcept;
  179. /** Creates a key-up message.
  180. @param channel the midi channel, in the range 1 to 16
  181. @param noteNumber the key number, 0 to 127
  182. @param velocity in the range 0 to 127
  183. @see isNoteOff
  184. */
  185. static MidiMessage noteOff (int channel, int noteNumber, uint8 velocity = 0) noexcept;
  186. /** Returns true if this message is a 'key-down' or 'key-up' event.
  187. @see isNoteOn, isNoteOff
  188. */
  189. bool isNoteOnOrOff() const noexcept;
  190. /** Returns the midi note number for note-on and note-off messages.
  191. If the message isn't a note-on or off, the value returned is undefined.
  192. @see isNoteOff, getMidiNoteName, getMidiNoteInHertz, setNoteNumber
  193. */
  194. int getNoteNumber() const noexcept;
  195. /** Changes the midi note number of a note-on or note-off message.
  196. If the message isn't a note on or off, this will do nothing.
  197. */
  198. void setNoteNumber (int newNoteNumber) noexcept;
  199. //==============================================================================
  200. /** Returns the velocity of a note-on or note-off message.
  201. The value returned will be in the range 0 to 127.
  202. If the message isn't a note-on or off event, it will return 0.
  203. @see getFloatVelocity
  204. */
  205. uint8 getVelocity() const noexcept;
  206. /** Returns the velocity of a note-on or note-off message.
  207. The value returned will be in the range 0 to 1.0
  208. If the message isn't a note-on or off event, it will return 0.
  209. @see getVelocity, setVelocity
  210. */
  211. float getFloatVelocity() const noexcept;
  212. /** Changes the velocity of a note-on or note-off message.
  213. If the message isn't a note on or off, this will do nothing.
  214. @param newVelocity the new velocity, in the range 0 to 1.0
  215. @see getFloatVelocity, multiplyVelocity
  216. */
  217. void setVelocity (float newVelocity) noexcept;
  218. /** Multiplies the velocity of a note-on or note-off message by a given amount.
  219. If the message isn't a note on or off, this will do nothing.
  220. @param scaleFactor the value by which to multiply the velocity
  221. @see setVelocity
  222. */
  223. void multiplyVelocity (float scaleFactor) noexcept;
  224. //==============================================================================
  225. /** Returns true if this message is a 'sustain pedal down' controller message. */
  226. bool isSustainPedalOn() const noexcept;
  227. /** Returns true if this message is a 'sustain pedal up' controller message. */
  228. bool isSustainPedalOff() const noexcept;
  229. /** Returns true if this message is a 'sostenuto pedal down' controller message. */
  230. bool isSostenutoPedalOn() const noexcept;
  231. /** Returns true if this message is a 'sostenuto pedal up' controller message. */
  232. bool isSostenutoPedalOff() const noexcept;
  233. /** Returns true if this message is a 'soft pedal down' controller message. */
  234. bool isSoftPedalOn() const noexcept;
  235. /** Returns true if this message is a 'soft pedal up' controller message. */
  236. bool isSoftPedalOff() const noexcept;
  237. //==============================================================================
  238. /** Returns true if the message is a program (patch) change message.
  239. @see getProgramChangeNumber, getGMInstrumentName
  240. */
  241. bool isProgramChange() const noexcept;
  242. /** Returns the new program number of a program change message.
  243. If the message isn't a program change, the value returned will be
  244. nonsense.
  245. @see isProgramChange, getGMInstrumentName
  246. */
  247. int getProgramChangeNumber() const noexcept;
  248. /** Creates a program-change message.
  249. @param channel the midi channel, in the range 1 to 16
  250. @param programNumber the midi program number, 0 to 127
  251. @see isProgramChange, getGMInstrumentName
  252. */
  253. static MidiMessage programChange (int channel, int programNumber) noexcept;
  254. //==============================================================================
  255. /** Returns true if the message is a pitch-wheel move.
  256. @see getPitchWheelValue, pitchWheel
  257. */
  258. bool isPitchWheel() const noexcept;
  259. /** Returns the pitch wheel position from a pitch-wheel move message.
  260. The value returned is a 14-bit number from 0 to 0x3fff, indicating the wheel position.
  261. If called for messages which aren't pitch wheel events, the number returned will be
  262. nonsense.
  263. @see isPitchWheel
  264. */
  265. int getPitchWheelValue() const noexcept;
  266. /** Creates a pitch-wheel move message.
  267. @param channel the midi channel, in the range 1 to 16
  268. @param position the wheel position, in the range 0 to 16383
  269. @see isPitchWheel
  270. */
  271. static MidiMessage pitchWheel (int channel, int position) noexcept;
  272. //==============================================================================
  273. /** Returns true if the message is an aftertouch event.
  274. For aftertouch events, use the getNoteNumber() method to find out the key
  275. that it applies to, and getAftertouchValue() to find out the amount. Use
  276. getChannel() to find out the channel.
  277. @see getAftertouchValue, getNoteNumber
  278. */
  279. bool isAftertouch() const noexcept;
  280. /** Returns the amount of aftertouch from an aftertouch messages.
  281. The value returned is in the range 0 to 127, and will be nonsense for messages
  282. other than aftertouch messages.
  283. @see isAftertouch
  284. */
  285. int getAfterTouchValue() const noexcept;
  286. /** Creates an aftertouch message.
  287. @param channel the midi channel, in the range 1 to 16
  288. @param noteNumber the key number, 0 to 127
  289. @param aftertouchAmount the amount of aftertouch, 0 to 127
  290. @see isAftertouch
  291. */
  292. static MidiMessage aftertouchChange (int channel,
  293. int noteNumber,
  294. int aftertouchAmount) noexcept;
  295. /** Returns true if the message is a channel-pressure change event.
  296. This is like aftertouch, but common to the whole channel rather than a specific
  297. note. Use getChannelPressureValue() to find out the pressure, and getChannel()
  298. to find out the channel.
  299. @see channelPressureChange
  300. */
  301. bool isChannelPressure() const noexcept;
  302. /** Returns the pressure from a channel pressure change message.
  303. @returns the pressure, in the range 0 to 127
  304. @see isChannelPressure, channelPressureChange
  305. */
  306. int getChannelPressureValue() const noexcept;
  307. /** Creates a channel-pressure change event.
  308. @param channel the midi channel: 1 to 16
  309. @param pressure the pressure, 0 to 127
  310. @see isChannelPressure
  311. */
  312. static MidiMessage channelPressureChange (int channel, int pressure) noexcept;
  313. //==============================================================================
  314. /** Returns true if this is a midi controller message.
  315. @see getControllerNumber, getControllerValue, controllerEvent
  316. */
  317. bool isController() const noexcept;
  318. /** Returns the controller number of a controller message.
  319. The name of the controller can be looked up using the getControllerName() method.
  320. Note that the value returned is invalid for messages that aren't controller changes.
  321. @see isController, getControllerName, getControllerValue
  322. */
  323. int getControllerNumber() const noexcept;
  324. /** Returns the controller value from a controller message.
  325. A value 0 to 127 is returned to indicate the new controller position.
  326. Note that the value returned is invalid for messages that aren't controller changes.
  327. @see isController, getControllerNumber
  328. */
  329. int getControllerValue() const noexcept;
  330. /** Returns true if this message is a controller message and if it has the specified
  331. controller type.
  332. */
  333. bool isControllerOfType (int controllerType) const noexcept;
  334. /** Creates a controller message.
  335. @param channel the midi channel, in the range 1 to 16
  336. @param controllerType the type of controller
  337. @param value the controller value
  338. @see isController
  339. */
  340. static MidiMessage controllerEvent (int channel,
  341. int controllerType,
  342. int value) noexcept;
  343. /** Checks whether this message is an all-notes-off message.
  344. @see allNotesOff
  345. */
  346. bool isAllNotesOff() const noexcept;
  347. /** Checks whether this message is an all-sound-off message.
  348. @see allSoundOff
  349. */
  350. bool isAllSoundOff() const noexcept;
  351. /** Creates an all-notes-off message.
  352. @param channel the midi channel, in the range 1 to 16
  353. @see isAllNotesOff
  354. */
  355. static MidiMessage allNotesOff (int channel) noexcept;
  356. /** Creates an all-sound-off message.
  357. @param channel the midi channel, in the range 1 to 16
  358. @see isAllSoundOff
  359. */
  360. static MidiMessage allSoundOff (int channel) noexcept;
  361. /** Creates an all-controllers-off message.
  362. @param channel the midi channel, in the range 1 to 16
  363. */
  364. static MidiMessage allControllersOff (int channel) noexcept;
  365. //==============================================================================
  366. /** Returns true if this event is a meta-event.
  367. Meta-events are things like tempo changes, track names, etc.
  368. @see getMetaEventType, isTrackMetaEvent, isEndOfTrackMetaEvent,
  369. isTextMetaEvent, isTrackNameEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
  370. isKeySignatureMetaEvent, isMidiChannelMetaEvent
  371. */
  372. bool isMetaEvent() const noexcept;
  373. /** Returns a meta-event's type number.
  374. If the message isn't a meta-event, this will return -1.
  375. @see isMetaEvent, isTrackMetaEvent, isEndOfTrackMetaEvent,
  376. isTextMetaEvent, isTrackNameEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
  377. isKeySignatureMetaEvent, isMidiChannelMetaEvent
  378. */
  379. int getMetaEventType() const noexcept;
  380. /** Returns a pointer to the data in a meta-event.
  381. @see isMetaEvent, getMetaEventLength
  382. */
  383. const uint8* getMetaEventData() const noexcept;
  384. /** Returns the length of the data for a meta-event.
  385. @see isMetaEvent, getMetaEventData
  386. */
  387. int getMetaEventLength() const noexcept;
  388. //==============================================================================
  389. /** Returns true if this is a 'track' meta-event. */
  390. bool isTrackMetaEvent() const noexcept;
  391. /** Returns true if this is an 'end-of-track' meta-event. */
  392. bool isEndOfTrackMetaEvent() const noexcept;
  393. /** Creates an end-of-track meta-event.
  394. @see isEndOfTrackMetaEvent
  395. */
  396. static MidiMessage endOfTrack() noexcept;
  397. /** Returns true if this is an 'track name' meta-event.
  398. You can use the getTextFromTextMetaEvent() method to get the track's name.
  399. */
  400. bool isTrackNameEvent() const noexcept;
  401. /** Returns true if this is a 'text' meta-event.
  402. @see getTextFromTextMetaEvent
  403. */
  404. bool isTextMetaEvent() const noexcept;
  405. /** Returns the text from a text meta-event.
  406. @see isTextMetaEvent
  407. */
  408. String getTextFromTextMetaEvent() const;
  409. //==============================================================================
  410. /** Returns true if this is a 'tempo' meta-event.
  411. @see getTempoMetaEventTickLength, getTempoSecondsPerQuarterNote
  412. */
  413. bool isTempoMetaEvent() const noexcept;
  414. /** Returns the tick length from a tempo meta-event.
  415. @param timeFormat the 16-bit time format value from the midi file's header.
  416. @returns the tick length (in seconds).
  417. @see isTempoMetaEvent
  418. */
  419. double getTempoMetaEventTickLength (short timeFormat) const noexcept;
  420. /** Calculates the seconds-per-quarter-note from a tempo meta-event.
  421. @see isTempoMetaEvent, getTempoMetaEventTickLength
  422. */
  423. double getTempoSecondsPerQuarterNote() const noexcept;
  424. /** Creates a tempo meta-event.
  425. @see isTempoMetaEvent
  426. */
  427. static MidiMessage tempoMetaEvent (int microsecondsPerQuarterNote) noexcept;
  428. //==============================================================================
  429. /** Returns true if this is a 'time-signature' meta-event.
  430. @see getTimeSignatureInfo
  431. */
  432. bool isTimeSignatureMetaEvent() const noexcept;
  433. /** Returns the time-signature values from a time-signature meta-event.
  434. @see isTimeSignatureMetaEvent
  435. */
  436. void getTimeSignatureInfo (int& numerator, int& denominator) const noexcept;
  437. /** Creates a time-signature meta-event.
  438. @see isTimeSignatureMetaEvent
  439. */
  440. static MidiMessage timeSignatureMetaEvent (int numerator, int denominator);
  441. //==============================================================================
  442. /** Returns true if this is a 'key-signature' meta-event.
  443. @see getKeySignatureNumberOfSharpsOrFlats
  444. */
  445. bool isKeySignatureMetaEvent() const noexcept;
  446. /** Returns the key from a key-signature meta-event.
  447. @see isKeySignatureMetaEvent
  448. */
  449. int getKeySignatureNumberOfSharpsOrFlats() const noexcept;
  450. //==============================================================================
  451. /** Returns true if this is a 'channel' meta-event.
  452. A channel meta-event specifies the midi channel that should be used
  453. for subsequent meta-events.
  454. @see getMidiChannelMetaEventChannel
  455. */
  456. bool isMidiChannelMetaEvent() const noexcept;
  457. /** Returns the channel number from a channel meta-event.
  458. @returns the channel, in the range 1 to 16.
  459. @see isMidiChannelMetaEvent
  460. */
  461. int getMidiChannelMetaEventChannel() const noexcept;
  462. /** Creates a midi channel meta-event.
  463. @param channel the midi channel, in the range 1 to 16
  464. @see isMidiChannelMetaEvent
  465. */
  466. static MidiMessage midiChannelMetaEvent (int channel) noexcept;
  467. //==============================================================================
  468. /** Returns true if this is an active-sense message. */
  469. bool isActiveSense() const noexcept;
  470. //==============================================================================
  471. /** Returns true if this is a midi start event.
  472. @see midiStart
  473. */
  474. bool isMidiStart() const noexcept;
  475. /** Creates a midi start event. */
  476. static MidiMessage midiStart() noexcept;
  477. /** Returns true if this is a midi continue event.
  478. @see midiContinue
  479. */
  480. bool isMidiContinue() const noexcept;
  481. /** Creates a midi continue event. */
  482. static MidiMessage midiContinue() noexcept;
  483. /** Returns true if this is a midi stop event.
  484. @see midiStop
  485. */
  486. bool isMidiStop() const noexcept;
  487. /** Creates a midi stop event. */
  488. static MidiMessage midiStop() noexcept;
  489. /** Returns true if this is a midi clock event.
  490. @see midiClock, songPositionPointer
  491. */
  492. bool isMidiClock() const noexcept;
  493. /** Creates a midi clock event. */
  494. static MidiMessage midiClock() noexcept;
  495. /** Returns true if this is a song-position-pointer message.
  496. @see getSongPositionPointerMidiBeat, songPositionPointer
  497. */
  498. bool isSongPositionPointer() const noexcept;
  499. /** Returns the midi beat-number of a song-position-pointer message.
  500. @see isSongPositionPointer, songPositionPointer
  501. */
  502. int getSongPositionPointerMidiBeat() const noexcept;
  503. /** Creates a song-position-pointer message.
  504. The position is a number of midi beats from the start of the song, where 1 midi
  505. beat is 6 midi clocks, and there are 24 midi clocks in a quarter-note. So there
  506. are 4 midi beats in a quarter-note.
  507. @see isSongPositionPointer, getSongPositionPointerMidiBeat
  508. */
  509. static MidiMessage songPositionPointer (int positionInMidiBeats) noexcept;
  510. //==============================================================================
  511. /** Returns true if this is a quarter-frame midi timecode message.
  512. @see quarterFrame, getQuarterFrameSequenceNumber, getQuarterFrameValue
  513. */
  514. bool isQuarterFrame() const noexcept;
  515. /** Returns the sequence number of a quarter-frame midi timecode message.
  516. This will be a value between 0 and 7.
  517. @see isQuarterFrame, getQuarterFrameValue, quarterFrame
  518. */
  519. int getQuarterFrameSequenceNumber() const noexcept;
  520. /** Returns the value from a quarter-frame message.
  521. This will be the lower nybble of the message's data-byte, a value
  522. between 0 and 15
  523. */
  524. int getQuarterFrameValue() const noexcept;
  525. /** Creates a quarter-frame MTC message.
  526. @param sequenceNumber a value 0 to 7 for the upper nybble of the message's data byte
  527. @param value a value 0 to 15 for the lower nybble of the message's data byte
  528. */
  529. static MidiMessage quarterFrame (int sequenceNumber, int value) noexcept;
  530. /** SMPTE timecode types.
  531. Used by the getFullFrameParameters() and fullFrame() methods.
  532. */
  533. enum SmpteTimecodeType
  534. {
  535. fps24 = 0,
  536. fps25 = 1,
  537. fps30drop = 2,
  538. fps30 = 3
  539. };
  540. /** Returns true if this is a full-frame midi timecode message.
  541. */
  542. bool isFullFrame() const noexcept;
  543. /** Extracts the timecode information from a full-frame midi timecode message.
  544. You should only call this on messages where you've used isFullFrame() to
  545. check that they're the right kind.
  546. */
  547. void getFullFrameParameters (int& hours,
  548. int& minutes,
  549. int& seconds,
  550. int& frames,
  551. SmpteTimecodeType& timecodeType) const noexcept;
  552. /** Creates a full-frame MTC message.
  553. */
  554. static MidiMessage fullFrame (int hours,
  555. int minutes,
  556. int seconds,
  557. int frames,
  558. SmpteTimecodeType timecodeType);
  559. //==============================================================================
  560. /** Types of MMC command.
  561. @see isMidiMachineControlMessage, getMidiMachineControlCommand, midiMachineControlCommand
  562. */
  563. enum MidiMachineControlCommand
  564. {
  565. mmc_stop = 1,
  566. mmc_play = 2,
  567. mmc_deferredplay = 3,
  568. mmc_fastforward = 4,
  569. mmc_rewind = 5,
  570. mmc_recordStart = 6,
  571. mmc_recordStop = 7,
  572. mmc_pause = 9
  573. };
  574. /** Checks whether this is an MMC message.
  575. If it is, you can use the getMidiMachineControlCommand() to find out its type.
  576. */
  577. bool isMidiMachineControlMessage() const noexcept;
  578. /** For an MMC message, this returns its type.
  579. Make sure it's actually an MMC message with isMidiMachineControlMessage() before
  580. calling this method.
  581. */
  582. MidiMachineControlCommand getMidiMachineControlCommand() const noexcept;
  583. /** Creates an MMC message.
  584. */
  585. static MidiMessage midiMachineControlCommand (MidiMachineControlCommand command);
  586. /** Checks whether this is an MMC "goto" message.
  587. If it is, the parameters passed-in are set to the time that the message contains.
  588. @see midiMachineControlGoto
  589. */
  590. bool isMidiMachineControlGoto (int& hours,
  591. int& minutes,
  592. int& seconds,
  593. int& frames) const noexcept;
  594. /** Creates an MMC "goto" message.
  595. This messages tells the device to go to a specific frame.
  596. @see isMidiMachineControlGoto
  597. */
  598. static MidiMessage midiMachineControlGoto (int hours,
  599. int minutes,
  600. int seconds,
  601. int frames);
  602. //==============================================================================
  603. /** Creates a master-volume change message.
  604. @param volume the volume, 0 to 1.0
  605. */
  606. static MidiMessage masterVolume (float volume);
  607. //==============================================================================
  608. /** Creates a system-exclusive message.
  609. The data passed in is wrapped with header and tail bytes of 0xf0 and 0xf7.
  610. */
  611. static MidiMessage createSysExMessage (const uint8* sysexData,
  612. int dataSize);
  613. //==============================================================================
  614. /** Reads a midi variable-length integer.
  615. @param data the data to read the number from
  616. @param numBytesUsed on return, this will be set to the number of bytes that were read
  617. */
  618. static int readVariableLengthVal (const uint8* data,
  619. int& numBytesUsed) noexcept;
  620. /** Based on the first byte of a short midi message, this uses a lookup table
  621. to return the message length (either 1, 2, or 3 bytes).
  622. The value passed in must be 0x80 or higher.
  623. */
  624. static int getMessageLengthFromFirstByte (const uint8 firstByte) noexcept;
  625. //==============================================================================
  626. /** Returns the name of a midi note number.
  627. E.g "C", "D#", etc.
  628. @param noteNumber the midi note number, 0 to 127
  629. @param useSharps if true, sharpened notes are used, e.g. "C#", otherwise
  630. they'll be flattened, e.g. "Db"
  631. @param includeOctaveNumber if true, the octave number will be appended to the string,
  632. e.g. "C#4"
  633. @param octaveNumForMiddleC if an octave number is being appended, this indicates the
  634. number that will be used for middle C's octave
  635. @see getMidiNoteInHertz
  636. */
  637. static String getMidiNoteName (int noteNumber,
  638. bool useSharps,
  639. bool includeOctaveNumber,
  640. int octaveNumForMiddleC);
  641. /** Returns the frequency of a midi note number.
  642. The frequencyOfA parameter is an optional frequency for 'A', normally 440-444Hz for concert pitch.
  643. @see getMidiNoteName
  644. */
  645. static const double getMidiNoteInHertz (int noteNumber, const double frequencyOfA = 440.0) noexcept;
  646. /** Returns the standard name of a GM instrument.
  647. @param midiInstrumentNumber the program number 0 to 127
  648. @see getProgramChangeNumber
  649. */
  650. static String getGMInstrumentName (int midiInstrumentNumber);
  651. /** Returns the name of a bank of GM instruments.
  652. @param midiBankNumber the bank, 0 to 15
  653. */
  654. static String getGMInstrumentBankName (int midiBankNumber);
  655. /** Returns the standard name of a channel 10 percussion sound.
  656. @param midiNoteNumber the key number, 35 to 81
  657. */
  658. static String getRhythmInstrumentName (int midiNoteNumber);
  659. /** Returns the name of a controller type number.
  660. @see getControllerNumber
  661. */
  662. static String getControllerName (int controllerNumber);
  663. private:
  664. //==============================================================================
  665. double timeStamp;
  666. uint8* data;
  667. int size;
  668. #ifndef DOXYGEN
  669. union
  670. {
  671. uint8 asBytes[4];
  672. uint32 asInt32;
  673. } preallocatedData;
  674. #endif
  675. void freeData() noexcept;
  676. void setToUseInternalData() noexcept;
  677. bool usesAllocatedData() const noexcept;
  678. };
  679. #endif // __JUCE_MIDIMESSAGE_JUCEHEADER__