From baed0f37f3cb3375f39b8d44f01eadb8796eb0d5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:34:09 +0100 Subject: Generalise the Changed message from SPL. --- src/lib/spl.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/spl.h b/src/lib/spl.h index 9637f6189..fa8f38105 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -93,6 +93,11 @@ private: class SignalSPL : public SPL { public: + enum class Change { + NAME, + CONTENT, + }; + SignalSPL () {} SignalSPL (std::string name) @@ -101,10 +106,10 @@ public: void set_name (std::string name) { SPL::set_name (name); - NameChanged (); + Changed(Change::NAME); } - boost::signals2::signal NameChanged; + boost::signals2::signal Changed; }; #endif -- cgit v1.2.3 From 0c5f0e48080a28d3cfa9f8e2f4948bbc57bc0307 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:51:54 +0100 Subject: Cleanup: white space. --- src/lib/spl.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/lib') diff --git a/src/lib/spl.h b/src/lib/spl.h index fa8f38105..49eb93df2 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -18,15 +18,18 @@ */ + #ifndef DCPOMATIC_SPL_H #define DCPOMATIC_SPL_H + #include "spl_entry.h" #include #include class ContentStore; + class SPL { public: -- cgit v1.2.3 From bf471e4e6d2502bb3b4e2eb4b1309d87e1003070 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:52:33 +0100 Subject: Add and use SPL::swap(). --- src/lib/spl.h | 4 ++++ src/tools/dcpomatic_playlist.cc | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/spl.h b/src/lib/spl.h index 49eb93df2..d7c746d1e 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -26,6 +26,8 @@ #include "spl_entry.h" #include #include +#include + class ContentStore; @@ -63,6 +65,8 @@ public: SPLEntry const & operator[] (std::size_t index) const { return _spl[index]; + void swap(size_t a, size_t b) { + std::iter_swap(_spl.begin() + a, _spl.begin() + b); } void read (boost::filesystem::path path, ContentStore* store); diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 9eada8b38..5a8ee9126 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -402,9 +402,7 @@ private: DCPOMATIC_ASSERT (_playlist); - auto tmp = (*_playlist)[s]; - (*_playlist)[s] = (*_playlist)[s-1]; - (*_playlist)[s-1] = tmp; + _playlist->swap(s, s - 1); set_item (s - 1, (*_playlist)[s-1]); set_item (s, (*_playlist)[s]); @@ -419,9 +417,7 @@ private: DCPOMATIC_ASSERT (_playlist); - auto tmp = (*_playlist)[s]; - (*_playlist)[s] = (*_playlist)[s+1]; - (*_playlist)[s+1] = tmp; + _playlist->swap(s, s + 1); set_item (s + 1, (*_playlist)[s+1]); set_item (s, (*_playlist)[s]); -- cgit v1.2.3 From 704e1112538d809fd55bd7f25385eaa5d064966c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 11:52:54 +0100 Subject: Remove unnecessary non-const operator[]. --- src/lib/spl.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/spl.h b/src/lib/spl.h index d7c746d1e..b002a0882 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -59,12 +59,10 @@ public: return _spl; } - SPLEntry & operator[] (std::size_t index) { + SPLEntry const & operator[] (std::size_t index) const { return _spl[index]; } - SPLEntry const & operator[] (std::size_t index) const { - return _spl[index]; void swap(size_t a, size_t b) { std::iter_swap(_spl.begin() + a, _spl.begin() + b); } -- cgit v1.2.3 From a733da8088152a2487691629753fe8a2addfa5a3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 1 Dec 2022 20:00:09 +0100 Subject: Save playlist when content is added, moved or removed. --- src/lib/spl.h | 15 +++++++++++++++ src/tools/dcpomatic_playlist.cc | 11 ++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/spl.h b/src/lib/spl.h index b002a0882..f55a9fe1f 100644 --- a/src/lib/spl.h +++ b/src/lib/spl.h @@ -114,6 +114,21 @@ public: Changed(Change::NAME); } + void add(SPLEntry e) { + SPL::add(e); + Changed(Change::CONTENT); + } + + void remove(std::size_t index) { + SPL::remove(index); + Changed(Change::CONTENT); + } + + void swap(size_t a, size_t b) { + SPL::swap(a, b); + Changed(Change::CONTENT); + } + boost::signals2::signal Changed; }; diff --git a/src/tools/dcpomatic_playlist.cc b/src/tools/dcpomatic_playlist.cc index 5a8ee9126..5368cb3af 100644 --- a/src/tools/dcpomatic_playlist.cc +++ b/src/tools/dcpomatic_playlist.cc @@ -176,7 +176,9 @@ private: return; } - if (change == SignalSPL::Change::NAME) { + switch (change) { + case SignalSPL::Change::NAME: + { int N = 0; for (auto i: _playlists) { if (i == playlist) { @@ -184,6 +186,13 @@ private: } ++N; } + break; + } + case SignalSPL::Change::CONTENT: + if (auto dir = Config::instance()->player_playlist_directory()) { + playlist->write(*dir / (playlist->id() + ".xml")); + } + break; } } -- cgit v1.2.3