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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 961 - (hide annotations) (download)
Sun Dec 3 18:26:13 2006 UTC (17 years, 3 months ago) by capela
File size: 25966 byte(s)
- Adding preliminary MIDI instrument mapping support; now
  with an instrument list widget and editing capabilities.

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

  ViewVC Help
Powered by ViewVC