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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 44 additions & 25 deletions src/core/CoreActionController.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
41 changes: 28 additions & 13 deletions src/gui/src/Mixer/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,26 @@ void Mixer::muteClicked(ComponentMixerLine* ref)
bool isMuteClicked = ref->isMuteClicked();

auto pCompo = pSong->getDrumkit()->getComponent( ref->getComponentID() );

pCompo->set_muted( isMuteClicked );
Hydrogen::get_instance()->setIsModified( true );
if ( isMuteClicked != pCompo->is_muted() ) {
pCompo->set_muted( isMuteClicked );
Hydrogen::get_instance()->setIsModified( true );
}
}

void Mixer::soloClicked(ComponentMixerLine* ref)
{
auto pSong = Hydrogen::get_instance()->getSong();
bool isSoloClicked = ref->isSoloClicked();
int nLine = findCompoMixerLineByRef(ref);

ComponentMixerLine* pComponentMixerLine = m_pComponentMixerLine[nLine];

pComponentMixerLine->setSoloClicked( isSoloClicked );
Hydrogen::get_instance()->setIsModified( true );
auto pCompo = pSong->getDrumkit()->getComponent( ref->getComponentID() );

if ( isSoloClicked != pCompo->is_soloed() ) {
pCompo->set_soloed( isSoloClicked );
pComponentMixerLine->setSoloClicked( isSoloClicked );
Hydrogen::get_instance()->setIsModified( true );
}
}

void Mixer::volumeChanged(ComponentMixerLine* ref)
Expand All @@ -255,8 +261,10 @@ void Mixer::volumeChanged(ComponentMixerLine* ref)

auto pCompo = pSong->getDrumkit()->getComponent( ref->getComponentID() );

pCompo->set_volume( newVolume );
Hydrogen::get_instance()->setIsModified( true );
if ( newVolume != pCompo->get_volume() ) {
pCompo->set_volume( newVolume );
Hydrogen::get_instance()->setIsModified( true );
}
}

void Mixer::soloClicked(MixerLine* ref)
Expand Down Expand Up @@ -737,9 +745,14 @@ void Mixer::knobChanged(MixerLine* ref, int nKnob) {
ERRORLOG( "No instrument selected" );
return;
}
float fLevel = ref->getFXLevel(nKnob);

if ( pSelectedInstrument->get_fx_level( nKnob) != fLevel ) {
pSelectedInstrument->set_fx_level( fLevel, nKnob );

pHydrogen->setIsModified( true );
}

pSelectedInstrument->set_fx_level( ref->getFXLevel(nKnob), nKnob );

QString sMessage = tr( "Set FX %1 level [%2] of instrument" )
.arg( nKnob )
.arg( ref->getFXLevel(nKnob), 0, 'f', 2 );
Expand All @@ -751,7 +764,6 @@ void Mixer::knobChanged(MixerLine* ref, int nKnob) {
( HydrogenApp::get_instance() )->
showStatusBarMessage( sMessage, sCaller );

pHydrogen->setIsModified( true );
}


Expand Down Expand Up @@ -847,7 +859,11 @@ void Mixer::ladspaVolumeChanged( LadspaFXMixerLine* ref)
if (ref == m_pLadspaFXLine[ nFX ] ) {
LadspaFX *pFX = Effects::get_instance()->getLadspaFX(nFX);
if ( pFX != nullptr ) {
pFX->setVolume( ref->getVolume() );
float fVolume = ref->getVolume();
if ( pFX->getVolume() != fVolume ) {
pFX->setVolume( fVolume );
Hydrogen::get_instance()->setIsModified( true );
}

QString sMessage = tr( "Set volume [%1] of FX" )
.arg( ref->getVolume(), 0, 'f', 2 );
Expand All @@ -858,7 +874,6 @@ void Mixer::ladspaVolumeChanged( LadspaFXMixerLine* ref)
HydrogenApp::get_instance()->
showStatusBarMessage( sMessage, sCaller );

Hydrogen::get_instance()->setIsModified( true );
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/gui/src/Mixer/MixerLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,17 @@ void MixerLine::updateMixerLine()
}

void MixerLine::muteBtnClicked() {
Hydrogen::get_instance()->setIsModified( true );
emit muteBtnClicked(this);
}

void MixerLine::soloBtnClicked() {
Hydrogen::get_instance()->setIsModified( true );
emit soloBtnClicked(this);
}

void MixerLine::faderChanged( WidgetWithInput *pRef ) {

assert( pRef );

Hydrogen::get_instance()->setIsModified( true );

emit volumeChanged(this);

WidgetWithInput* pFader = static_cast<Fader*>( pRef );
Expand Down Expand Up @@ -495,8 +492,7 @@ void ComponentMixerLine::soloBtnClicked() {
void ComponentMixerLine::faderChanged( WidgetWithInput *pRef ) {

assert( pRef );

Hydrogen::get_instance()->setIsModified( true );

emit volumeChanged(this);

WidgetWithInput* pFader = static_cast<Fader*>( pRef );
Expand Down Expand Up @@ -684,8 +680,6 @@ void MasterMixerLine::faderChanged( WidgetWithInput *pRef )

emit volumeChanged(this);

Hydrogen::get_instance()->setIsModified( true );

double value = (double) pFader->getValue();
( HydrogenApp::get_instance() )->
showStatusBarMessage( tr( "Set master volume [%1]" )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/Mixer/MixerLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MixerLine: public PixmapWidget, public H2Core::Object<MixerLine>
void setSoloClicked(bool isClicked);

float getVolume();
void setVolume(float value);
void setVolume( float value );

void setPeak_L( float peak );
float getPeak_L();
Expand Down
Loading