2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
20 ==============================================================================
26 //==============================================================================
28 Encapsulates a MIDI message.
30 @see MidiMessageSequence, MidiOutput, MidiInput
34 class JUCE_API MidiMessage
37 //==============================================================================
38 /** Creates a 3-byte short midi message.
40 @param byte1 message byte 1
41 @param byte2 message byte 2
42 @param byte3 message byte 3
43 @param timeStamp the time to give the midi message - this value doesn't
44 use any particular units, so will be application-specific
46 MidiMessage (int byte1
, int byte2
, int byte3
, double timeStamp
= 0) noexcept
;
48 /** Creates a 2-byte short midi message.
50 @param byte1 message byte 1
51 @param byte2 message byte 2
52 @param timeStamp the time to give the midi message - this value doesn't
53 use any particular units, so will be application-specific
55 MidiMessage (int byte1
, int byte2
, double timeStamp
= 0) noexcept
;
57 /** Creates a 1-byte short midi message.
59 @param byte1 message byte 1
60 @param timeStamp the time to give the midi message - this value doesn't
61 use any particular units, so will be application-specific
63 MidiMessage (int byte1
, double timeStamp
= 0) noexcept
;
65 /** Creates a midi message from a list of bytes. */
66 template <typename
... Data
>
67 MidiMessage (int byte1
, int byte2
, int byte3
, Data
... otherBytes
) : size (3 + sizeof... (otherBytes
))
69 // this checks that the length matches the data..
70 jassert (size
> 3 || byte1
>= 0xf0 || getMessageLengthFromFirstByte ((uint8
) byte1
) == size
);
72 const uint8 data
[] = { (uint8
) byte1
, (uint8
) byte2
, (uint8
) byte3
, static_cast<uint8
> (otherBytes
)... };
73 memcpy (allocateSpace (size
), data
, (size_t) size
);
77 /** Creates a midi message from a block of data. */
78 MidiMessage (const void* data
, int numBytes
, double timeStamp
= 0);
80 /** Reads the next midi message from some data.
82 This will read as many bytes from a data stream as it needs to make a
83 complete message, and will return the number of bytes it used. This lets
84 you read a sequence of midi messages from a file or stream.
86 @param data the data to read from
87 @param maxBytesToUse the maximum number of bytes it's allowed to read
88 @param numBytesUsed returns the number of bytes that were actually needed
89 @param lastStatusByte in a sequence of midi messages, the initial byte
90 can be dropped from a message if it's the same as the
91 first byte of the previous message, so this lets you
92 supply the byte to use if the first byte of the message
93 has in fact been dropped.
94 @param timeStamp the time to give the midi message - this value doesn't
95 use any particular units, so will be application-specific
96 @param sysexHasEmbeddedLength when reading sysexes, this flag indicates whether
97 to expect the data to begin with a variable-length
98 field indicating its size
100 MidiMessage (const void* data
, int maxBytesToUse
,
101 int& numBytesUsed
, uint8 lastStatusByte
,
102 double timeStamp
= 0,
103 bool sysexHasEmbeddedLength
= true);
105 /** Creates an empty sysex message.
107 Since the MidiMessage has to contain a valid message, this default constructor
108 just initialises it with an empty sysex message.
110 MidiMessage() noexcept
;
112 /** Creates a copy of another midi message. */
113 MidiMessage (const MidiMessage
&);
115 /** Creates a copy of another midi message, with a different timestamp. */
116 MidiMessage (const MidiMessage
&, double newTimeStamp
);
119 ~MidiMessage() noexcept
;
121 /** Copies this message from another one. */
122 MidiMessage
& operator= (const MidiMessage
& other
);
124 /** Move constructor */
125 MidiMessage (MidiMessage
&&) noexcept
;
127 /** Move assignment operator */
128 MidiMessage
& operator= (MidiMessage
&&) noexcept
;
130 //==============================================================================
131 /** Returns a pointer to the raw midi data.
134 const uint8
* getRawData() const noexcept
{ return getData(); }
136 /** Returns the number of bytes of data in the message.
139 int getRawDataSize() const noexcept
{ return size
; }
141 //==============================================================================
142 /** Returns a human-readable description of the midi message as a string,
143 for example "Note On C#3 Velocity 120 Channel 1".
145 String
getDescription() const;
147 //==============================================================================
148 /** Returns the timestamp associated with this message.
150 The exact meaning of this time and its units will vary, as messages are used in
151 a variety of different contexts.
153 If you're getting the message from a midi file, this could be a time in seconds, or
154 a number of ticks - see MidiFile::convertTimestampTicksToSeconds().
156 If the message is being used in a MidiBuffer, it might indicate the number of
157 audio samples from the start of the buffer.
159 If the message was created by a MidiInput, see MidiInputCallback::handleIncomingMidiMessage()
160 for details of the way that it initialises this value.
162 @see setTimeStamp, addToTimeStamp
164 double getTimeStamp() const noexcept
{ return timeStamp
; }
166 /** Changes the message's associated timestamp.
167 The units for the timestamp will be application-specific - see the notes for getTimeStamp().
168 @see addToTimeStamp, getTimeStamp
170 void setTimeStamp (double newTimestamp
) noexcept
{ timeStamp
= newTimestamp
; }
172 /** Adds a value to the message's timestamp.
173 The units for the timestamp will be application-specific.
175 void addToTimeStamp (double delta
) noexcept
{ timeStamp
+= delta
; }
177 /** Return a copy of this message with a new timestamp.
178 The units for the timestamp will be application-specific - see the notes for getTimeStamp().
180 MidiMessage
withTimeStamp (double newTimestamp
) const;
182 //==============================================================================
183 /** Returns the midi channel associated with the message.
185 @returns a value 1 to 16 if the message has a channel, or 0 if it hasn't (e.g.
187 @see isForChannel, setChannel
189 int getChannel() const noexcept
;
191 /** Returns true if the message applies to the given midi channel.
193 @param channelNumber the channel number to look for, in the range 1 to 16
194 @see getChannel, setChannel
196 bool isForChannel (int channelNumber
) const noexcept
;
198 /** Changes the message's midi channel.
199 This won't do anything for non-channel messages like sysexes.
200 @param newChannelNumber the channel number to change it to, in the range 1 to 16
202 void setChannel (int newChannelNumber
) noexcept
;
204 //==============================================================================
205 /** Returns true if this is a system-exclusive message.
207 bool isSysEx() const noexcept
;
209 /** Returns a pointer to the sysex data inside the message.
210 If this event isn't a sysex event, it'll return 0.
211 @see getSysExDataSize
213 const uint8
* getSysExData() const noexcept
;
215 /** Returns the size of the sysex data.
216 This value excludes the 0xf0 header byte and the 0xf7 at the end.
219 int getSysExDataSize() const noexcept
;
221 //==============================================================================
222 /** Returns true if this message is a 'key-down' event.
224 @param returnTrueForVelocity0 if true, then if this event is a note-on with
225 velocity 0, it will still be considered to be a note-on and the
226 method will return true. If returnTrueForVelocity0 is false, then
227 if this is a note-on event with velocity 0, it'll be regarded as
228 a note-off, and the method will return false
230 @see isNoteOff, getNoteNumber, getVelocity, noteOn
232 bool isNoteOn (bool returnTrueForVelocity0
= false) const noexcept
;
234 /** Creates a key-down message (using a floating-point velocity).
236 @param channel the midi channel, in the range 1 to 16
237 @param noteNumber the key number, 0 to 127
238 @param velocity in the range 0 to 1.0
241 static MidiMessage
noteOn (int channel
, int noteNumber
, float velocity
) noexcept
;
243 /** Creates a key-down message (using an integer velocity).
245 @param channel the midi channel, in the range 1 to 16
246 @param noteNumber the key number, 0 to 127
247 @param velocity in the range 0 to 127
250 static MidiMessage
noteOn (int channel
, int noteNumber
, uint8 velocity
) noexcept
;
252 /** Returns true if this message is a 'key-up' event.
254 If returnTrueForNoteOnVelocity0 is true, then his will also return true
255 for a note-on event with a velocity of 0.
257 @see isNoteOn, getNoteNumber, getVelocity, noteOff
259 bool isNoteOff (bool returnTrueForNoteOnVelocity0
= true) const noexcept
;
261 /** Creates a key-up message.
263 @param channel the midi channel, in the range 1 to 16
264 @param noteNumber the key number, 0 to 127
265 @param velocity in the range 0 to 1.0
268 static MidiMessage
noteOff (int channel
, int noteNumber
, float velocity
) noexcept
;
270 /** Creates a key-up message.
272 @param channel the midi channel, in the range 1 to 16
273 @param noteNumber the key number, 0 to 127
274 @param velocity in the range 0 to 127
277 static MidiMessage
noteOff (int channel
, int noteNumber
, uint8 velocity
) noexcept
;
279 /** Creates a key-up message.
281 @param channel the midi channel, in the range 1 to 16
282 @param noteNumber the key number, 0 to 127
285 static MidiMessage
noteOff (int channel
, int noteNumber
) noexcept
;
287 /** Returns true if this message is a 'key-down' or 'key-up' event.
289 @see isNoteOn, isNoteOff
291 bool isNoteOnOrOff() const noexcept
;
293 /** Returns the midi note number for note-on and note-off messages.
294 If the message isn't a note-on or off, the value returned is undefined.
295 @see isNoteOff, getMidiNoteName, getMidiNoteInHertz, setNoteNumber
297 int getNoteNumber() const noexcept
;
299 /** Changes the midi note number of a note-on or note-off message.
300 If the message isn't a note on or off, this will do nothing.
302 void setNoteNumber (int newNoteNumber
) noexcept
;
304 //==============================================================================
305 /** Returns the velocity of a note-on or note-off message.
307 The value returned will be in the range 0 to 127.
308 If the message isn't a note-on or off event, it will return 0.
310 @see getFloatVelocity
312 uint8
getVelocity() const noexcept
;
314 /** Returns the velocity of a note-on or note-off message.
316 The value returned will be in the range 0 to 1.0
317 If the message isn't a note-on or off event, it will return 0.
319 @see getVelocity, setVelocity
321 float getFloatVelocity() const noexcept
;
323 /** Changes the velocity of a note-on or note-off message.
325 If the message isn't a note on or off, this will do nothing.
327 @param newVelocity the new velocity, in the range 0 to 1.0
328 @see getFloatVelocity, multiplyVelocity
330 void setVelocity (float newVelocity
) noexcept
;
332 /** Multiplies the velocity of a note-on or note-off message by a given amount.
334 If the message isn't a note on or off, this will do nothing.
336 @param scaleFactor the value by which to multiply the velocity
339 void multiplyVelocity (float scaleFactor
) noexcept
;
341 //==============================================================================
342 /** Returns true if this message is a 'sustain pedal down' controller message. */
343 bool isSustainPedalOn() const noexcept
;
344 /** Returns true if this message is a 'sustain pedal up' controller message. */
345 bool isSustainPedalOff() const noexcept
;
347 /** Returns true if this message is a 'sostenuto pedal down' controller message. */
348 bool isSostenutoPedalOn() const noexcept
;
349 /** Returns true if this message is a 'sostenuto pedal up' controller message. */
350 bool isSostenutoPedalOff() const noexcept
;
352 /** Returns true if this message is a 'soft pedal down' controller message. */
353 bool isSoftPedalOn() const noexcept
;
354 /** Returns true if this message is a 'soft pedal up' controller message. */
355 bool isSoftPedalOff() const noexcept
;
357 //==============================================================================
358 /** Returns true if the message is a program (patch) change message.
359 @see getProgramChangeNumber, getGMInstrumentName
361 bool isProgramChange() const noexcept
;
363 /** Returns the new program number of a program change message.
364 If the message isn't a program change, the value returned is undefined.
365 @see isProgramChange, getGMInstrumentName
367 int getProgramChangeNumber() const noexcept
;
369 /** Creates a program-change message.
371 @param channel the midi channel, in the range 1 to 16
372 @param programNumber the midi program number, 0 to 127
373 @see isProgramChange, getGMInstrumentName
375 static MidiMessage
programChange (int channel
, int programNumber
) noexcept
;
377 //==============================================================================
378 /** Returns true if the message is a pitch-wheel move.
379 @see getPitchWheelValue, pitchWheel
381 bool isPitchWheel() const noexcept
;
383 /** Returns the pitch wheel position from a pitch-wheel move message.
385 The value returned is a 14-bit number from 0 to 0x3fff, indicating the wheel position.
386 If called for messages which aren't pitch wheel events, the number returned will be
391 int getPitchWheelValue() const noexcept
;
393 /** Creates a pitch-wheel move message.
395 @param channel the midi channel, in the range 1 to 16
396 @param position the wheel position, in the range 0 to 16383
399 static MidiMessage
pitchWheel (int channel
, int position
) noexcept
;
401 //==============================================================================
402 /** Returns true if the message is an aftertouch event.
404 For aftertouch events, use the getNoteNumber() method to find out the key
405 that it applies to, and getAfterTouchValue() to find out the amount. Use
406 getChannel() to find out the channel.
408 @see getAftertouchValue, getNoteNumber
410 bool isAftertouch() const noexcept
;
412 /** Returns the amount of aftertouch from an aftertouch messages.
414 The value returned is in the range 0 to 127, and will be nonsense for messages
415 other than aftertouch messages.
419 int getAfterTouchValue() const noexcept
;
421 /** Creates an aftertouch message.
423 @param channel the midi channel, in the range 1 to 16
424 @param noteNumber the key number, 0 to 127
425 @param aftertouchAmount the amount of aftertouch, 0 to 127
428 static MidiMessage
aftertouchChange (int channel
,
430 int aftertouchAmount
) noexcept
;
432 /** Returns true if the message is a channel-pressure change event.
434 This is like aftertouch, but common to the whole channel rather than a specific
435 note. Use getChannelPressureValue() to find out the pressure, and getChannel()
436 to find out the channel.
438 @see channelPressureChange
440 bool isChannelPressure() const noexcept
;
442 /** Returns the pressure from a channel pressure change message.
444 @returns the pressure, in the range 0 to 127
445 @see isChannelPressure, channelPressureChange
447 int getChannelPressureValue() const noexcept
;
449 /** Creates a channel-pressure change event.
451 @param channel the midi channel: 1 to 16
452 @param pressure the pressure, 0 to 127
453 @see isChannelPressure
455 static MidiMessage
channelPressureChange (int channel
, int pressure
) noexcept
;
457 //==============================================================================
458 /** Returns true if this is a midi controller message.
460 @see getControllerNumber, getControllerValue, controllerEvent
462 bool isController() const noexcept
;
464 /** Returns the controller number of a controller message.
466 The name of the controller can be looked up using the getControllerName() method.
467 Note that the value returned is invalid for messages that aren't controller changes.
469 @see isController, getControllerName, getControllerValue
471 int getControllerNumber() const noexcept
;
473 /** Returns the controller value from a controller message.
475 A value 0 to 127 is returned to indicate the new controller position.
476 Note that the value returned is invalid for messages that aren't controller changes.
478 @see isController, getControllerNumber
480 int getControllerValue() const noexcept
;
482 /** Returns true if this message is a controller message and if it has the specified
485 bool isControllerOfType (int controllerType
) const noexcept
;
487 /** Creates a controller message.
488 @param channel the midi channel, in the range 1 to 16
489 @param controllerType the type of controller
490 @param value the controller value
493 static MidiMessage
controllerEvent (int channel
,
497 /** Checks whether this message is an all-notes-off message.
500 bool isAllNotesOff() const noexcept
;
502 /** Checks whether this message is an all-sound-off message.
505 bool isAllSoundOff() const noexcept
;
507 /** Checks whether this message is a reset all controllers message.
508 @see allControllerOff
510 bool isResetAllControllers() const noexcept
;
512 /** Creates an all-notes-off message.
513 @param channel the midi channel, in the range 1 to 16
516 static MidiMessage
allNotesOff (int channel
) noexcept
;
518 /** Creates an all-sound-off message.
519 @param channel the midi channel, in the range 1 to 16
522 static MidiMessage
allSoundOff (int channel
) noexcept
;
524 /** Creates an all-controllers-off message.
525 @param channel the midi channel, in the range 1 to 16
527 static MidiMessage
allControllersOff (int channel
) noexcept
;
529 //==============================================================================
530 /** Returns true if this event is a meta-event.
532 Meta-events are things like tempo changes, track names, etc.
534 @see getMetaEventType, isTrackMetaEvent, isEndOfTrackMetaEvent,
535 isTextMetaEvent, isTrackNameEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
536 isKeySignatureMetaEvent, isMidiChannelMetaEvent
538 bool isMetaEvent() const noexcept
;
540 /** Returns a meta-event's type number.
542 If the message isn't a meta-event, this will return -1.
544 @see isMetaEvent, isTrackMetaEvent, isEndOfTrackMetaEvent,
545 isTextMetaEvent, isTrackNameEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
546 isKeySignatureMetaEvent, isMidiChannelMetaEvent
548 int getMetaEventType() const noexcept
;
550 /** Returns a pointer to the data in a meta-event.
551 @see isMetaEvent, getMetaEventLength
553 const uint8
* getMetaEventData() const noexcept
;
555 /** Returns the length of the data for a meta-event.
556 @see isMetaEvent, getMetaEventData
558 int getMetaEventLength() const noexcept
;
560 //==============================================================================
561 /** Returns true if this is a 'track' meta-event. */
562 bool isTrackMetaEvent() const noexcept
;
564 /** Returns true if this is an 'end-of-track' meta-event. */
565 bool isEndOfTrackMetaEvent() const noexcept
;
567 /** Creates an end-of-track meta-event.
568 @see isEndOfTrackMetaEvent
570 static MidiMessage
endOfTrack() noexcept
;
572 /** Returns true if this is an 'track name' meta-event.
573 You can use the getTextFromTextMetaEvent() method to get the track's name.
575 bool isTrackNameEvent() const noexcept
;
577 /** Returns true if this is a 'text' meta-event.
578 @see getTextFromTextMetaEvent
580 bool isTextMetaEvent() const noexcept
;
582 /** Returns the text from a text meta-event.
585 String
getTextFromTextMetaEvent() const;
587 /** Creates a text meta-event. */
588 static MidiMessage
textMetaEvent (int type
, StringRef text
);
590 //==============================================================================
591 /** Returns true if this is a 'tempo' meta-event.
592 @see getTempoMetaEventTickLength, getTempoSecondsPerQuarterNote
594 bool isTempoMetaEvent() const noexcept
;
596 /** Returns the tick length from a tempo meta-event.
598 @param timeFormat the 16-bit time format value from the midi file's header.
599 @returns the tick length (in seconds).
600 @see isTempoMetaEvent
602 double getTempoMetaEventTickLength (short timeFormat
) const noexcept
;
604 /** Calculates the seconds-per-quarter-note from a tempo meta-event.
605 @see isTempoMetaEvent, getTempoMetaEventTickLength
607 double getTempoSecondsPerQuarterNote() const noexcept
;
609 /** Creates a tempo meta-event.
610 @see isTempoMetaEvent
612 static MidiMessage
tempoMetaEvent (int microsecondsPerQuarterNote
) noexcept
;
614 //==============================================================================
615 /** Returns true if this is a 'time-signature' meta-event.
616 @see getTimeSignatureInfo
618 bool isTimeSignatureMetaEvent() const noexcept
;
620 /** Returns the time-signature values from a time-signature meta-event.
621 @see isTimeSignatureMetaEvent
623 void getTimeSignatureInfo (int& numerator
, int& denominator
) const noexcept
;
625 /** Creates a time-signature meta-event.
626 @see isTimeSignatureMetaEvent
628 static MidiMessage
timeSignatureMetaEvent (int numerator
, int denominator
);
630 //==============================================================================
631 /** Returns true if this is a 'key-signature' meta-event.
632 @see getKeySignatureNumberOfSharpsOrFlats, isKeySignatureMajorKey
634 bool isKeySignatureMetaEvent() const noexcept
;
636 /** Returns the key from a key-signature meta-event.
637 This method must only be called if isKeySignatureMetaEvent() is true.
638 A positive number here indicates the number of sharps in the key signature,
639 and a negative number indicates a number of flats. So e.g. 3 = F# + C# + G#,
641 @see isKeySignatureMetaEvent, isKeySignatureMajorKey
643 int getKeySignatureNumberOfSharpsOrFlats() const noexcept
;
645 /** Returns true if this key-signature event is major, or false if it's minor.
646 This method must only be called if isKeySignatureMetaEvent() is true.
648 bool isKeySignatureMajorKey() const noexcept
;
650 /** Creates a key-signature meta-event.
651 @param numberOfSharpsOrFlats if positive, this indicates the number of sharps
652 in the key; if negative, the number of flats
653 @param isMinorKey if true, the key is minor; if false, it is major
654 @see isKeySignatureMetaEvent
656 static MidiMessage
keySignatureMetaEvent (int numberOfSharpsOrFlats
, bool isMinorKey
);
658 //==============================================================================
659 /** Returns true if this is a 'channel' meta-event.
661 A channel meta-event specifies the midi channel that should be used
662 for subsequent meta-events.
664 @see getMidiChannelMetaEventChannel
666 bool isMidiChannelMetaEvent() const noexcept
;
668 /** Returns the channel number from a channel meta-event.
670 @returns the channel, in the range 1 to 16.
671 @see isMidiChannelMetaEvent
673 int getMidiChannelMetaEventChannel() const noexcept
;
675 /** Creates a midi channel meta-event.
677 @param channel the midi channel, in the range 1 to 16
678 @see isMidiChannelMetaEvent
680 static MidiMessage
midiChannelMetaEvent (int channel
) noexcept
;
682 //==============================================================================
683 /** Returns true if this is an active-sense message. */
684 bool isActiveSense() const noexcept
;
686 //==============================================================================
687 /** Returns true if this is a midi start event.
690 bool isMidiStart() const noexcept
;
692 /** Creates a midi start event. */
693 static MidiMessage
midiStart() noexcept
;
695 /** Returns true if this is a midi continue event.
698 bool isMidiContinue() const noexcept
;
700 /** Creates a midi continue event. */
701 static MidiMessage
midiContinue() noexcept
;
703 /** Returns true if this is a midi stop event.
706 bool isMidiStop() const noexcept
;
708 /** Creates a midi stop event. */
709 static MidiMessage
midiStop() noexcept
;
711 /** Returns true if this is a midi clock event.
712 @see midiClock, songPositionPointer
714 bool isMidiClock() const noexcept
;
716 /** Creates a midi clock event. */
717 static MidiMessage
midiClock() noexcept
;
719 /** Returns true if this is a song-position-pointer message.
720 @see getSongPositionPointerMidiBeat, songPositionPointer
722 bool isSongPositionPointer() const noexcept
;
724 /** Returns the midi beat-number of a song-position-pointer message.
725 @see isSongPositionPointer, songPositionPointer
727 int getSongPositionPointerMidiBeat() const noexcept
;
729 /** Creates a song-position-pointer message.
731 The position is a number of midi beats from the start of the song, where 1 midi
732 beat is 6 midi clocks, and there are 24 midi clocks in a quarter-note. So there
733 are 4 midi beats in a quarter-note.
735 @see isSongPositionPointer, getSongPositionPointerMidiBeat
737 static MidiMessage
songPositionPointer (int positionInMidiBeats
) noexcept
;
739 //==============================================================================
740 /** Returns true if this is a quarter-frame midi timecode message.
741 @see quarterFrame, getQuarterFrameSequenceNumber, getQuarterFrameValue
743 bool isQuarterFrame() const noexcept
;
745 /** Returns the sequence number of a quarter-frame midi timecode message.
746 This will be a value between 0 and 7.
747 @see isQuarterFrame, getQuarterFrameValue, quarterFrame
749 int getQuarterFrameSequenceNumber() const noexcept
;
751 /** Returns the value from a quarter-frame message.
752 This will be the lower nybble of the message's data-byte, a value between 0 and 15
754 int getQuarterFrameValue() const noexcept
;
756 /** Creates a quarter-frame MTC message.
758 @param sequenceNumber a value 0 to 7 for the upper nybble of the message's data byte
759 @param value a value 0 to 15 for the lower nybble of the message's data byte
761 static MidiMessage
quarterFrame (int sequenceNumber
, int value
) noexcept
;
763 /** SMPTE timecode types.
764 Used by the getFullFrameParameters() and fullFrame() methods.
766 enum SmpteTimecodeType
774 /** Returns true if this is a full-frame midi timecode message. */
775 bool isFullFrame() const noexcept
;
777 /** Extracts the timecode information from a full-frame midi timecode message.
779 You should only call this on messages where you've used isFullFrame() to
780 check that they're the right kind.
782 void getFullFrameParameters (int& hours
,
786 SmpteTimecodeType
& timecodeType
) const noexcept
;
788 /** Creates a full-frame MTC message. */
789 static MidiMessage
fullFrame (int hours
,
793 SmpteTimecodeType timecodeType
);
795 //==============================================================================
796 /** Types of MMC command.
798 @see isMidiMachineControlMessage, getMidiMachineControlCommand, midiMachineControlCommand
800 enum MidiMachineControlCommand
804 mmc_deferredplay
= 3,
812 /** Checks whether this is an MMC message.
813 If it is, you can use the getMidiMachineControlCommand() to find out its type.
815 bool isMidiMachineControlMessage() const noexcept
;
817 /** For an MMC message, this returns its type.
819 Make sure it's actually an MMC message with isMidiMachineControlMessage() before
822 MidiMachineControlCommand
getMidiMachineControlCommand() const noexcept
;
824 /** Creates an MMC message. */
825 static MidiMessage
midiMachineControlCommand (MidiMachineControlCommand command
);
827 /** Checks whether this is an MMC "goto" message.
828 If it is, the parameters passed-in are set to the time that the message contains.
829 @see midiMachineControlGoto
831 bool isMidiMachineControlGoto (int& hours
,
834 int& frames
) const noexcept
;
836 /** Creates an MMC "goto" message.
837 This messages tells the device to go to a specific frame.
838 @see isMidiMachineControlGoto
840 static MidiMessage
midiMachineControlGoto (int hours
,
845 //==============================================================================
846 /** Creates a master-volume change message.
847 @param volume the volume, 0 to 1.0
849 static MidiMessage
masterVolume (float volume
);
851 //==============================================================================
852 /** Creates a system-exclusive message.
853 The data passed in is wrapped with header and tail bytes of 0xf0 and 0xf7.
855 static MidiMessage
createSysExMessage (const void* sysexData
,
859 //==============================================================================
861 /** Reads a midi variable-length integer.
863 The `data` argument indicates the data to read the number from,
864 and `numBytesUsed` is used as an out-parameter to indicate the number
865 of bytes that were read.
867 [[deprecated ("This signature has been deprecated in favour of the safer readVariableLengthValue.")]]
868 static int readVariableLengthVal (const uint8
* data
, int& numBytesUsed
) noexcept
;
871 /** Holds information about a variable-length value which was parsed
872 from a stream of bytes.
874 A valid value requires that `bytesUsed` is greater than 0.
876 struct VariableLengthValue
878 VariableLengthValue() = default;
880 VariableLengthValue (int valueIn
, int bytesUsedIn
)
881 : value (valueIn
), bytesUsed (bytesUsedIn
) {}
883 bool isValid() const noexcept
{ return bytesUsed
> 0; }
889 /** Reads a midi variable-length integer, with protection against buffer overflow.
891 @param data the data to read the number from
892 @param maxBytesToUse the number of bytes in the region following `data`
893 @returns a struct containing the parsed value, and the number
894 of bytes that were read. If parsing fails, both the
895 `value` and `bytesUsed` fields will be set to 0 and
896 `isValid()` will return false
898 static VariableLengthValue
readVariableLengthValue (const uint8
* data
,
899 int maxBytesToUse
) noexcept
;
901 /** Based on the first byte of a short midi message, this uses a lookup table
902 to return the message length (either 1, 2, or 3 bytes).
904 The value passed in must be 0x80 or higher.
906 static int getMessageLengthFromFirstByte (uint8 firstByte
) noexcept
;
908 //==============================================================================
909 /** Returns the name of a midi note number.
913 @param noteNumber the midi note number, 0 to 127
914 @param useSharps if true, sharpened notes are used, e.g. "C#", otherwise
915 they'll be flattened, e.g. "Db"
916 @param includeOctaveNumber if true, the octave number will be appended to the string,
918 @param octaveNumForMiddleC if an octave number is being appended, this indicates the
919 number that will be used for middle C's octave
921 @see getMidiNoteInHertz
923 static String
getMidiNoteName (int noteNumber
,
925 bool includeOctaveNumber
,
926 int octaveNumForMiddleC
);
928 /** Returns the frequency of a midi note number.
930 The frequencyOfA parameter is an optional frequency for 'A', normally 440-444Hz for concert pitch.
933 static double getMidiNoteInHertz (int noteNumber
, double frequencyOfA
= 440.0) noexcept
;
935 /** Returns true if the given midi note number is a black key. */
936 static bool isMidiNoteBlack (int noteNumber
) noexcept
;
938 /** Returns the standard name of a GM instrument, or nullptr if unknown for this index.
940 @param midiInstrumentNumber the program number 0 to 127
941 @see getProgramChangeNumber
943 static const char* getGMInstrumentName (int midiInstrumentNumber
);
945 /** Returns the name of a bank of GM instruments, or nullptr if unknown for this bank number.
946 @param midiBankNumber the bank, 0 to 15
948 static const char* getGMInstrumentBankName (int midiBankNumber
);
950 /** Returns the standard name of a channel 10 percussion sound, or nullptr if unknown for this note number.
951 @param midiNoteNumber the key number, 35 to 81
953 static const char* getRhythmInstrumentName (int midiNoteNumber
);
955 /** Returns the name of a controller type number, or nullptr if unknown for this controller number.
956 @see getControllerNumber
958 static const char* getControllerName (int controllerNumber
);
960 /** Converts a floating-point value between 0 and 1 to a MIDI 7-bit value between 0 and 127. */
961 static uint8
floatValueToMidiByte (float valueBetween0and1
) noexcept
;
963 /** Converts a pitchbend value in semitones to a MIDI 14-bit pitchwheel position value. */
964 static uint16
pitchbendToPitchwheelPos (float pitchbendInSemitones
,
965 float pitchbendRangeInSemitones
) noexcept
;
968 //==============================================================================
972 uint8
* allocatedData
;
973 uint8 asBytes
[sizeof (uint8
*)];
976 PackedData packedData
;
977 double timeStamp
= 0;
981 inline bool isHeapAllocated() const noexcept
{ return size
> (int) sizeof (packedData
); }
982 inline uint8
* getData() const noexcept
{ return isHeapAllocated() ? packedData
.allocatedData
: const_cast<uint8
*>(packedData
.asBytes
); }
983 uint8
* allocateSpace (int);