openshot-audio  0.1.6
juce_MidiMessage.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_MIDIMESSAGE_H_INCLUDED
26 #define JUCE_MIDIMESSAGE_H_INCLUDED
27 
28 
29 //==============================================================================
36 {
37 public:
38  //==============================================================================
47  MidiMessage (int byte1, int byte2, int byte3, double timeStamp = 0) noexcept;
48 
56  MidiMessage (int byte1, int byte2, double timeStamp = 0) noexcept;
57 
64  MidiMessage (int byte1, double timeStamp = 0) noexcept;
65 
67  MidiMessage (const void* data, int numBytes, double timeStamp = 0);
68 
89  MidiMessage (const void* data, int maxBytesToUse,
90  int& numBytesUsed, uint8 lastStatusByte,
91  double timeStamp = 0,
92  bool sysexHasEmbeddedLength = true);
93 
99 
101  MidiMessage (const MidiMessage&);
102 
104  MidiMessage (const MidiMessage&, double newTimeStamp);
105 
107  ~MidiMessage();
108 
110  MidiMessage& operator= (const MidiMessage& other);
111 
112  #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
114  MidiMessage& operator= (MidiMessage&&) noexcept;
115  #endif
116 
117  //==============================================================================
121  const uint8* getRawData() const noexcept { return allocatedData != nullptr ? allocatedData.getData() : preallocatedData.asBytes; }
122 
126  int getRawDataSize() const noexcept { return size; }
127 
128  //==============================================================================
145  double getTimeStamp() const noexcept { return timeStamp; }
146 
151  void setTimeStamp (double newTimestamp) noexcept { timeStamp = newTimestamp; }
152 
156  void addToTimeStamp (double delta) noexcept { timeStamp += delta; }
157 
158  //==============================================================================
165  int getChannel() const noexcept;
166 
172  bool isForChannel (int channelNumber) const noexcept;
173 
178  void setChannel (int newChannelNumber) noexcept;
179 
180  //==============================================================================
183  bool isSysEx() const noexcept;
184 
189  const uint8* getSysExData() const noexcept;
190 
195  int getSysExDataSize() const noexcept;
196 
197  //==============================================================================
208  bool isNoteOn (bool returnTrueForVelocity0 = false) const noexcept;
209 
217  static MidiMessage noteOn (int channel, int noteNumber, float velocity) noexcept;
218 
226  static MidiMessage noteOn (int channel, int noteNumber, uint8 velocity) noexcept;
227 
235  bool isNoteOff (bool returnTrueForNoteOnVelocity0 = true) const noexcept;
236 
244  static MidiMessage noteOff (int channel, int noteNumber, uint8 velocity = 0) noexcept;
245 
250  bool isNoteOnOrOff() const noexcept;
251 
256  int getNoteNumber() const noexcept;
257 
261  void setNoteNumber (int newNoteNumber) noexcept;
262 
263  //==============================================================================
271  uint8 getVelocity() const noexcept;
272 
280  float getFloatVelocity() const noexcept;
281 
289  void setVelocity (float newVelocity) noexcept;
290 
298  void multiplyVelocity (float scaleFactor) noexcept;
299 
300  //==============================================================================
302  bool isSustainPedalOn() const noexcept;
304  bool isSustainPedalOff() const noexcept;
305 
307  bool isSostenutoPedalOn() const noexcept;
309  bool isSostenutoPedalOff() const noexcept;
310 
312  bool isSoftPedalOn() const noexcept;
314  bool isSoftPedalOff() const noexcept;
315 
316  //==============================================================================
320  bool isProgramChange() const noexcept;
321 
326  int getProgramChangeNumber() const noexcept;
327 
334  static MidiMessage programChange (int channel, int programNumber) noexcept;
335 
336  //==============================================================================
340  bool isPitchWheel() const noexcept;
341 
350  int getPitchWheelValue() const noexcept;
351 
358  static MidiMessage pitchWheel (int channel, int position) noexcept;
359 
360  //==============================================================================
369  bool isAftertouch() const noexcept;
370 
378  int getAfterTouchValue() const noexcept;
379 
387  static MidiMessage aftertouchChange (int channel,
388  int noteNumber,
389  int aftertouchAmount) noexcept;
390 
399  bool isChannelPressure() const noexcept;
400 
406  int getChannelPressureValue() const noexcept;
407 
414  static MidiMessage channelPressureChange (int channel, int pressure) noexcept;
415 
416  //==============================================================================
421  bool isController() const noexcept;
422 
430  int getControllerNumber() const noexcept;
431 
439  int getControllerValue() const noexcept;
440 
444  bool isControllerOfType (int controllerType) const noexcept;
445 
453  static MidiMessage controllerEvent (int channel,
454  int controllerType,
455  int value) noexcept;
456 
460  bool isAllNotesOff() const noexcept;
461 
465  bool isAllSoundOff() const noexcept;
466 
472  static MidiMessage allNotesOff (int channel) noexcept;
473 
479  static MidiMessage allSoundOff (int channel) noexcept;
480 
485  static MidiMessage allControllersOff (int channel) noexcept;
486 
487  //==============================================================================
496  bool isMetaEvent() const noexcept;
497 
506  int getMetaEventType() const noexcept;
507 
511  const uint8* getMetaEventData() const noexcept;
512 
516  int getMetaEventLength() const noexcept;
517 
518  //==============================================================================
520  bool isTrackMetaEvent() const noexcept;
521 
523  bool isEndOfTrackMetaEvent() const noexcept;
524 
528  static MidiMessage endOfTrack() noexcept;
529 
533  bool isTrackNameEvent() const noexcept;
534 
538  bool isTextMetaEvent() const noexcept;
539 
543  String getTextFromTextMetaEvent() const;
544 
546  static MidiMessage textMetaEvent (int type, StringRef text);
547 
548  //==============================================================================
552  bool isTempoMetaEvent() const noexcept;
553 
560  double getTempoMetaEventTickLength (short timeFormat) const noexcept;
561 
565  double getTempoSecondsPerQuarterNote() const noexcept;
566 
570  static MidiMessage tempoMetaEvent (int microsecondsPerQuarterNote) noexcept;
571 
572  //==============================================================================
576  bool isTimeSignatureMetaEvent() const noexcept;
577 
581  void getTimeSignatureInfo (int& numerator, int& denominator) const noexcept;
582 
586  static MidiMessage timeSignatureMetaEvent (int numerator, int denominator);
587 
588  //==============================================================================
592  bool isKeySignatureMetaEvent() const noexcept;
593 
601  int getKeySignatureNumberOfSharpsOrFlats() const noexcept;
602 
606  bool isKeySignatureMajorKey() const noexcept;
607 
614  static MidiMessage keySignatureMetaEvent (int numberOfSharpsOrFlats, bool isMinorKey);
615 
616  //==============================================================================
624  bool isMidiChannelMetaEvent() const noexcept;
625 
631  int getMidiChannelMetaEventChannel() const noexcept;
632 
638  static MidiMessage midiChannelMetaEvent (int channel) noexcept;
639 
640  //==============================================================================
642  bool isActiveSense() const noexcept;
643 
644  //==============================================================================
648  bool isMidiStart() const noexcept;
649 
651  static MidiMessage midiStart() noexcept;
652 
656  bool isMidiContinue() const noexcept;
657 
659  static MidiMessage midiContinue() noexcept;
660 
664  bool isMidiStop() const noexcept;
665 
667  static MidiMessage midiStop() noexcept;
668 
672  bool isMidiClock() const noexcept;
673 
675  static MidiMessage midiClock() noexcept;
676 
680  bool isSongPositionPointer() const noexcept;
681 
685  int getSongPositionPointerMidiBeat() const noexcept;
686 
695  static MidiMessage songPositionPointer (int positionInMidiBeats) noexcept;
696 
697  //==============================================================================
701  bool isQuarterFrame() const noexcept;
702 
707  int getQuarterFrameSequenceNumber() const noexcept;
708 
712  int getQuarterFrameValue() const noexcept;
713 
719  static MidiMessage quarterFrame (int sequenceNumber, int value) noexcept;
720 
725  {
726  fps24 = 0,
727  fps25 = 1,
728  fps30drop = 2,
729  fps30 = 3
730  };
731 
733  bool isFullFrame() const noexcept;
734 
740  void getFullFrameParameters (int& hours,
741  int& minutes,
742  int& seconds,
743  int& frames,
744  SmpteTimecodeType& timecodeType) const noexcept;
745 
747  static MidiMessage fullFrame (int hours,
748  int minutes,
749  int seconds,
750  int frames,
751  SmpteTimecodeType timecodeType);
752 
753  //==============================================================================
759  {
760  mmc_stop = 1,
761  mmc_play = 2,
762  mmc_deferredplay = 3,
763  mmc_fastforward = 4,
764  mmc_rewind = 5,
765  mmc_recordStart = 6,
766  mmc_recordStop = 7,
767  mmc_pause = 9
768  };
769 
773  bool isMidiMachineControlMessage() const noexcept;
774 
780  MidiMachineControlCommand getMidiMachineControlCommand() const noexcept;
781 
783  static MidiMessage midiMachineControlCommand (MidiMachineControlCommand command);
784 
789  bool isMidiMachineControlGoto (int& hours,
790  int& minutes,
791  int& seconds,
792  int& frames) const noexcept;
793 
798  static MidiMessage midiMachineControlGoto (int hours,
799  int minutes,
800  int seconds,
801  int frames);
802 
803  //==============================================================================
807  static MidiMessage masterVolume (float volume);
808 
809  //==============================================================================
813  static MidiMessage createSysExMessage (const void* sysexData,
814  int dataSize);
815 
816 
817  //==============================================================================
823  static int readVariableLengthVal (const uint8* data,
824  int& numBytesUsed) noexcept;
825 
831  static int getMessageLengthFromFirstByte (const uint8 firstByte) noexcept;
832 
833  //==============================================================================
848  static String getMidiNoteName (int noteNumber,
849  bool useSharps,
850  bool includeOctaveNumber,
851  int octaveNumForMiddleC);
852 
858  static double getMidiNoteInHertz (int noteNumber, const double frequencyOfA = 440.0) noexcept;
859 
861  static bool isMidiNoteBlack (int noteNumber) noexcept;
862 
868  static const char* getGMInstrumentName (int midiInstrumentNumber);
869 
873  static const char* getGMInstrumentBankName (int midiBankNumber);
874 
878  static const char* getRhythmInstrumentName (int midiNoteNumber);
879 
883  static const char* getControllerName (int controllerNumber);
884 
885 private:
886  //==============================================================================
887  double timeStamp;
888  HeapBlock<uint8> allocatedData;
889  int size;
890 
891  #ifndef DOXYGEN
892  union
893  {
894  uint8 asBytes[4];
896  } preallocatedData;
897  #endif
898 
899  inline uint8* getData() noexcept { return allocatedData != nullptr ? allocatedData.getData() : preallocatedData.asBytes; }
900  uint8* allocateSpace (int);
901 };
902 
903 #endif // JUCE_MIDIMESSAGE_H_INCLUDED
#define true
Definition: ordinals.h:82
#define noexcept
Definition: juce_CompilerSupport.h:141
MidiMachineControlCommand
Definition: juce_MidiMessage.h:758
SmpteTimecodeType
Definition: juce_MidiMessage.h:724
#define false
Definition: ordinals.h:83
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
#define const
void setTimeStamp(double newTimestamp) noexcept
Definition: juce_MidiMessage.h:151
uint32 asInt32
Definition: juce_MidiMessage.h:895
unsigned int uint32
Definition: juce_MathsFunctions.h:51
const uint8 * getRawData() const noexcept
Definition: juce_MidiMessage.h:121
double getTimeStamp() const noexcept
Definition: juce_MidiMessage.h:145
Definition: juce_HeapBlock.h:90
JSAMPIMAGE data
Definition: jpeglib.h:945
int getRawDataSize() const noexcept
Definition: juce_MidiMessage.h:126
unsigned char uint8
Definition: juce_MathsFunctions.h:43
Definition: juce_MidiMessage.h:35
void addToTimeStamp(double delta) noexcept
Definition: juce_MidiMessage.h:156
Definition: juce_StringRef.h:65