LMMS
Loading...
Searching...
No Matches
MidiEvent.h
Go to the documentation of this file.
1/*
2 * MidiEvent.h - MidiEvent class
3 *
4 * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
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.
12 *
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.
17 *
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.
22 *
23 */
24
25#ifndef LMMS_MIDI_EVENT_H
26#define LMMS_MIDI_EVENT_H
27
28#include <cstdlib>
29#include "Midi.h"
30#include "panning.h"
31#include "volume.h"
32
33namespace lmms
34{
35
37{
38public:
39 enum class Source { Internal, External };
40
42 int8_t channel = 0,
43 int16_t param1 = 0,
44 int16_t param2 = 0,
45 const void* sourcePort = nullptr,
47 m_type( type ),
53 {
54 m_data.m_param[0] = param1;
55 m_data.m_param[1] = param2;
56 }
57
58 MidiEvent(MidiEventTypes type, const char* sysExData, std::size_t dataLen, Source source = Source::External) :
59 m_type( type ),
61 m_channel( 0 ),
65 {
66 m_data.m_sysExDataLen = dataLen;
67 }
68
69 MidiEvent( const MidiEvent& other ) = default;
70
72 {
73 return m_type;
74 }
75
77 {
78 m_type = type;
79 }
80
85
87 {
88 return m_metaEvent;
89 }
90
92 {
93 return m_channel;
94 }
95
97 {
99 }
100
101 int16_t param( int i ) const
102 {
103 return m_data.m_param[i];
104 }
105
107 {
108 m_data.m_param[i] = value;
109 }
110
111 int16_t key() const
112 {
113 return param( 0 );
114 }
115
117 {
118 m_data.m_param[0] = key;
119 }
120
122 {
123 return m_data.m_param[1] & 0x7F;
124 }
125
127 {
128 m_data.m_param[1] = velocity;
129 }
130
132 {
133 return (panning_t) ( PanningLeft +
134 ( (float)( midiPanning() - MidiMinPanning ) ) /
135 ( (float)( MidiMaxPanning - MidiMinPanning ) ) *
136 ( (float)( PanningRight - PanningLeft ) ) );
137 }
139 {
140 return m_data.m_param[1];
141 }
142
143 volume_t volume( int midiBaseVelocity ) const
144 {
145 return (volume_t)( velocity() * DefaultVolume / midiBaseVelocity );
146 }
147
148 const void* sourcePort() const
149 {
150 return m_sourcePort;
151 }
152
154 {
155 return param( 0 ) & 0x7F;
156 }
157
159 {
160 setParam( 0, num );
161 }
162
164 {
165 return param( 1 );
166 }
167
169 {
170 setParam( 1, value );
171 }
172
174 {
175 return param( 0 );
176 }
177
179 {
180 return param( 0 );
181 }
182
184 {
185 return param( 0 );
186 }
187
189 {
190 setParam( 0, pitchBend );
191 }
192
193 auto sysExData() const -> const char* { return m_sysExData; }
194
196 {
197 return m_source;
198 }
199
201 {
202 m_source = value;
203 }
204
205
206private:
207 MidiEventTypes m_type; // MIDI event type
208 MidiMetaEventType m_metaEvent; // Meta event (mostly unused)
209 int8_t m_channel; // MIDI channel
210 union
211 {
212 int16_t m_param[2]; // first/second parameter (key/velocity)
213 uint8_t m_bytes[4]; // raw bytes
214 int32_t m_sysExDataLen; // len of m_sysExData
216
217 const char* m_sysExData;
218 const void* m_sourcePort;
219
220 // Stores the source of the MidiEvent: Internal or External (hardware controllers).
222} ;
223
224} // namespace lmms
225
226#endif // LMMS_MIDI_EVENT_H
#define nullptr
Definition DistrhoDefines.h:75
void setVelocity(int16_t velocity)
Definition MidiEvent.h:126
const void * sourcePort() const
Definition MidiEvent.h:148
int16_t param(int i) const
Definition MidiEvent.h:101
void setType(MidiEventTypes type)
Definition MidiEvent.h:76
int8_t channel() const
Definition MidiEvent.h:91
int16_t pitchBend() const
Definition MidiEvent.h:183
void setKey(int16_t key)
Definition MidiEvent.h:116
MidiEvent(MidiEventTypes type=MidiActiveSensing, int8_t channel=0, int16_t param1=0, int16_t param2=0, const void *sourcePort=nullptr, Source source=Source::External)
Definition MidiEvent.h:41
union lmms::MidiEvent::@277273065242267074241165130210163232060000333267 m_data
void setChannel(int8_t channel)
Definition MidiEvent.h:96
uint8_t controllerNumber() const
Definition MidiEvent.h:153
uint8_t controllerValue() const
Definition MidiEvent.h:163
auto sysExData() const -> const char *
Definition MidiEvent.h:193
void setParam(int i, uint16_t value)
Definition MidiEvent.h:106
int16_t m_param[2]
Definition MidiEvent.h:212
const void * m_sourcePort
Definition MidiEvent.h:218
MidiMetaEventType m_metaEvent
Definition MidiEvent.h:208
int16_t key() const
Definition MidiEvent.h:111
Source m_source
Definition MidiEvent.h:221
int8_t m_channel
Definition MidiEvent.h:209
panning_t panning() const
Definition MidiEvent.h:131
uint8_t channelPressure() const
Definition MidiEvent.h:178
MidiEvent(MidiEventTypes type, const char *sysExData, std::size_t dataLen, Source source=Source::External)
Definition MidiEvent.h:58
MidiEventTypes type() const
Definition MidiEvent.h:71
void setControllerNumber(uint8_t num)
Definition MidiEvent.h:158
Source source() const
Definition MidiEvent.h:195
MidiEventTypes m_type
Definition MidiEvent.h:207
void setPitchBend(uint16_t pitchBend)
Definition MidiEvent.h:188
void setControllerValue(uint8_t value)
Definition MidiEvent.h:168
Source
Definition MidiEvent.h:39
@ Internal
Definition MidiEvent.h:39
@ External
Definition MidiEvent.h:39
MidiMetaEventType metaEvent() const
Definition MidiEvent.h:86
const char * m_sysExData
Definition MidiEvent.h:217
void setSource(Source value)
Definition MidiEvent.h:200
uint8_t velocity() const
Definition MidiEvent.h:121
int16_t midiPanning() const
Definition MidiEvent.h:138
volume_t volume(int midiBaseVelocity) const
Definition MidiEvent.h:143
void setMetaEvent(MidiMetaEventType metaEvent)
Definition MidiEvent.h:81
uint8_t program() const
Definition MidiEvent.h:173
MidiEvent(const MidiEvent &other)=default
int32_t m_sysExDataLen
Definition MidiEvent.h:214
uint8_t m_bytes[4]
Definition MidiEvent.h:213
register unsigned i
Definition inflate.c:1575
static PuglViewHint int value
Definition pugl.h:1708
unsigned short uint16_t
Definition mid.cpp:99
int int32_t
Definition mid.cpp:97
short int16_t
Definition mid.cpp:96
unsigned char uint8_t
Definition mid.cpp:98
signed char int8_t
Definition mid.cpp:95
Definition AudioAlsa.cpp:35
constexpr volume_t DefaultVolume
Definition volume.h:37
@ MidiMetaInvalid
Definition Midi.h:65
constexpr panning_t PanningLeft
Definition panning.h:39
const int MidiMaxPanning
Definition Midi.h:135
const int MidiMinPanning
Definition Midi.h:136
std::int8_t panning_t
Definition LmmsTypes.h:37
constexpr panning_t PanningRight
Definition panning.h:38
MidiEventTypes
Definition Midi.h:34
@ MidiActiveSensing
Definition Midi.h:57
std::uint8_t volume_t
Definition LmmsTypes.h:36
MidiMetaEventTypes MidiMetaEventType
Definition Midi.h:82
#define const
Definition zconf.h:137