diff --git a/Mixer.cpp b/Mixer.cpp index 2a48a67..5a80aef 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -772,6 +772,19 @@ void Mixer::setCurrentIndex(int index) setCurrentSource( session_->at(index) ); } +void Mixer::moveIndex (int current_index, int target_index) +{ + // remember ptr to current source + Source *previous_current_source_ = currentSource(); + + // change order + session_->move(current_index, target_index); + + // restore current + unsetCurrentSource(); + setCurrentSource(previous_current_source_); +} + void Mixer::setCurrentNext() { if (session_->numSource() > 0) { @@ -831,11 +844,10 @@ int Mixer::indexCurrentSource() Source *Mixer::currentSource() { - if ( current_source_ == session_->end() ) + if ( current_source_ != session_->end() ) + return (*current_source_); + else return nullptr; - else { - return *(current_source_); - } } // management of view diff --git a/Mixer.h b/Mixer.h index 192e0d2..9369677 100644 --- a/Mixer.h +++ b/Mixer.h @@ -73,6 +73,7 @@ public: void unsetCurrentSource (); void setCurrentIndex (int index); + void moveIndex (int current_index, int target_index); int indexCurrentSource (); // browsing into sources diff --git a/SessionCreator.cpp b/SessionCreator.cpp index 77e1a6e..5925179 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -16,6 +16,7 @@ #include "ImageShader.h" #include "ImageProcessingShader.h" #include "MediaPlayer.h" +#include "SystemToolkit.h" #include #include "tinyxml2Toolkit.h" @@ -26,27 +27,30 @@ std::string SessionCreator::info(const std::string& filename) { std::string ret = ""; - XMLDocument doc; - XMLError eResult = doc.LoadFile(filename.c_str()); - if ( XMLResultError(eResult)) { - Log::Warning("%s could not be openned.", filename.c_str()); - return ret; - } + // if the file exists + if (SystemToolkit::file_exists(filename)) { + // try to load the file + XMLDocument doc; + XMLError eResult = doc.LoadFile(filename.c_str()); + // silently ignore on error + if ( !XMLResultError(eResult, false)) { - XMLElement *header = doc.FirstChildElement(APP_NAME); - if (header != nullptr && header->Attribute("date") != 0) { - int s = header->IntAttribute("size"); - ret = std::to_string( s ) + " source" + ( s > 1 ? "s\n" : "\n"); - const char *att_string = header->Attribute("resolution"); - if (att_string) - ret += std::string( att_string ) + "\n"; - att_string = header->Attribute("date"); - if (att_string) { - std::string date( att_string ); - ret += date.substr(6,2) + "/" + date.substr(4,2) + "/" + date.substr(0,4) + " @ "; - ret += date.substr(8,2) + ":" + date.substr(10,2); + XMLElement *header = doc.FirstChildElement(APP_NAME); + if (header != nullptr && header->Attribute("date") != 0) { + int s = header->IntAttribute("size"); + ret = std::to_string( s ) + " source" + ( s > 1 ? "s\n" : "\n"); + const char *att_string = header->Attribute("resolution"); + if (att_string) + ret += std::string( att_string ) + "\n"; + att_string = header->Attribute("date"); + if (att_string) { + std::string date( att_string ); + ret += date.substr(6,2) + "/" + date.substr(4,2) + "/" + date.substr(0,4) + " @ "; + ret += date.substr(8,2) + ":" + date.substr(10,2); + } + + } } - } return ret; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index ee8da92..49a066f 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -1582,19 +1582,22 @@ void MediaController::setMediaPlayer(MediaPlayer *mp) void MediaController::followCurrentSource() { Source *s = Mixer::manager().currentSource(); - if ( s != nullptr) { - MediaSource *ms = dynamic_cast(s); - if (ms) { - // update the internal mediaplayer if changed - if (mp_ != ms->mediaplayer()) { - mp_ = ms->mediaplayer(); - media_playing_mode_ = mp_->isPlaying(); - } - } else { - mp_ = nullptr; - media_playing_mode_ = false; + MediaSource *ms = nullptr; + + if ( s != nullptr) + ms = dynamic_cast(s); + + if ( ms != nullptr) { + // update the internal mediaplayer if changed + if (mp_ != ms->mediaplayer()) { + mp_ = ms->mediaplayer(); + media_playing_mode_ = mp_->isPlaying(); } } + else { + mp_ = nullptr; + media_playing_mode_ = false; + } } @@ -2153,11 +2156,11 @@ void Navigator::Render() if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_SOURCE")) { if ( payload->DataSize == sizeof(int) ) { + // drop means move index and reorder int payload_index = *(const int*)payload->Data; - int current_source_index = Mixer::manager().indexCurrentSource(); - Mixer::manager().session()->move(payload_index, index); - if (payload_index == current_source_index) - applyButtonSelection(index); + Mixer::manager().moveIndex(payload_index, index); + // index of current source changed + applyButtonSelection(Mixer::manager().indexCurrentSource()); } } ImGui::EndDragDropTarget(); @@ -2831,7 +2834,7 @@ void Navigator::RenderMainPannel() for(auto it = sessions_list.begin(); it != sessions_list.end(); it++) { std::string sessionfilename(*it); if (sessionfilename.empty()) - break; + continue; std::string shortname = SystemToolkit::filename(*it); if (ImGui::Selectable( shortname.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick )) { if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) || file_selected == it) { @@ -2857,7 +2860,7 @@ void Navigator::RenderMainPannel() file_info.clear(); file_selected = sessions_list.end(); } - if (!file_info.empty()) { + else if (!file_info.empty()) { ImGui::BeginTooltip(); ImGui::Text("%s", file_info.c_str()); ImGui::EndTooltip(); diff --git a/tinyxml2Toolkit.cpp b/tinyxml2Toolkit.cpp index 2ee88c4..b84de9f 100644 --- a/tinyxml2Toolkit.cpp +++ b/tinyxml2Toolkit.cpp @@ -237,12 +237,13 @@ bool tinyxml2::XMLSaveDoc(XMLDocument * const doc, std::string filename) return !XMLResultError(eResult); } -bool tinyxml2::XMLResultError(int result) +bool tinyxml2::XMLResultError(int result, bool verbose) { XMLError xmlresult = (XMLError) result; if ( xmlresult != XML_SUCCESS) { - Log::Info("XML error %i: %s", result, tinyxml2::XMLDocument::ErrorIDToName(xmlresult)); + if (verbose) + Log::Info("XML error %i: %s", result, tinyxml2::XMLDocument::ErrorIDToName(xmlresult)); return true; } return false; diff --git a/tinyxml2Toolkit.h b/tinyxml2Toolkit.h index 5342bdb..d276073 100644 --- a/tinyxml2Toolkit.h +++ b/tinyxml2Toolkit.h @@ -29,7 +29,7 @@ XMLElement *XMLElementEncodeArray(XMLDocument *doc, const void *array, uint arra bool XMLElementDecodeArray(XMLElement *elem, void *array, uint arraysize); bool XMLSaveDoc(tinyxml2::XMLDocument * const doc, std::string filename); -bool XMLResultError(int result); +bool XMLResultError(int result, bool verbose = true); }