1 |
// qsamplerChannel.cpp |
2 |
// |
3 |
/**************************************************************************** |
4 |
Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
6 |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
8 |
as published by the Free Software Foundation; either version 2 |
9 |
of the License, or (at your option) any later version. |
10 |
|
11 |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
15 |
|
16 |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
20 |
*****************************************************************************/ |
21 |
|
22 |
#include "qsamplerChannel.h" |
23 |
|
24 |
#include "qsamplerMainForm.h" |
25 |
|
26 |
#include "config.h" |
27 |
|
28 |
|
29 |
//------------------------------------------------------------------------- |
30 |
// qsamplerChannel - Sampler channel structure. |
31 |
// |
32 |
|
33 |
// Constructor. |
34 |
qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID ) |
35 |
{ |
36 |
m_pMainForm = pMainForm; |
37 |
m_iChannelID = iChannelID; |
38 |
|
39 |
// m_sEngineName = QObject::tr("(No engine)"); |
40 |
// m_sInstrumentFile = QObject::tr("(No instrument)"); |
41 |
m_iInstrumentNr = -1; |
42 |
m_iInstrumentStatus = -1; |
43 |
m_sMidiDriver = "Alsa"; // DEPRECATED. |
44 |
m_iMidiDevice = -1; |
45 |
m_iMidiPort = -1; |
46 |
m_iMidiChannel = -1; |
47 |
m_sAudioDriver = "Alsa"; // DEPRECATED. |
48 |
m_iAudioDevice = -1; |
49 |
m_fVolume = 0.0; |
50 |
|
51 |
} |
52 |
|
53 |
// Default destructor. |
54 |
qsamplerChannel::~qsamplerChannel (void) |
55 |
{ |
56 |
} |
57 |
|
58 |
|
59 |
// The global options settings delegated property. |
60 |
qsamplerOptions *qsamplerChannel::options (void) |
61 |
{ |
62 |
if (m_pMainForm == NULL) |
63 |
return NULL; |
64 |
|
65 |
return m_pMainForm->options(); |
66 |
} |
67 |
|
68 |
|
69 |
// The client descriptor delegated property. |
70 |
lscp_client_t *qsamplerChannel::client (void) |
71 |
{ |
72 |
if (m_pMainForm == NULL) |
73 |
return NULL; |
74 |
|
75 |
return m_pMainForm->client(); |
76 |
} |
77 |
|
78 |
|
79 |
// Channel-ID (aka Sammpler-Channel) accessors. |
80 |
int qsamplerChannel::channelID (void) |
81 |
{ |
82 |
return m_iChannelID; |
83 |
} |
84 |
|
85 |
void qsamplerChannel::setChannelID ( int iChannelID ) |
86 |
{ |
87 |
m_iChannelID = iChannelID; |
88 |
|
89 |
updateChannelInfo(); |
90 |
} |
91 |
|
92 |
|
93 |
// Engine name accessors. |
94 |
QString& qsamplerChannel::engineName (void) |
95 |
{ |
96 |
return m_sEngineName; |
97 |
} |
98 |
|
99 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
100 |
{ |
101 |
if (client() == NULL) |
102 |
return false; |
103 |
|
104 |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
105 |
appendMessagesClient("lscp_load_engine"); |
106 |
return false; |
107 |
} |
108 |
|
109 |
m_sEngineName = sEngineName; |
110 |
return true; |
111 |
} |
112 |
|
113 |
|
114 |
// Instrument filename accessor. |
115 |
QString& qsamplerChannel::instrumentFile (void) |
116 |
{ |
117 |
return m_sInstrumentFile; |
118 |
} |
119 |
|
120 |
// Instrument index accessor. |
121 |
int qsamplerChannel::instrumentNr (void) |
122 |
{ |
123 |
return m_iInstrumentNr; |
124 |
} |
125 |
|
126 |
// Instrument status accessor. |
127 |
int qsamplerChannel::instrumentStatus (void) |
128 |
{ |
129 |
return m_iInstrumentStatus; |
130 |
} |
131 |
|
132 |
// Instrument file loader. |
133 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
134 |
{ |
135 |
if (client() == NULL) |
136 |
return false; |
137 |
|
138 |
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
139 |
appendMessagesClient("lscp_load_instrument"); |
140 |
return false; |
141 |
} |
142 |
|
143 |
m_sInstrumentFile = sInstrumentFile; |
144 |
m_iInstrumentNr = iInstrumentNr; |
145 |
m_iInstrumentStatus = 0; |
146 |
|
147 |
return true; |
148 |
} |
149 |
|
150 |
|
151 |
// MIDI driver type accessors (DEPRECATED). |
152 |
QString& qsamplerChannel::midiDriver (void) |
153 |
{ |
154 |
return m_sMidiDriver; |
155 |
} |
156 |
|
157 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
158 |
{ |
159 |
if (client() == NULL) |
160 |
return false; |
161 |
|
162 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
163 |
appendMessagesClient("lscp_set_channel_midi_type"); |
164 |
return false; |
165 |
} |
166 |
|
167 |
m_sMidiDriver = sMidiDriver; |
168 |
return true; |
169 |
} |
170 |
|
171 |
|
172 |
// MIDI device accessors. |
173 |
int qsamplerChannel::midiDevice (void) |
174 |
{ |
175 |
return m_iMidiDevice; |
176 |
} |
177 |
|
178 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
179 |
{ |
180 |
if (client() == NULL) |
181 |
return false; |
182 |
|
183 |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
184 |
appendMessagesClient("lscp_set_channel_midi_device"); |
185 |
return false; |
186 |
} |
187 |
|
188 |
m_iMidiDevice = iMidiDevice; |
189 |
return true; |
190 |
} |
191 |
|
192 |
|
193 |
// MIDI port number accessor. |
194 |
int qsamplerChannel::midiPort (void) |
195 |
{ |
196 |
return m_iMidiPort; |
197 |
} |
198 |
|
199 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
200 |
{ |
201 |
if (client() == NULL) |
202 |
return false; |
203 |
|
204 |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
205 |
appendMessagesClient("lscp_set_channel_midi_port"); |
206 |
return false; |
207 |
} |
208 |
|
209 |
m_iMidiPort = iMidiPort; |
210 |
return true; |
211 |
} |
212 |
|
213 |
|
214 |
// MIDI channel accessor. |
215 |
int qsamplerChannel::midiChannel (void) |
216 |
{ |
217 |
return m_iMidiChannel; |
218 |
} |
219 |
|
220 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
221 |
{ |
222 |
if (client() == NULL) |
223 |
return false; |
224 |
|
225 |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
226 |
appendMessagesClient("lscp_set_channel_midi_channel"); |
227 |
return false; |
228 |
} |
229 |
|
230 |
m_iMidiChannel = iMidiChannel; |
231 |
return true; |
232 |
} |
233 |
|
234 |
|
235 |
// Audio device accessor. |
236 |
int qsamplerChannel::audioDevice (void) |
237 |
{ |
238 |
return m_iAudioDevice; |
239 |
} |
240 |
|
241 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
242 |
{ |
243 |
if (client() == NULL) |
244 |
return false; |
245 |
|
246 |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
247 |
appendMessagesClient("lscp_set_channel_audio_device"); |
248 |
return false; |
249 |
} |
250 |
|
251 |
m_iAudioDevice = iAudioDevice; |
252 |
return true; |
253 |
} |
254 |
|
255 |
|
256 |
// Audio driver type accessors (DEPRECATED). |
257 |
QString& qsamplerChannel::audioDriver (void) |
258 |
{ |
259 |
return m_sAudioDriver; |
260 |
} |
261 |
|
262 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
263 |
{ |
264 |
if (client() == NULL) |
265 |
return false; |
266 |
|
267 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
268 |
appendMessagesClient("lscp_set_channel_audio_type"); |
269 |
return false; |
270 |
} |
271 |
|
272 |
m_sAudioDriver = sAudioDriver; |
273 |
return true; |
274 |
} |
275 |
|
276 |
|
277 |
// Channel volume accessors. |
278 |
float qsamplerChannel::volume (void) |
279 |
{ |
280 |
return m_fVolume; |
281 |
} |
282 |
|
283 |
bool qsamplerChannel::setVolume ( float fVolume ) |
284 |
{ |
285 |
if (client() == NULL) |
286 |
return false; |
287 |
|
288 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
289 |
appendMessagesClient("lscp_set_channel_volume"); |
290 |
return false; |
291 |
} |
292 |
|
293 |
m_fVolume = fVolume; |
294 |
return true; |
295 |
} |
296 |
|
297 |
|
298 |
// Update whole channel info state. |
299 |
void qsamplerChannel::updateChannelInfo (void) |
300 |
{ |
301 |
// Check if we're up and connected. |
302 |
if (client() == NULL) |
303 |
return; |
304 |
|
305 |
// Read channel information. |
306 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
307 |
if (pChannelInfo == NULL) { |
308 |
appendMessagesClient("lscp_get_channel_info"); |
309 |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
310 |
} else { |
311 |
// Cache in channel information. |
312 |
m_sEngineName = pChannelInfo->engine_name; |
313 |
m_sInstrumentFile = pChannelInfo->instrument_file; |
314 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
315 |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
316 |
m_iMidiDevice = pChannelInfo->midi_device; |
317 |
m_iMidiPort = pChannelInfo->midi_port; |
318 |
m_iMidiChannel = pChannelInfo->midi_channel; |
319 |
m_iAudioDevice = pChannelInfo->audio_device; |
320 |
m_fVolume = pChannelInfo->volume; |
321 |
// Some sanity checks. |
322 |
if (m_sEngineName == "NONE") |
323 |
m_sEngineName = QString::null; |
324 |
if (m_sInstrumentFile == "NONE") |
325 |
m_sInstrumentFile = QString::null; |
326 |
} |
327 |
} |
328 |
|
329 |
|
330 |
// Reset channel method. |
331 |
void qsamplerChannel::resetChannel (void) |
332 |
{ |
333 |
// Check if we're up and connected. |
334 |
if (client() == NULL) |
335 |
return; |
336 |
|
337 |
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) |
338 |
appendMessagesClient("lscp_reset_channel"); |
339 |
else |
340 |
appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID)); |
341 |
} |
342 |
|
343 |
|
344 |
// Redirected messages output methods. |
345 |
void qsamplerChannel::appendMessages( const QString& s ) |
346 |
{ |
347 |
m_pMainForm->appendMessages(s); |
348 |
} |
349 |
|
350 |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
351 |
{ |
352 |
m_pMainForm->appendMessagesColor(s, c); |
353 |
} |
354 |
|
355 |
void qsamplerChannel::appendMessagesText( const QString& s ) |
356 |
{ |
357 |
m_pMainForm->appendMessagesText(s); |
358 |
} |
359 |
|
360 |
void qsamplerChannel::appendMessagesError( const QString& s ) |
361 |
{ |
362 |
m_pMainForm->appendMessagesError(s); |
363 |
} |
364 |
|
365 |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
366 |
{ |
367 |
m_pMainForm->appendMessagesClient(s); |
368 |
} |
369 |
|
370 |
|
371 |
// end of qsamplerChannel.cpp |