/[svn]/linuxsampler/trunk/src/engines/EngineChannel.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/EngineChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1424 - (show annotations) (download)
Sun Oct 14 22:00:17 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 8730 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 * *
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 #include <algorithm>
27
28 #include "../common/global_private.h"
29 #include "../drivers/midi/MidiInstrumentMapper.h"
30
31 #define NO_MIDI_INSTRUMENT_MAP -1
32 #define DEFAULT_MIDI_INSTRUMENT_MAP -2
33
34 namespace LinuxSampler {
35
36 EngineChannel::EngineChannel() {
37 iMute = 0;
38 bSolo = false;
39 uiMidiBankMsb = 0;
40 uiMidiBankLsb = 0;
41 uiMidiProgram = 0;
42 bProgramChangeReceived = bMidiBankMsbReceived = bMidiBankLsbReceived = false;
43 iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP;
44 uiVoiceCount = 0;
45 uiDiskStreamCount = 0;
46 ResetMidiRpnController();
47 }
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 /*
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 uint8_t EngineChannel::GetMidiProgram() {
92 return uiMidiProgram; // AFAIK atomic on all systems
93 }
94
95 void EngineChannel::SetMidiProgram(uint8_t Program) {
96 bProgramChangeReceived = true;
97 uiMidiProgram = Program; // AFAIK atomic on all systems
98 }
99
100 uint8_t EngineChannel::GetMidiBankMsb() {
101 return (bMidiBankMsbReceived && bMidiBankLsbReceived) ? uiMidiBankMsb : 0;
102 }
103
104 void EngineChannel::SetMidiBankMsb(uint8_t BankMSB) {
105 if (bProgramChangeReceived)
106 bProgramChangeReceived = bMidiBankLsbReceived = false;
107 bMidiBankMsbReceived = true;
108 uiMidiBankMsb = BankMSB; // AFAIK atomic on all systems
109 }
110
111 uint8_t EngineChannel::GetMidiBankLsb() {
112 return (!bMidiBankMsbReceived && !bMidiBankLsbReceived)
113 ? 0
114 : (bMidiBankMsbReceived && !bMidiBankLsbReceived)
115 ? uiMidiBankMsb
116 : uiMidiBankLsb;
117 }
118
119 void EngineChannel::SetMidiBankLsb(uint8_t BankLSB) {
120 if (bProgramChangeReceived)
121 bProgramChangeReceived = bMidiBankMsbReceived = false;
122 bMidiBankLsbReceived = true;
123 uiMidiBankLsb = BankLSB; // AFAIK atomic on all systems
124 }
125
126 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 if (iMidiInstrumentMap == NO_MIDI_INSTRUMENT_MAP) return;
151 iMidiInstrumentMap = NO_MIDI_INSTRUMENT_MAP;
152 StatusChanged(true);
153 }
154
155 void EngineChannel::SetMidiInstrumentMapToDefault() {
156 if (iMidiInstrumentMap == DEFAULT_MIDI_INSTRUMENT_MAP) return;
157 iMidiInstrumentMap = DEFAULT_MIDI_INSTRUMENT_MAP;
158 StatusChanged(true);
159 }
160
161 void EngineChannel::SetMidiInstrumentMap(int MidiMap) throw (Exception) {
162 if (iMidiInstrumentMap == MidiMap) return;
163
164 // 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 StatusChanged(true);
170 }
171
172 void EngineChannel::SetMidiRpnControllerMsb(uint8_t CtrlMSB) {
173 uiMidiRpnMsb = CtrlMSB;
174 bMidiRpnReceived = true;
175 }
176
177 void EngineChannel::SetMidiRpnControllerLsb(uint8_t CtrlLSB) {
178 uiMidiRpnLsb = CtrlLSB;
179 bMidiRpnReceived = true;
180 }
181
182 void EngineChannel::ResetMidiRpnController() {
183 uiMidiRpnMsb = uiMidiRpnLsb = 0;
184 bMidiRpnReceived = false;
185 }
186
187 int EngineChannel::GetMidiRpnController() {
188 return (bMidiRpnReceived) ? (uiMidiRpnMsb << 8) | uiMidiRpnLsb : -1;
189 }
190
191 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 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 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC