From 3d5be2bc55e17ad1b01936ee2191047acfd0cae8 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 18 Dec 2006 17:18:14 +0000 Subject: [PATCH] Fixed warning messages while compiling dialog_export.cpp and added a recent list for keyframe read/write. Originally committed to SVN as r576. --- core/dialog_export.cpp | 12 ++--- core/frame_main.cpp | 70 ++++++++++++++++++++++++++++ core/frame_main.h | 6 ++- core/frame_main_events.cpp | 93 ++++++++++++++++++-------------------- core/options.cpp | 2 + 5 files changed, 127 insertions(+), 56 deletions(-) diff --git a/core/dialog_export.cpp b/core/dialog_export.cpp index aad374e51..d068e87a4 100644 --- a/core/dialog_export.cpp +++ b/core/dialog_export.cpp @@ -61,7 +61,7 @@ DialogExport::DialogExport (wxWindow *parent) wxString cur = token.GetNextToken(); if (!cur.IsEmpty()) { n++; - for (int i=0;iGetCount();i++) { + for (unsigned int i=0;iGetCount();i++) { if (FilterList->GetString(i) == cur) { FilterList->Check(i); break; @@ -72,7 +72,7 @@ DialogExport::DialogExport (wxWindow *parent) // No filters listed on header, select all if (n == 0) { - for (int i=0;iGetCount();i++) { + for (unsigned int i=0;iGetCount();i++) { FilterList->Check(i); } } @@ -137,7 +137,7 @@ DialogExport::~DialogExport() { // Set script info data int n = 0; wxString infoList; - for (int i=0;iGetCount();i++) { + for (unsigned int i=0;iGetCount();i++) { if (FilterList->IsChecked(i)) { infoList += FilterList->GetString(i) + _T("|"); n++; @@ -187,7 +187,7 @@ void DialogExport::OnProcess(wxCommandEvent &event) { if (filename.empty()) return; // Add filters - for (int i=0;iGetCount();i++) { + for (unsigned int i=0;iGetCount();i++) { if (FilterList->IsChecked(i)) { Export->AddFilter(FilterList->GetString(i)); } @@ -274,7 +274,7 @@ void DialogExport::OnMoveDown(wxCommandEvent &event) { void DialogExport::OnSelectAll(wxCommandEvent &event) { Freeze(); FilterList->Freeze(); - for (int i=0;iGetCount();i++) { + for (unsigned int i=0;iGetCount();i++) { FilterList->Check(i,true); wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i)); if (sizer) MainSizer->Show(sizer,true,true); @@ -293,7 +293,7 @@ void DialogExport::OnSelectAll(wxCommandEvent &event) { void DialogExport::OnSelectNone(wxCommandEvent &event) { Freeze(); FilterList->Freeze(); - for (int i=0;iGetCount();i++) { + for (unsigned int i=0;iGetCount();i++) { FilterList->Check(i,false); wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i)); if (sizer) MainSizer->Show(sizer,false,true); diff --git a/core/frame_main.cpp b/core/frame_main.cpp index 76cefc428..ceac13d64 100644 --- a/core/frame_main.cpp +++ b/core/frame_main.cpp @@ -65,6 +65,7 @@ #include "hotkeys.h" #include "utils.h" #include "text_file_reader.h" +#include "text_file_writer.h" ///////////////////////// @@ -215,6 +216,7 @@ void FrameMain::InitMenu() { RecentVids = new wxMenu(); RecentAuds = new wxMenu(); RecentTimecodes = new wxMenu(); + RecentKeyframes = new wxMenu(); // Create file menu fileMenu = new wxMenu(); @@ -275,6 +277,8 @@ void FrameMain::InitMenu() { videoMenu->Append(Menu_Video_Load_Keyframes, _("Open keyframes..."), _("Opens a keyframe list file")); videoMenu->Append(Menu_Video_Save_Keyframes, _("Save keyframes..."), _("Saves the current keyframe list"))->Enable(false); videoMenu->Append(Menu_Video_Close_Keyframes, _("Close keyframes"), _("Closes the currently open keyframes list"))->Enable(false); + wxMenuItem *RecentKeyframesParent = new wxMenuItem(videoMenu, Menu_File_Recent_Keyframes_Parent, _("Recent"), _T(""), wxITEM_NORMAL, RecentKeyframes); + videoMenu->Append(RecentKeyframesParent); videoMenu->AppendSeparator(); AppendBitmapMenuItem (videoMenu,Menu_Video_JumpTo, _("&Jump To...\t") + Hotkeys.GetText(_T("Video Jump")), _("Jump to frame or time"), wxBITMAP(jumpto_button)); videoMenu->AppendSeparator(); @@ -998,6 +1002,72 @@ void FrameMain::LoadVFR(wxString filename) { } +////////////////// +// Load Keyframes +void FrameMain::LoadKeyframes(wxString filename) { + // Open file + wxArrayInt keyFrames; + keyFrames.Empty(); + TextFileReader file(filename,_T("ASCII")); + + // Read header + wxString cur = file.ReadLineFromFile(); + if (cur != _T("# keyframe format v1")) return; + cur = file.ReadLineFromFile(); + if (cur.Left(4) != _T("fps ")) return; + cur = cur.Mid(4); + double fps; + cur.ToDouble(&fps); + + // Read lines + while (file.HasMoreLines()) { + cur = file.ReadLineFromFile(); + if (!cur.IsEmpty() && cur.IsNumber()) { + long temp; + cur.ToLong(&temp); + keyFrames.Add(temp); + } + } + + // Set keyframes + videoBox->videoDisplay->SetOverKeyFrames(keyFrames); + + // Set FPS + if (!videoBox->videoDisplay->loaded) { + videoBox->videoDisplay->fps = fps; + VFR_Input.SetCFR(fps); + if (!VFR_Output.IsLoaded()) VFR_Output.SetCFR(fps); + } + + // Add to recent + Options.AddToRecentList(filename,_T("Recent keyframes")); + + // Refresh display + Refresh(); +} + + +////////////////// +// Save Keyframes +void FrameMain::SaveKeyframes(wxString filename) { + // Get keyframes + wxArrayInt keyFrames = videoBox->videoDisplay->GetKeyFrames(); + + // Write header + TextFileWriter file(filename,_T("ASCII")); + file.WriteLineToFile(_T("# keyframe format v1")); + file.WriteLineToFile(wxString::Format(_T("fps %f"),videoBox->videoDisplay->fps)); + + // Write keyframes + for (unsigned int i=0;i=0;) { RecentTimecodes->Destroy(RecentTimecodes->FindItemByPosition(i)); } + count = (int)RecentKeyframes->GetMenuItemCount(); + for (int i=count;--i>=0;) { + RecentKeyframes->Destroy(RecentKeyframes->FindItemByPosition(i)); + } // Rebuild recent videos int added = 0; @@ -346,6 +349,19 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) { added++; } if (added == 0) RecentTimecodes->Append(Menu_Timecodes_Recent,_T("Empty"))->Enable(false); + + // Rebuild recent Keyframes + added = 0; + entries = Options.GetRecentList(_T("Recent Keyframes")); + for (size_t i=0;iAppend(Menu_Keyframes_Recent+i,n + _T(" ") + filename); + added++; + } + if (added == 0) RecentKeyframes->Append(Menu_Keyframes_Recent,_T("Empty"))->Enable(false); } // Audio menu @@ -423,6 +439,15 @@ void FrameMain::OnOpenRecentTimecodes(wxCommandEvent &event) { } +//////////////////////////////// +// Open recent Keyframes entry +void FrameMain::OnOpenRecentKeyframes(wxCommandEvent &event) { + int number = event.GetId()-Menu_Keyframes_Recent; + wxString key = _T("Recent Keyframes #") + wxString::Format(_T("%i"),number+1); + LoadKeyframes(Options.AsText(key)); +} + + //////////////////////////////// // Open recent audio menu entry void FrameMain::OnOpenRecentAudio(wxCommandEvent &event) { @@ -506,6 +531,7 @@ void FrameMain::OnOpenVideo(wxCommandEvent& WXUNUSED(event)) { if (!filename.empty()) { LoadVideo(filename); Options.SetText(_T("Last open video path"), filename); + Options.Save(); } } @@ -525,6 +551,7 @@ void FrameMain::OnOpenAudio (wxCommandEvent& WXUNUSED(event)) { if (!filename.empty()) { LoadAudio(filename); Options.SetText(_T("Last open audio path"), filename); + Options.Save(); } } @@ -548,6 +575,7 @@ void FrameMain::OnOpenSubtitles(wxCommandEvent& WXUNUSED(event)) { LoadSubtitles(filename); wxFileName filepath(filename); Options.SetText(_T("Last open subtitles path"), filepath.GetPath()); + Options.Save(); } } @@ -567,6 +595,7 @@ void FrameMain::OnOpenSubtitlesCharset(wxCommandEvent& WXUNUSED(event)) { LoadSubtitles(filename,charset); } Options.SetText(_T("Last open subtitles path"), filename); + Options.Save(); } } @@ -619,6 +648,7 @@ void FrameMain::OnOpenVFR(wxCommandEvent &event) { if (!filename.empty()) { LoadVFR(filename); Options.SetText(_T("Last open timecodes path"), filename); + Options.Save(); } } @@ -634,42 +664,14 @@ void FrameMain::OnCloseVFR(wxCommandEvent &event) { // Open keyframes void FrameMain::OnOpenKeyframes (wxCommandEvent &event) { // Pick file - wxString filename = wxFileSelector(_T("Select the Keyframes file to open"),_T(""),_T(""),_T(".txt"),_T("Text files (*.txt)|*.txt"),wxFILE_MUST_EXIST | wxOPEN); + wxString path = Options.AsText(_T("Last open keyframes path")); + wxString filename = wxFileSelector(_T("Select the Keyframes file to open"),path,_T(""),_T(".txt"),_T("Text files (*.txt)|*.txt"),wxFILE_MUST_EXIST | wxOPEN); if (filename.IsEmpty()) return; + Options.SetText(_T("Last open keyframes path"),filename); + Options.Save(); - // Open file - wxArrayInt keyFrames; - TextFileReader file(filename,_T("ASCII")); - - // Read header - wxString cur = file.ReadLineFromFile(); - if (cur != _T("# keyframe format v1")) return; - cur = file.ReadLineFromFile(); - if (cur.Left(4) != _T("fps ")) return; - cur = cur.Mid(4); - double fps; - cur.ToDouble(&fps); - - // Read lines - while (file.HasMoreLines()) { - cur = file.ReadLineFromFile(); - long temp; - cur.ToLong(&temp); - keyFrames.Add(temp); - } - - // Set keyframes - videoBox->videoDisplay->SetOverKeyFrames(keyFrames); - - // Set FPS - if (!videoBox->videoDisplay->loaded) { - videoBox->videoDisplay->fps = fps; - VFR_Input.SetCFR(fps); - if (!VFR_Output.IsLoaded()) VFR_Output.SetCFR(fps); - } - - // Refresh display - Refresh(); + // Load + LoadKeyframes(filename); } @@ -684,21 +686,14 @@ void FrameMain::OnCloseKeyframes (wxCommandEvent &event) { // Save keyframes void FrameMain::OnSaveKeyframes (wxCommandEvent &event) { // Pick file - wxString filename = wxFileSelector(_T("Select the Keyframes file to open"),_T(""),_T(""),_T("*.key.txt"),_T("Text files (*.txt)|*.txt"),wxOVERWRITE_PROMPT | wxSAVE); + wxString path = Options.AsText(_T("Last open keyframes path")); + wxString filename = wxFileSelector(_T("Select the Keyframes file to open"),path,_T(""),_T("*.key.txt"),_T("Text files (*.txt)|*.txt"),wxOVERWRITE_PROMPT | wxSAVE); if (filename.IsEmpty()) return; + Options.SetText(_T("Last open keyframes path"),filename); + Options.Save(); - // Get keyframes - wxArrayInt keyFrames = videoBox->videoDisplay->GetKeyFrames(); - - // Write header - TextFileWriter file(_T("test.txt"),_T("ASCII")); - file.WriteLineToFile(_T("# keyframe format v1")); - file.WriteLineToFile(wxString::Format(_T("fps %f"),videoBox->videoDisplay->fps)); - - // Write keyframes - for (unsigned int i=0;i