OpenShot Audio Library | OpenShotAudio: juce_MidiMessage.h Source File

OpenShot Audio Library | OpenShotAudio 0.3.2

Loading...
Searching...
No Matches
juce_MidiMessage.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
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.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
34 class JUCE_API MidiMessage
35{
36public:
37 //==============================================================================
46 MidiMessage (int byte1, int byte2, int byte3, double timeStamp = 0) noexcept;
47
55 MidiMessage (int byte1, int byte2, double timeStamp = 0) noexcept;
56
63 MidiMessage (int byte1, double timeStamp = 0) noexcept;
64
66 template <typename... Data>
67 MidiMessage (int byte1, int byte2, int byte3, Data... otherBytes) : size (3 + sizeof... (otherBytes))
68 {
69 // this checks that the length matches the data..
70 jassert (size > 3 || byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == size);
71
72 const uint8 data[] = { (uint8) byte1, (uint8) byte2, (uint8) byte3, static_cast<uint8> (otherBytes)... };
73 memcpy (allocateSpace (size), data, (size_t) size);
74 }
75
76
78 MidiMessage (const void* data, int numBytes, double timeStamp = 0);
79
100 MidiMessage (const void* data, int maxBytesToUse,
101 int& numBytesUsed, uint8 lastStatusByte,
102 double timeStamp = 0,
103 bool sysexHasEmbeddedLength = true);
104
109 MidiMessage() noexcept;
110
112 MidiMessage (const MidiMessage&);
113
115 MidiMessage (const MidiMessage&, double newTimeStamp);
116
118 ~MidiMessage() noexcept;
119
121 MidiMessage& operator= (const MidiMessage& other);
122
124 MidiMessage (MidiMessage&&) noexcept;
125
127 MidiMessage& operator= (MidiMessage&&) noexcept;
128
129 //==============================================================================
133 const uint8* getRawData() const noexcept { return getData(); }
134
138 int getRawDataSize() const noexcept { return size; }
139
140 //==============================================================================
144 String getDescription() const;
145
146 //==============================================================================
163 double getTimeStamp() const noexcept { return timeStamp; }
164
169 void setTimeStamp (double newTimestamp) noexcept { timeStamp = newTimestamp; }
170
174 void addToTimeStamp (double delta) noexcept { timeStamp += delta; }
175
179 MidiMessage withTimeStamp (double newTimestamp) const;
180
181 //==============================================================================
188 int getChannel() const noexcept;
189
195 bool isForChannel (int channelNumber) const noexcept;
196
201 void setChannel (int newChannelNumber) noexcept;
202
203 //==============================================================================
206 bool isSysEx() const noexcept;
207
212 const uint8* getSysExData() const noexcept;
213
218 int getSysExDataSize() const noexcept;
219
220 //==============================================================================
231 bool isNoteOn (bool returnTrueForVelocity0 = false) const noexcept;
232
240 static MidiMessage noteOn (int channel, int noteNumber, float velocity) noexcept;
241
249 static MidiMessage noteOn (int channel, int noteNumber, uint8 velocity) noexcept;
250
258 bool isNoteOff (bool returnTrueForNoteOnVelocity0 = true) const noexcept;
259
267 static MidiMessage noteOff (int channel, int noteNumber, float velocity) noexcept;
268
276 static MidiMessage noteOff (int channel, int noteNumber, uint8 velocity) noexcept;
277
284 static MidiMessage noteOff (int channel, int noteNumber) noexcept;
285
290 bool isNoteOnOrOff() const noexcept;
291
296 int getNoteNumber() const noexcept;
297
301 void setNoteNumber (int newNoteNumber) noexcept;
302
303 //==============================================================================
311 uint8 getVelocity() const noexcept;
312
320 float getFloatVelocity() const noexcept;
321
329 void setVelocity (float newVelocity) noexcept;
330
338 void multiplyVelocity (float scaleFactor) noexcept;
339
340 //==============================================================================
342 bool isSustainPedalOn() const noexcept;
344 bool isSustainPedalOff() const noexcept;
345
347 bool isSostenutoPedalOn() const noexcept;
349 bool isSostenutoPedalOff() const noexcept;
350
352 bool isSoftPedalOn() const noexcept;
354 bool isSoftPedalOff() const noexcept;
355
356 //==============================================================================
360 bool isProgramChange() const noexcept;
361
366 int getProgramChangeNumber() const noexcept;
367
374 static MidiMessage programChange (int channel, int programNumber) noexcept;
375
376 //==============================================================================
380 bool isPitchWheel() const noexcept;
381
390 int getPitchWheelValue() const noexcept;
391
398 static MidiMessage pitchWheel (int channel, int position) noexcept;
399
400 //==============================================================================
409 bool isAftertouch() const noexcept;
410
418 int getAfterTouchValue() const noexcept;
419
427 static MidiMessage aftertouchChange (int channel,
428 int noteNumber,
429 int aftertouchAmount) noexcept;
430
439 bool isChannelPressure() const noexcept;
440
446 int getChannelPressureValue() const noexcept;
447
454 static MidiMessage channelPressureChange (int channel, int pressure) noexcept;
455
456 //==============================================================================
461 bool isController() const noexcept;
462
470 int getControllerNumber() const noexcept;
471
479 int getControllerValue() const noexcept;
480
484 bool isControllerOfType (int controllerType) const noexcept;
485
492 static MidiMessage controllerEvent (int channel,
493 int controllerType,
494 int value) noexcept;
495
499 bool isAllNotesOff() const noexcept;
500
504 bool isAllSoundOff() const noexcept;
505
509 bool isResetAllControllers() const noexcept;
510
515 static MidiMessage allNotesOff (int channel) noexcept;
516
521 static MidiMessage allSoundOff (int channel) noexcept;
522
526 static MidiMessage allControllersOff (int channel) noexcept;
527
528 //==============================================================================
537 bool isMetaEvent() const noexcept;
538
547 int getMetaEventType() const noexcept;
548
552 const uint8* getMetaEventData() const noexcept;
553
557 int getMetaEventLength() const noexcept;
558
559 //==============================================================================
561 bool isTrackMetaEvent() const noexcept;
562
564 bool isEndOfTrackMetaEvent() const noexcept;
565
569 static MidiMessage endOfTrack() noexcept;
570
574 bool isTrackNameEvent() const noexcept;
575
579 bool isTextMetaEvent() const noexcept;
580
584 String getTextFromTextMetaEvent() const;
585
587 static MidiMessage textMetaEvent (int type, StringRef text);
588
589 //==============================================================================
593 bool isTempoMetaEvent() const noexcept;
594
601 double getTempoMetaEventTickLength (short timeFormat) const noexcept;
602
606 double getTempoSecondsPerQuarterNote() const noexcept;
607
611 static MidiMessage tempoMetaEvent (int microsecondsPerQuarterNote) noexcept;
612
613 //==============================================================================
617 bool isTimeSignatureMetaEvent() const noexcept;
618
622 void getTimeSignatureInfo (int& numerator, int& denominator) const noexcept;
623
627 static MidiMessage timeSignatureMetaEvent (int numerator, int denominator);
628
629 //==============================================================================
633 bool isKeySignatureMetaEvent() const noexcept;
634
642 int getKeySignatureNumberOfSharpsOrFlats() const noexcept;
643
647 bool isKeySignatureMajorKey() const noexcept;
648
655 static MidiMessage keySignatureMetaEvent (int numberOfSharpsOrFlats, bool isMinorKey);
656
657 //==============================================================================
665 bool isMidiChannelMetaEvent() const noexcept;
666
672 int getMidiChannelMetaEventChannel() const noexcept;
673
679 static MidiMessage midiChannelMetaEvent (int channel) noexcept;
680
681 //==============================================================================
683 bool isActiveSense() const noexcept;
684
685 //==============================================================================
689 bool isMidiStart() const noexcept;
690
692 static MidiMessage midiStart() noexcept;
693
697 bool isMidiContinue() const noexcept;
698
700 static MidiMessage midiContinue() noexcept;
701
705 bool isMidiStop() const noexcept;
706
708 static MidiMessage midiStop() noexcept;
709
713 bool isMidiClock() const noexcept;
714
716 static MidiMessage midiClock() noexcept;
717
721 bool isSongPositionPointer() const noexcept;
722
726 int getSongPositionPointerMidiBeat() const noexcept;
727
736 static MidiMessage songPositionPointer (int positionInMidiBeats) noexcept;
737
738 //==============================================================================
742 bool isQuarterFrame() const noexcept;
743
748 int getQuarterFrameSequenceNumber() const noexcept;
749
753 int getQuarterFrameValue() const noexcept;
754
760 static MidiMessage quarterFrame (int sequenceNumber, int value) noexcept;
761
765 enum SmpteTimecodeType
766 {
767 fps24 = 0,
768 fps25 = 1,
769 fps30drop = 2,
770 fps30 = 3
771 };
772
774 bool isFullFrame() const noexcept;
775
781 void getFullFrameParameters (int& hours,
782 int& minutes,
783 int& seconds,
784 int& frames,
785 SmpteTimecodeType& timecodeType) const noexcept;
786
788 static MidiMessage fullFrame (int hours,
789 int minutes,
790 int seconds,
791 int frames,
792 SmpteTimecodeType timecodeType);
793
794 //==============================================================================
799 enum MidiMachineControlCommand
800 {
801 mmc_stop = 1,
802 mmc_play = 2,
803 mmc_deferredplay = 3,
804 mmc_fastforward = 4,
805 mmc_rewind = 5,
806 mmc_recordStart = 6,
807 mmc_recordStop = 7,
808 mmc_pause = 9
809 };
810
814 bool isMidiMachineControlMessage() const noexcept;
815
821 MidiMachineControlCommand getMidiMachineControlCommand() const noexcept;
822
824 static MidiMessage midiMachineControlCommand (MidiMachineControlCommand command);
825
830 bool isMidiMachineControlGoto (int& hours,
831 int& minutes,
832 int& seconds,
833 int& frames) const noexcept;
834
839 static MidiMessage midiMachineControlGoto (int hours,
840 int minutes,
841 int seconds,
842 int frames);
843
844 //==============================================================================
848 static MidiMessage masterVolume (float volume);
849
850 //==============================================================================
854 static MidiMessage createSysExMessage (const void* sysexData,
855 int dataSize);
856
857
858 //==============================================================================
864 static int readVariableLengthVal (const uint8* data,
865 int& numBytesUsed) noexcept;
866
872 static int getMessageLengthFromFirstByte (uint8 firstByte) noexcept;
873
874 //==============================================================================
889 static String getMidiNoteName (int noteNumber,
890 bool useSharps,
891 bool includeOctaveNumber,
892 int octaveNumForMiddleC);
893
899 static double getMidiNoteInHertz (int noteNumber, double frequencyOfA = 440.0) noexcept;
900
902 static bool isMidiNoteBlack (int noteNumber) noexcept;
903
909 static const char* getGMInstrumentName (int midiInstrumentNumber);
910
914 static const char* getGMInstrumentBankName (int midiBankNumber);
915
919 static const char* getRhythmInstrumentName (int midiNoteNumber);
920
924 static const char* getControllerName (int controllerNumber);
925
927 static uint8 floatValueToMidiByte (float valueBetween0and1) noexcept;
928
930 static uint16 pitchbendToPitchwheelPos (float pitchbendInSemitones,
931 float pitchbendRangeInSemitones) noexcept;
932
933private:
934 //==============================================================================
935 #ifndef DOXYGEN
936 union PackedData
937 {
938 uint8* allocatedData;
939 uint8 asBytes[sizeof (uint8*)];
940 };
941
942 PackedData packedData;
943 double timeStamp = 0;
944 int size;
945 #endif
946
947 inline bool isHeapAllocated() const noexcept { return size > (int) sizeof (packedData); }
948 inline uint8* getData() const noexcept { return isHeapAllocated() ? packedData.allocatedData : (uint8*) packedData.asBytes; }
949 uint8* allocateSpace (int);
950};
951
952} // namespace juce
juce::MidiMessage
Definition: juce_MidiMessage.h:35
juce::MidiMessage::MidiMessage
MidiMessage(int byte1, int byte2, int byte3, Data... otherBytes)
Definition: juce_MidiMessage.h:67
juce::MidiMessage::getTimeStamp
double getTimeStamp() const noexcept
Definition: juce_MidiMessage.h:163
juce::MidiMessage::MidiMachineControlCommand
MidiMachineControlCommand
Definition: juce_MidiMessage.h:800
juce::MidiMessage::addToTimeStamp
void addToTimeStamp(double delta) noexcept
Definition: juce_MidiMessage.h:174
juce::MidiMessage::setTimeStamp
void setTimeStamp(double newTimestamp) noexcept
Definition: juce_MidiMessage.h:169
juce::MidiMessage::SmpteTimecodeType
SmpteTimecodeType
Definition: juce_MidiMessage.h:766
juce::MidiMessage::getRawDataSize
int getRawDataSize() const noexcept
Definition: juce_MidiMessage.h:138
juce::StringRef
Definition: juce_StringRef.h:62
juce::String
Definition: juce_String.h:39