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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1372 - (hide annotations) (download)
Wed Oct 3 11:34:30 2007 UTC (16 years, 5 months ago) by capela
File size: 28035 byte(s)
* The new channel instrument editor tool is now also accessible
  from the main menu and toolbar.

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

  ViewVC Help
Powered by ViewVC