Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove autosave files when user declines to restore from them #1962

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 44 additions & 25 deletions src/core/CoreActionController.cpp
Expand Up @@ -77,14 +77,16 @@ bool CoreActionController::setStripVolume( int nStrip, float fVolumeValue, bool

auto pInstr = getStrip( nStrip );
if ( pInstr != nullptr ) {


if ( pInstr->get_volume() != fVolumeValue ) {
pHydrogen->setIsModified( true );
}

pInstr->set_volume( fVolumeValue );

if ( bSelectStrip ) {
pHydrogen->setSelectedInstrumentNumber( nStrip );
}

pHydrogen->setIsModified( true );

return sendStripVolumeFeedback( nStrip );
}
Expand All @@ -108,10 +110,12 @@ bool CoreActionController::setMasterIsMuted( bool bIsMuted )
ERRORLOG( "no song set" );
return false;
}


if ( pSong->getIsMuted() != bIsMuted ) {
pHydrogen->setIsModified( true );
}

pSong->setIsMuted( bIsMuted );

pHydrogen->setIsModified( true );

return sendMasterIsMutedFeedback();
}
Expand All @@ -131,11 +135,13 @@ bool CoreActionController::setStripIsMuted( int nStrip, bool bIsMuted )
auto pHydrogen = Hydrogen::get_instance();
auto pInstr = getStrip( nStrip );
if ( pInstr != nullptr ) {
if ( pInstr->is_muted() != bIsMuted ) {
pHydrogen->setIsModified( true );
}

pInstr->set_muted( bIsMuted );

EventQueue::get_instance()->push_event( EVENT_INSTRUMENT_PARAMETERS_CHANGED, nStrip );

pHydrogen->setIsModified( true );

return sendStripIsMutedFeedback( nStrip );
}
Expand All @@ -153,17 +159,18 @@ bool CoreActionController::toggleStripIsSoloed( int nStrip )
return setStripIsSoloed( nStrip, !pInstr->is_soloed() );
}

