Skip to content

Commit

Permalink
Save/Restore Export Dialog settings
Browse files Browse the repository at this point in the history
Filename / Dir is not saved/restored at the moment..
  • Loading branch information
mauser committed Jul 15, 2018
1 parent dcd3690 commit bc57598
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 54 deletions.
108 changes: 63 additions & 45 deletions src/gui/src/ExportSongDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ ExportSongDialog::ExportSongDialog(QWidget* parent)
: QDialog(parent)
, Object( __class_name )
, m_bExporting( false )
, m_pEngine( Hydrogen::get_instance() )
, m_pPreferences( Preferences::get_instance() )
{
setupUi( this );
setModal( true );
Expand All @@ -72,17 +74,21 @@ ExportSongDialog::ExportSongDialog(QWidget* parent)
exportTypeCombo->addItem(trUtf8("Both"));

HydrogenApp::get_instance()->addEventListener( this );
Hydrogen * pHydrogen = Hydrogen::get_instance();
Preferences *pPref = Preferences::get_instance();

m_pProgressBar->setValue( 0 );
sampleRateCombo->setCurrentIndex(1);
sampleDepthCombo->setCurrentIndex(1);

QString defaultFilename( pHydrogen->getSong()->get_filename() );

if( pHydrogen->getSong()->get_filename().isEmpty() ){
defaultFilename = pHydrogen->getSong()->__name;
/*
* Use a sane default filename / filepath
*
* 1. If the user exported a song before, use that directory again
* 2. If no song has been exported yet, use the path of the current song. If it has no path, then use our homedir.
*
*/

QString defaultFilename( m_pEngine->getSong()->get_filename() );

if( m_pEngine->getSong()->get_filename().isEmpty() ){
defaultFilename = m_pEngine->getSong()->__name;
}

defaultFilename.replace( '*', "_" );
Expand All @@ -98,24 +104,24 @@ ExportSongDialog::ExportSongDialog(QWidget* parent)

// use of rubberband batch
if(checkUseOfRubberband()){
m_bOldRubberbandBatchMode = pPref->getRubberBandBatchMode();
toggleRubberbandCheckBox->setChecked(pPref->getRubberBandBatchMode());
m_bOldRubberbandBatchMode = m_pPreferences->getRubberBandBatchMode();
toggleRubberbandCheckBox->setChecked(m_pPreferences->getRubberBandBatchMode());
connect(toggleRubberbandCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleRubberbandBatchMode( bool )));
}else
{
m_bOldRubberbandBatchMode = pPref->getRubberBandBatchMode();
m_bOldRubberbandBatchMode = m_pPreferences->getRubberBandBatchMode();
toggleRubberbandCheckBox->setEnabled( false );
}


// use of timeline
if( pHydrogen->getTimeline()->m_timelinevector.size() > 0 ){
toggleTimeLineBPMCheckBox->setChecked(pPref->getUseTimelineBpm());
m_bOldTimeLineBPMMode = pPref->getUseTimelineBpm();
if( m_pEngine->getTimeline()->m_timelinevector.size() > 0 ){
toggleTimeLineBPMCheckBox->setChecked(m_pPreferences->getUseTimelineBpm());
m_bOldTimeLineBPMMode = m_pPreferences->getUseTimelineBpm();
connect(toggleTimeLineBPMCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleTimeLineBPMMode( bool )));
}else
{
m_bOldTimeLineBPMMode = pPref->getUseTimelineBpm();
m_bOldTimeLineBPMMode = m_pPreferences->getUseTimelineBpm();
toggleTimeLineBPMCheckBox->setEnabled( false );
}

Expand All @@ -129,18 +135,34 @@ ExportSongDialog::ExportSongDialog(QWidget* parent)
if(m_bOldRubberbandBatchMode){
calculateRubberbandTime();
}

//Load the other settings..
restoreSettingsFromPreferences();

// Have the dialog find the best size
adjustSize();
}



ExportSongDialog::~ExportSongDialog()
{
HydrogenApp::get_instance()->removeEventListener( this );
}

void ExportSongDialog::saveSettingsToPreferences()
{
m_pPreferences->setExportMode( exportTypeCombo->currentIndex() );
m_pPreferences->setExportTemplate( templateCombo->currentIndex() );
m_pPreferences->setExportSampleRate( sampleRateCombo->currentIndex() );
m_pPreferences->setExportSampleDepth( sampleDepthCombo->currentIndex() );
}

