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 |
|
|
29 |
|
#include <qfileinfo.h> |
30 |
|
|
31 |
|
#ifdef CONFIG_LIBGIG |
32 |
|
#include "gig.h" |
33 |
|
#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. |
182 |
return m_iInstrumentNr; |
return m_iInstrumentNr; |
183 |
} |
} |
184 |
|
|
185 |
|
// Instrument name accessor. |
186 |
|
QString& qsamplerChannel::instrumentName (void) |
187 |
|
{ |
188 |
|
return m_sInstrumentName; |
189 |
|
} |
190 |
|
|
191 |
// Instrument status accessor. |
// Instrument status accessor. |
192 |
int qsamplerChannel::instrumentStatus (void) |
int qsamplerChannel::instrumentStatus (void) |
193 |
{ |
{ |
207 |
|
|
208 |
m_sInstrumentFile = sInstrumentFile; |
m_sInstrumentFile = sInstrumentFile; |
209 |
m_iInstrumentNr = iInstrumentNr; |
m_iInstrumentNr = iInstrumentNr; |
210 |
|
#ifdef CONFIG_INSTRUMENT_NAME |
211 |
|
m_sInstrumentName = QString::null; // We'll get it later on channel_info... |
212 |
|
#else |
213 |
|
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
214 |
|
#endif |
215 |
m_iInstrumentStatus = 0; |
m_iInstrumentStatus = 0; |
216 |
|
|
217 |
return true; |
return true; |
365 |
} |
} |
366 |
|
|
367 |
|
|
368 |
|
// Istrument name remapper. |
369 |
|
void qsamplerChannel::updateInstrumentName (void) |
370 |
|
{ |
371 |
|
#ifndef CONFIG_INSTRUMENT_NAME |
372 |
|
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
373 |
|
m_iInstrumentNr, (options() && options()->bInstrumentNames)); |
374 |
|
#endif |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
// Update whole channel info state. |
// Update whole channel info state. |
379 |
bool qsamplerChannel::updateChannelInfo (void) |
bool qsamplerChannel::updateChannelInfo (void) |
380 |
{ |
{ |
389 |
return false; |
return false; |
390 |
} |
} |
391 |
|
|
392 |
// Cache in channel information. |
#ifdef CONFIG_INSTRUMENT_NAME |
393 |
|
// We got all actual instrument datum... |
394 |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
395 |
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
396 |
|
m_sInstrumentName = pChannelInfo->instrument_name; |
397 |
|
#else |
398 |
|
// First, check if intrument name has changed, |
399 |
|
// taking care that instrument name lookup might be expensive, |
400 |
|
// so we better make it only once and when really needed... |
401 |
|
if ((m_sInstrumentFile != pChannelInfo->instrument_file) || |
402 |
|
(m_iInstrumentNr != pChannelInfo->instrument_nr)) { |
403 |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
404 |
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
405 |
|
updateInstrumentName(); |
406 |
|
} |
407 |
|
#endif |
408 |
|
// Cache in other channel information. |
409 |
m_sEngineName = pChannelInfo->engine_name; |
m_sEngineName = pChannelInfo->engine_name; |
|
m_sInstrumentFile = pChannelInfo->instrument_file; |
|
|
m_iInstrumentNr = pChannelInfo->instrument_nr; |
|
410 |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
m_iInstrumentStatus = pChannelInfo->instrument_status; |
411 |
m_iMidiDevice = pChannelInfo->midi_device; |
m_iMidiDevice = pChannelInfo->midi_device; |
412 |
m_iMidiPort = pChannelInfo->midi_port; |
m_iMidiPort = pChannelInfo->midi_port; |
416 |
// Some sanity checks. |
// Some sanity checks. |
417 |
if (m_sEngineName == "NONE") |
if (m_sEngineName == "NONE") |
418 |
m_sEngineName = QString::null; |
m_sEngineName = QString::null; |
419 |
if (m_sInstrumentFile == "NONE") |
if (m_sInstrumentFile == "NONE") { |
420 |
m_sInstrumentFile = QString::null; |
m_sInstrumentFile = QString::null; |
421 |
|
m_sInstrumentName = QString::null; |
422 |
|
} |
423 |
|
|
424 |
return true; |
return true; |
425 |
} |
} |
441 |
} |
} |
442 |
|
|
443 |
|
|
444 |
|
// Channel setup dialog form. |
445 |
|
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
446 |
|
{ |
447 |
|
bool bResult = false; |
448 |
|
|
449 |
|
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); |
450 |
|
if (pChannelForm) { |
451 |
|
pChannelForm->setup(this); |
452 |
|
bResult = pChannelForm->exec(); |
453 |
|
delete pChannelForm; |
454 |
|
} |
455 |
|
|
456 |
|
return bResult; |
457 |
|
} |
458 |
|
|
459 |
|
|
460 |
// Redirected messages output methods. |
// Redirected messages output methods. |
461 |
void qsamplerChannel::appendMessages( const QString& s ) |
void qsamplerChannel::appendMessages( const QString& s ) |
462 |
{ |
{ |
463 |
m_pMainForm->appendMessages(s); |
if (m_pMainForm) m_pMainForm->appendMessages(s); |
464 |
} |
} |
465 |
|
|
466 |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) |
467 |
{ |
{ |
468 |
m_pMainForm->appendMessagesColor(s, c); |
if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c); |
469 |
} |
} |
470 |
|
|
471 |
void qsamplerChannel::appendMessagesText( const QString& s ) |
void qsamplerChannel::appendMessagesText( const QString& s ) |
472 |
{ |
{ |
473 |
m_pMainForm->appendMessagesText(s); |
if (m_pMainForm) m_pMainForm->appendMessagesText(s); |
474 |
} |
} |
475 |
|
|
476 |
void qsamplerChannel::appendMessagesError( const QString& s ) |
void qsamplerChannel::appendMessagesError( const QString& s ) |
477 |
{ |
{ |
478 |
m_pMainForm->appendMessagesError(s); |
if (m_pMainForm) m_pMainForm->appendMessagesError(s); |
479 |
} |
} |
480 |
|
|
481 |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
void qsamplerChannel::appendMessagesClient( const QString& s ) |
482 |
{ |
{ |
483 |
m_pMainForm->appendMessagesClient(s); |
if (m_pMainForm) m_pMainForm->appendMessagesClient(s); |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
|
// Context menu event handler. |
488 |
|
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
489 |
|
{ |
490 |
|
if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent); |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
|
// Retrieve the instrument list of a instrument file (.gig). |
495 |
|
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
496 |
|
bool bInstrumentNames ) |
497 |
|
{ |
498 |
|
QFileInfo fileinfo(sInstrumentFile); |
499 |
|
QString sInstrumentName = fileinfo.fileName(); |
500 |
|
QStringList instlist; |
501 |
|
|
502 |
|
if (fileinfo.exists()) { |
503 |
|
#ifdef CONFIG_LIBGIG |
504 |
|
if (bInstrumentNames) { |
505 |
|
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
506 |
|
gig::File *pGig = new gig::File(pRiff); |
507 |
|
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
508 |
|
while (pInstrument) { |
509 |
|
instlist.append((pInstrument->pInfo)->Name.c_str()); |
510 |
|
pInstrument = pGig->GetNextInstrument(); |
511 |
|
} |
512 |
|
delete pGig; |
513 |
|
delete pRiff; |
514 |
|
} |
515 |
|
else |
516 |
|
#endif |
517 |
|
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
518 |
|
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
519 |
|
} |
520 |
|
else instlist.append(sInstrumentName); |
521 |
|
|
522 |
|
return instlist; |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
527 |
|
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
528 |
|
int iInstrumentNr, bool bInstrumentNames ) |
529 |
|
{ |
530 |
|
QFileInfo fileinfo(sInstrumentFile); |
531 |
|
QString sInstrumentName = fileinfo.fileName(); |
532 |
|
|
533 |
|
if (fileinfo.exists()) { |
534 |
|
#ifdef CONFIG_LIBGIG |
535 |
|
if (bInstrumentNames) { |
536 |
|
RIFF::File *pRiff = new RIFF::File(sInstrumentFile); |
537 |
|
gig::File *pGig = new gig::File(pRiff); |
538 |
|
int iIndex = 0; |
539 |
|
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
540 |
|
while (pInstrument) { |
541 |
|
if (iIndex == iInstrumentNr) { |
542 |
|
sInstrumentName = (pInstrument->pInfo)->Name.c_str(); |
543 |
|
break; |
544 |
|
} |
545 |
|
iIndex++; |
546 |
|
pInstrument = pGig->GetNextInstrument(); |
547 |
|
} |
548 |
|
delete pGig; |
549 |
|
delete pRiff; |
550 |
|
} |
551 |
|
else |
552 |
|
#endif |
553 |
|
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
554 |
|
} |
555 |
|
|
556 |
|
return sInstrumentName; |
557 |
} |
} |
558 |
|
|
559 |
|
|