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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1414 - (hide annotations) (download)
Fri Oct 12 22:50:47 2007 UTC (16 years, 6 months ago) by capela
File size: 28225 byte(s)
* Changed client interface function, for editing instrument,
  from: lscp_edit_instrument() to lscp_edit_channel_instrument().

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

  ViewVC Help
Powered by ViewVC