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.

929 lines
34KB

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