diff --git a/Mixer.cpp b/Mixer.cpp index 9b10802..a63a64e 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -108,7 +108,7 @@ Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullpt newSession(); // auto load if Settings ask to - if ( Settings::application.recentSessions.automatic ) { + if ( Settings::application.recentSessions.load_at_start ) { if ( Settings::application.recentSessions.filenames.size() > 0 ) open( Settings::application.recentSessions.filenames.back() ); } @@ -120,18 +120,23 @@ Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullpt void Mixer::update() { - // swap front and back sessions when loading is finished + // change session when threaded loading is finished if (sessionLoadFinished_) { - // finished loading, swap front and back sessions - swap(); - // done - sessionFilename_ = sessionThreadFilename_; sessionLoadFinished_ = false; - Settings::application.recentSessions.push(sessionFilename_); + // successfully loading + if ( back_session_ ) { + // swap front and back sessions + swap(); + // set session filename and remember it + sessionFilename_ = sessionThreadFilename_; + Settings::application.recentSessions.push(sessionFilename_); + } } + // confirm when threaded saving is finished if (sessionSaveFinished_) { - sessionFilename_ = sessionThreadFilename_; sessionSaveFinished_ = false; + // set (new) session filename and remember it + sessionFilename_ = sessionThreadFilename_; Settings::application.recentSessions.push(sessionFilename_); } @@ -166,6 +171,9 @@ void Mixer::createSourceMedia(std::string path) MediaSource *m = new MediaSource(); m->setPath(path); + // remember in recent media + Settings::application.recentMedia.push(path); + // propose a new name based on uri renameSource(m, SystemToolkit::base_filename(path)); @@ -185,6 +193,13 @@ void Mixer::insertSource(Source *s) geometry_.scene.fg()->attach(s->group(View::GEOMETRY)); } + + +void Mixer::deleteCurrentSource() +{ + deleteSource( currentSource() ); +} + void Mixer::deleteSource(Source *s) { // in case.. @@ -228,15 +243,14 @@ void Mixer::setCurrentSource(SourceList::iterator it) if ( current_source_ == it ) return; + unsetCurrentSource(); + // change current if ( it != session_->end() ) { current_source_ = it; current_source_index_ = session_->index(it); (*current_source_)->setOverlayVisible(true); } - // default - else - unsetCurrentSource(); } void Mixer::setCurrentSource(Node *node) @@ -416,5 +430,6 @@ void Mixer::newSession() mixing_.restoreSettings(); geometry_.restoreSettings(); - sessionFilename_ = "newsession.vmx"; + // empty session file name (does not save) + sessionFilename_ = ""; } diff --git a/Mixer.h b/Mixer.h index b0f7b89..7092906 100644 --- a/Mixer.h +++ b/Mixer.h @@ -36,8 +36,8 @@ public: // manangement of sources void createSourceMedia(std::string path); - // TODO: deleteSource(); void deleteSource(Source *s); + void deleteCurrentSource(); // operations on sources void renameSource(Source *s, const std::string &newname); diff --git a/Settings.cpp b/Settings.cpp index 420a045..dbc3438 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -96,7 +96,8 @@ void Settings::Save() XMLElement *recentsession = xmlDoc.NewElement( "Session" ); recentsession->SetAttribute("path", application.recentSessions.path.c_str()); - recentsession->SetAttribute("auto", application.recentSessions.automatic); + recentsession->SetAttribute("autoload", application.recentSessions.load_at_start); + recentsession->SetAttribute("autosave", application.recentSessions.save_on_exit); for(auto it = application.recentSessions.filenames.begin(); it != application.recentSessions.filenames.end(); it++) { XMLElement *fileNode = xmlDoc.NewElement("path"); @@ -111,7 +112,7 @@ void Settings::Save() for(auto it = application.recentMedia.filenames.begin(); it != application.recentMedia.filenames.end(); it++) { - XMLElement *fileNode = xmlDoc.NewElement("uri"); + XMLElement *fileNode = xmlDoc.NewElement("path"); XMLText *text = xmlDoc.NewText( (*it).c_str() ); fileNode->InsertEndChild( text ); recentmedia->InsertEndChild(fileNode); @@ -229,7 +230,8 @@ void Settings::Load() application.recentSessions.path = std::string(path_); else application.recentSessions.path = SystemToolkit::home_path(); - pSession->QueryBoolAttribute("auto", &application.recentSessions.automatic); + pSession->QueryBoolAttribute("autoload", &application.recentSessions.load_at_start); + pSession->QueryBoolAttribute("autosave", &application.recentSessions.save_on_exit); application.recentSessions.filenames.clear(); XMLElement* path = pSession->FirstChildElement("path"); for( ; path ; path = path->NextSiblingElement()) diff --git a/Settings.h b/Settings.h index 320eeff..5d89f35 100644 --- a/Settings.h +++ b/Settings.h @@ -38,10 +38,12 @@ struct History { std::string path; std::list filenames; - bool automatic; + bool load_at_start; + bool save_on_exit; History() { - automatic = false; + load_at_start = false; + save_on_exit = false; } void push(std::string filename) { filenames.remove(filename); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 84ef90f..b6a99fe 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -443,6 +443,9 @@ void UserInterface::Render() void UserInterface::Terminate() { + if (Settings::application.recentSessions.save_on_exit) + Mixer::manager().save(); + // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); @@ -815,6 +818,7 @@ Navigator::Navigator() clearSelection(); selected_source_index = -1; width = 100; + pannel_width = 5.f * width; height = 100; padding_width = 100; } @@ -974,13 +978,14 @@ void Navigator::RenderSourcePannel(Source *s) { // Next window is a side pannel ImGui::SetNextWindowPos( ImVec2(width, 0), ImGuiCond_Always ); - ImGui::SetNextWindowSize( ImVec2( 5.f * width, height), ImGuiCond_Always ); + ImGui::SetNextWindowSize( ImVec2(pannel_width, height), ImGuiCond_Always ); ImGui::SetNextWindowBgAlpha(0.85f); // Transparent background if (ImGui::Begin("##navigatorSource", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)) { // TITLE ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE); ImGui::Text("Source"); + ImGui::Text(""); ImGui::PopFont(); static char buf5[128]; @@ -1001,7 +1006,6 @@ void Navigator::RenderSourcePannel(Source *s) // delete button ImGui::Text(" "); if ( ImGui::Button("Delete", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) { - Mixer::manager().deleteSource(s); } } @@ -1010,55 +1014,71 @@ void Navigator::RenderSourcePannel(Source *s) void Navigator::setMediaUri(std::string path) { -// std::string uri = SystemToolkit::path_to_uri(path); - sprintf(uri_, "%s", path.c_str()); + sprintf(media_path_, "%s", path.c_str()); } void Navigator::RenderNewPannel() { // Next window is a side pannel ImGui::SetNextWindowPos( ImVec2(width, 0), ImGuiCond_Always ); - ImGui::SetNextWindowSize( ImVec2( 5.f * width, height), ImGuiCond_Always ); + ImGui::SetNextWindowSize( ImVec2(pannel_width, height), ImGuiCond_Always ); ImGui::SetNextWindowBgAlpha(0.85f); // Transparent background if (ImGui::Begin("##navigatorNewSource", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)) { // TITLE ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE); ImGui::Text("New Source"); + ImGui::Text(""); ImGui::PopFont(); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); static int new_source_type = 0; ImGui::Combo("Type", &new_source_type, "Media\0Render\0Clone\0"); if (new_source_type == 0) { + // helper + ImGui::SetCursorPosX(pannel_width - 30 + IMGUI_RIGHT_ALIGN); + ImGuiToolkit::HelpMarker("A Media source displays an image or a video file."); // browse folder if (ImGuiToolkit::ButtonIcon(2, 5)) { Log::Info("Settings::application.recentMedia.path %s", Settings::application.recentMedia.path.c_str()); std::thread (MediaDialogOpen, Settings::application.recentMedia.path).detach(); } - // uri text entry + // combo recent ImGui::SameLine(0, 10); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); - if (ImGui::InputText("Uri", uri_, IM_ARRAYSIZE(uri_), ImGuiInputTextFlags_EnterReturnsTrue) ) { - Mixer::manager().createSourceMedia(uri_); + if (ImGui::BeginCombo("##RecentMedia", "Select recent")) + { + std::for_each(Settings::application.recentMedia.filenames.begin(), + Settings::application.recentMedia.filenames.end(), [](std::string& path) { + int right = MIN( 40, path.size()); + if (ImGui::Selectable( path.substr( path.size() - right ).c_str() )) { + UserInterface::manager().navigator.setMediaUri(path); + } + }); + ImGui::EndCombo(); + } + // uri text entry + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); + if (ImGui::InputText("Path", media_path_, IM_ARRAYSIZE(media_path_), ImGuiInputTextFlags_EnterReturnsTrue) ) { + Mixer::manager().createSourceMedia(media_path_); selected_button[NAV_NEW] = false; } - // Description - ImGuiToolkit::HelpMarker("A Media source displays an image or a video file."); // Validate button ImGui::Text(" "); - if ( ImGui::Button("Create !", ImVec2(5.f * width - padding_width, 0)) ) { - Mixer::manager().createSourceMedia(uri_); + if ( ImGui::Button("Create !", ImVec2(pannel_width - padding_width, 0)) ) { + Mixer::manager().createSourceMedia(media_path_); selected_button[NAV_NEW] = false; } } else if (new_source_type == 1){ - + // helper + ImGui::SetCursorPosX(pannel_width - 30 + IMGUI_RIGHT_ALIGN); ImGuiToolkit::HelpMarker("A Render source replicates the rendering of the output."); } else { - + // helper + ImGui::SetCursorPosX(pannel_width - 30 + IMGUI_RIGHT_ALIGN); ImGuiToolkit::HelpMarker("A Clone source duplicates the content of another source."); } @@ -1071,18 +1091,19 @@ void Navigator::RenderMainPannel() { // Next window is a side pannel ImGui::SetNextWindowPos( ImVec2(width, 0), ImGuiCond_Always ); - ImGui::SetNextWindowSize( ImVec2( 5.f * width, height), ImGuiCond_Always ); + ImGui::SetNextWindowSize( ImVec2(pannel_width, height), ImGuiCond_Always ); ImGui::SetNextWindowBgAlpha(0.85f); // Transparent background if (ImGui::Begin("##navigatorMain", NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav)) { // TITLE ImGuiToolkit::PushFont(ImGuiToolkit::FONT_LARGE); ImGui::Text(APP_NAME); + ImGui::Text(""); ImGui::PopFont(); ImGui::Text("Session"); ImGui::SameLine(); - ImGui::SetCursorPosX( 5.f * width IMGUI_RIGHT_ALIGN); + ImGui::SetCursorPosX(pannel_width IMGUI_RIGHT_ALIGN); if (ImGui::BeginMenu("File")) { UserInterface::manager().showMenuFile(); @@ -1092,7 +1113,7 @@ void Navigator::RenderMainPannel() // combo box with list of recent session files from Settings static bool recentselected = false; recentselected = false; - if (ImGui::BeginCombo("Recent", "Select")) + if (ImGui::BeginCombo("##Recent", "Open recent")) { std::for_each(Settings::application.recentSessions.filenames.begin(), Settings::application.recentSessions.filenames.end(), [](std::string& filename) { @@ -1106,7 +1127,8 @@ void Navigator::RenderMainPannel() } if (recentselected) hidePannel(); - ImGuiToolkit::ButtonSwitch( "Load most recent on start", &Settings::application.recentSessions.automatic); + ImGuiToolkit::ButtonSwitch( "Load most recent on start", &Settings::application.recentSessions.load_at_start); + ImGuiToolkit::ButtonSwitch( "Save on exit", &Settings::application.recentSessions.save_on_exit); ImGui::Text(" "); ImGui::Text("Windows"); @@ -1130,7 +1152,7 @@ void Navigator::RenderMainPannel() // Bottom aligned ImGui::SetCursorPosY(height - 4.f * ImGui::GetTextLineHeightWithSpacing()); ImGui::Text("About"); - if ( ImGui::Button( " About vimix", ImVec2(5.f * width - padding_width, 0)) ) + if ( ImGui::Button( " About vimix", ImVec2(pannel_width - padding_width, 0)) ) UserInterface::manager().show_about = true; if ( ImGui::Button("About ImGui")) UserInterface::manager().show_imgui_about = true; diff --git a/UserInterfaceManager.h b/UserInterfaceManager.h index 19a4bce..4db70dd 100644 --- a/UserInterfaceManager.h +++ b/UserInterfaceManager.h @@ -17,6 +17,7 @@ class Navigator { // geometry left bar float width; + float pannel_width; float height; float sourcelist_height; float padding_width; @@ -32,7 +33,7 @@ class Navigator void RenderNewPannel(); void RenderMainPannel(); - char uri_[1024]; + char media_path_[1024]; public: Navigator(); diff --git a/defines.h b/defines.h index f52ba05..a8e70d7 100644 --- a/defines.h +++ b/defines.h @@ -31,6 +31,7 @@ #define IMGUI_TITLE_TOOLBOX ICON_FA_WRENCH " Tools" #define IMGUI_TITLE_SHADEREDITOR ICON_FA_CODE " Shader Editor" #define IMGUI_TITLE_PREVIEW ICON_FA_LAPTOP " Preview" +#define IMGUI_TITLE_DELETE ICON_FA_BROOM " Delete?" #define IMGUI_RIGHT_ALIGN -100 #define COLOR_BGROUND 0.2f, 0.2f, 0.2f