void ExportSongDialog::restoreSettingsFromPreferences()
{
templateCombo->setCurrentIndex( m_pPreferences->getExportTemplate() );
exportTypeCombo->setCurrentIndex( m_pPreferences->getExportMode() );
sampleRateCombo->setCurrentIndex( m_pPreferences->getExportSampleRate() );
sampleDepthCombo->setCurrentIndex( m_pPreferences->getExportSampleDepth() );
}

void ExportSongDialog::on_browseBtn_clicked()
{
Expand Down Expand Up @@ -200,8 +222,9 @@ void ExportSongDialog::on_okBtn_clicked()
return;
}

Hydrogen *pEngine = Hydrogen::get_instance();
Song *pSong = pEngine->getSong();
saveSettingsToPreferences();

Song *pSong = m_pEngine->getSong();
InstrumentList *pInstrumentList = pSong->get_instrument_list();

m_bOverwriteFiles = false;
Expand Down Expand Up @@ -237,15 +260,15 @@ void ExportSongDialog::on_okBtn_clicked()
pInstrumentList->get(i)->set_currently_exported( true );
}

pEngine->startExportSession( sampleRateCombo->currentText().toInt(), sampleDepthCombo->currentText().toInt());
pEngine->startExportSong( filename );
m_pEngine->startExportSession( sampleRateCombo->currentText().toInt(), sampleDepthCombo->currentText().toInt());
m_pEngine->startExportSong( filename );

return;
}

if( exportTypeCombo->currentIndex() == EXPORT_TO_SEPARATE_TRACKS ){
m_bExportTrackouts = true;
pEngine->startExportSession(sampleRateCombo->currentText().toInt(), sampleDepthCombo->currentText().toInt());
m_pEngine->startExportSession(sampleRateCombo->currentText().toInt(), sampleDepthCombo->currentText().toInt());
exportTracks();
return;
}
Expand All @@ -254,8 +277,7 @@ void ExportSongDialog::on_okBtn_clicked()

