~ubuntu-branches/ubuntu/karmic/qsampler/karmic

« back to all changes in this revision

Viewing changes to src/qsamplerChannel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2008-08-28 08:43:21 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080828084321-guq8v04yg31co9gm
Tags: 0.2.1-1
* New upstream release
* Uploaded to Debian (Closes: #280576)

Show diffs side-by-side

added added

removed removed

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