1 |
// qsamplerChannel.cpp |
2 |
// |
3 |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, 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 along |
17 |
with this program; if not, write to the Free Software Foundation, Inc., |
18 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
*****************************************************************************/ |
21 |
|
22 |
#include "qsamplerUtilities.h" |
23 |
#include "qsamplerAbout.h" |
24 |
#include "qsamplerChannel.h" |
25 |
|
26 |
#include "qsamplerMainForm.h" |
27 |
#include "qsamplerChannelForm.h" |
28 |
|
29 |
#include <qfileinfo.h> |
30 |
#include <qcombobox.h> |
31 |
|
32 |
#ifdef CONFIG_LIBGIG |
33 |
#include "gig.h" |
34 |
#endif |
35 |
|
36 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
37 |
|
38 |
using namespace QSampler; |
39 |
|
40 |
//------------------------------------------------------------------------- |
41 |
// qsamplerChannel - Sampler channel structure. |
42 |
// |
43 |
|
44 |
// Constructor. |
45 |
qsamplerChannel::qsamplerChannel ( int iChannelID ) |
46 |
{ |
47 |
m_iChannelID = iChannelID; |
48 |
|
49 |
// m_sEngineName = noEngineName(); |
50 |
// m_sInstrumentName = noInstrumentName(); |
51 |
// m_sInstrumentFile = m_sInstrumentName; |
52 |
m_iInstrumentNr = -1; |
53 |
m_iInstrumentStatus = -1; |
54 |
m_sMidiDriver = "ALSA"; |
55 |
m_iMidiDevice = -1; |
56 |
m_iMidiPort = -1; |
57 |
m_iMidiChannel = -1; |
58 |
m_iMidiMap = -1; |
59 |
m_sAudioDriver = "ALSA"; |
60 |
m_iAudioDevice = -1; |
61 |
m_fVolume = 0.0; |
62 |
m_bMute = false; |
63 |
m_bSolo = false; |
64 |
} |
65 |
|
66 |
// Default destructor. |
67 |
qsamplerChannel::~qsamplerChannel (void) |
68 |
{ |
69 |
} |
70 |
|
71 |
|
72 |
// Create a new sampler channel, if not already. |
73 |
bool qsamplerChannel::addChannel (void) |
74 |
{ |
75 |
MainForm* pMainForm = MainForm::getInstance(); |
76 |
if (pMainForm == NULL) |
77 |
return false; |
78 |
if (pMainForm->client() == NULL) |
79 |
return false; |
80 |
|
81 |
// Are we a new channel? |
82 |
if (m_iChannelID < 0) { |
83 |
m_iChannelID = ::lscp_add_channel(pMainForm->client()); |
84 |
if (m_iChannelID < 0) { |
85 |
appendMessagesClient("lscp_add_channel"); |
86 |
appendMessagesError( |
87 |
QObject::tr("Could not add channel.\n\nSorry.")); |
88 |
} // Otherwise it's created... |
89 |
else appendMessages(QObject::tr("added.")); |
90 |
} |
91 |
|
92 |
// Return whether we're a valid channel... |
93 |
return (m_iChannelID >= 0); |
94 |
} |
95 |
|
96 |
|
97 |
// Remove sampler channel. |
98 |
bool qsamplerChannel::removeChannel (void) |
99 |
{ |
100 |
MainForm *pMainForm = MainForm::getInstance(); |
101 |
if (pMainForm == NULL) |
102 |
return false; |
103 |
if (pMainForm->client() == NULL) |
104 |
return false; |
105 |
|
106 |
// Are we an existing channel? |
107 |
if (m_iChannelID >= 0) { |
108 |
if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
109 |
appendMessagesClient("lscp_remove_channel"); |
110 |
appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); |
111 |
} else { |
112 |
// Otherwise it's removed. |
113 |
appendMessages(QObject::tr("removed.")); |
114 |
m_iChannelID = -1; |
115 |
} |
116 |
} |
117 |
|
118 |
// Return whether we've removed the channel... |
119 |
return (m_iChannelID < 0); |
120 |
} |
121 |
|
122 |
|
123 |
// Channel-ID (aka Sammpler-Channel) accessors. |
124 |
int qsamplerChannel::channelID (void) const |
125 |
{ |
126 |
return m_iChannelID; |
127 |
} |
128 |
|
129 |
void qsamplerChannel::setChannelID ( int iChannelID ) |
130 |
{ |
131 |
m_iChannelID = iChannelID; |
132 |
} |
133 |
|
134 |
|
135 |
// Readable channel name. |
136 |
QString qsamplerChannel::channelName (void) const |
137 |
{ |
138 |
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); |
139 |
} |
140 |
|
141 |
|
142 |
// Engine name accessors. |
143 |
const QString& qsamplerChannel::engineName (void) const |
144 |
{ |
145 |
return m_sEngineName; |
146 |
} |
147 |
|
148 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
149 |
{ |
150 |
MainForm *pMainForm = MainForm::getInstance(); |
151 |
if (pMainForm == NULL) |
152 |
return false; |
153 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
154 |
return false; |
155 |
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) |
156 |
return true; |
157 |
|
158 |
if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
159 |
appendMessagesClient("lscp_load_engine"); |
160 |
return false; |
161 |
} |
162 |
|
163 |
appendMessages(QObject::tr("Engine: %1.").arg(sEngineName)); |
164 |
|
165 |
m_sEngineName = sEngineName; |
166 |
return true; |
167 |
} |
168 |
|
169 |
|
170 |
// Instrument filename accessor. |
171 |
const QString& qsamplerChannel::instrumentFile (void) const |
172 |
{ |
173 |
return m_sInstrumentFile; |
174 |
} |
175 |
|
176 |
// Instrument index accessor. |
177 |
int qsamplerChannel::instrumentNr (void) const |
178 |
{ |
179 |
return m_iInstrumentNr; |
180 |
} |
181 |
|
182 |
// Instrument name accessor. |
183 |
const QString& qsamplerChannel::instrumentName (void) const |
184 |
{ |
185 |
return m_sInstrumentName; |
186 |
} |
187 |
|
188 |
// Instrument status accessor. |
189 |
int qsamplerChannel::instrumentStatus (void) const |
190 |
{ |
191 |
return m_iInstrumentStatus; |
192 |
} |
193 |
|
194 |
// Instrument file loader. |
195 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
196 |
{ |
197 |
MainForm *pMainForm = MainForm::getInstance(); |
198 |
if (pMainForm == NULL) |
199 |
return false; |
200 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
201 |
return false; |
202 |
if (!isInstrumentFile(sInstrumentFile)) |
203 |
return false; |
204 |
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
205 |
return true; |
206 |
|
207 |
if ( |
208 |
::lscp_load_instrument_non_modal( |
209 |
pMainForm->client(), |
210 |
qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(), |
211 |
iInstrumentNr, m_iChannelID |
212 |
) != LSCP_OK |
213 |
) { |
214 |
appendMessagesClient("lscp_load_instrument"); |
215 |
return false; |
216 |
} |
217 |
|
218 |
appendMessages(QObject::tr("Instrument: \"%1\" (%2).") |
219 |
.arg(sInstrumentFile).arg(iInstrumentNr)); |
220 |
|
221 |
return setInstrument(sInstrumentFile, iInstrumentNr); |
222 |
} |
223 |
|
224 |
|
225 |
// Special instrument file/name/number settler. |
226 |
bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
227 |
{ |
228 |
m_sInstrumentFile = sInstrumentFile; |
229 |
m_iInstrumentNr = iInstrumentNr; |
230 |
#ifdef CONFIG_INSTRUMENT_NAME |
231 |
m_sInstrumentName = QString::null; // We'll get it, maybe later, on channel_info... |
232 |
#else |
233 |
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
234 |
#endif |
235 |
m_iInstrumentStatus = 0; |
236 |
|
237 |
return true; |
238 |
} |
239 |
|
240 |
|
241 |
// MIDI driver type accessors (DEPRECATED). |
242 |
const QString& qsamplerChannel::midiDriver (void) const |
243 |
{ |
244 |
return m_sMidiDriver; |
245 |
} |
246 |
|
247 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
248 |
{ |
249 |
MainForm *pMainForm = MainForm::getInstance(); |
250 |
if (pMainForm == NULL) |
251 |
return false; |
252 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
253 |
return false; |
254 |
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) |
255 |
return true; |
256 |
|
257 |
if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
258 |
appendMessagesClient("lscp_set_channel_midi_type"); |
259 |
return false; |
260 |
} |
261 |
|
262 |
appendMessages(QObject::tr("MIDI driver: %1.").arg(sMidiDriver)); |
263 |
|
264 |
m_sMidiDriver = sMidiDriver; |
265 |
return true; |
266 |
} |
267 |
|
268 |
|
269 |
// MIDI device accessors. |
270 |
int qsamplerChannel::midiDevice (void) const |
271 |
{ |
272 |
return m_iMidiDevice; |
273 |
} |
274 |
|
275 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
276 |
{ |
277 |
MainForm *pMainForm = MainForm::getInstance(); |
278 |
if (pMainForm == NULL) |
279 |
return false; |
280 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
281 |
return false; |
282 |
if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice) |
283 |
return true; |
284 |
|
285 |
if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
286 |
appendMessagesClient("lscp_set_channel_midi_device"); |
287 |
return false; |
288 |
} |
289 |
|
290 |
appendMessages(QObject::tr("MIDI device: %1.").arg(iMidiDevice)); |
291 |
|
292 |
m_iMidiDevice = iMidiDevice; |
293 |
return true; |
294 |
} |
295 |
|
296 |
|
297 |
// MIDI port number accessor. |
298 |
int qsamplerChannel::midiPort (void) const |
299 |
{ |
300 |
return m_iMidiPort; |
301 |
} |
302 |
|
303 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
304 |
{ |
305 |
MainForm *pMainForm = MainForm::getInstance(); |
306 |
if (pMainForm == NULL) |
307 |
return false; |
308 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
309 |
return false; |
310 |
if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort) |
311 |
return true; |
312 |
|
313 |
if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
314 |
appendMessagesClient("lscp_set_channel_midi_port"); |
315 |
return false; |
316 |
} |
317 |
|
318 |
appendMessages(QObject::tr("MIDI port: %1.").arg(iMidiPort)); |
319 |
|
320 |
m_iMidiPort = iMidiPort; |
321 |
return true; |
322 |
} |
323 |
|
324 |
|
325 |
// MIDI channel accessor. |
326 |
int qsamplerChannel::midiChannel (void) const |
327 |
{ |
328 |
return m_iMidiChannel; |
329 |
} |
330 |
|
331 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
332 |
{ |
333 |
MainForm *pMainForm = MainForm::getInstance(); |
334 |
if (pMainForm == NULL) |
335 |
return false; |
336 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
337 |
return false; |
338 |
if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel) |
339 |
return true; |
340 |
|
341 |
if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
342 |
appendMessagesClient("lscp_set_channel_midi_channel"); |
343 |
return false; |
344 |
} |
345 |
|
346 |
appendMessages(QObject::tr("MIDI channel: %1.").arg(iMidiChannel)); |
347 |
|
348 |
m_iMidiChannel = iMidiChannel; |
349 |
return true; |
350 |
} |
351 |
|
352 |
|
353 |
// MIDI instrument map accessor. |
354 |
int qsamplerChannel::midiMap (void) const |
355 |
{ |
356 |
return m_iMidiMap; |
357 |
} |
358 |
|
359 |
bool qsamplerChannel::setMidiMap ( int iMidiMap ) |
360 |
{ |
361 |
MainForm *pMainForm = MainForm::getInstance(); |
362 |
if (pMainForm == NULL) |
363 |
return false; |
364 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
365 |
return false; |
366 |
if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap) |
367 |
return true; |
368 |
#ifdef CONFIG_MIDI_INSTRUMENT |
369 |
if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) { |
370 |
appendMessagesClient("lscp_set_channel_midi_map"); |
371 |
return false; |
372 |
} |
373 |
#endif |
374 |
appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap)); |
375 |
|
376 |
m_iMidiMap = iMidiMap; |
377 |
return true; |
378 |
} |
379 |
|
380 |
|
381 |
// Audio device accessor. |
382 |
int qsamplerChannel::audioDevice (void) const |
383 |
{ |
384 |
return m_iAudioDevice; |
385 |
} |
386 |
|
387 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
388 |
{ |
389 |
MainForm *pMainForm = MainForm::getInstance(); |
390 |
if (pMainForm == NULL) |
391 |
return false; |
392 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
393 |
return false; |
394 |
if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice) |
395 |
return true; |
396 |
|
397 |
if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
398 |
appendMessagesClient("lscp_set_channel_audio_device"); |
399 |
return false; |
400 |
} |
401 |
|
402 |
appendMessages(QObject::tr("Audio device: %1.").arg(iAudioDevice)); |
403 |
|
404 |
m_iAudioDevice = iAudioDevice; |
405 |
return true; |
406 |
} |
407 |
|
408 |
|
409 |
// Audio driver type accessors (DEPRECATED). |
410 |
const QString& qsamplerChannel::audioDriver (void) const |
411 |
{ |
412 |
return m_sAudioDriver; |
413 |
} |
414 |
|
415 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
416 |
{ |
417 |
MainForm *pMainForm = MainForm::getInstance(); |
418 |
if (pMainForm == NULL) |
419 |
return false; |
420 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
421 |
return false; |
422 |
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) |
423 |
return true; |
424 |
|
425 |
if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
426 |
appendMessagesClient("lscp_set_channel_audio_type"); |
427 |
return false; |
428 |
} |
429 |
|
430 |
appendMessages(QObject::tr("Audio driver: %1.").arg(sAudioDriver)); |
431 |
|
432 |
m_sAudioDriver = sAudioDriver; |
433 |
return true; |
434 |
} |
435 |
|
436 |
|
437 |
// Channel volume accessors. |
438 |
float qsamplerChannel::volume (void) const |
439 |
{ |
440 |
return m_fVolume; |
441 |
} |
442 |
|
443 |
bool qsamplerChannel::setVolume ( float fVolume ) |
444 |
{ |
445 |
MainForm *pMainForm = MainForm::getInstance(); |
446 |
if (pMainForm == NULL) |
447 |
return false; |
448 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
449 |
return false; |
450 |
if (m_iInstrumentStatus == 100 && m_fVolume == fVolume) |
451 |
return true; |
452 |
|
453 |
if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) { |
454 |
appendMessagesClient("lscp_set_channel_volume"); |
455 |
return false; |
456 |
} |
457 |
|
458 |
appendMessages(QObject::tr("Volume: %1.").arg(fVolume)); |
459 |
|
460 |
m_fVolume = fVolume; |
461 |
return true; |
462 |
} |
463 |
|
464 |
|
465 |
// Sampler channel mute state. |
466 |
bool qsamplerChannel::channelMute (void) const |
467 |
{ |
468 |
return m_bMute; |
469 |
} |
470 |
|
471 |
bool qsamplerChannel::setChannelMute ( bool bMute ) |
472 |
{ |
473 |
MainForm *pMainForm = MainForm::getInstance(); |
474 |
if (pMainForm == NULL) |
475 |
return false; |
476 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
477 |
return false; |
478 |
if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute))) |
479 |
return true; |
480 |
|
481 |
#ifdef CONFIG_MUTE_SOLO |
482 |
if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) { |
483 |
appendMessagesClient("lscp_set_channel_mute"); |
484 |
return false; |
485 |
} |
486 |
appendMessages(QObject::tr("Mute: %1.").arg((int) bMute)); |
487 |
m_bMute = bMute; |
488 |
return true; |
489 |
#else |
490 |
return false; |
491 |
#endif |
492 |
} |
493 |
|
494 |
|
495 |
// Sampler channel solo state. |
496 |
bool qsamplerChannel::channelSolo (void) const |
497 |
{ |
498 |
return m_bSolo; |
499 |
} |
500 |
|
501 |
bool qsamplerChannel::setChannelSolo ( bool bSolo ) |
502 |
{ |
503 |
MainForm *pMainForm = MainForm::getInstance(); |
504 |
if (pMainForm == NULL) |
505 |
return false; |
506 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
507 |
return false; |
508 |
if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo))) |
509 |
return true; |
510 |
|
511 |
#ifdef CONFIG_MUTE_SOLO |
512 |
if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) { |
513 |
appendMessagesClient("lscp_set_channel_solo"); |
514 |
return false; |
515 |
} |
516 |
appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo)); |
517 |
m_bSolo = bSolo; |
518 |
return true; |
519 |
#else |
520 |
return false; |
521 |
#endif |
522 |
} |
523 |
|
524 |
|
525 |
// Audio routing accessors. |
526 |
int qsamplerChannel::audioChannel ( int iAudioOut ) const |
527 |
{ |
528 |
return m_audioRouting[iAudioOut]; |
529 |
} |
530 |
|
531 |
bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
532 |
{ |
533 |
MainForm *pMainForm = MainForm::getInstance(); |
534 |
if (pMainForm == NULL) |
535 |
return false; |
536 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
537 |
return false; |
538 |
if (m_iInstrumentStatus == 100 && |
539 |
m_audioRouting[iAudioOut] == iAudioIn) |
540 |
return true; |
541 |
|
542 |
if (::lscp_set_channel_audio_channel(pMainForm->client(), |
543 |
m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) { |
544 |
appendMessagesClient("lscp_set_channel_audio_channel"); |
545 |
return false; |
546 |
} |
547 |
|
548 |
appendMessages(QObject::tr("Audio Channel: %1 -> %2.") |
549 |
.arg(iAudioOut).arg(iAudioIn)); |
550 |
|
551 |
m_audioRouting[iAudioOut] = iAudioIn; |
552 |
return true; |
553 |
} |
554 |
|
555 |
// The audio routing map itself. |
556 |
const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const |
557 |
{ |
558 |
return m_audioRouting; |
559 |
} |
560 |
|
561 |
|
562 |
// Istrument name remapper. |
563 |
void qsamplerChannel::updateInstrumentName (void) |
564 |
{ |
565 |
#ifndef CONFIG_INSTRUMENT_NAME |
566 |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
567 |
m_iInstrumentNr, (options() && options()->bInstrumentNames)); |
568 |
#endif |
569 |
} |
570 |
|
571 |
|
572 |
// Update whole channel info state. |
573 |
bool qsamplerChannel::updateChannelInfo (void) |
574 |
{ |
575 |
MainForm *pMainForm = MainForm::getInstance(); |
576 |
if (pMainForm == NULL) |
577 |
return false; |
578 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
579 |
return false; |
580 |
|
581 |
// Read channel information. |
582 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID); |
583 |
if (pChannelInfo == NULL) { |
584 |
appendMessagesClient("lscp_get_channel_info"); |
585 |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
586 |
return false; |
587 |
} |
588 |
|
589 |
#ifdef CONFIG_INSTRUMENT_NAME |
590 |
// We got all actual instrument datum... |
591 |
m_sInstrumentFile = |
592 |
qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file); |
593 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
594 |
m_sInstrumentName = |
595 |
qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name); |
596 |
#else |
597 |
// First, check if intrument name has changed, |
598 |
// taking care that instrument name lookup might be expensive, |
599 |
// so we better make it only once and when really needed... |
600 |
if ((m_sInstrumentFile != pChannelInfo->instrument_file) || |
601 |
(m_iInstrumentNr != pChannelInfo->instrument_nr)) { |
602 |
m_sInstrumentFile = pChannelInfo->instrument_file; |
603 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
604 |
updateInstrumentName(); |
605 |
} |
606 |
#endif |
607 |
// Cache in other channel information. |
608 |
m_sEngineName = pChannelInfo->engine_name; |
609 |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
610 |
m_iMidiDevice = pChannelInfo->midi_device; |
611 |
m_iMidiPort = pChannelInfo->midi_port; |
612 |
m_iMidiChannel = pChannelInfo->midi_channel; |
613 |
#ifdef CONFIG_MIDI_INSTRUMENT |
614 |
m_iMidiMap = pChannelInfo->midi_map; |
615 |
#endif |
616 |
m_iAudioDevice = pChannelInfo->audio_device; |
617 |
m_fVolume = pChannelInfo->volume; |
618 |
#ifdef CONFIG_MUTE_SOLO |
619 |
m_bMute = pChannelInfo->mute; |
620 |
m_bSolo = pChannelInfo->solo; |
621 |
#endif |
622 |
// Some sanity checks. |
623 |
if (m_sEngineName == "NONE" || m_sEngineName.isEmpty()) |
624 |
m_sEngineName = QString::null; |
625 |
if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) { |
626 |
m_sInstrumentFile = QString::null; |
627 |
m_sInstrumentName = QString::null; |
628 |
} |
629 |
|
630 |
// Time for device info grabbing... |
631 |
lscp_device_info_t *pDeviceInfo; |
632 |
const QString sNone = QObject::tr("(none)"); |
633 |
// Audio device driver type. |
634 |
pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice); |
635 |
if (pDeviceInfo == NULL) { |
636 |
appendMessagesClient("lscp_get_audio_device_info"); |
637 |
m_sAudioDriver = sNone; |
638 |
} else { |
639 |
m_sAudioDriver = pDeviceInfo->driver; |
640 |
} |
641 |
// MIDI device driver type. |
642 |
pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice); |
643 |
if (pDeviceInfo == NULL) { |
644 |
appendMessagesClient("lscp_get_midi_device_info"); |
645 |
m_sMidiDriver = sNone; |
646 |
} else { |
647 |
m_sMidiDriver = pDeviceInfo->driver; |
648 |
} |
649 |
|
650 |
// Set the audio routing map. |
651 |
m_audioRouting.clear(); |
652 |
#ifdef CONFIG_AUDIO_ROUTING |
653 |
int *piAudioRouting = pChannelInfo->audio_routing; |
654 |
for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++) |
655 |
m_audioRouting[i] = piAudioRouting[i]; |
656 |
#else |
657 |
char **ppszAudioRouting = pChannelInfo->audio_routing; |
658 |
for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++) |
659 |
m_audioRouting[i] = ::atoi(ppszAudioRouting[i]); |
660 |
#endif |
661 |
|
662 |
return true; |
663 |
} |
664 |
|
665 |
|
666 |
// Reset channel method. |
667 |
bool qsamplerChannel::channelReset (void) |
668 |
{ |
669 |
MainForm *pMainForm = MainForm::getInstance(); |
670 |
if (pMainForm == NULL) |
671 |
return false; |
672 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
673 |
return false; |
674 |
|
675 |
if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
676 |
appendMessagesClient("lscp_reset_channel"); |
677 |
return false; |
678 |
} |
679 |
|
680 |
appendMessages(QObject::tr("reset.")); |
681 |
|
682 |
return true; |
683 |
} |
684 |
|
685 |
|
686 |
// Spawn instrument editor method. |
687 |
bool qsamplerChannel::editChannel (void) |
688 |
{ |
689 |
#ifdef CONFIG_EDIT_INSTRUMENT |
690 |
|
691 |
MainForm *pMainForm = MainForm::getInstance(); |
692 |
if (pMainForm == NULL) |
693 |
return false; |
694 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
695 |
return false; |
696 |
|
697 |
if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID) |
698 |
!= LSCP_OK) { |
699 |
appendMessagesClient("lscp_edit_channel_instrument"); |
700 |
appendMessagesError(QObject::tr( |
701 |
"Could not launch an appropriate instrument editor " |
702 |
"for the given instrument!\n" |
703 |
"Make sure you have an appropriate " |
704 |
"instrument editor like 'gigedit' installed\n" |
705 |
"and that it placed its mandatory DLL file " |
706 |
"into the sampler's plugin directory.") |
707 |
); |
708 |
return false; |
709 |
} |
710 |
|
711 |
appendMessages(QObject::tr("edit instrument.")); |
712 |
|
713 |
return true; |
714 |
|
715 |
#else |
716 |
|
717 |
appendMessagesError(QObject::tr( |
718 |
"Sorry, QSampler was compiled for a version of liblscp " |
719 |
"which lacks this feature.\n" |
720 |
"You may want to update liblscp and recompile QSampler afterwards.") |
721 |
); |
722 |
|
723 |
return false; |
724 |
|
725 |
#endif |
726 |
} |
727 |
|
728 |
|
729 |
// Channel setup dialog form. |
730 |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
731 |
{ |
732 |
MainForm *pMainForm = MainForm::getInstance(); |
733 |
if (pMainForm == NULL) |
734 |
return false; |
735 |
|
736 |
bool bResult = false; |
737 |
|
738 |
appendMessages(QObject::tr("setup...")); |
739 |
|
740 |
ChannelForm *pChannelForm = new ChannelForm(pParent); |
741 |
if (pChannelForm) { |
742 |
pChannelForm->setup(this); |
743 |
bResult = pChannelForm->exec(); |
744 |
delete pChannelForm; |
745 |
} |
746 |
|
747 |
return bResult; |
748 |
} |
749 |
|
750 |
|
751 |
// Redirected messages output methods. |
752 |
void qsamplerChannel::appendMessages( const QString& s ) const |
753 |
{ |
754 |
MainForm *pMainForm = MainForm::getInstance(); |
755 |
if (pMainForm) |
756 |
pMainForm->appendMessages(channelName() + ' ' + s); |
757 |
} |
758 |
|
759 |
void qsamplerChannel::appendMessagesColor( const QString& s, |
760 |
const QString& c ) const |
761 |
{ |
762 |
MainForm *pMainForm = MainForm::getInstance(); |
763 |
if (pMainForm) |
764 |
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
765 |
} |
766 |
|
767 |
void qsamplerChannel::appendMessagesText( const QString& s ) const |
768 |
{ |
769 |
MainForm *pMainForm = MainForm::getInstance(); |
770 |
if (pMainForm) |
771 |
pMainForm->appendMessagesText(channelName() + ' ' + s); |
772 |
} |
773 |
|
774 |
void qsamplerChannel::appendMessagesError( const QString& s ) const |
775 |
{ |
776 |
MainForm *pMainForm = MainForm::getInstance(); |
777 |
if (pMainForm) |
778 |
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
779 |
} |
780 |
|
781 |
void qsamplerChannel::appendMessagesClient( const QString& s ) const |
782 |
{ |
783 |
MainForm *pMainForm = MainForm::getInstance(); |
784 |
if (pMainForm) |
785 |
pMainForm->appendMessagesClient(channelName() + ' ' + s); |
786 |
} |
787 |
|
788 |
|
789 |
// Context menu event handler. |
790 |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
791 |
{ |
792 |
MainForm *pMainForm = MainForm::getInstance(); |
793 |
if (pMainForm) |
794 |
pMainForm->contextMenuEvent(pEvent); |
795 |
} |
796 |
|
797 |
|
798 |
// FIXME: Check whether a given file is an instrument file. |
799 |
bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile ) |
800 |
{ |
801 |
bool bResult = false; |
802 |
|
803 |
QFile file(sInstrumentFile); |
804 |
if (file.open(IO_ReadOnly)) { |
805 |
char achHeader[16]; |
806 |
if (file.readBlock(achHeader, 16)) { |
807 |
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
808 |
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); |
809 |
} |
810 |
file.close(); |
811 |
} |
812 |
|
813 |
return bResult; |
814 |
} |
815 |
|
816 |
|
817 |
// Retrieve the instrument list of a instrument file (.gig). |
818 |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
819 |
bool bInstrumentNames ) |
820 |
{ |
821 |
QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
822 |
QStringList instlist; |
823 |
|
824 |
if (isInstrumentFile(sInstrumentFile)) { |
825 |
#ifdef CONFIG_LIBGIG |
826 |
if (bInstrumentNames) { |
827 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
828 |
gig::File *pGig = new gig::File(pRiff); |
829 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
830 |
while (pInstrument) { |
831 |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
832 |
pInstrument = pGig->GetNextInstrument(); |
833 |
} |
834 |
delete pGig; |
835 |
delete pRiff; |
836 |
} |
837 |
else |
838 |
#endif |
839 |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
840 |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
841 |
} |
842 |
else instlist.append(noInstrumentName()); |
843 |
|
844 |
return instlist; |
845 |
} |
846 |
|
847 |
|
848 |
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
849 |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
850 |
int iInstrumentNr, bool bInstrumentNames ) |
851 |
{ |
852 |
QString sInstrumentName; |
853 |
|
854 |
if (isInstrumentFile(sInstrumentFile)) { |
855 |
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
856 |
#ifdef CONFIG_LIBGIG |
857 |
if (bInstrumentNames) { |
858 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
859 |
gig::File *pGig = new gig::File(pRiff); |
860 |
int iIndex = 0; |
861 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
862 |
while (pInstrument) { |
863 |
if (iIndex == iInstrumentNr) { |
864 |
sInstrumentName = (pInstrument->pInfo)->Name.c_str(); |
865 |
break; |
866 |
} |
867 |
iIndex++; |
868 |
pInstrument = pGig->GetNextInstrument(); |
869 |
} |
870 |
delete pGig; |
871 |
delete pRiff; |
872 |
} |
873 |
else |
874 |
#endif |
875 |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
876 |
} |
877 |
else sInstrumentName = noInstrumentName(); |
878 |
|
879 |
return sInstrumentName; |
880 |
} |
881 |
|
882 |
|
883 |
// Common invalid name-helpers. |
884 |
QString qsamplerChannel::noEngineName (void) |
885 |
{ |
886 |
return QObject::tr("(No engine)"); |
887 |
} |
888 |
|
889 |
QString qsamplerChannel::noInstrumentName (void) |
890 |
{ |
891 |
return QObject::tr("(No instrument)"); |
892 |
} |
893 |
|
894 |
QString qsamplerChannel::loadingInstrument (void) { |
895 |
return QObject::tr("(Loading instrument...)"); |
896 |
} |
897 |
|
898 |
|
899 |
|
900 |
//------------------------------------------------------------------------- |
901 |
// qsamplerChannelRoutingTable - Channel routing table. |
902 |
// |
903 |
#if 0 |
904 |
// Constructor. |
905 |
qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( |
906 |
QWidget *pParent, const char *pszName ) |
907 |
: QTable(pParent, pszName) |
908 |
{ |
909 |
// Set fixed number of columns. |
910 |
QTable::setNumCols(2); |
911 |
QTable::setShowGrid(false); |
912 |
QTable::setSorting(false); |
913 |
QTable::setFocusStyle(QTable::FollowStyle); |
914 |
QTable::setSelectionMode(QTable::NoSelection); |
915 |
// No vertical header. |
916 |
QTable::verticalHeader()->hide(); |
917 |
QTable::setLeftMargin(0); |
918 |
// Initialize the fixed table column headings. |
919 |
QHeader *pHeader = QTable::horizontalHeader(); |
920 |
pHeader->setLabel(0, tr("Sampler Channel")); |
921 |
pHeader->setLabel(1, tr("Device Channel")); |
922 |
// Set read-onlyness of each column |
923 |
QTable::setColumnReadOnly(0, true); |
924 |
// QTable::setColumnReadOnly(1, false); -- of course not. |
925 |
QTable::setColumnStretchable(1, true); |
926 |
} |
927 |
|
928 |
// Default destructor. |
929 |
qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void) |
930 |
{ |
931 |
} |
932 |
|
933 |
|
934 |
// Routing map table renderer. |
935 |
void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice, |
936 |
const qsamplerChannelRoutingMap& routing ) |
937 |
{ |
938 |
if (pDevice == NULL) |
939 |
return; |
940 |
|
941 |
// Always (re)start it empty. |
942 |
QTable::setUpdatesEnabled(false); |
943 |
QTable::setNumRows(0); |
944 |
|
945 |
// The common device port item list. |
946 |
QStringList opts; |
947 |
qsamplerDevicePortList& ports = pDevice->ports(); |
948 |
qsamplerDevicePort *pPort; |
949 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
950 |
opts.append(pDevice->deviceTypeName() |
951 |
+ ' ' + pDevice->driverName() |
952 |
+ ' ' + pPort->portName()); |
953 |
} |
954 |
|
955 |
// Those items shall have a proper pixmap... |
956 |
QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png"); |
957 |
QPixmap pmDevice; |
958 |
switch (pDevice->deviceType()) { |
959 |
case qsamplerDevice::Audio: |
960 |
pmDevice = QPixmap::fromMimeSource("audio2.png"); |
961 |
break; |
962 |
case qsamplerDevice::Midi: |
963 |
pmDevice = QPixmap::fromMimeSource("midi2.png"); |
964 |
break; |
965 |
case qsamplerDevice::None: |
966 |
break; |
967 |
} |
968 |
|
969 |
// Fill the routing table... |
970 |
QTable::insertRows(0, routing.count()); |
971 |
int iRow = 0; |
972 |
qsamplerChannelRoutingMap::ConstIterator iter; |
973 |
for (iter = routing.begin(); iter != routing.end(); ++iter) { |
974 |
QTable::setPixmap(iRow, 0, pmChannel); |
975 |
QTable::setText(iRow, 0, pDevice->deviceTypeName() |
976 |
+ ' ' + QString::number(iter.key())); |
977 |
qsamplerChannelRoutingComboBox *pComboItem = |
978 |
new qsamplerChannelRoutingComboBox(this, opts, pmDevice); |
979 |
pComboItem->setCurrentItem(iter.data()); |
980 |
QTable::setItem(iRow, 1, pComboItem); |
981 |
++iRow; |
982 |
} |
983 |
|
984 |
// Adjust optimal column widths. |
985 |
QTable::adjustColumn(0); |
986 |
QTable::adjustColumn(1); |
987 |
|
988 |
QTable::setUpdatesEnabled(true); |
989 |
QTable::updateContents(); |
990 |
} |
991 |
|
992 |
|
993 |
// Commit any pending editing. |
994 |
void qsamplerChannelRoutingTable::flush (void) |
995 |
{ |
996 |
if (QTable::isEditing()) |
997 |
QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true); |
998 |
} |
999 |
#endif |
1000 |
|
1001 |
ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { |
1002 |
} |
1003 |
|
1004 |
int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const { |
1005 |
return routing.size(); |
1006 |
} |
1007 |
|
1008 |
int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const { |
1009 |
return 1; |
1010 |
} |
1011 |
|
1012 |
QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { |
1013 |
if (!index.isValid()) |
1014 |
return QVariant(); |
1015 |
if (role != Qt::DisplayRole) |
1016 |
return QVariant(); |
1017 |
|
1018 |
ChannelRoutingItem item; |
1019 |
|
1020 |
// The common device port item list. |
1021 |
qsamplerDevicePortList& ports = pDevice->ports(); |
1022 |
qsamplerDevicePort* pPort; |
1023 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
1024 |
item.options.append( |
1025 |
pDevice->deviceTypeName() |
1026 |
+ ' ' + pDevice->driverName() |
1027 |
+ ' ' + pPort->portName() |
1028 |
); |
1029 |
} |
1030 |
|
1031 |
item.selection = routing[index.column()]; |
1032 |
|
1033 |
return QVariant::fromValue(item); |
1034 |
} |
1035 |
|
1036 |
QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { |
1037 |
if (role != Qt::DisplayRole) return QVariant(); |
1038 |
|
1039 |
if (orientation == Qt::Horizontal) |
1040 |
return QObject::tr("Device Channel"); |
1041 |
|
1042 |
if (orientation == Qt::Vertical) |
1043 |
return QObject::tr("Sampler Channel Output ") + |
1044 |
QString(section); |
1045 |
|
1046 |
return QVariant(); |
1047 |
} |
1048 |
|
1049 |
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
1050 |
const qsamplerChannelRoutingMap& routing ) |
1051 |
{ |
1052 |
this->pDevice = pDevice; |
1053 |
this->routing = routing; |
1054 |
} |
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { |
1060 |
} |
1061 |
|
1062 |
QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, |
1063 |
const QStyleOptionViewItem &/* option */, |
1064 |
const QModelIndex& index) const |
1065 |
{ |
1066 |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1067 |
|
1068 |
QComboBox* editor = new QComboBox(parent); |
1069 |
editor->addItems(item.options); |
1070 |
editor->setCurrentIndex(item.selection); |
1071 |
editor->installEventFilter(const_cast<ChannelRoutingDelegate*>(this)); |
1072 |
return editor; |
1073 |
} |
1074 |
|
1075 |
void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
1076 |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1077 |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1078 |
comboBox->setCurrentIndex(item.selection); |
1079 |
} |
1080 |
|
1081 |
void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
1082 |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1083 |
model->setData(index, comboBox->currentIndex()); |
1084 |
} |
1085 |
|
1086 |
void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor, |
1087 |
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1088 |
{ |
1089 |
editor->setGeometry(option.rect); |
1090 |
} |
1091 |
|
1092 |
|
1093 |
|
1094 |
//------------------------------------------------------------------------- |
1095 |
// qsamplerChannelRoutingComboBox - Custom combo box for routing table. |
1096 |
// |
1097 |
|
1098 |
#if 0 |
1099 |
// Constructor. |
1100 |
qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( |
1101 |
QTable *pTable, const QStringList& list, const QPixmap& pixmap ) |
1102 |
: QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap), |
1103 |
m_list(list) |
1104 |
{ |
1105 |
m_iCurrentItem = 0; |
1106 |
} |
1107 |
|
1108 |
// Public accessors. |
1109 |
void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem ) |
1110 |
{ |
1111 |
m_iCurrentItem = iCurrentItem; |
1112 |
|
1113 |
QTableItem::setText(m_list[iCurrentItem]); |
1114 |
} |
1115 |
|
1116 |
int qsamplerChannelRoutingComboBox::currentItem (void) const |
1117 |
{ |
1118 |
return m_iCurrentItem; |
1119 |
} |
1120 |
|
1121 |
// Virtual implemetations. |
1122 |
QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const |
1123 |
{ |
1124 |
QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport()); |
1125 |
QObject::connect(pComboBox, SIGNAL(activated(int)), |
1126 |
QTableItem::table(), SLOT(doValueChanged())); |
1127 |
for (QStringList::ConstIterator iter = m_list.begin(); |
1128 |
iter != m_list.end(); iter++) { |
1129 |
pComboBox->insertItem(QTableItem::pixmap(), *iter); |
1130 |
} |
1131 |
pComboBox->setCurrentItem(m_iCurrentItem); |
1132 |
return pComboBox; |
1133 |
} |
1134 |
|
1135 |
void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget ) |
1136 |
{ |
1137 |
if (pWidget->inherits("QComboBox")) { |
1138 |
QComboBox *pComboBox = (QComboBox *) pWidget; |
1139 |
m_iCurrentItem = pComboBox->currentItem(); |
1140 |
QTableItem::setText(pComboBox->currentText()); |
1141 |
} |
1142 |
else QTableItem::setContentFromEditor(pWidget); |
1143 |
} |
1144 |
|
1145 |
#endif |