bool ExportSongDialog::currentInstrumentHasNotes()
{
Hydrogen *pEngine = Hydrogen::get_instance();
Song *pSong = pEngine->getSong();
Song *pSong = m_pEngine->getSong();
unsigned nPatterns = pSong->get_pattern_list()->size();

bool bInstrumentHasNotes = false;
Expand All @@ -279,8 +301,7 @@ bool ExportSongDialog::currentInstrumentHasNotes()

QString ExportSongDialog::findUniqueExportFilenameForInstrument(Instrument* pInstrument)
{
Hydrogen *pEngine = Hydrogen::get_instance();
Song *pSong = pEngine->getSong();
Song *pSong = m_pEngine->getSong();
QString uniqueInstrumentName;

int instrumentOccurence = 0;
Expand All @@ -301,8 +322,7 @@ QString ExportSongDialog::findUniqueExportFilenameForInstrument(Instrument* pIns

void ExportSongDialog::exportTracks()
{
Hydrogen *pEngine = Hydrogen::get_instance();
Song *pSong = pEngine->getSong();
Song *pSong = m_pEngine->getSong();
InstrumentList *pInstrumentList = pSong->get_instrument_list();

if( m_nInstrument < pInstrumentList->size() ){
Expand Down Expand Up @@ -339,7 +359,7 @@ void ExportSongDialog::exportTracks()
}

if( m_nInstrument > 0 ){
pEngine->stopExportSong();
m_pEngine->stopExportSong();
m_bExporting = false;
}

Expand All @@ -349,7 +369,7 @@ void ExportSongDialog::exportTracks()

pSong->get_instrument_list()->get(m_nInstrument)->set_currently_exported( true );

pEngine->startExportSong( filename );
m_pEngine->startExportSong( filename );

if(! (m_nInstrument == pInstrumentList->size()) ){
m_nInstrument++;
Expand All @@ -361,16 +381,16 @@ void ExportSongDialog::exportTracks()
void ExportSongDialog::on_closeBtn_clicked()
{

Hydrogen::get_instance()->stopExportSong();
Hydrogen::get_instance()->stopExportSession();
m_pEngine->stopExportSong();
m_pEngine->stopExportSession();

m_bExporting = false;

if(Preferences::get_instance()->getRubberBandBatchMode()){
if(m_pPreferences->getRubberBandBatchMode()){
EventQueue::get_instance()->push_event( EVENT_RECALCULATERUBBERBAND, -1);
}
Preferences::get_instance()->setRubberBandBatchMode( m_bOldRubberbandBatchMode );
Preferences::get_instance()->setUseTimelineBpm( m_bOldTimeLineBPMMode );
m_pPreferences->setRubberBandBatchMode( m_bOldRubberbandBatchMode );
m_pPreferences->setUseTimelineBpm( m_bOldTimeLineBPMMode );
setResamplerMode(m_nOldInterpolation);
accept();

Expand Down Expand Up @@ -565,15 +585,15 @@ void ExportSongDialog::progressEvent( int nValue )

void ExportSongDialog::toggleRubberbandBatchMode(bool toggled)
{
Preferences::get_instance()->setRubberBandBatchMode(toggled);
m_pPreferences->setRubberBandBatchMode(toggled);
if(toggled){
calculateRubberbandTime();
}
}

void ExportSongDialog::toggleTimeLineBPMMode(bool toggled)
{
Preferences::get_instance()->setUseTimelineBpm(toggled);
m_pPreferences->setUseTimelineBpm(toggled);
}

void ExportSongDialog::resampleComboBoIndexChanged(int index )
Expand Down Expand Up @@ -610,10 +630,9 @@ void ExportSongDialog::calculateRubberbandTime()
resampleComboBox->setEnabled(false);
okBtn->setEnabled(false);

Hydrogen *pEngine = Hydrogen::get_instance();
Timeline* pTimeline = pEngine->getTimeline();
Timeline* pTimeline = m_pEngine->getTimeline();

float oldBPM = pEngine->getSong()->__bpm;
float oldBPM = m_pEngine->getSong()->__bpm;
float lowBPM = oldBPM;

if( pTimeline->m_timelinevector.size() >= 1 ){
Expand All @@ -625,10 +644,10 @@ void ExportSongDialog::calculateRubberbandTime()
}
}

pEngine->setBPM(lowBPM);
m_pEngine->setBPM(lowBPM);
time_t sTime = time(NULL);

Song *pSong = pEngine->getSong();
Song *pSong = m_pEngine->getSong();
assert(pSong);

if(pSong){
Expand Down Expand Up @@ -673,7 +692,7 @@ void ExportSongDialog::calculateRubberbandTime()

Preferences::get_instance()->setRubberBandCalcTime(time(NULL) - sTime);

pEngine->setBPM(oldBPM);
m_pEngine->setBPM(oldBPM);

closeBtn->setEnabled(true);
resampleComboBox->setEnabled(true);
Expand All @@ -683,8 +702,7 @@ void ExportSongDialog::calculateRubberbandTime()

bool ExportSongDialog::checkUseOfRubberband()
{
Hydrogen *pEngine = Hydrogen::get_instance();
Song *pSong = pEngine->getSong();
Song *pSong = m_pEngine->getSong();
assert(pSong);

if(pSong){
Expand Down
25 changes: 16 additions & 9 deletions src/gui/src/ExportSongDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

namespace H2Core {
class Instrument;
class Hydrogen;
class Preferences;
}

///
Expand Down Expand Up @@ -64,20 +66,25 @@ private slots:
void calculateRubberbandTime();
bool checkUseOfRubberband();

void saveSettingsToPreferences();
void restoreSettingsFromPreferences();

bool currentInstrumentHasNotes();
QString findUniqueExportFilenameForInstrument(H2Core::Instrument* pInstrument);

void exportTracks();

bool m_bExporting;
bool m_bExportTrackouts;
bool m_bOverwriteFiles;
uint m_nInstrument;
QString m_sExtension;
bool m_bOldRubberbandBatchMode;
bool m_bOldTimeLineBPMMode;
int m_nOldInterpolation;
bool m_bQfileDialog;
bool m_bExporting;
bool m_bExportTrackouts;
bool m_bOverwriteFiles;
uint m_nInstrument;
QString m_sExtension;
bool m_bOldRubberbandBatchMode;
bool m_bOldTimeLineBPMMode;
int m_nOldInterpolation;
bool m_bQfileDialog;
H2Core::Hydrogen * m_pEngine;
H2Core::Preferences* m_pPreferences;
};


Expand Down

0 comments on commit bc57598

Please sign in to comment.