2 ==============================================================================
4 This file is part of the Water library.
5 Copyright (c) 2016 ROLI Ltd.
6 Copyright (C) 2017-2022 Filipe Coelho <falktx@falktx.com>
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 ==============================================================================
26 #ifndef WATER_MIDIMESSAGE_H_INCLUDED
27 #define WATER_MIDIMESSAGE_H_INCLUDED
33 //==============================================================================
35 Encapsulates a MIDI message.
37 @see MidiMessageSequence, MidiOutput, MidiInput
42 //==============================================================================
43 /** Creates a 3-byte short midi message.
45 @param byte1 message byte 1
46 @param byte2 message byte 2
47 @param byte3 message byte 3
48 @param timeStamp the time to give the midi message - this value doesn't
49 use any particular units, so will be application-specific
51 MidiMessage (int byte1
, int byte2
, int byte3
, double timeStamp
= 0) noexcept
;
53 /** Creates a 2-byte short midi message.
55 @param byte1 message byte 1
56 @param byte2 message byte 2
57 @param timeStamp the time to give the midi message - this value doesn't
58 use any particular units, so will be application-specific
60 MidiMessage (int byte1
, int byte2
, double timeStamp
= 0) noexcept
;
62 /** Creates a 1-byte short midi message.
64 @param byte1 message byte 1
65 @param timeStamp the time to give the midi message - this value doesn't
66 use any particular units, so will be application-specific
68 MidiMessage (int byte1
, double timeStamp
= 0) noexcept
;
70 /** Creates a midi message from a block of data. */
71 MidiMessage (const void* data
, int numBytes
, double timeStamp
= 0);
73 /** Reads the next midi message from some data.
75 This will read as many bytes from a data stream as it needs to make a
76 complete message, and will return the number of bytes it used. This lets
77 you read a sequence of midi messages from a file or stream.
79 @param data the data to read from
80 @param maxBytesToUse the maximum number of bytes it's allowed to read
81 @param numBytesUsed returns the number of bytes that were actually needed
82 @param lastStatusByte in a sequence of midi messages, the initial byte
83 can be dropped from a message if it's the same as the
84 first byte of the previous message, so this lets you
85 supply the byte to use if the first byte of the message
86 has in fact been dropped.
87 @param timeStamp the time to give the midi message - this value doesn't
88 use any particular units, so will be application-specific
89 @param sysexHasEmbeddedLength when reading sysexes, this flag indicates whether
90 to expect the data to begin with a variable-length field
93 MidiMessage (const void* data
, int maxBytesToUse
,
94 int& numBytesUsed
, uint8 lastStatusByte
,
96 bool sysexHasEmbeddedLength
= true);
98 /** Creates an active-sense message.
99 Since the MidiMessage has to contain a valid message, this default constructor
100 just initialises it with an empty sysex message.
102 MidiMessage() noexcept
;
104 /** Creates a copy of another midi message. */
105 MidiMessage (const MidiMessage
&);
107 /** Creates a copy of another midi message, with a different timestamp. */
108 MidiMessage (const MidiMessage
&, double newTimeStamp
);
111 ~MidiMessage() noexcept
;
113 /** Copies this message from another one. */
114 MidiMessage
& operator= (const MidiMessage
& other
);
116 //==============================================================================
117 /** Returns a pointer to the raw midi data.
120 const uint8
* getRawData() const noexcept
{ return getData(); }
122 /** Returns the number of bytes of data in the message.
125 int getRawDataSize() const noexcept
{ return size
; }
127 //==============================================================================
128 /** Returns the timestamp associated with this message.
130 The exact meaning of this time and its units will vary, as messages are used in
131 a variety of different contexts.
133 If you're getting the message from a midi file, this could be a time in seconds, or
134 a number of ticks - see MidiFile::convertTimestampTicksToSeconds().
136 If the message is being used in a MidiBuffer, it might indicate the number of
137 audio samples from the start of the buffer.
139 If the message was created by a MidiInput, see MidiInputCallback::handleIncomingMidiMessage()
140 for details of the way that it initialises this value.
142 @see setTimeStamp, addToTimeStamp
144 double getTimeStamp() const noexcept
{ return timeStamp
; }
146 /** Changes the message's associated timestamp.
147 The units for the timestamp will be application-specific - see the notes for getTimeStamp().
148 @see addToTimeStamp, getTimeStamp
150 void setTimeStamp (double newTimestamp
) noexcept
{ timeStamp
= newTimestamp
; }
152 /** Adds a value to the message's timestamp.
153 The units for the timestamp will be application-specific.
155 void addToTimeStamp (double delta
) noexcept
{ timeStamp
+= delta
; }
157 //==============================================================================
158 /** Returns the midi channel associated with the message.
160 @returns a value 1 to 16 if the message has a channel, or 0 if it hasn't (e.g.
162 @see isForChannel, setChannel
164 int getChannel() const noexcept
;
166 /** Returns true if the message applies to the given midi channel.
168 @param channelNumber the channel number to look for, in the range 1 to 16
169 @see getChannel, setChannel
171 bool isForChannel (int channelNumber
) const noexcept
;
173 /** Changes the message's midi channel.
174 This won't do anything for non-channel messages like sysexes.
175 @param newChannelNumber the channel number to change it to, in the range 1 to 16
177 void setChannel (int newChannelNumber
) noexcept
;
179 //==============================================================================
180 /** Returns true if this is a system-exclusive message.
182 bool isSysEx() const noexcept
;
184 /** Returns a pointer to the sysex data inside the message.
185 If this event isn't a sysex event, it'll return 0.
186 @see getSysExDataSize
188 const uint8
* getSysExData() const noexcept
;
190 /** Returns the size of the sysex data.
191 This value excludes the 0xf0 header byte and the 0xf7 at the end.
194 int getSysExDataSize() const noexcept
;
196 //==============================================================================
197 /** Returns true if this message is a 'key-down' event.
199 @param returnTrueForVelocity0 if true, then if this event is a note-on with
200 velocity 0, it will still be considered to be a note-on and the
201 method will return true. If returnTrueForVelocity0 is false, then
202 if this is a note-on event with velocity 0, it'll be regarded as
203 a note-off, and the method will return false
205 @see isNoteOff, getNoteNumber, getVelocity, noteOn
207 bool isNoteOn (bool returnTrueForVelocity0
= false) const noexcept
;
209 /** Creates a key-down message (using a floating-point velocity).
211 @param channel the midi channel, in the range 1 to 16
212 @param noteNumber the key number, 0 to 127
213 @param velocity in the range 0 to 1.0
216 static MidiMessage
noteOn (int channel
, int noteNumber
, float velocity
) noexcept
;
218 /** Creates a key-down message (using an integer velocity).
220 @param channel the midi channel, in the range 1 to 16
221 @param noteNumber the key number, 0 to 127
222 @param velocity in the range 0 to 127
225 static MidiMessage
noteOn (int channel
, int noteNumber
, uint8 velocity
) noexcept
;
227 /** Returns true if this message is a 'key-up' event.
229 If returnTrueForNoteOnVelocity0 is true, then his will also return true
230 for a note-on event with a velocity of 0.
232 @see isNoteOn, getNoteNumber, getVelocity, noteOff
234 bool isNoteOff (bool returnTrueForNoteOnVelocity0
= true) const noexcept
;
236 /** Creates a key-up message.
238 @param channel the midi channel, in the range 1 to 16
239 @param noteNumber the key number, 0 to 127
240 @param velocity in the range 0 to 1.0
243 static MidiMessage
noteOff (int channel
, int noteNumber
, float velocity
) noexcept
;
245 /** Creates a key-up message.
247 @param channel the midi channel, in the range 1 to 16
248 @param noteNumber the key number, 0 to 127
249 @param velocity in the range 0 to 127
252 static MidiMessage
noteOff (int channel
, int noteNumber
, uint8 velocity
) noexcept
;
254 /** Creates a key-up message.
256 @param channel the midi channel, in the range 1 to 16
257 @param noteNumber the key number, 0 to 127
260 static MidiMessage
noteOff (int channel
, int noteNumber
) noexcept
;
262 /** Returns true if this message is a 'key-down' or 'key-up' event.
264 @see isNoteOn, isNoteOff
266 bool isNoteOnOrOff() const noexcept
;
268 /** Returns the midi note number for note-on and note-off messages.
269 If the message isn't a note-on or off, the value returned is undefined.
270 @see isNoteOff, getMidiNoteName, getMidiNoteInHertz, setNoteNumber
272 int getNoteNumber() const noexcept
;
274 /** Changes the midi note number of a note-on or note-off message.
275 If the message isn't a note on or off, this will do nothing.
277 void setNoteNumber (int newNoteNumber
) noexcept
;
279 //==============================================================================
280 /** Returns the velocity of a note-on or note-off message.
282 The value returned will be in the range 0 to 127.
283 If the message isn't a note-on or off event, it will return 0.
285 @see getFloatVelocity
287 uint8
getVelocity() const noexcept
;
289 /** Returns the velocity of a note-on or note-off message.
291 The value returned will be in the range 0 to 1.0
292 If the message isn't a note-on or off event, it will return 0.
294 @see getVelocity, setVelocity
296 float getFloatVelocity() const noexcept
;
298 /** Changes the velocity of a note-on or note-off message.
300 If the message isn't a note on or off, this will do nothing.
302 @param newVelocity the new velocity, in the range 0 to 1.0
303 @see getFloatVelocity, multiplyVelocity
305 void setVelocity (float newVelocity
) noexcept
;
307 /** Multiplies the velocity of a note-on or note-off message by a given amount.
309 If the message isn't a note on or off, this will do nothing.
311 @param scaleFactor the value by which to multiply the velocity
314 void multiplyVelocity (float scaleFactor
) noexcept
;
316 //==============================================================================
317 /** Returns true if this message is a 'sustain pedal down' controller message. */
318 bool isSustainPedalOn() const noexcept
;
319 /** Returns true if this message is a 'sustain pedal up' controller message. */
320 bool isSustainPedalOff() const noexcept
;
322 /** Returns true if this message is a 'sostenuto pedal down' controller message. */
323 bool isSostenutoPedalOn() const noexcept
;
324 /** Returns true if this message is a 'sostenuto pedal up' controller message. */
325 bool isSostenutoPedalOff() const noexcept
;
327 /** Returns true if this message is a 'soft pedal down' controller message. */
328 bool isSoftPedalOn() const noexcept
;
329 /** Returns true if this message is a 'soft pedal up' controller message. */
330 bool isSoftPedalOff() const noexcept
;
332 //==============================================================================
333 /** Returns true if the message is a program (patch) change message.
334 @see getProgramChangeNumber
336 bool isProgramChange() const noexcept
;
338 /** Returns the new program number of a program change message.
339 If the message isn't a program change, the value returned is undefined.
342 int getProgramChangeNumber() const noexcept
;
344 /** Creates a program-change message.
346 @param channel the midi channel, in the range 1 to 16
347 @param programNumber the midi program number, 0 to 127
350 static MidiMessage
programChange (int channel
, int programNumber
) noexcept
;
352 //==============================================================================
353 /** Returns true if the message is a pitch-wheel move.
354 @see getPitchWheelValue, pitchWheel
356 bool isPitchWheel() const noexcept
;
358 /** Returns the pitch wheel position from a pitch-wheel move message.
360 The value returned is a 14-bit number from 0 to 0x3fff, indicating the wheel position.
361 If called for messages which aren't pitch wheel events, the number returned will be
366 int getPitchWheelValue() const noexcept
;
368 /** Creates a pitch-wheel move message.
370 @param channel the midi channel, in the range 1 to 16
371 @param position the wheel position, in the range 0 to 16383
374 static MidiMessage
pitchWheel (int channel
, int position
) noexcept
;
376 //==============================================================================
377 /** Returns true if the message is an aftertouch event.
379 For aftertouch events, use the getNoteNumber() method to find out the key
380 that it applies to, and getAftertouchValue() to find out the amount. Use
381 getChannel() to find out the channel.
383 @see getAftertouchValue, getNoteNumber
385 bool isAftertouch() const noexcept
;
387 /** Returns the amount of aftertouch from an aftertouch messages.
389 The value returned is in the range 0 to 127, and will be nonsense for messages
390 other than aftertouch messages.
394 int getAfterTouchValue() const noexcept
;
396 /** Creates an aftertouch message.
398 @param channel the midi channel, in the range 1 to 16
399 @param noteNumber the key number, 0 to 127
400 @param aftertouchAmount the amount of aftertouch, 0 to 127
403 static MidiMessage
aftertouchChange (int channel
,
405 int aftertouchAmount
) noexcept
;
407 /** Returns true if the message is a channel-pressure change event.
409 This is like aftertouch, but common to the whole channel rather than a specific
410 note. Use getChannelPressureValue() to find out the pressure, and getChannel()
411 to find out the channel.
413 @see channelPressureChange
415 bool isChannelPressure() const noexcept
;
417 /** Returns the pressure from a channel pressure change message.
419 @returns the pressure, in the range 0 to 127
420 @see isChannelPressure, channelPressureChange
422 int getChannelPressureValue() const noexcept
;
424 /** Creates a channel-pressure change event.
426 @param channel the midi channel: 1 to 16
427 @param pressure the pressure, 0 to 127
428 @see isChannelPressure
430 static MidiMessage
channelPressureChange (int channel
, int pressure
) noexcept
;
432 //==============================================================================
433 /** Returns true if this is a midi controller message.
435 @see getControllerNumber, getControllerValue, controllerEvent
437 bool isController() const noexcept
;
439 /** Returns the controller number of a controller message.
441 The name of the controller can be looked up using the getControllerName() method.
442 Note that the value returned is invalid for messages that aren't controller changes.
444 @see isController, getControllerName, getControllerValue
446 int getControllerNumber() const noexcept
;
448 /** Returns the controller value from a controller message.
450 A value 0 to 127 is returned to indicate the new controller position.
451 Note that the value returned is invalid for messages that aren't controller changes.
453 @see isController, getControllerNumber
455 int getControllerValue() const noexcept
;
457 /** Returns true if this message is a controller message and if it has the specified
460 bool isControllerOfType (int controllerType
) const noexcept
;
462 /** Creates a controller message.
464 @param channel the midi channel, in the range 1 to 16
465 @param controllerType the type of controller
466 @param value the controller value
469 static MidiMessage
controllerEvent (int channel
,
473 /** Checks whether this message is an all-notes-off message.
476 bool isAllNotesOff() const noexcept
;
478 /** Checks whether this message is an all-sound-off message.
481 bool isAllSoundOff() const noexcept
;
483 /** Creates an all-notes-off message.
485 @param channel the midi channel, in the range 1 to 16
488 static MidiMessage
allNotesOff (int channel
) noexcept
;
490 /** Creates an all-sound-off message.
492 @param channel the midi channel, in the range 1 to 16
495 static MidiMessage
allSoundOff (int channel
) noexcept
;
497 /** Creates an all-controllers-off message.
499 @param channel the midi channel, in the range 1 to 16
501 static MidiMessage
allControllersOff (int channel
) noexcept
;
503 //==============================================================================
504 /** Returns true if this event is a meta-event.
506 Meta-events are things like tempo changes, track names, etc.
508 @see getMetaEventType, isTempoMetaEvent, isTimeSignatureMetaEvent,
509 isKeySignatureMetaEvent, isMidiChannelMetaEvent
511 bool isMetaEvent() const noexcept
;
513 /** Returns a meta-event's type number.
515 If the message isn't a meta-event, this will return -1.
517 @see isMetaEvent, isTempoMetaEvent, isTimeSignatureMetaEvent,
518 isKeySignatureMetaEvent, isMidiChannelMetaEvent
520 int getMetaEventType() const noexcept
;
522 /** Returns a pointer to the data in a meta-event.
523 @see isMetaEvent, getMetaEventLength
525 const uint8
* getMetaEventData() const noexcept
;
527 /** Returns the length of the data for a meta-event.
528 @see isMetaEvent, getMetaEventData
530 int getMetaEventLength() const noexcept
;
532 //==============================================================================
533 /** Returns true if this is a 'tempo' meta-event.
534 @see getTempoMetaEventTickLength, getTempoSecondsPerQuarterNote
536 bool isTempoMetaEvent() const noexcept
;
538 /** Returns the tick length from a tempo meta-event.
540 @param timeFormat the 16-bit time format value from the midi file's header.
541 @returns the tick length (in seconds).
542 @see isTempoMetaEvent
544 double getTempoMetaEventTickLength (short timeFormat
) const noexcept
;
546 /** Calculates the seconds-per-quarter-note from a tempo meta-event.
547 @see isTempoMetaEvent, getTempoMetaEventTickLength
549 double getTempoSecondsPerQuarterNote() const noexcept
;
551 /** Creates a tempo meta-event.
552 @see isTempoMetaEvent
554 static MidiMessage
tempoMetaEvent (int microsecondsPerQuarterNote
) noexcept
;
556 //==============================================================================
557 /** Returns true if this is a 'time-signature' meta-event.
558 @see getTimeSignatureInfo
560 bool isTimeSignatureMetaEvent() const noexcept
;
562 /** Returns the time-signature values from a time-signature meta-event.
563 @see isTimeSignatureMetaEvent
565 void getTimeSignatureInfo (int& numerator
, int& denominator
) const noexcept
;
567 /** Creates a time-signature meta-event.
568 @see isTimeSignatureMetaEvent
570 static MidiMessage
timeSignatureMetaEvent (int numerator
, int denominator
);
572 //==============================================================================
573 /** Returns true if this is a 'key-signature' meta-event.
574 @see getKeySignatureNumberOfSharpsOrFlats, isKeySignatureMajorKey
576 bool isKeySignatureMetaEvent() const noexcept
;
578 /** Returns the key from a key-signature meta-event.
579 This method must only be called if isKeySignatureMetaEvent() is true.
580 A positive number here indicates the number of sharps in the key signature,
581 and a negative number indicates a number of flats. So e.g. 3 = F# + C# + G#,
583 @see isKeySignatureMetaEvent, isKeySignatureMajorKey
585 int getKeySignatureNumberOfSharpsOrFlats() const noexcept
;
587 /** Returns true if this key-signature event is major, or false if it's minor.
588 This method must only be called if isKeySignatureMetaEvent() is true.
590 bool isKeySignatureMajorKey() const noexcept
;
592 /** Creates a key-signature meta-event.
593 @param numberOfSharpsOrFlats if positive, this indicates the number of sharps
594 in the key; if negative, the number of flats
595 @param isMinorKey if true, the key is minor; if false, it is major
596 @see isKeySignatureMetaEvent
598 static MidiMessage
keySignatureMetaEvent (int numberOfSharpsOrFlats
, bool isMinorKey
);
600 //==============================================================================
601 /** Returns true if this is a 'channel' meta-event.
603 A channel meta-event specifies the midi channel that should be used
604 for subsequent meta-events.
606 @see getMidiChannelMetaEventChannel
608 bool isMidiChannelMetaEvent() const noexcept
;
610 /** Returns the channel number from a channel meta-event.
612 @returns the channel, in the range 1 to 16.
613 @see isMidiChannelMetaEvent
615 int getMidiChannelMetaEventChannel() const noexcept
;
617 /** Creates a midi channel meta-event.
619 @param channel the midi channel, in the range 1 to 16
620 @see isMidiChannelMetaEvent
622 static MidiMessage
midiChannelMetaEvent (int channel
) noexcept
;
624 //==============================================================================
625 /** Returns true if this is an active-sense message. */
626 bool isActiveSense() const noexcept
;
628 //==============================================================================
629 /** Returns true if this is a midi start event.
632 bool isMidiStart() const noexcept
;
634 /** Creates a midi start event. */
635 static MidiMessage
midiStart() noexcept
;
637 /** Returns true if this is a midi continue event.
640 bool isMidiContinue() const noexcept
;
642 /** Creates a midi continue event. */
643 static MidiMessage
midiContinue() noexcept
;
645 /** Returns true if this is a midi stop event.
648 bool isMidiStop() const noexcept
;
650 /** Creates a midi stop event. */
651 static MidiMessage
midiStop() noexcept
;
653 /** Returns true if this is a midi clock event.
654 @see midiClock, songPositionPointer
656 bool isMidiClock() const noexcept
;
658 /** Creates a midi clock event. */
659 static MidiMessage
midiClock() noexcept
;
661 /** Returns true if this is a song-position-pointer message.
662 @see getSongPositionPointerMidiBeat, songPositionPointer
664 bool isSongPositionPointer() const noexcept
;
666 /** Returns the midi beat-number of a song-position-pointer message.
667 @see isSongPositionPointer, songPositionPointer
669 int getSongPositionPointerMidiBeat() const noexcept
;
671 /** Creates a song-position-pointer message.
673 The position is a number of midi beats from the start of the song, where 1 midi
674 beat is 6 midi clocks, and there are 24 midi clocks in a quarter-note. So there
675 are 4 midi beats in a quarter-note.
677 @see isSongPositionPointer, getSongPositionPointerMidiBeat
679 static MidiMessage
songPositionPointer (int positionInMidiBeats
) noexcept
;
681 //==============================================================================
682 /** Returns true if this is a quarter-frame midi timecode message.
683 @see quarterFrame, getQuarterFrameSequenceNumber, getQuarterFrameValue
685 bool isQuarterFrame() const noexcept
;
687 /** Returns the sequence number of a quarter-frame midi timecode message.
688 This will be a value between 0 and 7.
689 @see isQuarterFrame, getQuarterFrameValue, quarterFrame
691 int getQuarterFrameSequenceNumber() const noexcept
;
693 /** Returns the value from a quarter-frame message.
694 This will be the lower nybble of the message's data-byte, a value between 0 and 15
696 int getQuarterFrameValue() const noexcept
;
698 /** Creates a quarter-frame MTC message.
700 @param sequenceNumber a value 0 to 7 for the upper nybble of the message's data byte
701 @param value a value 0 to 15 for the lower nybble of the message's data byte
703 static MidiMessage
quarterFrame (int sequenceNumber
, int value
) noexcept
;
705 /** SMPTE timecode types.
706 Used by the getFullFrameParameters() and fullFrame() methods.
708 enum SmpteTimecodeType
716 /** Returns true if this is a full-frame midi timecode message. */
717 bool isFullFrame() const noexcept
;
719 /** Extracts the timecode information from a full-frame midi timecode message.
721 You should only call this on messages where you've used isFullFrame() to
722 check that they're the right kind.
724 void getFullFrameParameters (int& hours
,
728 SmpteTimecodeType
& timecodeType
) const noexcept
;
730 /** Creates a full-frame MTC message. */
731 static MidiMessage
fullFrame (int hours
,
735 SmpteTimecodeType timecodeType
);
737 //==============================================================================
738 /** Types of MMC command.
740 @see isMidiMachineControlMessage, getMidiMachineControlCommand, midiMachineControlCommand
742 enum MidiMachineControlCommand
746 mmc_deferredplay
= 3,
754 /** Checks whether this is an MMC message.
755 If it is, you can use the getMidiMachineControlCommand() to find out its type.
757 bool isMidiMachineControlMessage() const noexcept
;
759 /** For an MMC message, this returns its type.
761 Make sure it's actually an MMC message with isMidiMachineControlMessage() before
764 MidiMachineControlCommand
getMidiMachineControlCommand() const noexcept
;
766 /** Creates an MMC message. */
767 static MidiMessage
midiMachineControlCommand (MidiMachineControlCommand command
);
769 /** Checks whether this is an MMC "goto" message.
770 If it is, the parameters passed-in are set to the time that the message contains.
771 @see midiMachineControlGoto
773 bool isMidiMachineControlGoto (int& hours
,
776 int& frames
) const noexcept
;
778 /** Creates an MMC "goto" message.
779 This messages tells the device to go to a specific frame.
780 @see isMidiMachineControlGoto
782 static MidiMessage
midiMachineControlGoto (int hours
,
787 //==============================================================================
788 /** Creates a master-volume change message.
789 @param volume the volume, 0 to 1.0
791 static MidiMessage
masterVolume (float volume
);
793 //==============================================================================
794 /** Creates a system-exclusive message.
795 The data passed in is wrapped with header and tail bytes of 0xf0 and 0xf7.
797 static MidiMessage
createSysExMessage (const void* sysexData
,
801 //==============================================================================
802 /** Reads a midi variable-length integer.
804 @param data the data to read the number from
805 @param numBytesUsed on return, this will be set to the number of bytes that were read
807 static int readVariableLengthVal (const uint8
* data
,
808 int& numBytesUsed
) noexcept
;
810 /** Based on the first byte of a short midi message, this uses a lookup table
811 to return the message length (either 1, 2, or 3 bytes).
813 The value passed in must be 0x80 or higher.
815 static int getMessageLengthFromFirstByte (uint8 firstByte
) noexcept
;
817 //==============================================================================
818 /** Returns the frequency of a midi note number.
820 The frequencyOfA parameter is an optional frequency for 'A', normally 440-444Hz for concert pitch.
823 static double getMidiNoteInHertz (int noteNumber
, double frequencyOfA
= 440.0) noexcept
;
825 /** Returns true if the given midi note number is a black key. */
826 static bool isMidiNoteBlack (int noteNumber
) noexcept
;
828 /** Converts a floating-point value between 0 and 1 to a MIDI 7-bit value between 0 and 127. */
829 static uint8
floatValueToMidiByte (float valueBetween0and1
) noexcept
;
831 /** Converts a pitchbend value in semitones to a MIDI 14-bit pitchwheel position value. */
832 static uint16
pitchbendToPitchwheelPos (float pitchbendInSemitones
,
833 float pitchbendRangeInSemitones
) noexcept
;
836 //==============================================================================
839 uint8
* allocatedData
;
840 uint8 asBytes
[sizeof (uint8
*)];
843 PackedData packedData
;
847 inline bool isHeapAllocated() const noexcept
{ return size
> (int) sizeof (packedData
); }
848 inline uint8
* getData() noexcept
{ return isHeapAllocated() ? packedData
.allocatedData
: packedData
.asBytes
; }
849 inline const uint8
* getData() const noexcept
{ return isHeapAllocated() ? packedData
.allocatedData
: packedData
.asBytes
; }
850 uint8
* allocateSpace (int);
855 #endif // WATER_MIDIMESSAGE_H_INCLUDED