NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
midi.h
Go to the documentation of this file.
1/*
2 * NiCMidi - A C++ Class Library for MIDI
3 *
4 * Copyright (C) 2004 J.D. Koftinoff Software, Ltd.
5 * www.jdkoftinoff.com jeffk@jdkoftinoff.com
6 * Copyright (C) 2021, 2022 Nicola Cassetta
7 * https://github.com/ncassetta/NiCMidi
8 *
9 * This file is part of NiCMidi.
10 *
11 * NiCMidi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as
13 * published by the Free Software Foundation, either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * NiCMidi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with NiCMidi. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25
28
29
30#ifndef _NICMIDI_MIDI_H
31#define _NICMIDI_MIDI_H
32
33
36
40typedef unsigned long MIDIClockTime;
41
44
47const MIDIClockTime TIME_INFINITE = 0xffffffff;
51const unsigned int DEFAULT_CLKS_PER_BEAT = 120;
53
55
56/* TODO: THIS IS EXPERIMENTAL; FOR NOW NOT IMPLEMENTED
59enum {
60 CHANS_FROM_1 = 1,
61 MEAS_FROM_1 = 2,
62 TRACKS_FROM_1 = 4,
63 PORTS_FROM_1 = 8
64};
65
66static unsigned char From1Flag = 0;
67
68void SetChansFrom1(bool f) { (From1Flag &= (~CHANS_FROM_1)) |= (CHANS_FROM_1 * f); };
69void SetMeasFrom1(bool f) { (From1Flag &= (~MEAS_FROM_1)) |= (MEAS_FROM_1 * f); };
70void SetTracksFrom1(bool f) { (From1Flag &= (~TRACKS_FROM_1)) |= (TRACKS_FROM_1 * f); };
71void SetPortsFrom1(bool f) { (From1Flag &= (~PORTS_FROM_1)) |= (PORTS_FROM_1 * f); };
72void SetFrom1(unsigned char c) { From1Flag = c; }
73int GetChansFrom1() { return (From1Flag & CHANS_FROM_1) == CHANS_FROM_1; };
74int GetMeasFrom1() { return (From1Flag & MEAS_FROM_1) == MEAS_FROM_1; };
75int GetTracksFrom1() { return (From1Flag & TRACKS_FROM_1) == TRACKS_FROM_1; };
76int GetPortsFrom1() { return (From1Flag & PORTS_FROM_1) == PORTS_FROM_1; };
77unsigned char GetFrom1Flag() { return From1Flag; };
78
80*/
81
82
83
88
93enum : unsigned char {
94 NOTE_OFF =0x80,
95 NOTE_ON =0x90,
102 MTC =0xf1,
106 SYSEX_END =0xf7,
107 RESET =0xff,
108 META_EVENT =0xff
109 // TODO: these should be merged with MIDI real time messages, but this should not retrocompatible
112
113
116
118enum : unsigned char {
121 RT_START =0xfa,
123 RT_STOP =0xfc,
124 RT_ACTIVE_SENSE =0xfe
127
128
131
135enum : unsigned char {
136 C_LSB =0x20,
137 C_GM_BANK =0x00,
139 C_BREATH =0x02,
140 C_FOOT =0x04,
144 C_BALANCE =0x08,
145 C_PAN =0x0a,
151
152 C_DAMPER =0x40,
153 C_PORTA =0x41,
156 C_HOLD_2 =0x45,
157
162
168
171
174 C_RPN_LSB =0x64,
175 C_RPN_MSB =0x65,
176
178 C_RESET =0x79,
179 C_LOCAL =0x7a,
182 C_OMNI_ON =0x7d,
183 C_MONO =0x7e,
184 C_POLY =0x7f
187
188
191
193enum : unsigned char {
196 RPN_COARSE_TUNE =0x02
199
202
208enum : unsigned char {
237 //META_TRACK_LOOP = 0x2E, I found no documentation for this
264
265
267// these are used by MIDIMessage class
268extern const signed char chan_msg_len[16];
269extern const signed char sys_msg_len[16];
271
272
277
279const char* GetChanMsgName(unsigned char status);
282const char* GetChanModeMsgName(unsigned char number);
284const char* GetSysMsgName(unsigned char status);
286const char* GetMetaMsgName(unsigned char type);
290const char* GetGMProgramName(unsigned char number, int format = 0);
294const char* GetGMDrumkitName(unsigned char number, int format = 0);
296bool IsNoteWhite(unsigned char note);
298bool IsNoteBlack(unsigned char note);
299
301inline int GetNoteOctave(unsigned char note) {
302 return (note/12)-1;
303}
304
311const char* KeyName (signed char sharp_flats, unsigned char major_minor, bool uppercase = true,
312 bool space = false, bool use_Mm = true);
313
314// unsigned char NoteNumber(const char*name);
315
317
318
323const double MIDI_DEFAULT_TEMPO = 120.0;
328
329
330#endif
331
const char * GetSysMsgName(unsigned char status)
Returns a readable name for the given sys message status.
const char * GetMetaMsgName(unsigned char type)
Returns a readable name for the given meta message status.
const double MIDI_DEFAULT_TEMPO
Musical tempo.
Definition: midi.h:323
unsigned long MIDIClockTime
The type of a variable which can hold a time in MIDI ticks.
Definition: midi.h:40
const MIDIClockTime TIME_INFINITE
A constant which represents an infinite time.
Definition: midi.h:47
const char * GetChanModeMsgName(unsigned char number)
Returns a readable name for the given channel mode (Control change with controller number between 0x7...
const char * GetGMDrumkitName(unsigned char number, int format=0)
Returns a readable name for a GM program number on channel 10 (drumkit).
const int MIDI_DEFAULT_TIMESIG_DENOMINATOR
Timesig denominator.
Definition: midi.h:322
const int MIDI_DEFAULT_TIMESIG_NUMERATOR
Timesig numerator.
Definition: midi.h:321
const char * GetChanMsgName(unsigned char status)
Returns a readable name for the given channel message status.
const int MIDI_DEFAULT_KEYSIG_KEY
Keysig key (C)
Definition: midi.h:324
const int MIDI_DEFAULT_KEYSIG_MODE
Keysig mode (major)
Definition: midi.h:325
const unsigned int DEFAULT_CLKS_PER_BEAT
The default clocks per beat parameter when initializing a MIDIMultiTrack.
Definition: midi.h:51
bool IsNoteBlack(unsigned char note)
Returns true if the MIDI number of the note denotes a black key.
int GetNoteOctave(unsigned char note)
MIDI note number to standard octave conversion.
Definition: midi.h:301
const char * KeyName(signed char sharp_flats, unsigned char major_minor, bool uppercase=true, bool space=false, bool use_Mm=true)
Converts a MIDI key signature into a readable form.
bool IsNoteWhite(unsigned char note)
Returns true if the MIDI number of the note denotes a white key.
const char * GetGMProgramName(unsigned char number, int format=0)
Returns a readable name for a GM program number.
@ META_CHANNEL_PREFIX
Associates a MIDI channel with following meta events. Its effect is terminated by another MIDI Channe...
Definition: midi.h:233
@ META_INSTRUMENT_NAME
Text: instrument name.
Definition: midi.h:218
@ META_CUE_TEXT
Text: cue point.
Definition: midi.h:221
@ META_MARKER_TEXT
Text: marker.
Definition: midi.h:220
@ META_OUTPUT_CABLE
This may be used in multiport environments to associate a track with a specific port....
Definition: midi.h:236
@ META_COPYRIGHT
Text: copyright.
Definition: midi.h:216
@ META_SMPTE
Specifies the initial SMPTE offset of the beginning of playback. It has 5 data bytes (stored in the s...
Definition: midi.h:246
@ META_END_OF_TRACK
The end of track marker in a MIDI file (also used in the MIDITrack object). The data length is 0 byte...
Definition: midi.h:239
@ META_TEMPO
Specifies a tempo change and has a length of 3 bytes. The data is a 3-byte integer,...
Definition: midi.h:243
@ META_GENERIC_TEXT_F
Text: generic f.
Definition: midi.h:229
@ META_DEVICE_NAME
Text: device name.
Definition: midi.h:223
@ META_GENERIC_TEXT_B
Text: generic b.
Definition: midi.h:225
@ META_KEYSIG
Specifies a musical key signature change. It has 2 data bytes: the 1st is a signed char denoting the ...
Definition: midi.h:256
@ META_GENERIC_TEXT_D
Text: generic d.
Definition: midi.h:227
@ META_PROGRAM_NAME
Text: program name.
Definition: midi.h:222
@ META_SEQUENCE_NUMBER
Defines the pattern number of a Type 2 MIDI file or the number of a sequence in a Type 0 or Type 1 MI...
Definition: midi.h:212
@ META_SEQUENCER_SPECIFIC
Used to give informations specific to a hardware or software sequencer. The first Data byte (or three...
Definition: midi.h:260
@ META_GENERIC_TEXT_E
Text: generic e.
Definition: midi.h:228
@ META_TIMESIG
Specifies a musical time signature change. It has 4 data bytes (stored in the sysex object) which den...
Definition: midi.h:252
@ META_LYRIC_TEXT
Text: lyric.
Definition: midi.h:219
@ META_TRACK_NAME
Text: track name.
Definition: midi.h:217
@ META_GENERIC_TEXT_C
Text: generic c.
Definition: midi.h:226
@ META_GENERIC_TEXT_A
Text: generic a.
Definition: midi.h:224
@ META_GENERIC_TEXT
This and the following are used for embedding ascii text in a MIDI file. They have variable data leng...
Definition: midi.h:215
@ C_LSB
add this to a non-switch controller to access the LSB.
Definition: midi.h:136
@ C_RPN_LSB
registered parameter LSB
Definition: midi.h:174
@ C_CELESTE_DEPTH
celeste (detune) depth
Definition: midi.h:166
@ C_BREATH
breath controller
Definition: midi.h:139
@ C_OMNI_ON
omni on, all notes off
Definition: midi.h:182
@ C_BALANCE
balance control
Definition: midi.h:144
@ C_SOSTENUTO
sostenuto switch
Definition: midi.h:154
@ C_GENERAL_7
general purpose controller 7
Definition: midi.h:160
@ C_NRPN_MSB
non registered parameter MSB
Definition: midi.h:173
@ C_GENERAL_2
general purpose controller 2
Definition: midi.h:148
@ C_MONO
mono on, all notes off
Definition: midi.h:183
@ C_ALL_NOTES_OFF
all notes off
Definition: midi.h:180
@ C_SOFT_PEDAL
soft pedal
Definition: midi.h:155
@ C_POLY
poly on, all notes off
Definition: midi.h:184
@ C_RESET
reset all controllers
Definition: midi.h:178
@ C_PHASER_DEPTH
phaser effect depth
Definition: midi.h:167
@ C_DAMPER
hold pedal (sustain)
Definition: midi.h:152
@ C_DATA_INC
increment data value
Definition: midi.h:169
@ C_ALL_SOUND_OFF
all sound off
Definition: midi.h:177
@ C_GM_BANK
General Midi bank select.
Definition: midi.h:137
@ C_MAIN_VOLUME
main volume control
Definition: midi.h:143
@ C_HOLD_2
hold pedal 2
Definition: midi.h:156
@ C_PORTA
portamento switch
Definition: midi.h:153
@ C_DATA_ENTRY
data entry value
Definition: midi.h:142
@ C_GENERAL_8
general purpose controller 8
Definition: midi.h:161
@ C_LOCAL
local control on/off
Definition: midi.h:179
@ C_MODULATION
modulation
Definition: midi.h:138
@ C_GENERAL_1
general purpose controller 1
Definition: midi.h:147
@ C_FOOT
foot controller
Definition: midi.h:140
@ C_PORTA_TIME
portamento time
Definition: midi.h:141
@ C_CHORUS_DEPTH
chorus depth
Definition: midi.h:165
@ C_EFFECT_DEPTH
external effects depth
Definition: midi.h:163
@ C_PAN
panpot stereo control
Definition: midi.h:145
@ C_OMNI_OFF
omni off, all notes off
Definition: midi.h:181
@ C_DATA_DEC
decrement data value
Definition: midi.h:170
@ C_RPN_MSB
registered parameter MSB
Definition: midi.h:175
@ C_GENERAL_6
general purpose controller 6
Definition: midi.h:159
@ C_GENERAL_5
general purpose controller 5
Definition: midi.h:158
@ C_EXPRESSION
expression control
Definition: midi.h:146
@ C_NRPN_LSB
non registered parameter LSB
Definition: midi.h:172
@ C_GENERAL_4
general purpose controller 4
Definition: midi.h:150
@ C_GENERAL_3
general purpose controller 3
Definition: midi.h:149
@ C_TREMELO_DEPTH
tremelo depth
Definition: midi.h:164
@ TUNE_REQUEST
Tune request.
Definition: midi.h:105
@ PROGRAM_CHANGE
Program (patch) change.
Definition: midi.h:98
@ PITCH_BEND
Pitch bend.
Definition: midi.h:100
@ SONG_SELECT
Song Select Pointer.
Definition: midi.h:104
@ META_EVENT
Meta event.
Definition: midi.h:108
@ SONG_POSITION
Song Position pointer.
Definition: midi.h:103
@ RESET
0xff never used as reset in a MIDIMessage
Definition: midi.h:107
@ MTC
MIDI Time Code.
Definition: midi.h:102
@ CONTROL_CHANGE
Control change.
Definition: midi.h:97
@ CHANNEL_PRESSURE
Channel (afertouch) pressure.
Definition: midi.h:99
@ NOTE_ON
Note on.
Definition: midi.h:95
@ NOTE_OFF
Note off.
Definition: midi.h:94
@ SYSEX_START
Start of a sysex.
Definition: midi.h:101
@ POLY_PRESSURE
Polyphonic (aftertouch) pressure.
Definition: midi.h:96
@ SYSEX_END
End of a sysex.
Definition: midi.h:106
@ RPN_COARSE_TUNE
coarse tuning
Definition: midi.h:196
@ RPN_FINE_TUNE
fine tuning
Definition: midi.h:195
@ RPN_BEND_WIDTH
bender sensitivity
Definition: midi.h:194
@ RT_TIMING_CLOCK
MIDI Real time clock.
Definition: midi.h:119
@ RT_START
Sequencer start.
Definition: midi.h:121
@ RT_ACTIVE_SENSE
MIDI Active sensing.
Definition: midi.h:124
@ RT_CONTINUE
Sequencer continue.
Definition: midi.h:122
@ RT_STOP
Sequencer stop.
Definition: midi.h:123
@ RT_MEASURE_END
Proposed measure end byte UNUSED.
Definition: midi.h:120