midi_control/
consts.rs

1//
2// Copied from https://codeberg.org/PieterPenninckx/midi-consts/src/commit/68597aa8725c29137b354f70171be9695d26a536/src/lib.rs
3//
4// License: MIT OR Apache-2.0
5// Author: Pieter Penninckx <pieter-codeberg-midiconsts@nckx.be>
6// Additions: Hubert Figuière <hub@figuiere.net>
7
8//! Constants for dealing with midi events.
9//! Currently, only channel events are supported.
10
11/// Constants for channel events
12///
13/// Channel events consist of two or three bytes:
14/// * byte 1: event type (first four bits) and midi channel (last four bits)
15/// * byte 2: parameter 1
16/// * byte 3: parameter 2 (used for most, but not all event types)
17pub mod channel_event {
18    /// The first byte of a channel event contains both the event type
19    /// and the midi channel in one byte.
20    /// Use this bit mask to get the event type.
21    ///
22    /// ## Example
23    /// ```
24    /// use midi_control::consts::channel_event::EVENT_TYPE_MASK;
25    /// # fn get_byte() -> u8 { 0x94}
26    /// let byte: u8 = get_byte(); // Suppose we got this byte somewhere.
27    /// let event_type = byte & EVENT_TYPE_MASK; // (binary AND)
28    /// match event_type {
29    ///     EVENT_TYPE_NOTE_OFF => { /* ... */ },
30    ///     EVENT_TYPE_NOTE_ON => { /* ... */ },
31    ///     // ...
32    ///     _ => { /* ...*/ }
33    /// }
34    /// ```
35    pub const EVENT_TYPE_MASK: u8 = 0b1111_0000;
36
37    /// The first byte of a channel event contains both the event type
38    /// and the midi channel in one byte.
39    /// Use this bit mask to get the midi channel.
40    ///
41    /// ## Example
42    /// ```
43    /// use midi_control::consts::channel_event::MIDI_CHANNEL_MASK;
44    /// # fn get_byte() -> u8 { 0x94}
45    /// let byte: u8 = get_byte(); // Suppose we got this byte somewhere.
46    /// let midi_channel: u8 = byte & MIDI_CHANNEL_MASK; // (binary AND)
47    /// ```
48    pub const MIDI_CHANNEL_MASK: u8 = 0b0000_1111;
49
50    /// Event type of note off event.
51    ///
52    /// A channel event of this type is as follows:
53    /// * byte 1: `NOTE_OFF | channel`
54    /// * byte 2: note number (0-127)
55    /// * byte 3: velocity (how hard the key was released)
56    ///
57    /// # Remark
58    /// A note off event is often represented as a note on event
59    /// with velocity `0`.
60    pub const NOTE_OFF: u8 = 0x80;
61
62    /// Event type of note on event.
63    ///
64    /// A channel event of this type is as follows:
65    /// * byte one: `NOTE_ON | channel`
66    /// * byte two: note number (0-127)
67    /// * byte three: velocity (how hard the key was pressed)
68    ///
69    /// # Remark
70    /// A note off event is often represented as a note on event
71    /// with velocity `0`.
72    pub const NOTE_ON: u8 = 0x90;
73
74    /// Event type for polyphonic key pressure ("aftertouch").
75    ///
76    /// A channel event of this type is as follows:
77    /// * byte one: `POLYPHONIC_KEY_PRESSURE | channel`, where `channel` is the channel (0-16)
78    /// * byte two: note number (0-127)
79    /// * byte three: aftertouch value
80    pub const POLYPHONIC_KEY_PRESSURE: u8 = 0xA0;
81
82    /// Event type of a controller event.
83    ///
84    /// A channel event of this type is as follows:
85    /// * byte one: `CONTROL_CHANGE | channel`, where `channel` is the channel (0-16)
86    /// * byte two: controller type (0-127)
87    /// * byte three: new controller value
88    ///
89    /// See the [`control_change`] module for more details.
90    ///
91    /// [`control_change`]: ./control_change/index.html
92    pub const CONTROL_CHANGE: u8 = 0xB0;
93
94    /// Event type of a program change.
95    ///
96    /// A channel event of this type has only two bytes and is as follows:
97    /// * byte one: `PROGRAM_CHANGE | channel`, where `channel` is the channel (0-16)
98    /// * byte two: program number (0-127)
99    pub const PROGRAM_CHANGE: u8 = 0xC0;
100
101    /// Event type of channel pressure ("channel aftertouch").
102    ///
103    /// Events of this type are assumed to effect all currently
104    /// playing notes for the specified channel.
105    /// A channel event of this type has only two bytes and is as follows:
106    /// * byte one: `CHANNEL_KEY_PRESSURE | channel`, where `channel` is the channel (0-16)
107    /// * byte two: pressure amount (0-127)
108    pub const CHANNEL_KEY_PRESSURE: u8 = 0xD0;
109
110    /// Event type of a pitch bend event.
111    ///
112    /// A channel event of this type is as follows:
113    /// * byte one: `PITCH_BEND_CHANGE | channel`, where `channel` is the channel (0-16)
114    /// * byte two: least significant byte of the pitch bend amount (0-127)
115    /// * byte three: most significant byte of the pitch bend amount
116    ///
117    /// By combining the two bytes that make up the pitch bend amount, you
118    /// can get a `u16` value that describes the pitch bend amount.
119    /// Value 8192 means "no pitch change", lower values mean decrease in pitch
120    /// and higher values mean increase in pitch.
121    pub const PITCH_BEND_CHANGE: u8 = 0xE0;
122
123    /// Constants to represent controller change types.
124    ///
125    /// A control change channel event is as follows:
126    /// * byte one: `CONTROL_CHANGE | channel`, where `channel` is the channel (0-16)
127    /// * byte two: controller type (0-127). This module contains constants for these types.
128    /// * byte three: new controller value
129    ///
130    /// # Remark
131    /// Some control change types come in pairs: one with the most significant byte (MSB)
132    /// and one with the least significant byte (LSB).
133    pub mod control_change {
134        const LSB_MASK: u8 = 0x20;
135
136        /// Bank select: most significant byte.
137        pub const BANK_SELECT_MSB: u8 = 0x00;
138
139        /// Bank select: least significant byte.
140        pub const BANK_SELECT_LSB: u8 = BANK_SELECT_MSB | LSB_MASK;
141
142        /// Modulation: most significant byte.
143        pub const MODULATION_MSB: u8 = 0x01;
144
145        /// Modulation: least significant byte.
146        pub const MODULATION_LSB: u8 = MODULATION_MSB | LSB_MASK;
147
148        /// Breath controller: most significant byte.
149        pub const BREATH_CONTROLLER_MSB: u8 = 0x02;
150
151        /// Breach controller: least significant byte.
152        pub const BREATH_CONTROLLER_LSB: u8 = BREATH_CONTROLLER_MSB | LSB_MASK;
153
154        /// Foot controller: most significant byte.
155        pub const FOOT_CONTROLLER_MSB: u8 = 0x04;
156
157        /// Foot controller: least significant byte.
158        pub const FOOT_CONTROLLER_LSB: u8 = FOOT_CONTROLLER_MSB | LSB_MASK;
159
160        /// Portamento: most significant byte.
161        pub const PORTAMENTO_TIME_MSB: u8 = 0x05;
162
163        /// Portamento: least significant byte.
164        pub const PORTAMENTO_TIME_LSB: u8 = PORTAMENTO_TIME_MSB | LSB_MASK;
165
166        /// Data entry: most significant byte.
167        pub const DATA_ENTRY_MSB: u8 = 0x06;
168
169        /// Data entry: least significant byte.
170        pub const DATA_ENTRY_LSB: u8 = DATA_ENTRY_MSB | LSB_MASK;
171
172        /// Main volume: most significant byte.
173        pub const MAIN_VOLUME_MSB: u8 = 0x07;
174
175        /// Main volume: least significant byte.
176        pub const MAIN_VOLUME_LSB: u8 = MAIN_VOLUME_MSB | LSB_MASK;
177
178        /// Balance: most significant byte.
179        pub const BALANCE_MSB: u8 = 0x08;
180
181        /// Balance: least significant byte.
182        pub const BALANCE_LSB: u8 = BALANCE_MSB | LSB_MASK;
183
184        /// Pan: most significant byte.
185        pub const PAN_MSB: u8 = 0x0A;
186
187        /// Pan: least significant byte.
188        pub const PAN_LSB: u8 = PAN_MSB | LSB_MASK;
189
190        /// Expression controller: most significant byte.
191        pub const EXPRESSION_CONTROLLER_MSB: u8 = 0x0B;
192
193        /// Expression controller: least significant byte.
194        pub const EXPRESSION_CONTROLLER_LSB: u8 = EXPRESSION_CONTROLLER_MSB | LSB_MASK;
195
196        /// Effect control 1: most significant byte.
197        pub const EFFECT_CONTROL_1_MSB: u8 = 0x0C;
198
199        /// Effect control 1: least significant byte.
200        pub const EFFECT_CONTROL_1_LSB: u8 = EFFECT_CONTROL_1_MSB | LSB_MASK;
201
202        /// Effect control 2: most significant byte.
203        pub const EFFECT_CONTROL_2_MSB: u8 = 0x0D;
204
205        /// Effect control 2: least significant byte.
206        pub const EFFECT_CONTROL_2_LSB: u8 = EFFECT_CONTROL_2_MSB | LSB_MASK;
207
208        /// General purpose controller 1: most significant byte.
209        pub const GENERAL_PURPOSE_CONTROLLER_1_MSB: u8 = 0x10;
210
211        /// General purpose controller 1: least significant byte.
212        pub const GENERAL_PURPOSE_CONTROLLER_1_LSB: u8 =
213            GENERAL_PURPOSE_CONTROLLER_1_MSB | LSB_MASK;
214
215        /// General purpose controller 2: most significant byte.
216        pub const GENERAL_PURPOSE_CONTROLLER_2_MSB: u8 = 0x11;
217
218        /// General purpose controller 2: least significant byte.
219        pub const GENERAL_PURPOSE_CONTROLLER_2_LSB: u8 =
220            GENERAL_PURPOSE_CONTROLLER_2_MSB | LSB_MASK;
221
222        /// General purpose controller 3: most significant byte.
223        pub const GENERAL_PURPOSE_CONTROLLER_3_MSB: u8 = 0x12;
224
225        /// General purpose controller 3: least significant byte.
226        pub const GENERAL_PURPOSE_CONTROLLER_3_LSB: u8 =
227            GENERAL_PURPOSE_CONTROLLER_3_MSB | LSB_MASK;
228
229        /// General purpose controller 4: most significant byte.
230        pub const GENERAL_PURPOSE_CONTROLLER_4_MSB: u8 = 0x13;
231
232        /// General purpose controller 4: least significant byte.
233        pub const GENERAL_PURPOSE_CONTROLLER_4_LSB: u8 =
234            GENERAL_PURPOSE_CONTROLLER_4_MSB | LSB_MASK;
235
236        /// Damper pedal.
237        pub const DAMPER_PEDAL: u8 = 0x40;
238
239        /// Portamento.
240        pub const PORTAMENTO: u8 = 0x41;
241
242        /// Sustenuto.
243        pub const SUSTENUTO: u8 = 0x42;
244
245        /// Soft pedal.
246        pub const SOFT_PEDAL: u8 = 0x43;
247
248        /// Legato footswitch.
249        pub const LEGATO_FOOTSWITCH: u8 = 0x44;
250
251        /// Hold 2.
252        pub const HOLD_2: u8 = 0x45;
253
254        /// Sound controller 1. Default: Timber variation
255        pub const SOUND_CONTROLLER_1: u8 = 0x46;
256
257        /// Sound controller 2. Default: Timber/harmonic content
258        pub const SOUND_CONTROLLER_2: u8 = 0x47;
259
260        /// Sound controller 3. Default: Release time
261        pub const SOUND_CONTROLLER_3: u8 = 0x48;
262
263        /// Sound controller 4. Default: Attack time
264        pub const SOUND_CONTROLLER_4: u8 = 0x49;
265
266        /// Sound controller 5.
267        pub const SOUND_CONTROLLER_5: u8 = 0x4A;
268
269        /// Sound controller 6.
270        pub const SOUND_CONTROLLER_6: u8 = 0x4B;
271
272        /// Sound controller 7.
273        pub const SOUND_CONTROLLER_7: u8 = 0x4C;
274
275        /// Sound controller 8.
276        pub const SOUND_CONTROLLER_8: u8 = 0x4D;
277
278        /// Sound controller 9.
279        pub const SOUND_CONTROLLER_9: u8 = 0x4E;
280
281        /// Sound controller 10.
282        pub const SOUND_CONTROLLER_10: u8 = 0x4F;
283
284        /// General purpose controller 5: most significant byte.
285        ///
286        /// # Remark
287        /// As far as I know, this has no LSB (least significant byte) variant.
288        pub const GENERAL_PURPOSE_CONTROLLER_5_MSB: u8 = 0x50;
289
290        /// General purpose controller 6: most significant byte.
291        ///
292        /// # Remark
293        /// As far as I know, this has no LSB (least significant byte) variant.
294        pub const GENERAL_PURPOSE_CONTROLLER_6_MSB: u8 = 0x51;
295
296        /// General purpose controller 7: most significant byte.
297        ///
298        /// # Remark
299        /// As far as I know, this has no LSB (least significant byte) variant.
300        pub const GENERAL_PURPOSE_CONTROLLER_7_MSB: u8 = 0x52;
301
302        /// General purpose controller 8: most significant byte.
303        ///
304        /// # Remark
305        /// As far as I know, this has no LSB (least significant byte) variant.
306        pub const GENERAL_PURPOSE_CONTROLLER_8_MSB: u8 = 0x53;
307
308        /// Portamento.
309        pub const PORTAMENTO_CONTROL: u8 = 0x54;
310
311        /// Effects depth 1. Formerly "External Effects Depth"
312        pub const EFFECTS_1_DEPTH: u8 = 0x5B;
313
314        /// Effects depth 2. Formerly "Tremolo Depth"
315        pub const EFFECTS_2_DEPTH: u8 = 0x5C;
316
317        /// Effects depth 3. Formerly "Chorus Depth"
318        pub const EFFECTS_3_DEPTH: u8 = 0x5D;
319
320        /// Effects depth 4. Formerly "Celeste Detune"
321        pub const EFFECTS_4_DEPTH: u8 = 0x5E;
322
323        /// Effects depth 5. Formerly "Phaser Depth"
324        pub const EFFECTS_5_DEPTH: u8 = 0x5F;
325
326        /// Non-registered parameter number: least significant byte.
327        pub const NON_REGISTERED_PARAMETER_NUMBER_LSB: u8 = 0x62;
328
329        /// Non-registered parameter number: most significant byte.
330        pub const NON_REGISTERED_PARAMETER_NUMBER_MSB: u8 = 0x63;
331
332        /// Registered parameter number: least significant byte.
333        pub const REGISTERED_PARAMETER_NUMBER_LSB: u8 = 0x64;
334
335        /// Registered parameter number: most significant byte.
336        pub const REGISTERED_PARAMETER_NUMBER_MSB: u8 = 0x65;
337
338        /// Mode message: all sound off.
339        ///
340        /// For this event, the data byte (the third byte of the event) should be `0`
341        pub const ALL_SOUND_OFF: u8 = 0x78;
342
343        /// Mode message: reset all controllers.
344        ///
345        /// For this event, the data byte (the third byte of the event) should be `0`
346        pub const RESET_ALL_CONTROLLERS: u8 = 0x79;
347
348        /// Mode message: local control.
349        ///
350        /// When local control is on (default), the device responds to its local controls.
351        /// When local control is off, it only responds to data recieved over MIDI.
352        ///
353        /// See the module [`local_control`] for possible values of the data byte
354        /// (the third byte of the event).
355        ///
356        /// [`local_control`]: ./local_control/index.html
357        pub const LOCAL_CONTROL: u8 = 0x7A;
358
359        /// Constants for the data byte (3rd byte) of a local control control change event.
360        pub mod local_control {
361            /// Local control off: the device only responds to data recieved over MIDI.
362            pub const LOCAL_CONTROL_OFF: u8 = 0;
363            /// Local control on: the device also responds to local events (keys played, ...).
364            pub const LOCAL_CONTROL_ON: u8 = 127;
365        }
366
367        /// Mode message: all notes off.
368        ///
369        /// For this event, the data byte (the third byte of the event) should be `0`.
370        pub const ALL_NOTES_OFF: u8 = 0x7B;
371
372        /// Mode message: omni mode off.
373        ///
374        /// For this event, the data byte (the third byte of the event) should be `0`.
375        /// # Remark
376        /// This message also causes all notes off.
377        pub const OMNI_MODE_OFF: u8 = 0x7C;
378
379        /// Mode message: omni mode on.
380        ///
381        /// For this event, the data byte (the third byte of the event) should be `0`.
382        /// # Remark
383        /// This message also causes all notes off.
384        pub const OMNI_MODE_ON: u8 = 0x7D;
385
386        /// Mode message: mono mode on
387        ///
388        /// For this event, the data byte (the third byte of the event)
389        /// indicates the number of channels (omni off) or `0` (omni on).
390        /// # Remark
391        /// This message also causes all notes off.
392        pub const MONO_MODE_ON: u8 = 0x7E;
393
394        /// Poly mode on
395        ///
396        /// # Remark
397        /// This message also causes all notes off.
398        pub const POLY_MODE_ON: u8 = 0x7F;
399    }
400}
401
402pub mod system_event {
403    /// System Exclusive message
404    /// System exclusive messages have a variable length and thus
405    /// terminated by an EOX.
406    /// * byte two: manufacturer
407    /// * byte n: EOX
408    pub const SYSEX: u8 = 240;
409
410    /// Content for the manufacturer (byte two) of SysEx
411    /// Include Universal System Exclusive Message
412    ///
413    /// Unless byte two is not any of these value up to 3 more bytes
414    /// are defined.
415    pub mod sysex {
416        /// Manufacturer is extended ID
417        /// * byte three: extension group
418        /// * byte four: extended manufacturer ID
419        pub const ID_EXTENSION: u8 = 0;
420        /// Non Real Time universal exclusive message
421        /// * byte three: device ID. 7f is all call.
422        /// * byte four: Sub ID #1
423        /// * byte five: Sub ID #2
424        pub const NON_REAL_TIME: u8 = 0x7e;
425        /// Real Time universal exclusive message
426        /// * byte three: device ID. ALL_CALL is all call.
427        /// * byte four: Sub ID #1
428        /// * byte five: Sub ID #2
429        pub const REAL_TIME: u8 = 0x7f;
430    }
431
432    /// Constants for Universal System Exclusive
433    /// Both realtime and non realtime
434    pub mod usysex {
435        /// Send this for all devices to listen.
436        pub const ALL_CALL: u8 = 0x7f;
437    }
438
439    /// System common messages
440
441    /// MTC Quarter Frame
442    pub const MTC_QUARTER_FRAME: u8 = 241;
443
444    /// Song position Pointer
445    /// * byte two: LSB of the pointer
446    /// * byte three: MSB of the pointer
447    pub const SONG_POSITION_POINTER: u8 = 242;
448
449    /// Song Select
450    /// * byte two: Song # 0-127
451    pub const SONG_SELECT: u8 = 243;
452
453    /// Tune Request
454    pub const TUNE_REQUEST: u8 = 246;
455
456    /// End Of eXclusive message
457    /// This is the last byte of the SysEx
458    pub const EOX: u8 = 247;
459
460    /// System real time messages
461
462    /// Timing Clock
463    pub const RT_TIMING_CLOCK: u8 = 248;
464
465    /// Start playback
466    pub const RT_START: u8 = 250;
467    /// Continue playback
468    pub const RT_CONTINUE: u8 = 251;
469    /// Stop playback
470    pub const RT_STOP: u8 = 252;
471
472    /// Active Sensing
473    pub const RT_ACTIVE_SENSING: u8 = 254;
474
475    /// Reset all
476    pub const RT_SYSTEM_RESET: u8 = 255;
477}
478
479pub use channel_event::*;
480pub use system_event::*;