/[svn]/qsampler/trunk/src/qsamplerChannel.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1527 - (hide annotations) (download)
Mon Nov 26 16:00:21 2007 UTC (16 years, 4 months ago) by schoenebeck
File size: 27660 byte(s)
* Added recent new support of libgig for retrieving instrument names in a
  very fast way. If libgig provides this feature, then the respective
  name retrieval setting in qsampler is enabled by default.

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

  ViewVC Help
Powered by ViewVC