xref: /aosp_15_r20/external/walt/ios/WALT/MIDIMessage.h (revision bf47c6829f95be9dd55f4c5bbc44a71c90aad403)
1*bf47c682SAndroid Build Coastguard Worker /*
2*bf47c682SAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*bf47c682SAndroid Build Coastguard Worker  *
4*bf47c682SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*bf47c682SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*bf47c682SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*bf47c682SAndroid Build Coastguard Worker  *
8*bf47c682SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*bf47c682SAndroid Build Coastguard Worker  *
10*bf47c682SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*bf47c682SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*bf47c682SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*bf47c682SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*bf47c682SAndroid Build Coastguard Worker  * limitations under the License.
15*bf47c682SAndroid Build Coastguard Worker  */
16*bf47c682SAndroid Build Coastguard Worker 
17*bf47c682SAndroid Build Coastguard Worker #import <Foundation/Foundation.h>
18*bf47c682SAndroid Build Coastguard Worker 
19*bf47c682SAndroid Build Coastguard Worker /**
20*bf47c682SAndroid Build Coastguard Worker  * A MIDI channel number.
21*bf47c682SAndroid Build Coastguard Worker  *
22*bf47c682SAndroid Build Coastguard Worker  * Note that the first channel is '1'.
23*bf47c682SAndroid Build Coastguard Worker  */
24*bf47c682SAndroid Build Coastguard Worker typedef uint8_t MIDIChannel;
25*bf47c682SAndroid Build Coastguard Worker typedef uint8_t MIDIByte;
26*bf47c682SAndroid Build Coastguard Worker 
27*bf47c682SAndroid Build Coastguard Worker typedef NS_ENUM(MIDIByte, MIDIMessageType) {
28*bf47c682SAndroid Build Coastguard Worker   // Channel messages
29*bf47c682SAndroid Build Coastguard Worker   MIDIMessageNoteOff          = 0x08,
30*bf47c682SAndroid Build Coastguard Worker   MIDIMessageNoteOn           = 0x09,
31*bf47c682SAndroid Build Coastguard Worker   MIDIMessageKeyPressure      = 0x0A,
32*bf47c682SAndroid Build Coastguard Worker   MIDIMessageControlChange    = 0x0B,
33*bf47c682SAndroid Build Coastguard Worker   MIDIMessageProgramChange    = 0x0C,
34*bf47c682SAndroid Build Coastguard Worker   MIDIMessageChannelPressure  = 0x0D,
35*bf47c682SAndroid Build Coastguard Worker   MIDIMessagePitchBend        = 0x0E,
36*bf47c682SAndroid Build Coastguard Worker 
37*bf47c682SAndroid Build Coastguard Worker   // System messages
38*bf47c682SAndroid Build Coastguard Worker   MIDIMessageSysEx            = 0xF0,
39*bf47c682SAndroid Build Coastguard Worker   MIDIMessageQuarterFrame     = 0xF1,
40*bf47c682SAndroid Build Coastguard Worker   MIDIMessageSongPosition     = 0xF2,
41*bf47c682SAndroid Build Coastguard Worker   MIDIMessageSongSelect       = 0xF3,
42*bf47c682SAndroid Build Coastguard Worker   MIDIMessageTuneRequest      = 0xF6,
43*bf47c682SAndroid Build Coastguard Worker   MIDIMessageSysExEnd         = 0xF7,
44*bf47c682SAndroid Build Coastguard Worker   MIDIMessageTimingClock      = 0xF8,
45*bf47c682SAndroid Build Coastguard Worker   MIDIMessageStart            = 0xFA,
46*bf47c682SAndroid Build Coastguard Worker   MIDIMessageContinue         = 0xFB,
47*bf47c682SAndroid Build Coastguard Worker   MIDIMessageStop             = 0xFC,
48*bf47c682SAndroid Build Coastguard Worker   MIDIMessageActiveSensing    = 0xFE,
49*bf47c682SAndroid Build Coastguard Worker   MIDIMessageReset            = 0xFF,
50*bf47c682SAndroid Build Coastguard Worker };
51*bf47c682SAndroid Build Coastguard Worker 
52*bf47c682SAndroid Build Coastguard Worker extern const MIDIChannel kMIDINoChannel;
53*bf47c682SAndroid Build Coastguard Worker 
54*bf47c682SAndroid Build Coastguard Worker #pragma mark Message Parsing
55*bf47c682SAndroid Build Coastguard Worker 
56*bf47c682SAndroid Build Coastguard Worker /** Returns the MIDIMessageType for a given status byte. */
57*bf47c682SAndroid Build Coastguard Worker MIDIMessageType MIDIMessageTypeFromStatus(MIDIByte status);
58*bf47c682SAndroid Build Coastguard Worker 
59*bf47c682SAndroid Build Coastguard Worker /**
60*bf47c682SAndroid Build Coastguard Worker  * Returns the MIDIChannel for a given status byte, or kMIDINoChannel if the status byte does not
61*bf47c682SAndroid Build Coastguard Worker  * describe a channel message.
62*bf47c682SAndroid Build Coastguard Worker  */
63*bf47c682SAndroid Build Coastguard Worker MIDIChannel MIDIChannelFromStatus(MIDIByte status);
64*bf47c682SAndroid Build Coastguard Worker 
65*bf47c682SAndroid Build Coastguard Worker /**
66*bf47c682SAndroid Build Coastguard Worker  * Returns the body portion from a complete MIDI message (i.e., without leading or trailing data).
67*bf47c682SAndroid Build Coastguard Worker  */
68*bf47c682SAndroid Build Coastguard Worker NSData *MIDIMessageBody(NSData *message);
69*bf47c682SAndroid Build Coastguard Worker 
70*bf47c682SAndroid Build Coastguard Worker #pragma mark Message Building
71*bf47c682SAndroid Build Coastguard Worker 
72*bf47c682SAndroid Build Coastguard Worker /** Returns the MIDI status byte for a message type sent to a particular channel. */
73*bf47c682SAndroid Build Coastguard Worker MIDIByte MIDIStatusByte(MIDIMessageType type, MIDIChannel channel);
74*bf47c682SAndroid Build Coastguard Worker 
75*bf47c682SAndroid Build Coastguard Worker /** Creates a complete MIDI message packet for a given message type, channel, and its body. */
76*bf47c682SAndroid Build Coastguard Worker NSData *MIDIMessageCreate(MIDIMessageType type, MIDIChannel channel, NSData *body);
77*bf47c682SAndroid Build Coastguard Worker 
78*bf47c682SAndroid Build Coastguard Worker /** Creates a complete MIDI message packet for a simple message containing one data byte. */
79*bf47c682SAndroid Build Coastguard Worker NSData *MIDIMessageCreateSimple1(MIDIMessageType type, MIDIChannel channel, MIDIByte first);
80*bf47c682SAndroid Build Coastguard Worker 
81*bf47c682SAndroid Build Coastguard Worker /** Creates a complete MIDI message packet for a simple message containing two data bytes. */
82*bf47c682SAndroid Build Coastguard Worker NSData *MIDIMessageCreateSimple2(MIDIMessageType type,
83*bf47c682SAndroid Build Coastguard Worker                                  MIDIChannel channel,
84*bf47c682SAndroid Build Coastguard Worker                                  MIDIByte first,
85*bf47c682SAndroid Build Coastguard Worker                                  MIDIByte second);
86