1 |
schoenebeck |
888 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
1041 |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
schoenebeck |
888 |
* * |
8 |
|
|
* This program is free software; you can redistribute it and/or modify * |
9 |
|
|
* it under the terms of the GNU General Public License as published by * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (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 * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
|
|
* along with this program; if not, write to the Free Software * |
20 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#include "EngineChannel.h" |
25 |
|
|
|
26 |
schoenebeck |
973 |
#include <algorithm> |
27 |
|
|
|
28 |
schoenebeck |
1424 |
#include "../common/global_private.h" |
29 |
schoenebeck |
973 |
#include "../drivers/midi/MidiInstrumentMapper.h" |
30 |
|
|
|
31 |
|
|
#define NO_MIDI_INSTRUMENT_MAP -1 |
32 |
|
|
#define DEFAULT_MIDI_INSTRUMENT_MAP -2 |
33 |
|
|
|
34 |
schoenebeck |
888 |
namespace LinuxSampler { |
35 |
|
|
|
36 |
|
|
EngineChannel::EngineChannel() { |
37 |
|
|
iMute = 0; |
38 |
|
|
bSolo = false; |
39 |
schoenebeck |
947 |
uiMidiBankMsb = 0; |
40 |
|
|
uiMidiBankLsb = 0; |
41 |
|
|
uiMidiProgram = 0; |
42 |
schoenebeck |
973 |
bProgramChangeReceived = bMidiBankMsbReceived = bMidiBankLsbReceived = false; |
43 |
|
|
iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP; |
44 |
iliev |
1297 |
uiVoiceCount = 0; |
45 |
|
|
uiDiskStreamCount = 0; |
46 |
schoenebeck |
1044 |
ResetMidiRpnController(); |
47 |
schoenebeck |
888 |
} |
48 |
|
|
|
49 |
|
|
void EngineChannel::SetMute(int state) throw (Exception) { |
50 |
|
|
if(iMute == state) return; |
51 |
|
|
if(state < -1 || state > 1) |
52 |
|
|
throw Exception("Invalid Mute state: " + ToString(state)); |
53 |
|
|
|
54 |
|
|
iMute = state; |
55 |
|
|
|
56 |
|
|
StatusChanged(true); |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
int EngineChannel::GetMute() { |
60 |
|
|
return iMute; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
void EngineChannel::SetSolo(bool solo) { |
64 |
|
|
if(bSolo == solo) return; |
65 |
|
|
bSolo = solo; |
66 |
|
|
StatusChanged(true); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
bool EngineChannel::GetSolo() { |
70 |
|
|
return bSolo; |
71 |
|
|
} |
72 |
|
|
|
73 |
schoenebeck |
973 |
/* |
74 |
|
|
We use a workaround for MIDI devices (i.e. old keyboards) which either |
75 |
|
|
only send bank select MSB or only bank select LSB messages. Bank |
76 |
|
|
selects will be modified according to the following table: |
77 |
|
|
|
78 |
|
|
MIDI Sequence received: -> GetMidiBankMsb()= | GetMidiBankLsb()= |
79 |
|
|
--------------------------------------------------------------------------- |
80 |
|
|
program change -> 0 | 0 |
81 |
|
|
bank LSB, program change -> 0 | LSB value |
82 |
|
|
bank MSB, program change -> 0 | MSB value |
83 |
|
|
bank LSB, bank MSB, program change -> MSB value | LSB value |
84 |
|
|
bank MSB, bank LSB, program change -> MSB value | LSB value |
85 |
|
|
--------------------------------------------------------------------------- |
86 |
|
|
|
87 |
|
|
That way we ensure those limited devices always to switch between the |
88 |
|
|
following set of MIDI instrument banks: { 0, 1, 2, ..., 127 } |
89 |
|
|
*/ |
90 |
|
|
|
91 |
schoenebeck |
947 |
uint8_t EngineChannel::GetMidiProgram() { |
92 |
|
|
return uiMidiProgram; // AFAIK atomic on all systems |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
void EngineChannel::SetMidiProgram(uint8_t Program) { |
96 |
schoenebeck |
973 |
bProgramChangeReceived = true; |
97 |
schoenebeck |
947 |
uiMidiProgram = Program; // AFAIK atomic on all systems |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
uint8_t EngineChannel::GetMidiBankMsb() { |
101 |
schoenebeck |
973 |
return (bMidiBankMsbReceived && bMidiBankLsbReceived) ? uiMidiBankMsb : 0; |
102 |
schoenebeck |
947 |
} |
103 |
|
|
|
104 |
|
|
void EngineChannel::SetMidiBankMsb(uint8_t BankMSB) { |
105 |
schoenebeck |
973 |
if (bProgramChangeReceived) |
106 |
|
|
bProgramChangeReceived = bMidiBankLsbReceived = false; |
107 |
|
|
bMidiBankMsbReceived = true; |
108 |
schoenebeck |
947 |
uiMidiBankMsb = BankMSB; // AFAIK atomic on all systems |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
uint8_t EngineChannel::GetMidiBankLsb() { |
112 |
schoenebeck |
973 |
return (!bMidiBankMsbReceived && !bMidiBankLsbReceived) |
113 |
|
|
? 0 |
114 |
|
|
: (bMidiBankMsbReceived && !bMidiBankLsbReceived) |
115 |
|
|
? uiMidiBankMsb |
116 |
|
|
: uiMidiBankLsb; |
117 |
schoenebeck |
947 |
} |
118 |
|
|
|
119 |
|
|
void EngineChannel::SetMidiBankLsb(uint8_t BankLSB) { |
120 |
schoenebeck |
973 |
if (bProgramChangeReceived) |
121 |
|
|
bProgramChangeReceived = bMidiBankMsbReceived = false; |
122 |
|
|
bMidiBankLsbReceived = true; |
123 |
schoenebeck |
947 |
uiMidiBankLsb = BankLSB; // AFAIK atomic on all systems |
124 |
|
|
} |
125 |
|
|
|
126 |
schoenebeck |
973 |
bool EngineChannel::UsesNoMidiInstrumentMap() { |
127 |
|
|
return (iMidiInstrumentMap == NO_MIDI_INSTRUMENT_MAP); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
bool EngineChannel::UsesDefaultMidiInstrumentMap() { |
131 |
|
|
return (iMidiInstrumentMap == DEFAULT_MIDI_INSTRUMENT_MAP); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
int EngineChannel::GetMidiInstrumentMap() throw (Exception) { |
135 |
|
|
if (UsesNoMidiInstrumentMap()) |
136 |
|
|
throw Exception("EngineChannel is using no MIDI instrument map"); |
137 |
|
|
if (UsesDefaultMidiInstrumentMap()) |
138 |
|
|
throw Exception("EngineChannel is using default MIDI instrument map"); |
139 |
|
|
// check if the stored map still exists in the MIDI instrument mapper |
140 |
|
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
141 |
|
|
if (find(maps.begin(), maps.end(), iMidiInstrumentMap) == maps.end()) { |
142 |
|
|
// it doesn't exist anymore, so fall back to NONE and throw an exception |
143 |
|
|
iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP; |
144 |
|
|
throw Exception("Assigned MIDI instrument map doesn't exist anymore, falling back to NONE"); |
145 |
|
|
} |
146 |
|
|
return iMidiInstrumentMap; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
void EngineChannel::SetMidiInstrumentMapToNone() { |
150 |
iliev |
1254 |
if (iMidiInstrumentMap == NO_MIDI_INSTRUMENT_MAP) return; |
151 |
schoenebeck |
973 |
iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP; |
152 |
iliev |
1254 |
StatusChanged(true); |
153 |
schoenebeck |
973 |
} |
154 |
|
|
|
155 |
|
|
void EngineChannel::SetMidiInstrumentMapToDefault() { |
156 |
iliev |
1254 |
if (iMidiInstrumentMap == DEFAULT_MIDI_INSTRUMENT_MAP) return; |
157 |
schoenebeck |
973 |
iMidiInstrumentMap = DEFAULT_MIDI_INSTRUMENT_MAP; |
158 |
iliev |
1254 |
StatusChanged(true); |
159 |
schoenebeck |
973 |
} |
160 |
|
|
|
161 |
|
|
void EngineChannel::SetMidiInstrumentMap(int MidiMap) throw (Exception) { |
162 |
iliev |
1254 |
if (iMidiInstrumentMap == MidiMap) return; |
163 |
|
|
|
164 |
schoenebeck |
973 |
// check if given map actually exists in the MIDI instrument mapper |
165 |
|
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
166 |
|
|
if (find(maps.begin(), maps.end(), MidiMap) == maps.end()) |
167 |
|
|
throw Exception("MIDI instrument map doesn't exist"); |
168 |
|
|
iMidiInstrumentMap = MidiMap; // assign the new map ID |
169 |
iliev |
1254 |
StatusChanged(true); |
170 |
schoenebeck |
973 |
} |
171 |
|
|
|
172 |
schoenebeck |
1041 |
void EngineChannel::SetMidiRpnControllerMsb(uint8_t CtrlMSB) { |
173 |
|
|
uiMidiRpnMsb = CtrlMSB; |
174 |
schoenebeck |
1044 |
bMidiRpnReceived = true; |
175 |
schoenebeck |
1041 |
} |
176 |
|
|
|
177 |
|
|
void EngineChannel::SetMidiRpnControllerLsb(uint8_t CtrlLSB) { |
178 |
|
|
uiMidiRpnLsb = CtrlLSB; |
179 |
schoenebeck |
1044 |
bMidiRpnReceived = true; |
180 |
schoenebeck |
1041 |
} |
181 |
|
|
|
182 |
schoenebeck |
1044 |
void EngineChannel::ResetMidiRpnController() { |
183 |
|
|
uiMidiRpnMsb = uiMidiRpnLsb = 0; |
184 |
|
|
bMidiRpnReceived = false; |
185 |
|
|
} |
186 |
|
|
|
187 |
schoenebeck |
1041 |
int EngineChannel::GetMidiRpnController() { |
188 |
schoenebeck |
1044 |
return (bMidiRpnReceived) ? (uiMidiRpnMsb << 8) | uiMidiRpnLsb : -1; |
189 |
schoenebeck |
1041 |
} |
190 |
|
|
|
191 |
iliev |
1297 |
uint EngineChannel::GetVoiceCount() { |
192 |
|
|
return uiVoiceCount; |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
void EngineChannel::SetVoiceCount(uint Voices) { |
196 |
|
|
uiVoiceCount = Voices; |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
uint EngineChannel::GetDiskStreamCount() { |
200 |
|
|
return uiDiskStreamCount; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
void EngineChannel::SetDiskStreamCount(uint Streams) { |
204 |
|
|
uiDiskStreamCount = Streams; |
205 |
|
|
} |
206 |
|
|
|
207 |
iliev |
1130 |
void EngineChannel::AddFxSendCountListener(FxSendCountListener* l) { |
208 |
|
|
llFxSendCountListeners.AddListener(l); |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
void EngineChannel::RemoveFxSendCountListener(FxSendCountListener* l) { |
212 |
|
|
llFxSendCountListeners.RemoveListener(l); |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
void EngineChannel::RemoveAllFxSendCountListeners() { |
216 |
|
|
llFxSendCountListeners.RemoveAllListeners(); |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
void EngineChannel::fireFxSendCountChanged(int ChannelId, int NewCount) { |
220 |
|
|
for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) { |
221 |
|
|
llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount); |
222 |
|
|
} |
223 |
|
|
} |
224 |
|
|
|
225 |
schoenebeck |
888 |
} // namespace LinuxSampler |