1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
7 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
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 |
|
|
30 |
|
|
31 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
32 |
#include "gig.h" |
#include "gig.h" |
|
#else |
|
|
#define QSAMPLER_INSTRUMENT_MAX 10 |
|
33 |
#endif |
#endif |
34 |
|
|
35 |
|
#define QSAMPLER_INSTRUMENT_MAX 8 |
36 |
|
|
37 |
|
|
38 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
39 |
// qsamplerChannel - Sampler channel structure. |
// qsamplerChannel - Sampler channel structure. |
46 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
47 |
|
|
48 |
// m_sEngineName = QObject::tr("(No engine)"); |
// m_sEngineName = QObject::tr("(No engine)"); |
49 |
// m_sInstrumentFile = QObject::tr("(No instrument)"); |
// m_sInstrumentName = QObject::tr("(No instrument)"); |
50 |
|
// m_sInstrumentFile = m_sInstrumentName; |
51 |
m_iInstrumentNr = -1; |
m_iInstrumentNr = -1; |
52 |
m_iInstrumentStatus = -1; |
m_iInstrumentStatus = -1; |
53 |
m_sMidiDriver = "Alsa"; // DEPRECATED. |
m_sMidiDriver = "Alsa"; // DEPRECATED. |
170 |
} |
} |
171 |
|
|
172 |
|
|
173 |
|
// Instrument name accessor. |
174 |
|
QString& qsamplerChannel::instrumentName (void) |
175 |
|
{ |
176 |
|
return m_sInstrumentName; |
177 |
|
} |
178 |
|
|
179 |
// Instrument filename accessor. |
// Instrument filename accessor. |
180 |
QString& qsamplerChannel::instrumentFile (void) |
QString& qsamplerChannel::instrumentFile (void) |
181 |
{ |
{ |
205 |
return false; |
return false; |
206 |
} |
} |
207 |
|
|
208 |
|
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
209 |
m_sInstrumentFile = sInstrumentFile; |
m_sInstrumentFile = sInstrumentFile; |
210 |
m_iInstrumentNr = iInstrumentNr; |
m_iInstrumentNr = iInstrumentNr; |
211 |
m_iInstrumentStatus = 0; |
m_iInstrumentStatus = 0; |
375 |
return false; |
return false; |
376 |
} |
} |
377 |
|
|
378 |
// Cache in channel information. |
// First, check if intrument name has changed, |
379 |
|
// taking care that instrument name lookup might be expensive, |
380 |
|
// so we better make it only once and when really needed... |
381 |
|
if ((m_sInstrumentFile != pChannelInfo->instrument_file) || |
382 |
|
(m_iInstrumentNr != pChannelInfo->instrument_nr)) { |
383 |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
384 |
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
385 |
|
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
386 |
|
m_iInstrumentNr, (options() && options()->bInstrumentNames)); |
387 |
|
} |
388 |
|
// Cache in other channel information. |
389 |
m_sEngineName = pChannelInfo->engine_name; |
m_sEngineName = pChannelInfo->engine_name; |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
|
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
|
390 |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
391 |
m_iMidiDevice = pChannelInfo->midi_device; |
m_iMidiDevice = pChannelInfo->midi_device; |
392 |
m_iMidiPort = pChannelInfo->midi_port; |
m_iMidiPort = pChannelInfo->midi_port; |
396 |
// Some sanity checks. |
// Some sanity checks. |
397 |
if (m_sEngineName == "NONE") |
if (m_sEngineName == "NONE") |
398 |
m_sEngineName = QString::null; |
m_sEngineName = QString::null; |
399 |
if (m_sInstrumentFile == "NONE") |
if (m_sInstrumentFile == "NONE") { |
400 |
m_sInstrumentFile = QString::null; |
m_sInstrumentFile = QString::null; |
401 |
|
m_sInstrumentName = QString::null; |
402 |
|
} |
403 |
|
|
404 |
return true; |
return true; |
405 |
} |
} |
421 |
} |
} |
422 |
|
|
423 |
|
|
424 |
|
// Channel setup dialog form. |
425 |
|
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
426 |
|
{ |
427 |
|
bool bResult = false; |
428 |
|
|
429 |
|
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); |
430 |
|
if (pChannelForm) { |
431 |
|
pChannelForm->setup(this); |
432 |
|
bResult = pChannelForm->exec(); |
433 |
|
delete pChannelForm; |
434 |
|
} |
435 |
|
|
436 |
|
return bResult; |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
// Redirected messages output methods. |
// Redirected messages output methods. |
441 |
void qsamplerChannel::appendMessages( const QString& s ) |
void qsamplerChannel::appendMessages( const QString& s ) |
442 |
{ |
{ |
443 |
m_pMainForm->appendMessages(s); |
if (m_pMainForm) m_pMainForm->appendMessages(s); |
444 |
} |
} |
445 |
|
|
446 |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
447 |
{ |
{ |
448 |
m_pMainForm->appendMessagesColor(s, c); |
if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c); |
449 |
} |
} |
450 |
|
|
451 |
void qsamplerChannel::appendMessagesText( const QString& s ) |
void qsamplerChannel::appendMessagesText( const QString& s ) |
452 |
{ |
{ |
453 |
m_pMainForm->appendMessagesText(s); |
if (m_pMainForm) m_pMainForm->appendMessagesText(s); |
454 |
} |
} |
455 |
|
|
456 |
void qsamplerChannel::appendMessagesError( const QString& s ) |
void qsamplerChannel::appendMessagesError( const QString& s ) |
457 |
{ |
{ |
458 |
m_pMainForm->appendMessagesError(s); |
if (m_pMainForm) m_pMainForm->appendMessagesError(s); |
459 |
} |
} |
460 |
|
|
461 |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
462 |
{ |
{ |
463 |
m_pMainForm->appendMessagesClient(s); |
if (m_pMainForm) m_pMainForm->appendMessagesClient(s); |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
|
// Context menu event handler. |
468 |
|
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
469 |
|
{ |
470 |
|
if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent); |
471 |
} |
} |
472 |
|
|
473 |
|
|
474 |
// Retrieve the instrument list of a instrument file (.gig). |
// Retrieve the instrument list of a instrument file (.gig). |
475 |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile ) |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
476 |
|
bool bInstrumentNames ) |
477 |
{ |
{ |
478 |
QFileInfo fileinfo(sInstrumentFile); |
QFileInfo fileinfo(sInstrumentFile); |
479 |
QString sInstrumentName = fileinfo.fileName(); |
QString sInstrumentName = fileinfo.fileName(); |
481 |
|
|
482 |
if (fileinfo.exists()) { |
if (fileinfo.exists()) { |
483 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
484 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
if (bInstrumentNames) { |
485 |
gig::File *pGig = new gig::File(pRiff); |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
486 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::File *pGig = new gig::File(pRiff); |
487 |
while (pInstrument) { |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
488 |
sInstrumentName = (pInstrument->pInfo)->Name; |
while (pInstrument) { |
489 |
instlist.append(sInstrumentName); |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
490 |
pInstrument = pGig->GetNextInstrument(); |
pInstrument = pGig->GetNextInstrument(); |
491 |
} |
} |
492 |
delete pGig; |
delete pGig; |
493 |
delete pRiff; |
delete pRiff; |
494 |
#else |
} |
495 |
|
else |
496 |
|
#endif |
497 |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
498 |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
|
#endif |
|
499 |
} |
} |
500 |
else instlist.append(sInstrumentName); |
else instlist.append(sInstrumentName); |
501 |
|
|
502 |
return instlist; |
return instlist; |
503 |
} |
} |
504 |
|
|
505 |
|
|
506 |
// 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. |
507 |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr ) |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
508 |
|
int iInstrumentNr, bool bInstrumentNames ) |
509 |
{ |
{ |
510 |
QFileInfo fileinfo(sInstrumentFile); |
QFileInfo fileinfo(sInstrumentFile); |
511 |
QString sInstrumentName = fileinfo.fileName(); |
QString sInstrumentName = fileinfo.fileName(); |
512 |
|
|
513 |
if (fileinfo.exists()) { |
if (fileinfo.exists()) { |
514 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
515 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
if (bInstrumentNames) { |
516 |
gig::File *pGig = new gig::File(pRiff); |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
517 |
int iIndex = 0; |
gig::File *pGig = new gig::File(pRiff); |
518 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
int iIndex = 0; |
519 |
while (pInstrument) { |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
520 |
if (iIndex == iInstrumentNr) { |
while (pInstrument) { |
521 |
sInstrumentName = (pInstrument->pInfo)->Name; |
if (iIndex == iInstrumentNr) { |
522 |
break; |
sInstrumentName = (pInstrument->pInfo)->Name.c_str(); |
523 |
} |
break; |
524 |
iIndex++; |
} |
525 |
pInstrument = pGig->GetNextInstrument(); |
iIndex++; |
526 |
} |
pInstrument = pGig->GetNextInstrument(); |
527 |
delete pGig; |
} |
528 |
delete pRiff; |
delete pGig; |
529 |
#else |
delete pRiff; |
530 |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
} |
531 |
|
else |
532 |
#endif |
#endif |
533 |
|
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
534 |
} |
} |
535 |
|
|
536 |
return sInstrumentName; |
return sInstrumentName; |