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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC