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