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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1461 - (hide annotations) (download)
Sun Oct 28 23:30:36 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 30652 byte(s)
* started to port QSampler to Qt4 (NOTE: this version is yet broken, use
  the latest tarball release 0.1.5 until the Qt4 port is completed)

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

  ViewVC Help
Powered by ViewVC