RemoteVstPlugin: fixed too short arrays for preset names
[lmms.git] / include / midi.h
blob61a9e8ebfa2b2125860907eacc247ac24b4c4ae3
1 /*
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.
25 #ifndef _MIDI_H
26 #define _MIDI_H
28 #include "lmms_basics.h"
29 #include "panning_constants.h"
30 #include <cstdlib>
33 enum MidiEventTypes
35 // messages
36 MidiNoteOff = 0x80,
37 MidiNoteOn = 0x90,
38 MidiKeyPressure = 0xA0,
39 MidiControlChange = 0xB0,
40 MidiProgramChange = 0xC0,
41 MidiChannelPressure = 0xD0,
42 MidiPitchBend = 0xE0,
43 // system exclusive
44 MidiSysEx= 0xF0,
45 // system common - never in midi files
46 MidiTimeCode= 0xF1,
47 MidiSongPosition = 0xF2,
48 MidiSongSelect = 0xF3,
49 MidiTuneRequest = 0xF6,
50 MidiEOX= 0xF7,
51 // system real-time - never in midi files
52 MidiSync = 0xF8,
53 MidiTick = 0xF9,
54 MidiStart = 0xFA,
55 MidiContinue = 0xFB,
56 MidiStop = 0xFC,
57 MidiActiveSensing = 0xFE,
58 MidiSystemReset = 0xFF,
59 // meta event - for midi files only
60 MidiMetaEvent = 0xFF
61 } ;
63 enum MidiMetaEvents
65 MidiMetaInvalid = 0x00,
66 MidiCopyright = 0x02,
67 MidiTrackName = 0x03,
68 MidiInstName = 0x04,
69 MidiLyric = 0x05,
70 MidiMarker = 0x06,
71 MidiCuePoint = 0x07,
72 MidiPortNumber = 0x21,
73 MidiEOT = 0x2f,
74 MidiSetTempo = 0x51,
75 MidiSMPTEOffset = 0x54,
76 MidiTimeSignature = 0x58,
77 MidiKeySignature = 0x59,
78 MidiSequencerEvent = 0x7f,
79 MidiMetaCustom = 0x80,
80 MidiNotePanning
81 } ;
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;
114 struct midiEvent
116 midiEvent( MidiEventTypes _type = MidiActiveSensing,
117 Sint8 _channel = 0,
118 Sint16 _param1 = 0,
119 Sint16 _param2 = 0,
120 const void * _sourcePort = NULL ) :
121 m_type( _type ),
122 m_metaEvent( MidiMetaInvalid ),
123 m_channel( _channel ),
124 m_sysExData( NULL ),
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,
132 int _data_len ) :
133 m_type( _type ),
134 m_metaEvent( MidiMetaInvalid ),
135 m_channel( 0 ),
136 m_sysExData( _sysex_data ),
137 m_sourcePort( NULL )
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
154 return m_type;
157 inline int channel() const
159 return m_channel;
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
204 return m_sourcePort;
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
219 union
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
224 } m_data;
226 const char * m_sysExData;
227 const void * m_sourcePort;
232 #endif