22 |
#include "qsamplerChannel.h" |
#include "qsamplerChannel.h" |
23 |
|
|
24 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
25 |
|
#include "qsamplerChannelForm.h" |
26 |
|
|
27 |
#include "config.h" |
#include "config.h" |
28 |
|
|
29 |
|
#include <qfileinfo.h> |
30 |
|
|
31 |
|
#ifdef CONFIG_LIBGIG |
32 |
|
#include "gig.h" |
33 |
|
#else |
34 |
|
#define QSAMPLER_INSTRUMENT_MAX 8 |
35 |
|
#endif |
36 |
|
|
37 |
|
|
38 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
39 |
// qsamplerChannel - Sampler channel structure. |
// qsamplerChannel - Sampler channel structure. |
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
|
// Create a new sampler channel, if not already. |
89 |
|
bool qsamplerChannel::addChannel (void) |
90 |
|
{ |
91 |
|
if (client() == NULL) |
92 |
|
return false; |
93 |
|
|
94 |
|
// Are we a new channel? |
95 |
|
if (m_iChannelID < 0) { |
96 |
|
m_iChannelID = ::lscp_add_channel(client()); |
97 |
|
if (m_iChannelID < 0) { |
98 |
|
appendMessagesClient("lscp_add_channel"); |
99 |
|
appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry.")); |
100 |
|
} // Otherwise it's created... |
101 |
|
else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID)); |
102 |
|
} |
103 |
|
|
104 |
|
// Return whether we're a valid channel... |
105 |
|
return (m_iChannelID >= 0); |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
// Remove sampler channel. |
110 |
|
bool qsamplerChannel::removeChannel (void) |
111 |
|
{ |
112 |
|
if (client() == NULL) |
113 |
|
return false; |
114 |
|
|
115 |
|
// Are we an existing channel? |
116 |
|
if (m_iChannelID >= 0) { |
117 |
|
if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) { |
118 |
|
appendMessagesClient("lscp_remove_channel"); |
119 |
|
appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); |
120 |
|
} else { |
121 |
|
// Otherwise it's removed. |
122 |
|
appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID)); |
123 |
|
m_iChannelID = -1; |
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
|
// Return whether we've removed the channel... |
128 |
|
return (m_iChannelID < 0); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
// Channel-ID (aka Sammpler-Channel) accessors. |
// Channel-ID (aka Sammpler-Channel) accessors. |
133 |
int qsamplerChannel::channelID (void) |
int qsamplerChannel::channelID (void) |
134 |
{ |
{ |
141 |
} |
} |
142 |
|
|
143 |
|
|
144 |
|
// Readable channel name. |
145 |
|
QString qsamplerChannel::channelName (void) |
146 |
|
{ |
147 |
|
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
// Engine name accessors. |
// Engine name accessors. |
152 |
QString& qsamplerChannel::engineName (void) |
QString& qsamplerChannel::engineName (void) |
153 |
{ |
{ |
156 |
|
|
157 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
158 |
{ |
{ |
159 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
160 |
return false; |
return false; |
161 |
|
|
162 |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
190 |
// Instrument file loader. |
// Instrument file loader. |
191 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
192 |
{ |
{ |
193 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
194 |
return false; |
return false; |
195 |
|
|
196 |
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
214 |
|
|
215 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
216 |
{ |
{ |
217 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
218 |
return false; |
return false; |
219 |
|
|
220 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
235 |
|
|
236 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
237 |
{ |
{ |
238 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
239 |
return false; |
return false; |
240 |
|
|
241 |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
256 |
|
|
257 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
258 |
{ |
{ |
259 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
260 |
return false; |
return false; |
261 |
|
|
262 |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
277 |
|
|
278 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
279 |
{ |
{ |
280 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
281 |
return false; |
return false; |
282 |
|
|
283 |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
298 |
|
|
299 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
300 |
{ |
{ |
301 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
302 |
return false; |
return false; |
303 |
|
|
304 |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
319 |
|
|
320 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
321 |
{ |
{ |
322 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
323 |
return false; |
return false; |
324 |
|
|
325 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
340 |
|
|
341 |
bool qsamplerChannel::setVolume ( float fVolume ) |
bool qsamplerChannel::setVolume ( float fVolume ) |
342 |
{ |
{ |
343 |
if (client() == NULL) |
if (client() == NULL || m_iChannelID < 0) |
344 |
return false; |
return false; |
345 |
|
|
346 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
354 |
|
|
355 |
|
|
356 |
// Update whole channel info state. |
// Update whole channel info state. |
357 |
void qsamplerChannel::updateChannelInfo (void) |
bool qsamplerChannel::updateChannelInfo (void) |
358 |
{ |
{ |
359 |
// Check if we're up and connected. |
if (client() == NULL || m_iChannelID < 0) |
360 |
if (client() == NULL) |
return false; |
|
return; |
|
361 |
|
|
362 |
// Read channel information. |
// Read channel information. |
363 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
364 |
if (pChannelInfo == NULL) { |
if (pChannelInfo == NULL) { |
365 |
appendMessagesClient("lscp_get_channel_info"); |
appendMessagesClient("lscp_get_channel_info"); |
366 |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
367 |
} else { |
return false; |
|
// Cache in channel information. |
|
|
m_sEngineName = pChannelInfo->engine_name; |
|
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
|
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
|
|
m_iInstrumentStatus = pChannelInfo->instrument_status; |
|
|
m_iMidiDevice = pChannelInfo->midi_device; |
|
|
m_iMidiPort = pChannelInfo->midi_port; |
|
|
m_iMidiChannel = pChannelInfo->midi_channel; |
|
|
m_iAudioDevice = pChannelInfo->audio_device; |
|
|
m_fVolume = pChannelInfo->volume; |
|
|
// Some sanity checks. |
|
|
if (m_sEngineName == "NONE") |
|
|
m_sEngineName = QString::null; |
|
|
if (m_sInstrumentFile == "NONE") |
|
|
m_sInstrumentFile = QString::null; |
|
368 |
} |
} |
369 |
|
|
370 |
|
// Cache in channel information. |
371 |
|
m_sEngineName = pChannelInfo->engine_name; |
372 |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
373 |
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
374 |
|
m_iInstrumentStatus = pChannelInfo->instrument_status; |
375 |
|
m_iMidiDevice = pChannelInfo->midi_device; |
376 |
|
m_iMidiPort = pChannelInfo->midi_port; |
377 |
|
m_iMidiChannel = pChannelInfo->midi_channel; |
378 |
|
m_iAudioDevice = pChannelInfo->audio_device; |
379 |
|
m_fVolume = pChannelInfo->volume; |
380 |
|
// Some sanity checks. |
381 |
|
if (m_sEngineName == "NONE") |
382 |
|
m_sEngineName = QString::null; |
383 |
|
if (m_sInstrumentFile == "NONE") |
384 |
|
m_sInstrumentFile = QString::null; |
385 |
|
|
386 |
|
return true; |
387 |
} |
} |
388 |
|
|
389 |
|
|
390 |
// Reset channel method. |
// Reset channel method. |
391 |
void qsamplerChannel::resetChannel (void) |
bool qsamplerChannel::resetChannel (void) |
392 |
{ |
{ |
393 |
// Check if we're up and connected. |
if (client() == NULL || m_iChannelID < 0) |
394 |
if (client() == NULL) |
return false; |
|
return; |
|
395 |
|
|
396 |
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) |
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) { |
397 |
appendMessagesClient("lscp_reset_channel"); |
appendMessagesClient("lscp_reset_channel"); |
398 |
else |
return false; |
399 |
appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID)); |
} |
400 |
|
|
401 |
|
appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID)); |
402 |
|
return true; |
403 |
|
} |
404 |
|
|
405 |
|
|
406 |
|
// Channel setup dialog form. |
407 |
|
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
408 |
|
{ |
409 |
|
bool bResult = false; |
410 |
|
|
411 |
|
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); |
412 |
|
if (pChannelForm) { |
413 |
|
pChannelForm->setup(this); |
414 |
|
bResult = pChannelForm->exec(); |
415 |
|
delete pChannelForm; |
416 |
|
} |
417 |
|
|
418 |
|
return bResult; |
419 |
} |
} |
420 |
|
|
421 |
|
|
422 |
// Redirected messages output methods. |
// Redirected messages output methods. |
423 |
void qsamplerChannel::appendMessages( const QString& s ) |
void qsamplerChannel::appendMessages( const QString& s ) |
424 |
{ |
{ |
425 |
m_pMainForm->appendMessages(s); |
if (m_pMainForm) m_pMainForm->appendMessages(s); |
426 |
} |
} |
427 |
|
|
428 |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
429 |
{ |
{ |
430 |
m_pMainForm->appendMessagesColor(s, c); |
if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c); |
431 |
} |
} |
432 |
|
|
433 |
void qsamplerChannel::appendMessagesText( const QString& s ) |
void qsamplerChannel::appendMessagesText( const QString& s ) |
434 |
{ |
{ |
435 |
m_pMainForm->appendMessagesText(s); |
if (m_pMainForm) m_pMainForm->appendMessagesText(s); |
436 |
} |
} |
437 |
|
|
438 |
void qsamplerChannel::appendMessagesError( const QString& s ) |
void qsamplerChannel::appendMessagesError( const QString& s ) |
439 |
{ |
{ |
440 |
m_pMainForm->appendMessagesError(s); |
if (m_pMainForm) m_pMainForm->appendMessagesError(s); |
441 |
} |
} |
442 |
|
|
443 |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
444 |
{ |
{ |
445 |
m_pMainForm->appendMessagesClient(s); |
if (m_pMainForm) m_pMainForm->appendMessagesClient(s); |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
|
// Context menu event handler. |
450 |
|
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
451 |
|
{ |
452 |
|
if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent); |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
|
// Retrieve the instrument list of a instrument file (.gig). |
457 |
|
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile ) |
458 |
|
{ |
459 |
|
QFileInfo fileinfo(sInstrumentFile); |
460 |
|
QString sInstrumentName = fileinfo.fileName(); |
461 |
|
QStringList instlist; |
462 |
|
|
463 |
|
if (fileinfo.exists()) { |
464 |
|
#ifdef CONFIG_LIBGIG |
465 |
|
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
466 |
|
gig::File *pGig = new gig::File(pRiff); |
467 |
|
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
468 |
|
while (pInstrument) { |
469 |
|
instlist.append((pInstrument->pInfo)->Name.c_str()); |
470 |
|
pInstrument = pGig->GetNextInstrument(); |
471 |
|
} |
472 |
|
delete pGig; |
473 |
|
delete pRiff; |
474 |
|
#else |
475 |
|
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
476 |
|
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
477 |
|
#endif |
478 |
|
} |
479 |
|
else instlist.append(sInstrumentName); |
480 |
|
|
481 |
|
return instlist; |
482 |
|
} |
483 |
|
|
484 |
|
|
485 |
|
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
486 |
|
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr ) |
487 |
|
{ |
488 |
|
QFileInfo fileinfo(sInstrumentFile); |
489 |
|
QString sInstrumentName = fileinfo.fileName(); |
490 |
|
|
491 |
|
if (fileinfo.exists()) { |
492 |
|
#ifdef CONFIG_LIBGIG |
493 |
|
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
494 |
|
gig::File *pGig = new gig::File(pRiff); |
495 |
|
int iIndex = 0; |
496 |
|
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
497 |
|
while (pInstrument) { |
498 |
|
if (iIndex == iInstrumentNr) { |
499 |
|
sInstrumentName = (pInstrument->pInfo)->Name.c_str(); |
500 |
|
break; |
501 |
|
} |
502 |
|
iIndex++; |
503 |
|
pInstrument = pGig->GetNextInstrument(); |
504 |
|
} |
505 |
|
delete pGig; |
506 |
|
delete pRiff; |
507 |
|
#else |
508 |
|
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
509 |
|
#endif |
510 |
|
} |
511 |
|
|
512 |
|
return sInstrumentName; |
513 |
} |
} |
514 |
|
|
515 |
|
|