From 676a98c17e2727fe9719605ff02c67529de2c019 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 4 Mar 2012 18:02:01 -0800 Subject: [PATCH] Mixer: Implement NSM dirtiness notification. --- mixer/src/Mixer.C | 15 +++++++++++++++ mixer/src/Mixer.H | 2 ++ mixer/src/Project.C | 4 ++-- mixer/src/main.C | 2 +- nonlib/Loggable.C | 13 ++++++++++--- nonlib/Loggable.H | 11 ++++++++++- session-manager/src/nsmd.C | 15 +++++++++++++++ 7 files changed, 55 insertions(+), 7 deletions(-) diff --git a/mixer/src/Mixer.C b/mixer/src/Mixer.C index 25bf57a..ca3f6f6 100644 --- a/mixer/src/Mixer.C +++ b/mixer/src/Mixer.C @@ -382,6 +382,8 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) : Fl::scheme( "plastic" ); color_scheme( "dark" ); + Loggable::dirty_callback( &Mixer::handle_dirty, this ); + _rows = 1; box( FL_NO_BOX ); labelsize( 96 ); @@ -668,6 +670,19 @@ Mixer::get_unique_track_name ( const char *name ) return strdup( pat ); } +void +Mixer::handle_dirty ( int d, void *v ) +{ + //Mixer *m = (Mixer*)v; + if ( !nsm ) + return; + + if ( d == 1 ) + nsm->is_dirty(); + else if ( d == 0 ) + nsm->is_clean(); +} + void Mixer::snapshot ( void ) diff --git a/mixer/src/Mixer.H b/mixer/src/Mixer.H index 338b527..1df1b28 100644 --- a/mixer/src/Mixer.H +++ b/mixer/src/Mixer.H @@ -67,6 +67,8 @@ private: void redraw_windows ( void ); + static void handle_dirty ( int, void *v ); + protected: int handle ( int m ); diff --git a/mixer/src/Project.C b/mixer/src/Project.C index 195c90d..608bfbd 100644 --- a/mixer/src/Project.C +++ b/mixer/src/Project.C @@ -174,7 +174,7 @@ Project::save ( void ) int r = mixer->save(); - Loggable::clear_dirty(); +// Loggable::clear_dirty(); return r; // return Loggable::save_unjournaled_state(); @@ -282,7 +282,7 @@ Project::open ( const char *name ) // timeline->zoom_fit(); - Loggable::clear_dirty(); +// Loggable::clear_dirty(); MESSAGE( "Loaded project \"%s\"", name ); diff --git a/mixer/src/main.C b/mixer/src/main.C index 8463042..4d2b75e 100644 --- a/mixer/src/main.C +++ b/mixer/src/main.C @@ -120,7 +120,7 @@ check_sigterm ( void * ) if ( got_sigterm ) { MESSAGE( "Got SIGTERM, quitting..." ); - mixer->command_quit(); + mixer->quit(); } } diff --git a/nonlib/Loggable.C b/nonlib/Loggable.C index 2fc8b6d..89e8d79 100644 --- a/nonlib/Loggable.C +++ b/nonlib/Loggable.C @@ -59,6 +59,9 @@ void *Loggable::_progress_callback_arg = NULL; snapshot_func *Loggable::_snapshot_callback = NULL; void *Loggable::_snapshot_callback_arg = NULL; +dirty_func *Loggable::_dirty_callback = NULL; +void *Loggable::_dirty_callback_arg = NULL; + Loggable::~Loggable ( ) @@ -213,6 +216,8 @@ Loggable::replay ( FILE *fp ) if ( _progress_callback ) _progress_callback( 0, _progress_callback_arg ); + clear_dirty(); + return true; } @@ -511,6 +516,8 @@ Loggable::snapshot ( FILE *fp ) _fp = ofp; + clear_dirty(); + return true; } @@ -712,7 +719,7 @@ Loggable::log_end ( void ) log_print( _old_state, new_state ); - ++_dirty; + set_dirty(); } delete new_state; @@ -730,7 +737,7 @@ Loggable::log_end ( void ) void Loggable::log_create ( void ) const { - ++_dirty; + set_dirty(); if ( ! _fp ) /* replaying, don't bother */ @@ -782,7 +789,7 @@ Loggable::log_destroy ( void ) const /* the unjournaled state may have changed: make a note of it. */ record_unjournaled(); - ++_dirty; + set_dirty(); if ( ! _fp ) /* tearing down... don't bother */ diff --git a/nonlib/Loggable.H b/nonlib/Loggable.H index 65b9357..84aa242 100644 --- a/nonlib/Loggable.H +++ b/nonlib/Loggable.H @@ -35,6 +35,7 @@ typedef void (progress_func)( int, void * ); typedef void (snapshot_func)( void * ); +typedef void (dirty_func)( int, void * ); class Log_Entry; class Loggable; @@ -87,6 +88,9 @@ class Loggable static snapshot_func *_snapshot_callback; static void *_snapshot_callback_arg; + static dirty_func *_dirty_callback; + static void *_dirty_callback_arg; + private: static unsigned int _relative_id; @@ -132,6 +136,10 @@ private: static bool replay ( FILE *fp ); + static void signal_dirty ( int v ) { if ( _dirty_callback ) _dirty_callback( v, _dirty_callback_arg ); } + static void set_dirty ( void ) { signal_dirty( ++_dirty ); } + static void clear_dirty ( void ) { signal_dirty( _dirty = 0 ); } + public: static bool replay ( const char *name ); @@ -141,6 +149,8 @@ public: static void snapshot_callback ( snapshot_func *p, void *arg ) { _snapshot_callback = p; _snapshot_callback_arg = arg; } static void progress_callback ( progress_func *p, void *arg ) { _progress_callback = p; _progress_callback_arg = arg;} + static void dirty_callback ( dirty_func *p, void *arg ) { _dirty_callback = p; _dirty_callback_arg = arg;} + static const char *escape ( const char *s ); unsigned int id ( void ) const { return _id; } @@ -192,7 +202,6 @@ public: static bool do_this ( const char *s, bool reverse ); static int dirty ( void ) { return _dirty; } - static void clear_dirty ( void ) { _dirty = 0; } void log_create ( void ) const; diff --git a/session-manager/src/nsmd.C b/session-manager/src/nsmd.C index 520db63..5181d56 100644 --- a/session-manager/src/nsmd.C +++ b/session-manager/src/nsmd.C @@ -1607,6 +1607,9 @@ OSC_HANDLER( is_dirty ) MESSAGE( "Client sends dirty" ); Client *c = get_client_by_address( lo_message_get_source( msg ) ); + + if ( ! c ) + return 0; c->dirty = 1; @@ -1622,6 +1625,9 @@ OSC_HANDLER( is_clean ) Client *c = get_client_by_address( lo_message_get_source( msg ) ); + if ( ! c ) + return 0; + c->dirty = 0; if ( gui_is_active ) @@ -1635,6 +1641,9 @@ OSC_HANDLER( message ) { Client *c = get_client_by_address( lo_message_get_source( msg ) ); + if ( ! c ) + return 0; + if ( gui_is_active ) osc_server->send( gui_addr, "/nsm/gui/client/message", c->client_id, argv[0]->i, &argv[1]->s ); @@ -1650,6 +1659,12 @@ OSC_HANDLER( error ) { Client *c = get_client_by_address( lo_message_get_source( msg ) ); + if ( ! c ) + { + WARNING( "Error from unknown client" ); + return 0; + } + // const char *rpath = &argv[0]->s; int err_code = argv[1]->i;