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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1489 - (hide annotations) (download)
Mon Nov 19 03:29:57 2007 UTC (16 years, 4 months ago) by schoenebeck
File size: 27398 byte(s)
* Qt4 migration: finished channel setup dialog
* cosmetical fixes of channel strip

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

  ViewVC Help
Powered by ViewVC