bool CoreActionController::setStripIsSoloed( int nStrip, bool isSoloed )
bool CoreActionController::setStripIsSoloed( int nStrip, bool bIsSoloed )
{
auto pHydrogen = Hydrogen::get_instance();
auto pInstr = getStrip( nStrip );
if ( pInstr != nullptr ) {
if ( pInstr->is_soloed() != bIsSoloed ) {
pHydrogen->setIsModified( true );
}

pInstr->set_soloed( isSoloed );
pInstr->set_soloed( bIsSoloed );

EventQueue::get_instance()->push_event( EVENT_INSTRUMENT_PARAMETERS_CHANGED, nStrip );

pHydrogen->setIsModified( true );

return sendStripIsSoloedFeedback( nStrip );
}
Expand All @@ -176,13 +183,15 @@ bool CoreActionController::setStripPan( int nStrip, float fValue, bool bSelectSt
auto pHydrogen = Hydrogen::get_instance();
auto pInstr = getStrip( nStrip );
if ( pInstr != nullptr ) {


if ( pInstr->getPanWithRangeFrom0To1() != fValue ) {
pHydrogen->setIsModified( true );
}

pInstr->setPanWithRangeFrom0To1( fValue );

EventQueue::get_instance()->push_event( EVENT_INSTRUMENT_PARAMETERS_CHANGED, nStrip );

pHydrogen->setIsModified( true );

if ( bSelectStrip ) {
pHydrogen->setSelectedInstrumentNumber( nStrip );
}
Expand All @@ -199,13 +208,15 @@ bool CoreActionController::setStripPanSym( int nStrip, float fValue, bool bSelec
auto pHydrogen = Hydrogen::get_instance();
auto pInstr = getStrip( nStrip );
if ( pInstr != nullptr ) {


if ( pInstr->getPan() != fValue ) {
pHydrogen->setIsModified( true );
}

pInstr->setPan( fValue );

EventQueue::get_instance()->push_event( EVENT_INSTRUMENT_PARAMETERS_CHANGED, nStrip );

pHydrogen->setIsModified( true );


if ( bSelectStrip ) {
pHydrogen->setSelectedInstrumentNumber( nStrip );
}
Expand Down Expand Up @@ -526,6 +537,7 @@ bool CoreActionController::newSong( const QString& sSongPath ) {

bool CoreActionController::openSong( const QString& sSongPath, const QString& sRecoverSongPath ) {
auto pHydrogen = Hydrogen::get_instance();
bool bModified = false;

// Check whether the provided path is valid.
if ( !Filesystem::isSongPathValid( sSongPath, true ) ) {
Expand All @@ -540,6 +552,9 @@ bool CoreActionController::openSong( const QString& sSongPath, const QString& sR
if ( pSong != nullptr ) {
pSong->setFilename( sSongPath );
}
// The autosaved file we've just recovered counts as a modified version
// of the intended song.
bModified = true;
} else {
pSong = Song::load( sSongPath );
}
Expand All @@ -549,8 +564,10 @@ bool CoreActionController::openSong( const QString& sSongPath, const QString& sR
.arg( sSongPath ) );
return false;
}

return setSong( pSong );

setSong( pSong );
pSong->setIsModified( bModified );
return true;
}

bool CoreActionController::openSong( std::shared_ptr<Song> pSong ) {
Expand Down Expand Up @@ -1795,10 +1812,12 @@ void CoreActionController::setBpm( float fBpm ) {
pAudioEngine->setNextBpm( fBpm );
pAudioEngine->unlock();

// Store it's value in the .h2song file.
pHydrogen->getSong()->setBpm( fBpm );
if ( pHydrogen->getSong()->getBpm() != fBpm ) {
// Store it's value in the .h2song file.
pHydrogen->getSong()->setBpm( fBpm );

pHydrogen->setIsModified( true );
pHydrogen->setIsModified( true );
}

EventQueue::get_instance()->push_event( EVENT_TEMPO_CHANGED, -1 );
}
Expand Down
14 changes: 11 additions & 3 deletions src/gui/src/HydrogenApp.cpp
Expand Up @@ -425,14 +425,22 @@ bool HydrogenApp::openSong( QString sFilename ) {
// HydrogenApp was instantiated.
msgBox.setText( tr( "There are unsaved changes." ) );
msgBox.setInformativeText( tr( "Do you want to recover them?" ) );
msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::Discard );
msgBox.setDefaultButton( QMessageBox::Discard );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::Discard | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::No );
msgBox.setWindowTitle( "Hydrogen" );
msgBox.setIcon( QMessageBox::Question );
int nRet = msgBox.exec();

if ( nRet == QMessageBox::Discard ) {
switch ( nRet ) {
case QMessageBox::Discard: {
QFile file( sRecoverFilename );
file.remove();
sRecoverFilename = "";
break;
}
case QMessageBox::No:
sRecoverFilename = "";
break;
}
}

Expand Down
37 changes: 18 additions & 19 deletions src/gui/src/InstrumentEditor/InstrumentEditor.cpp
Expand Up @@ -599,11 +599,6 @@ void InstrumentEditor::updateSongEvent( int nValue ) {
if ( nValue == 0 ) {
updateComponentLabels();
selectedInstrumentChangedEvent();

// The function call above sets some spurious isModified when
// updating the states of the widgets. This has to be reset
// for a freshly loaded song.
H2Core::Hydrogen::get_instance()->setIsModified( false );
}
}

Expand Down Expand Up @@ -1376,9 +1371,9 @@ void InstrumentEditor::selectLayer( int nLayer )

void InstrumentEditor::muteGroupChanged( double fValue )
{
if ( m_pInstrument == nullptr ) {
return;
}
if ( m_pInstrument == nullptr ) {
return;
}

m_pInstrument->set_mute_group( static_cast<int>(fValue) );
selectedInstrumentChangedEvent(); // force an update
Expand All @@ -1387,23 +1382,27 @@ void InstrumentEditor::muteGroupChanged( double fValue )
void InstrumentEditor::onIsStopNoteCheckBoxClicked( bool on )
{
if ( m_pInstrument == nullptr ) {
return;
}
return;
}

m_pInstrument->set_stop_notes( on );
Hydrogen::get_instance()->setIsModified( true );
selectedInstrumentChangedEvent(); // force an update
if ( m_pInstrument->is_stop_notes() != on ) {
m_pInstrument->set_stop_notes( on );
Hydrogen::get_instance()->setIsModified( true );
selectedInstrumentChangedEvent(); // force an update
}
}

void InstrumentEditor::onIsApplyVelocityCheckBoxClicked( bool on )
{
if ( m_pInstrument == nullptr ) {
return;
}
if ( m_pInstrument == nullptr ) {
return;
}

m_pInstrument->set_apply_velocity( on );
Hydrogen::get_instance()->setIsModified( true );
selectedInstrumentChangedEvent(); // force an update
if ( m_pInstrument->get_apply_velocity() != on ) {
m_pInstrument->set_apply_velocity( on );
Hydrogen::get_instance()->setIsModified( true );
selectedInstrumentChangedEvent(); // force an update
}
}

void InstrumentEditor::midiOutChannelChanged( double fValue ) {
Expand Down
5 changes: 1 addition & 4 deletions src/gui/src/main.cpp
Expand Up @@ -630,11 +630,8 @@ int main(int argc, char *argv[])
pHydrogen->setIsModified( true );
}
else {
NsmClient::get_instance()->sendDirtyState( false );
pHydrogen->setIsModified( false );
NsmClient::get_instance()->sendDirtyState( pHydrogen->getIsModified() );
}
#else
pHydrogen->setIsModified( false );
#endif
}

Expand Down