diff --git a/Settings.cpp b/Settings.cpp index 6a28f5c..5cebd1f 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -170,6 +170,7 @@ void Settings::Save(uint64_t runtime) SourceConfNode->SetAttribute("new_type", application.source.new_type); SourceConfNode->SetAttribute("ratio", application.source.ratio); SourceConfNode->SetAttribute("res", application.source.res); + SourceConfNode->SetAttribute("capture_naming", application.source.capture_naming); SourceConfNode->SetAttribute("capture_path", application.source.capture_path.c_str()); pRoot->InsertEndChild(SourceConfNode); @@ -413,7 +414,8 @@ void Settings::Load() sourceconfnode->QueryIntAttribute("ratio", &application.source.ratio); sourceconfnode->QueryIntAttribute("res", &application.source.res); - const char *path_ = recordnode->Attribute("capture_path"); + sourceconfnode->QueryIntAttribute("capture_naming", &application.source.capture_naming); + const char *path_ = sourceconfnode->Attribute("capture_path"); if (path_) application.source.capture_path = std::string(path_); else diff --git a/Settings.h b/Settings.h index 9a52046..fda2d95 100644 --- a/Settings.h +++ b/Settings.h @@ -166,11 +166,13 @@ struct SourceConfig int ratio; int res; std::string capture_path; + int capture_naming; SourceConfig() { new_type = 0; ratio = 3; res = 1; + capture_naming = 0; } }; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 309081b..bc107d0 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -2240,9 +2240,32 @@ void SourceController::Update() if (source != nullptr) { // back from capture of FBO: can save file if ( capture.isFull() ){ - std::string filename = SystemToolkit::full_filename( Settings::application.source.capture_path, source->name() + SystemToolkit::date_time_string() + ".png" ); - capture.save( filename ); - Log::Notify("Frame saved %s", filename.c_str() ); + // default naming of file with date prefix + std::ostringstream filename; + filename << Settings::application.source.capture_path << PATH_SEP; + filename << SystemToolkit::date_time_string() << "_" << source->name() << ".png"; + + // if sequencial naming of file is selected + if (Settings::application.source.capture_naming == 0 ) + { + // list all files in the target directory that potentially match the sequence naming pattern + std::list pattern; + pattern.push_back( source->name() + "*.png" ); + std::list ls = SystemToolkit::list_directory(Settings::application.source.capture_path, pattern); + // establish a filename for a consecutive sequence of numbers + for (int i = 0; i < ls.size() + 1; ++i) { + filename.str(std::string()); // clear + filename << Settings::application.source.capture_path << PATH_SEP; + filename << source->name() << "_" ; + filename << std::setw(4) << std::setfill('0') << i << ".png"; + // use that filename if was not already used + if ( std::find( ls.begin(), ls.end(), filename.str() ) == ls.end() ) + break; + } + } + // save capture and inform user + capture.save( filename.str() ); + Log::Notify("Frame saved in %s", filename.str().c_str() ); } // request capture : initiate capture of FBO if ( capture_request_ ) { @@ -2293,43 +2316,6 @@ void SourceController::Render() } if (ImGui::BeginMenu(IMGUI_TITLE_MEDIAPLAYER)) { - // - // Menu section for play control - // - if (ImGui::MenuItem( ICON_FA_FAST_BACKWARD " Restart", CTRL_MOD "Space", nullptr, !selection_.empty())) - replay_request_ = true; - if (ImGui::MenuItem( ICON_FA_PLAY " Play | Pause", "Space", nullptr, !selection_.empty())) - play_toggle_request_ = true; - ImGui::Separator(); - - // - // Menu for capture frame - // - if (ImGui::MenuItem( ICON_FA_CAMERA_RETRO " Capture frame", "F10", nullptr, !selection_.empty())) - capture_request_ = true; - // path - static char* name_path[4] = { nullptr }; - if ( name_path[0] == nullptr ) { - for (int i = 0; i < 4; ++i) - name_path[i] = (char *) malloc( 1024 * sizeof(char)); - sprintf( name_path[1], "%s", ICON_FA_HOME " Home"); - sprintf( name_path[2], "%s", ICON_FA_FOLDER " Session location"); - sprintf( name_path[3], "%s", ICON_FA_FOLDER_PLUS " Select"); - } - if (Settings::application.source.capture_path.empty()) - Settings::application.source.capture_path = SystemToolkit::home_path(); - sprintf( name_path[0], "%s", Settings::application.source.capture_path.c_str()); - int selected_path = 0; - ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); - ImGui::Combo("Path", &selected_path, name_path, 4); - if (selected_path > 2) - captureFolderDialog->open(); - else if (selected_path > 1) - Settings::application.source.capture_path = SystemToolkit::path_filename( Mixer::manager().session()->filename() ); - else if (selected_path > 0) - Settings::application.source.capture_path = SystemToolkit::home_path(); - - ImGui::Separator(); // // Menu section for display // @@ -2376,6 +2362,54 @@ void SourceController::Render() ImGui::EndMenu(); } + if (ImGui::BeginMenu(ICON_FA_PLAY " Control")) + { + // + // Menu section for play control + // + if (ImGui::MenuItem( ICON_FA_FAST_BACKWARD " Restart", CTRL_MOD "Space", nullptr, !selection_.empty())) + replay_request_ = true; + if (ImGui::MenuItem( ICON_FA_PLAY " Play | Pause", "Space", nullptr, !selection_.empty())) + play_toggle_request_ = true; + + ImGui::Separator(); + // + // Menu for capture frame + // + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(IMGUI_COLOR_CAPTURE, 0.8f)); + if (ImGui::MenuItem( ICON_FA_CAMERA_RETRO " Capture frame", "F10", nullptr, Mixer::manager().currentSource() != nullptr )) + capture_request_ = true; + ImGui::PopStyleColor(1); + + // path + static char* name_path[4] = { nullptr }; + if ( name_path[0] == nullptr ) { + for (int i = 0; i < 4; ++i) + name_path[i] = (char *) malloc( 1024 * sizeof(char)); + sprintf( name_path[1], "%s", ICON_FA_HOME " Home"); + sprintf( name_path[2], "%s", ICON_FA_FOLDER " Session location"); + sprintf( name_path[3], "%s", ICON_FA_FOLDER_PLUS " Select"); + } + if (Settings::application.source.capture_path.empty()) + Settings::application.source.capture_path = SystemToolkit::home_path(); + sprintf( name_path[0], "%s", Settings::application.source.capture_path.c_str()); + int selected_path = 0; + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); + ImGui::Combo("Path", &selected_path, name_path, 4); + if (selected_path > 2) + captureFolderDialog->open(); + else if (selected_path > 1) + Settings::application.source.capture_path = SystemToolkit::path_filename( Mixer::manager().session()->filename() ); + else if (selected_path > 0) + Settings::application.source.capture_path = SystemToolkit::home_path(); + + static const char* naming_style[2] = { ICON_FA_SORT_NUMERIC_DOWN " Sequence", ICON_FA_CALENDAR " Date" }; + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); + ImGui::Combo("Naming", &Settings::application.source.capture_naming, naming_style, IM_ARRAYSIZE(naming_style)); + + ImGui::EndMenu(); + } + if (ImGui::BeginMenu(active_label_.c_str())) { // info on selection status