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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC