Skip to content

Commit

Permalink
Add "Song has been modified" indicator to the window title
Browse files Browse the repository at this point in the history
  • Loading branch information
mauser committed Oct 4, 2015
1 parent 265ce38 commit f1df665
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 93 deletions.
2 changes: 2 additions & 0 deletions src/core/include/hydrogen/basics/song.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class Song : public H2Core::Object
__song_mode = mode;
}

void set_is_modified(bool is_modified);

std::vector<DrumkitComponent*>* get_components() {
return __components;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/include/hydrogen/event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ enum EventType {
EVENT_PROGRESS,
EVENT_JACK_SESSION,
EVENT_PLAYLIST_LOADSONG,
EVENT_UNDO_REDO
EVENT_UNDO_REDO,
EVENT_SONG_MODIFIED
};


Expand Down
17 changes: 15 additions & 2 deletions src/core/src/basics/song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

#include <cassert>

#include <hydrogen/basics/adsr.h>

#include <hydrogen/LocalFileMng.h>
#include <hydrogen/Preferences.h>

#include <hydrogen/event_queue.h>
#include <hydrogen/fx/Effects.h>
#include <hydrogen/globals.h>
#include <hydrogen/timeline.h>
Expand Down Expand Up @@ -219,6 +219,19 @@ void Song::set_swing_factor( float factor )
__swing_factor = factor;
}

void Song::set_is_modified(bool is_modified){
bool Notify = false;

if(__is_modified != is_modified){
Notify = true;
}

__is_modified = is_modified;

if(Notify){
EventQueue::get_instance()->push_event( EVENT_SONG_MODIFIED, -1 );
}
}

void Song::readTempPatternList( QString filename )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/hydrogen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ void Hydrogen::removeInstrument( int instrumentnumber, bool conditional )
// delete the instrument from the instruments list
AudioEngine::get_instance()->lock( RIGHT_HERE );
getSong()->get_instrument_list()->del( instrumentnumber );
getSong()->__is_modified = true;
getSong()->set_is_modified( true );
AudioEngine::get_instance()->unlock();

// At this point the instrument has been removed from both the
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/local_file_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ int SongWriter::writeSong( Song *song, const QString& filename )
if( rv ) {
WARNINGLOG("File save reported an error.");
} else {
song->__is_modified = false;
song->set_is_modified( false );
INFOLOG("Save was successful.");
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/src/sampler/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ void Sampler::setPlayingNotelength( Instrument* instrument, unsigned long ticks,
if ( ticks > patternsize )
ticks = patternsize - noteOnTick;
pNote->set_length( ticks );
Hydrogen::get_instance()->getSong()->__is_modified = true;
Hydrogen::get_instance()->getSong()->set_is_modified( true );
AudioEngine::get_instance()->unlock(); // unlock the audio engine
}
}else
Expand All @@ -915,7 +915,7 @@ void Sampler::setPlayingNotelength( Instrument* instrument, unsigned long ticks,
if ( ticks > patternsize )
ticks = patternsize - noteOnTick;
pNote->set_length( ticks );
Hydrogen::get_instance()->getSong()->__is_modified = true;
Hydrogen::get_instance()->getSong()->set_is_modified( true );
AudioEngine::get_instance()->unlock(); // unlock the audio engine
}
}
Expand All @@ -924,6 +924,7 @@ void Sampler::setPlayingNotelength( Instrument* instrument, unsigned long ticks,
}
}
}

EventQueue::get_instance()->push_event( EVENT_PATTERN_MODIFIED, -1 );
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/src/EventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class EventListener
virtual void stateChangedEvent(int nState) { UNUSED( nState ); }
virtual void patternChangedEvent() {}
virtual void patternModifiedEvent() {}
virtual void songModifiedEvent() {}
virtual void selectedPatternChangedEvent() {}
virtual void selectedInstrumentChangedEvent() {}
virtual void midiActivityEvent() {}
Expand Down
47 changes: 32 additions & 15 deletions src/gui/src/HydrogenApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,7 @@ HydrogenApp::HydrogenApp( MainForm *pMainForm, Song *pFirstSong )
//setup the undo stack
m_undoStack = new QUndoStack( this );

// set initial title
QString qsSongName( pFirstSong->__name );
if( qsSongName == "Untitled Song" && !pFirstSong->get_filename().isEmpty() ){
qsSongName = pFirstSong->get_filename();
qsSongName = qsSongName.section( '/', -1 );
}

setWindowTitle( qsSongName );
setWindowTitle();

Preferences *pPref = Preferences::get_instance();

Expand Down Expand Up @@ -321,12 +314,7 @@ void HydrogenApp::setSong(Song* song)
m_pSongEditorPanel->updateAll();
m_pPatternEditorPanel->updateSLnameLabel();

QString songName( song->__name );
if( songName == "Untitled Song" && !song->get_filename().isEmpty() ){
songName = song->get_filename();
songName = songName.section( '/', -1 );
}
setWindowTitle( songName );
setWindowTitle();

m_pMainForm->updateRecentUsedSongList();
}
Expand Down Expand Up @@ -385,7 +373,28 @@ void HydrogenApp::setStatusBarMessage( const QString& msg, int msec )
getPlayerControl()->showMessage( msg, msec );
}

void HydrogenApp::setWindowTitle( const QString& title){
void HydrogenApp::setWindowTitle()
{
Song *pSong = Hydrogen::get_instance()->getSong();
assert(pSong);

QString title;

// special handling for initial title
QString qsSongName( pSong->__name );

if( qsSongName == "Untitled Song" && !pSong->get_filename().isEmpty() ){
qsSongName = qsSongName.section( '/', -1 );
} else {
qsSongName = pSong->get_filename();
}

if(pSong->__is_modified){
title = qsSongName + " (" + QString(trUtf8("modified")) + ")";
} else {
title = qsSongName;
}

m_pMainForm->setWindowTitle( ( "Hydrogen " + QString( get_version().c_str()) + QString( " - " ) + title ) );
}

Expand Down Expand Up @@ -485,6 +494,10 @@ void HydrogenApp::enableDestructiveRecMode(){
m_pPatternEditorPanel->displayorHidePrePostCB();
}

void HydrogenApp::songModifiedEvent()
{
setWindowTitle();
}

void HydrogenApp::onEventQueueTimer()
{
Expand All @@ -509,6 +522,10 @@ void HydrogenApp::onEventQueueTimer()
pListener->patternModifiedEvent();
break;

case EVENT_SONG_MODIFIED:
songModifiedEvent();
break;

case EVENT_SELECTED_PATTERN_CHANGED:
pListener->selectedPatternChangedEvent();
break;
Expand Down
5 changes: 3 additions & 2 deletions src/gui/src/HydrogenApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class HydrogenApp : public QObject, public H2Core::Object

void setStatusBarMessage( const QString& msg, int msec = 0 );
void setScrollStatusBarMessage( const QString& msg, int msec = 0, bool test = true );
void setWindowTitle( const QString& title);
void setWindowTitle();

#ifdef H2CORE_HAVE_LADSPA
LadspaFXProperties* getLadspaFXProperties(uint nFX) { return m_pLadspaFXProperties[nFX]; }
Expand All @@ -116,6 +116,7 @@ class HydrogenApp : public QObject, public H2Core::Object
void onEventQueueTimer();
void currentTabChanged(int);


private:
static HydrogenApp *m_pInstance; ///< HydrogenApp instance

Expand All @@ -142,8 +143,8 @@ class HydrogenApp : public QObject, public H2Core::Object
// implement EngineListener interface
void engineError(uint nErrorCode);

//void setupTopLevelInterface();
void setupSinglePanedInterface();
virtual void songModifiedEvent();
void showInfoSplash();
};

Expand Down
4 changes: 2 additions & 2 deletions src/gui/src/LadspaFXProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void LadspaFXProperties::faderChanged( Fader * ref )
m_pInputControlLabel[ i ]->setText( sValue );
}
}
pSong->__is_modified = true;
pSong->set_is_modified( true );
#endif
}

Expand Down Expand Up @@ -364,7 +364,7 @@ void LadspaFXProperties::selectFXBtnClicked()
}
}
Song *pSong = (Hydrogen::get_instance() )->getSong();
pSong->__is_modified = true;
pSong->set_is_modified(true);

Effects::get_instance()->setLadspaFX( pFX, m_nLadspaFX );

Expand Down
17 changes: 8 additions & 9 deletions src/gui/src/MainForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void MainForm::action_file_save_as()
action_file_save();
}
h2app->setScrollStatusBarMessage( trUtf8("Song saved as.") + QString(" Into: ") + defaultFilename, 2000 );
h2app->setWindowTitle( filename );
h2app->setWindowTitle();
}


Expand Down Expand Up @@ -709,11 +709,11 @@ void MainForm::action_file_open() {
void MainForm::action_file_openPattern()
{

Hydrogen *engine = Hydrogen::get_instance();
Song *song = engine->getSong();
PatternList *pPatternList = song->get_pattern_list();
Hydrogen *pEngine = Hydrogen::get_instance();
Song *pSong = pEngine->getSong();
PatternList *pPatternList = pSong->get_pattern_list();

Instrument *instr = song->get_instrument_list()->get ( 0 );
Instrument *instr = pSong->get_instrument_list()->get ( 0 );
assert ( instr );

QDir dirPattern( Preferences::get_instance()->getDataDirectory() + "/patterns" );
Expand All @@ -732,8 +732,6 @@ void MainForm::action_file_openPattern()
}
QString patternname = filename;


LocalFileMng mng;
LocalFileMng fileMng;
Pattern* err = fileMng.loadPattern ( patternname );
if ( err == 0 )
Expand All @@ -745,7 +743,8 @@ void MainForm::action_file_openPattern()
{
H2Core::Pattern *pNewPattern = err;
pPatternList->add ( pNewPattern );
song->__is_modified = true;
pSong->set_is_modified( true );
EventQueue::get_instance()->push_event( EVENT_SONG_MODIFIED, -1 );
}

HydrogenApp::get_instance()->getSongEditorPanel()->updateAll();
Expand Down Expand Up @@ -1519,7 +1518,7 @@ void MainForm::action_file_songProperties()
{
SongPropertiesDialog *pDialog = new SongPropertiesDialog( this );
if ( pDialog->exec() == QDialog::Accepted ) {
Hydrogen::get_instance()->getSong()->__is_modified = true;
Hydrogen::get_instance()->getSong()->set_is_modified( true );
}
delete pDialog;
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/src/Mixer/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ void Mixer::ladspaEditBtnClicked( LadspaFXMixerLine *ref )
HydrogenApp::get_instance()->getLadspaFXProperties(nFX)->show();
}
}
Hydrogen::get_instance()->getSong()->__is_modified = true;
Hydrogen::get_instance()->getSong()->set_is_modified( true );
#endif
}

Expand All @@ -923,7 +923,7 @@ void Mixer::ladspaVolumeChanged( LadspaFXMixerLine* ref)
{
#ifdef H2CORE_HAVE_LADSPA
Song *pSong = (Hydrogen::get_instance() )->getSong();
pSong->__is_modified = true;
pSong->set_is_modified( true );

for (uint nFX = 0; nFX < MAX_FX; nFX++) {
if (ref == m_pLadspaFXLine[ nFX ] ) {
Expand Down
Loading

0 comments on commit f1df665

Please sign in to comment.