diff --git a/include/core/dispatch.hpp b/include/core/dispatch.hpp index 48022d56..ecb7a9c5 100644 --- a/include/core/dispatch.hpp +++ b/include/core/dispatch.hpp @@ -381,6 +381,16 @@ public: * Call on_new_core on on all objects. */ static void do_new_core() throw(); +/** + * Notify about changes to voice streams. + * + * Default implementation does nothing. + */ + virtual void on_voice_stream_change(); +/** + * Call on_voice_stream_change on all objects. + */ + static void do_voice_stream_change() throw(); protected: /** * Call to indicate this target is interested in sound sample data. diff --git a/src/core/dispatch.cpp b/src/core/dispatch.cpp index 0c8c0863..09ddd4f9 100644 --- a/src/core/dispatch.cpp +++ b/src/core/dispatch.cpp @@ -497,3 +497,19 @@ void information_dispatch::do_new_core() throw() END_EH_BLOCK(i, "on_new_core"); } } + +void information_dispatch::on_voice_stream_change() +{ + //Do nothing. +} + +void information_dispatch::do_voice_stream_change() throw() +{ + if(in_global_ctors()) + return; + for(auto& i : dispatch()) { + START_EH_BLOCK + i->on_voice_stream_change(); + END_EH_BLOCK(i, "on_voice_stream_change"); + } +} diff --git a/src/core/inthread.cpp b/src/core/inthread.cpp index e0024542..8d99d8ac 100644 --- a/src/core/inthread.cpp +++ b/src/core/inthread.cpp @@ -9,6 +9,7 @@ #include "library/ogg.hpp" #include "core/audioapi.hpp" #include "core/command.hpp" +#include "core/dispatch.hpp" #include "core/framerate.hpp" #include "core/inthread.hpp" #include "core/keymapper.hpp" @@ -1669,6 +1670,7 @@ out: messages << "Can't add stream: " << e.what() << std::endl; active_stream->put_ref(); } + information_dispatch::do_voice_stream_change(); } else active_stream->put_ref(); active_stream = NULL; @@ -1925,6 +1927,7 @@ uint64_t voicesub_import_stream(uint64_t ts, const std::string& filename, extern throw; } st->unlock(); //Not locked. + information_dispatch::do_voice_stream_change(); return id; } @@ -1934,6 +1937,7 @@ void voicesub_delete_stream(uint64_t id) if(!current_collection) throw std::runtime_error("No collection loaded"); current_collection->delete_stream(id); + information_dispatch::do_voice_stream_change(); } void voicesub_export_superstream(const std::string& filename) @@ -1957,6 +1961,7 @@ void voicesub_load_collection(const std::string& filename) if(current_collection) delete current_collection; current_collection = newc; + information_dispatch::do_voice_stream_change(); } void voicesub_unload_collection() @@ -1965,6 +1970,7 @@ void voicesub_unload_collection() if(current_collection) delete current_collection; current_collection = NULL; + information_dispatch::do_voice_stream_change(); } void voicesub_alter_timebase(uint64_t id, uint64_t ts) @@ -1973,6 +1979,7 @@ void voicesub_alter_timebase(uint64_t id, uint64_t ts) if(!current_collection) throw std::runtime_error("No collection loaded"); current_collection->alter_stream_timebase(id, ts); + information_dispatch::do_voice_stream_change(); } double voicesub_ts_seconds(uint64_t ts) diff --git a/src/platform/wxwidgets/editor-voicesub.cpp b/src/platform/wxwidgets/editor-voicesub.cpp index 58a48b3f..3bc9ecc4 100644 --- a/src/platform/wxwidgets/editor-voicesub.cpp +++ b/src/platform/wxwidgets/editor-voicesub.cpp @@ -9,6 +9,7 @@ #include #include +#include "core/dispatch.hpp" #include "library/string.hpp" #define NOTHING 0xFFFFFFFFFFFFFFFFULL @@ -22,6 +23,7 @@ class wxeditor_voicesub : public wxDialog { public: wxeditor_voicesub(wxWindow* parent); + ~wxeditor_voicesub() throw(); bool ShouldPreventAppExit() const; void on_select(wxCommandEvent& e); void on_play(wxCommandEvent& e); @@ -39,9 +41,23 @@ public: void on_refresh(wxCommandEvent& e); void on_close(wxCommandEvent& e); void on_wclose(wxCloseEvent& e); -private: - bool closing; void refresh(); +private: + struct refresh_listener : public information_dispatch + { + refresh_listener(wxeditor_voicesub* v) + : information_dispatch("voicesub-editor-change-listner") + { + obj = v; + } + void on_voice_stream_change() + { + wxeditor_voicesub* _obj = obj; + runuifun([_obj]() -> void { _obj->refresh(); }); + } + wxeditor_voicesub* obj; + }; + bool closing; uint64_t get_id(); std::map smap; wxListBox* subtitles; @@ -59,6 +75,8 @@ private: wxButton* unloadbutton; wxButton* refreshbutton; wxButton* closebutton; + refresh_listener* rlistener; + }; wxeditor_voicesub::wxeditor_voicesub(wxWindow* parent) @@ -150,9 +168,15 @@ wxeditor_voicesub::wxeditor_voicesub(wxWindow* parent) top_s->SetSizeHints(this); Fit(); + rlistener = new refresh_listener(this); refresh(); } +wxeditor_voicesub::~wxeditor_voicesub() throw() +{ + delete rlistener; +} + void wxeditor_voicesub::on_select(wxCommandEvent& e) { if(closing) @@ -177,7 +201,6 @@ void wxeditor_voicesub::on_play(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error playing", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_delete(wxCommandEvent& e) @@ -190,7 +213,6 @@ void wxeditor_voicesub::on_delete(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error deleting", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_export_o(wxCommandEvent& e) @@ -209,7 +231,6 @@ void wxeditor_voicesub::on_export_o(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error exporting", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_export_p(wxCommandEvent& e) @@ -228,7 +249,6 @@ void wxeditor_voicesub::on_export_p(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error exporting", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_export_q(wxCommandEvent& e) @@ -247,7 +267,6 @@ void wxeditor_voicesub::on_export_q(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error exporting", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_export_s(wxCommandEvent& e) @@ -263,7 +282,6 @@ void wxeditor_voicesub::on_export_s(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error exporting superstream", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_import_o(wxCommandEvent& e) @@ -282,7 +300,6 @@ void wxeditor_voicesub::on_import_o(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error importing", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_import_p(wxCommandEvent& e) @@ -301,7 +318,6 @@ void wxeditor_voicesub::on_import_p(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error importing", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_import_q(wxCommandEvent& e) @@ -320,7 +336,6 @@ void wxeditor_voicesub::on_import_q(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error importing", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_change_ts(wxCommandEvent& e) @@ -340,7 +355,6 @@ void wxeditor_voicesub::on_change_ts(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error changing timebase", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_load(wxCommandEvent& e) @@ -356,13 +370,11 @@ void wxeditor_voicesub::on_load(wxCommandEvent& e) } catch(std::exception& e) { show_message_ok(this, "Error loading collection", e.what(), wxICON_EXCLAMATION); } - refresh(); } void wxeditor_voicesub::on_unload(wxCommandEvent& e) { voicesub_unload_collection(); - refresh(); } void wxeditor_voicesub::on_refresh(wxCommandEvent& e) @@ -378,6 +390,8 @@ void wxeditor_voicesub::on_close(wxCommandEvent& e) void wxeditor_voicesub::refresh() { + if(closing) + return; bool cflag = voicesub_collection_loaded(); unloadbutton->Enable(cflag); exportsbutton->Enable(cflag);