2 * midi.h - constants, structs etc. concerning MIDI
4 * Copyright (c) 2005-2012 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
28 #include "lmms_basics.h"
29 #include "panning_constants.h"
38 MidiKeyPressure
= 0xA0,
39 MidiControlChange
= 0xB0,
40 MidiProgramChange
= 0xC0,
41 MidiChannelPressure
= 0xD0,
45 // system common - never in midi files
47 MidiSongPosition
= 0xF2,
48 MidiSongSelect
= 0xF3,
49 MidiTuneRequest
= 0xF6,
51 // system real-time - never in midi files
57 MidiActiveSensing
= 0xFE,
58 MidiSystemReset
= 0xFF,
59 // meta event - for midi files only
65 MidiMetaInvalid
= 0x00,
72 MidiPortNumber
= 0x21,
75 MidiSMPTEOffset
= 0x54,
76 MidiTimeSignature
= 0x58,
77 MidiKeySignature
= 0x59,
78 MidiSequencerEvent
= 0x7f,
79 MidiMetaCustom
= 0x80,
84 enum MidiStandardControllers
86 MidiControllerBankSelect
= 0,
87 MidiControllerModulationWheel
= 1,
88 MidiControllerBreathController
= 2,
89 MidiControllerFootController
= 4,
90 MidiControllerPortamentoTime
= 5,
91 MidiControllerMainVolume
= 7,
92 MidiControllerBalance
= 8,
93 MidiControllerPan
= 10,
94 MidiControllerEffectControl1
= 12,
95 MidiControllerEffectControl2
= 13,
96 MidiControllerSustain
= 64,
97 MidiControllerPortamento
= 65,
98 MidiControllerSostenuto
= 66,
99 MidiControllerSoftPedal
= 67,
100 MidiControllerLegatoFootswitch
= 68,
103 const int MidiChannelCount
= 16;
104 const int MidiControllerCount
= 128;
105 const int MidiProgramCount
= 128;
106 const int MidiMaxVelocity
= 127;
107 const int MidiMaxControllerValue
= 127;
108 const int MidiMaxNote
= 127;
110 const int MidiMaxPanning
= 127;
111 const int MidiMinPanning
= -128;
116 midiEvent( MidiEventTypes _type
= MidiActiveSensing
,
120 const void * _sourcePort
= NULL
) :
122 m_metaEvent( MidiMetaInvalid
),
123 m_channel( _channel
),
125 m_sourcePort( _sourcePort
)
127 m_data
.m_param
[0] = _param1
;
128 m_data
.m_param
[1] = _param2
;
131 midiEvent( MidiEventTypes _type
, const char * _sysex_data
,
134 m_metaEvent( MidiMetaInvalid
),
136 m_sysExData( _sysex_data
),
139 m_data
.m_sysExDataLen
= _data_len
;
142 midiEvent( const midiEvent
& _copy
) :
143 m_type( _copy
.m_type
),
144 m_metaEvent( _copy
.m_metaEvent
),
145 m_channel( _copy
.m_channel
),
146 m_data( _copy
.m_data
),
147 m_sysExData( _copy
.m_sysExData
),
148 m_sourcePort( _copy
.m_sourcePort
)
152 inline MidiEventTypes
type() const
157 inline int channel() const
162 inline Sint16
key() const
164 return m_data
.m_param
[0];
167 inline Sint16
& key()
169 return m_data
.m_param
[0];
172 inline uint8_t controllerNumber() const
174 return m_data
.m_param
[0];
177 inline uint8_t controllerValue() const
179 return m_data
.m_param
[1];
182 inline Sint16
velocity() const
184 return m_data
.m_param
[1];
187 inline Sint16
& velocity()
189 return m_data
.m_param
[1];
192 inline Sint16
midiPanning() const
194 return m_data
.m_param
[1];
197 inline volume_t
getVolume() const
199 return (volume_t
)( velocity() * 100 / MidiMaxVelocity
);
202 inline const void * sourcePort() const
207 inline panning_t
getPanning() const
209 return (panning_t
) ( PanningLeft
+
210 ( (float)( midiPanning() - MidiMinPanning
) ) /
211 ( (float)( MidiMaxPanning
- MidiMinPanning
) ) *
212 ( (float)( PanningRight
- PanningLeft
) ) );
216 MidiEventTypes m_type
; // MIDI event type
217 MidiMetaEvents m_metaEvent
; // Meta event (mostly unused)
218 Sint8 m_channel
; // MIDI channel
221 Sint16 m_param
[2]; // first/second parameter (key/velocity)
222 Uint8 m_bytes
[4]; // raw bytes
223 Sint32 m_sysExDataLen
; // len of m_sysExData
226 const char * m_sysExData
;
227 const void * m_sourcePort
;