From 4706201425e9ce7d8f4609cb920f4b28f261ee63 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 18 Mar 2019 15:33:05 +0100 Subject: NO-OP: Use API to set/test state-of-the-state --- libs/ardour/ardour/session.h | 27 ++++++++++++----------- libs/ardour/audio_track.cc | 2 +- libs/ardour/audioengine.cc | 4 +--- libs/ardour/io.cc | 2 +- libs/ardour/midi_track.cc | 2 +- libs/ardour/session.cc | 44 +++++++++++++++++++------------------- libs/ardour/session_process.cc | 4 ++-- libs/ardour/session_state.cc | 46 +++++++++++++++++++++++----------------- libs/ardour/session_transport.cc | 2 +- 9 files changed, 70 insertions(+), 63 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 560ccbf2c4..d744cd1d0e 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -213,16 +213,21 @@ public: bool path_is_within_session (const std::string&); bool writable() const { return _writable; } - void set_dirty (); - void set_clean (); - bool dirty() const { return _state_of_the_state & Dirty; } - void set_deletion_in_progress (); - void clear_deletion_in_progress (); - bool reconnection_in_progress() const { return _reconnecting_routes_in_progress; } - bool deletion_in_progress() const { return _state_of_the_state & Deletion; } - bool routes_deletion_in_progress() const { return _route_deletion_in_progress; } - bool peaks_cleanup_in_progres() const { return _state_of_the_state & PeakCleanup; } - bool loading () const { return _state_of_the_state & Loading; } + void set_clean (); // == Clean and emit DirtyChanged IFF session was Dirty + void set_dirty (); // |= Dirty and emit DirtyChanged (unless already dirty or Loading, Deletion) + void unset_dirty (bool emit_dirty_changed = false); // &= ~Dirty + void set_deletion_in_progress (); // |= Deletion + void clear_deletion_in_progress (); // &= ~Deletion + + bool reconnection_in_progress () const { return _reconnecting_routes_in_progress; } + bool routes_deletion_in_progress () const { return _route_deletion_in_progress; } + bool dirty () const { return _state_of_the_state & Dirty; } + bool deletion_in_progress () const { return _state_of_the_state & Deletion; } + bool peaks_cleanup_in_progres () const { return _state_of_the_state & PeakCleanup; } + bool loading () const { return _state_of_the_state & Loading; } + bool cannot_save () const { return _state_of_the_state & CannotSave; } + bool in_cleanup () const { return _state_of_the_state & InCleanup; } + bool inital_connect_or_deletion_in_progress () { return _state_of_the_state & (InitialConnecting | Deletion); } PBD::Signal0 DirtyChanged; @@ -583,8 +588,6 @@ public: PeakCleanup = 0x40 }; - StateOfTheState state_of_the_state() const { return _state_of_the_state; } - class StateProtector { public: StateProtector (Session* s) : _session (s) { diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index 46aff98122..477d07e83b 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -152,7 +152,7 @@ AudioTrack::set_state (const XMLNode& node, int version) pending_state = const_cast (&node); - if (_session.state_of_the_state() & Session::Loading) { + if (_session.loading ()) { _session.StateReady.connect_same_thread (*this, boost::bind (&AudioTrack::set_state_part_two, this)); } else { set_state_part_two (); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 4ba6f6cf0a..6b0c70b44c 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -985,9 +985,7 @@ AudioEngine::stop (bool for_latency) _running = false; } - if (_session && was_running_will_stop && - (_session->state_of_the_state() & Session::Loading) == 0 && - (_session->state_of_the_state() & Session::Deletion) == 0) { + if (_session && was_running_will_stop && !_session->loading() && !_session->deletion_in_progress()) { // it's not a halt, but should be handled the same way: // disable record, stop transport and I/O processign but save the data. _session->engine_halted (); diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 59e452633a..5d6d343f2e 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -105,7 +105,7 @@ IO::~IO () void IO::disconnect_check (boost::shared_ptr a, boost::shared_ptr b) { - if (_session.state_of_the_state () & Session::Deletion) { + if (_session.deletion_in_progress ()) { return; } /* this could be called from within our own ::disconnect() method(s) diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index 1608f13c7e..9ef9532b63 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -184,7 +184,7 @@ MidiTrack::set_state (const XMLNode& node, int version) pending_state = const_cast (&node); - if (_session.state_of_the_state() & Session::Loading) { + if (_session.loading ()) { _session.StateReady.connect_same_thread ( *this, boost::bind (&MidiTrack::set_state_part_two, this)); } else { diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index afdca9b683..ca16628db5 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -229,7 +229,7 @@ Session::Session (AudioEngine &eng, , _current_snapshot_name (snapshot_name) , state_tree (0) , state_was_pending (false) - , _state_of_the_state (StateOfTheState(CannotSave|InitialConnecting|Loading)) + , _state_of_the_state (StateOfTheState (CannotSave | InitialConnecting | Loading)) , _suspend_save (0) , _save_queued (false) , _last_roll_location (0) @@ -434,8 +434,7 @@ Session::Session (AudioEngine &eng, store_recent_sessions (_name, _path); bool was_dirty = dirty(); - - _state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty); + unset_dirty (); PresentationInfo::Change.connect_same_thread (*this, boost::bind (&Session::notify_presentation_info_change, this)); @@ -641,7 +640,7 @@ Session::destroy () Analyser::flush (); - _state_of_the_state = StateOfTheState (CannotSave|Deletion); + _state_of_the_state = StateOfTheState (CannotSave | Deletion); { Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ()); @@ -1160,7 +1159,7 @@ Session::remove_monitor_section () } /* allow deletion when session is unloaded */ - if (!_engine.running() && !(_state_of_the_state & Deletion)) { + if (!_engine.running() && !deletion_in_progress ()) { error << _("Cannot remove monitor section while the engine is offline.") << endmsg; return; } @@ -2307,7 +2306,7 @@ Session::resort_routes () are being destroyed. */ - if (_state_of_the_state & (InitialConnecting | Deletion)) { + if (inital_connect_or_deletion_in_progress ()) { return; } @@ -3820,7 +3819,7 @@ Session::remove_routes (boost::shared_ptr routes_to_remove) resort_routes (); #endif - if (_process_graph && !(_state_of_the_state & Deletion) && _engine.running()) { + if (_process_graph && !deletion_in_progress() && _engine.running()) { _process_graph->clear_other_chain (); } @@ -4630,7 +4629,7 @@ Session::playlist_region_added (boost::weak_ptr w) void Session::maybe_update_session_range (samplepos_t a, samplepos_t b) { - if (_state_of_the_state & Loading) { + if (loading ()) { return; } @@ -4815,7 +4814,7 @@ Session::add_source (boost::shared_ptr source) void Session::remove_source (boost::weak_ptr src) { - if (_state_of_the_state & Deletion) { + if (deletion_in_progress ()) { return; } @@ -4834,11 +4833,11 @@ Session::remove_source (boost::weak_ptr src) } } - if (!(_state_of_the_state & StateOfTheState (InCleanup|Loading))) { + if (!in_cleanup () && !loading ()) { /* save state so we don't end up with a session file - referring to non-existent sources. - */ + * referring to non-existent sources. + */ save_state (_current_snapshot_name); } @@ -5341,7 +5340,7 @@ Session::add_playlist (boost::shared_ptr playlist, bool unused) void Session::remove_playlist (boost::weak_ptr weak_playlist) { - if (_state_of_the_state & Deletion) { + if (deletion_in_progress ()) { return; } @@ -5660,7 +5659,7 @@ Session::graph_reordered () from a set_state() call or creating new tracks. Ditto for deletion. */ - if ((_state_of_the_state & (InitialConnecting|Deletion)) || _adding_routes_in_progress || _reconnecting_routes_in_progress || _route_deletion_in_progress) { + if (inital_connect_or_deletion_in_progress () || _adding_routes_in_progress || _reconnecting_routes_in_progress || _route_deletion_in_progress) { return; } @@ -5953,7 +5952,9 @@ Session::unmark_aux_send_id (uint32_t id) void Session::unmark_return_id (uint32_t id) { - if (_state_of_the_state & Deletion) { return; } + if (deletion_in_progress ()) { + return; + } if (id < return_bitset.size()) { return_bitset[id] = false; } @@ -5975,9 +5976,8 @@ Session::reset_native_file_format () for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) { boost::shared_ptr tr = boost::dynamic_pointer_cast (*i); if (tr) { - /* don't save state as we do this, there's no point - */ - _state_of_the_state = StateOfTheState (_state_of_the_state|InCleanup); + /* don't save state as we do this, there's no point */ + _state_of_the_state = StateOfTheState (_state_of_the_state | InCleanup); tr->reset_write_sources (false); _state_of_the_state = StateOfTheState (_state_of_the_state & ~InCleanup); } @@ -6874,7 +6874,7 @@ Session::update_latency (bool playback) { DEBUG_TRACE (DEBUG::Latency, string_compose ("JACK latency callback: %1\n", (playback ? "PLAYBACK" : "CAPTURE"))); - if ((_state_of_the_state & (InitialConnecting|Deletion)) || _adding_routes_in_progress || _route_deletion_in_progress) { + if (inital_connect_or_deletion_in_progress () || _adding_routes_in_progress || _route_deletion_in_progress) { return; } if (!_engine.running()) { @@ -6929,7 +6929,7 @@ Session::set_worst_io_latencies () void Session::set_worst_output_latency () { - if (_state_of_the_state & (InitialConnecting|Deletion)) { + if (inital_connect_or_deletion_in_progress ()) { return; } @@ -6953,7 +6953,7 @@ Session::set_worst_output_latency () void Session::set_worst_input_latency () { - if (_state_of_the_state & (InitialConnecting|Deletion)) { + if (inital_connect_or_deletion_in_progress ()) { return; } @@ -6975,7 +6975,7 @@ Session::set_worst_input_latency () void Session::update_latency_compensation (bool force_whole_graph) { - if (_state_of_the_state & (InitialConnecting|Deletion)) { + if (inital_connect_or_deletion_in_progress ()) { return; } /* this lock is not usually contended, but under certain conditions, diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index 319634499b..c3eb3aa296 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -843,9 +843,9 @@ Session::maybe_sync_start (pframes_t & nframes) void Session::queue_event (SessionEvent* ev) { - if (_state_of_the_state & Deletion) { + if (deletion_in_progress ()) { return; - } else if (_state_of_the_state & Loading) { + } else if (loading ()) { merge_event (ev); } else { Glib::Threads::Mutex::Lock lm (rb_write_lock); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 1a25fd4e36..9773364523 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -364,7 +364,7 @@ Session::post_engine_init () auto_connect_master_bus (); } - _state_of_the_state = StateOfTheState (_state_of_the_state & ~(CannotSave|Dirty)); + _state_of_the_state = StateOfTheState (_state_of_the_state & ~(CannotSave | Dirty)); /* update latencies */ @@ -784,7 +784,7 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot lx.acquire (); } - if (!_writable || (_state_of_the_state & CannotSave)) { + if (!_writable || cannot_save()) { return 1; } @@ -920,13 +920,7 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot save_history (snapshot_name); if (mark_as_clean) { - bool was_dirty = dirty(); - - _state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty); - - if (was_dirty) { - DirtyChanged (); /* EMIT SIGNAL */ - } + unset_dirty (/* EMIT SIGNAL */ true); } StateSaved (snapshot_name); /* EMIT SIGNAL */ @@ -1445,7 +1439,7 @@ Session::state (bool save_template, snapshot_t snapshot_type, bool only_used_ass */ if (!was_dirty) { - _state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty); + unset_dirty (); } } @@ -1544,7 +1538,7 @@ Session::set_state (const XMLNode& node, int version) XMLNode* child; int ret = -1; - _state_of_the_state = StateOfTheState (_state_of_the_state|CannotSave); + _state_of_the_state = StateOfTheState (_state_of_the_state | CannotSave); if (node.name() != X_("Session")) { fatal << _("programming error: Session: incorrect XML node sent to set_state()") << endmsg; @@ -2320,7 +2314,7 @@ Session::reset_write_sources (bool mark_write_complete, bool force) for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) { boost::shared_ptr tr = boost::dynamic_pointer_cast (*i); if (tr) { - _state_of_the_state = StateOfTheState (_state_of_the_state|InCleanup); + _state_of_the_state = StateOfTheState (_state_of_the_state | InCleanup); tr->reset_write_sources(mark_write_complete, force); _state_of_the_state = StateOfTheState (_state_of_the_state & ~InCleanup); } @@ -2488,7 +2482,7 @@ Session::XMLSourceFactory (const XMLNode& node) int Session::save_template (const string& template_name, const string& description, bool replace_existing) { - if ((_state_of_the_state & CannotSave) || template_name.empty ()) { + if (cannot_save () || template_name.empty ()) { return -1; } @@ -3293,7 +3287,7 @@ Session::can_cleanup_peakfiles () const if (deletion_in_progress()) { return false; } - if (!_writable || (_state_of_the_state & CannotSave)) { + if (!_writable || cannot_save ()) { warning << _("Cannot cleanup peak-files for read-only session.") << endmsg; return false; } @@ -3366,7 +3360,7 @@ Session::cleanup_sources (CleanupReport& rep) Searchpath msp; set > sources_used_by_this_snapshot; - _state_of_the_state = (StateOfTheState) (_state_of_the_state | InCleanup); + _state_of_the_state = StateOfTheState (_state_of_the_state | InCleanup); /* this is mostly for windows which doesn't allow file * renaming if the file is in use. But we don't special @@ -3650,7 +3644,7 @@ Session::cleanup_sources (CleanupReport& rep) ret = 0; out: - _state_of_the_state = (StateOfTheState) (_state_of_the_state & ~InCleanup); + _state_of_the_state = StateOfTheState (_state_of_the_state & ~InCleanup); return ret; } @@ -3685,7 +3679,7 @@ Session::set_dirty () } /* never mark session dirty during loading */ - if (_state_of_the_state & (Loading | Deletion)) { + if (loading () || deletion_in_progress ()) { return; } @@ -3705,6 +3699,18 @@ Session::set_clean () } } +void +Session::unset_dirty (bool emit_dirty_changed) +{ + bool was_dirty = dirty(); + + _state_of_the_state = StateOfTheState (_state_of_the_state & (~Dirty)); + + if (was_dirty && emit_dirty_changed) { + DirtyChanged (); /* EMIT SIGNAL */ + } +} + void Session::set_deletion_in_progress () { @@ -3735,7 +3741,7 @@ struct null_deleter { void operator()(void const *) const {} }; void Session::remove_controllable (Controllable* c) { - if (_state_of_the_state & Deletion) { + if (deletion_in_progress()) { return; } @@ -4274,7 +4280,7 @@ Session::rename (const std::string& new_name) string const old_sources_root = _session_dir->sources_root(); - if (!_writable || (_state_of_the_state & CannotSave)) { + if (!_writable || cannot_save ()) { error << _("Cannot rename read-only session.") << endmsg; return 0; // don't show "messed up" warning } @@ -5125,7 +5131,7 @@ Session::save_as (SaveAs& saveas) */ if (!saveas.include_media) { - _state_of_the_state = StateOfTheState (_state_of_the_state & ~Dirty); + unset_dirty (); } save_state ("", false, false, !saveas.include_media); diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 060d5ac74f..e45fb2b096 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -1533,7 +1533,7 @@ Session::non_realtime_stop (bool abort, int on_entry, bool& finished) if (abort && did_record) { /* no reason to save the session file when we remove sources */ - _state_of_the_state = StateOfTheState (_state_of_the_state|InCleanup); + _state_of_the_state = StateOfTheState (_state_of_the_state | InCleanup); } for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) { -- cgit v1.2.3