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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1490 - (hide annotations) (download)
Mon Nov 19 04:09:30 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 27497 byte(s)
- minor cosmetics (show unicode right arrow instead of "->")

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

  ViewVC Help
Powered by ViewVC