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