Finished isolating videobox

Originally committed to SVN as r770.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-11 05:33:36 +00:00
parent 3784a131dd
commit 71b8e4b81f
8 changed files with 425 additions and 400 deletions

View file

@ -1,292 +0,0 @@
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////////////
// Include headers
#include "setup.h"
#if USE_FEXTRACKER == 1
#include <wx/wxprec.h>
#include <wx/mimetype.h>
#include <wx/filename.h>
#include <wx/tglbtn.h>
#include <wx/rawbmp.h>
#include "subs_grid.h"
#include "frame_main.h"
#include "video_provider.h"
#include "video_display.h"
#include "video_box.h"
#include "ass_file.h"
#include "ass_dialogue.h"
#include "vfr.h"
#include "subs_edit_box.h"
#include "options.h"
#include "../FexTrackerSource/FexTracker.h"
#include "../FexTrackerSource/FexTrackingFeature.h"
#include "../FexTrackerSource/FexMovement.h"
#include "dialog_progress.h"
#include "dialog_fextracker.h"
///////////////////
// Tracker Menu
void FrameMain::OnVideoTrackerMenu(wxCommandEvent &event) {
wxMenu menu( _("FexTracker") );
AppendBitmapMenuItem(&menu, Video_Track_Points, _("Track points"), _T(""), wxBITMAP(button_track_points));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Point_Add, _("Add points to movement"), _T(""), wxBITMAP(button_track_point_add));
AppendBitmapMenuItem(&menu, Video_Track_Point_Del, _("Remove points from movement"), _T(""), wxBITMAP(button_track_point_del));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Movement, _("Generate movement from points"), _T(""), wxBITMAP(button_track_movement));
PopupMenu(&menu);
}
///////////////////
// Movement Menu
void FrameMain::OnVideoTrackerMenu2(wxCommandEvent &event) {
wxMenu menu( _("FexMovement") );
AppendBitmapMenuItem(&menu, Video_Track_Movement_Empty, _("Generate empty movement"), _T(""), wxBITMAP(button_track_move));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveAll, _("Move subtitle"), _T(""), wxBITMAP(button_track_move));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveBefore, _("Move subtitle (this frame and preceeding frames)"), _T(""), wxBITMAP(button_track_move));
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveOne, _("Move subtitle (this frame)"), _T(""), wxBITMAP(button_track_move));
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveAfter, _("Move subtitle (this frame and following frames)"), _T(""), wxBITMAP(button_track_move));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Split_Line, _("Split line for movement"), _T(""), wxBITMAP(button_track_split_line));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Link_File, _("Link movement file"), _T(""), wxBITMAP(button_track_move));
PopupMenu(&menu);
}
///////////////////
// Track current line
void FrameMain::OnVideoTrackPoints(wxCommandEvent &event) {
videoBox->videoDisplay->Stop();
// Get line
AssDialogue *curline = SubsBox->GetDialogue(EditBox->linen);
if (!curline) return;
FexTrackerConfig config;
DialogFexTracker configDlg( this, &config );
configDlg.ShowModal();
if( !config.FeatureNumber ) return;
// Get Video
VideoProvider *movie = VideoProvider::GetProvider(videoBox->videoDisplay->videoName, wxString(_T("")));
// Create Tracker
if( curline->Tracker ) delete curline->Tracker;
curline->Tracker = new FexTracker( movie->GetWidth(), movie->GetHeight(), config.FeatureNumber );
curline->Tracker->minFeatures = config.FeatureNumber;
curline->Tracker->Cfg = config;
// Start progress
volatile bool canceled = false;
DialogProgress *progress = new DialogProgress(this,_("FexTracker"),&canceled,_("Tracking points"),0,1);
progress->Show();
// Allocate temp image
float* FloatImg = new float[ movie->GetWidth()*movie->GetHeight() ];
int StartFrame = VFR_Output.GetFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.GetFrameAtTime(curline->End.GetMS(),false);
for( int Frame = StartFrame; Frame <= EndFrame; Frame ++ )
{
progress->SetProgress( Frame-StartFrame, EndFrame-StartFrame );
if( canceled ) break;
movie->GetFloatFrame( FloatImg, Frame );
curline->Tracker->ProcessImage( FloatImg );
}
delete FloatImg;
delete movie;
// Clean up progress
if (!canceled)
progress->Destroy();
else
{
delete curline->Tracker;
curline->Tracker = 0;
}
videoBox->videoDisplay->RefreshVideo();
}
///////////////////
// Track current line
void FrameMain::OnVideoTrackMovement(wxCommandEvent &event) {
videoBox->videoDisplay->Stop();
// Get line
AssDialogue *curline = SubsBox->GetDialogue(EditBox->linen);
if (!curline) return;
if( !curline->Tracker ) return;
// Create Movement
if( curline->Movement ) DeleteMovement( curline->Movement );
curline->Movement = curline->Tracker->GetMovement();
videoBox->videoDisplay->RefreshVideo();
}
///////////////////
// split current line
void FrameMain::OnVideoTrackSplitLine(wxCommandEvent &event) {
videoBox->videoDisplay->Stop();
// Get line
AssDialogue *curline = SubsBox->GetDialogue(EditBox->linen);
if (!curline) return;
if( !curline->Movement ) return;
// Create split lines
int StartFrame = VFR_Output.GetFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.GetFrameAtTime(curline->End.GetMS(),false);
AssFile *subs = AssFile::top;
int ResXValue,ResYValue;
swscanf( subs->GetScriptInfo(_T("PlayResX")), _T("%d"), &ResXValue );
swscanf( subs->GetScriptInfo(_T("PlayResY")), _T("%d"), &ResYValue );
int SrcXValue = videoBox->videoDisplay->provider->GetSourceWidth();
int SrcYValue = videoBox->videoDisplay->provider->GetSourceHeight();
float sx = float(ResXValue)/float(SrcXValue);
float sy = float(ResYValue)/float(SrcYValue);
for( int Frame = StartFrame; Frame < EndFrame; Frame ++ )
{
int localframe = Frame - StartFrame;
while( curline->Movement->Frames.size() <= localframe ) localframe--;
FexMovementFrame f = curline->Movement->Frames[localframe];
// f.Pos.x /= videoBox->videoDisplay->GetW
AssDialogue *cur = new AssDialogue( curline->GetEntryData() );
cur->Start.SetMS(VFR_Output.GetTimeAtFrame(Frame,true));
cur->End.SetMS(VFR_Output.GetTimeAtFrame(Frame,false));
cur->Text = wxString::Format( _T("{\\pos(%.0f,%.0f)\\fscx%.2f\\fscy%.2f}"), f.Pos.x*sx, f.Pos.y*sy, f.Scale.x*100, f.Scale.y*100 ) + cur->Text;
cur->UpdateData();
SubsBox->InsertLine(cur,EditBox->linen + Frame - StartFrame,true,false);
}
// Remove Movement
DeleteMovement( curline->Movement );
curline->Movement = 0;
// Remove Tracker
delete curline->Tracker;
curline->Tracker = 0;
// Remove this line
SubsBox->DeleteLines(SubsBox->GetRangeArray(EditBox->linen, EditBox->linen));
videoBox->videoDisplay->RefreshVideo();
}
///////////////////
// generate empty movement
void FrameMain::OnVideoTrackMovementEmpty(wxCommandEvent &event) {
// Get line
AssDialogue *curline = SubsBox->GetDialogue(EditBox->linen);
if (!curline) return;
if( curline->Movement ) DeleteMovement( curline->Movement );
curline->Movement = CreateMovement();
// Create split lines
int StartFrame = VFR_Output.GetFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.GetFrameAtTime(curline->End.GetMS(),false);
FexMovementFrame f;
memset( &f, 0x00, sizeof(f) );
f.Scale.x = f.Scale.y = 1;
for( int i=StartFrame;i<EndFrame;i++ )
curline->Movement->Frames.Add( f );
}
///////////////////
// link line to move file
void FrameMain::OnVideoTrackLinkFile(wxCommandEvent &event) {
videoBox->videoDisplay->Stop();
// Get line
AssDialogue *curline = SubsBox->GetDialogue(EditBox->linen);
if (!curline) return;
wxString link = wxGetTextFromUser(_("Link name:"), _("Link line to movement file"), curline->Movement?curline->Movement->FileName:_T(""), this);
if( link.empty() ) curline->Effect = _T("");
else curline->Effect = _T("FexMovement:")+link;
curline->UpdateData();
if( !curline->Effect.empty() && curline->Movement )
SaveMovement( curline->Movement, curline->Effect.AfterFirst(':').c_str() );
}
///////////////////
// Increase Influence
void FrameMain::OnVideoTrackPointAdd(wxCommandEvent &event) {
videoBox->videoDisplay->TrackerEdit = 1;
videoBox->videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Decrease Influence
void FrameMain::OnVideoTrackPointDel(wxCommandEvent &event) {
videoBox->videoDisplay->TrackerEdit = -1;
videoBox->videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move All
void FrameMain::OnVideoTrackMovementMoveAll(wxCommandEvent &event) {
videoBox->videoDisplay->MovementEdit = 1;
videoBox->videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move One
void FrameMain::OnVideoTrackMovementMoveOne(wxCommandEvent &event) {
videoBox->videoDisplay->MovementEdit = 2;
videoBox->videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move Before
void FrameMain::OnVideoTrackMovementMoveBefore(wxCommandEvent &event) {
videoBox->videoDisplay->MovementEdit = 3;
videoBox->videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move After
void FrameMain::OnVideoTrackMovementMoveAfter(wxCommandEvent &event) {
videoBox->videoDisplay->MovementEdit = 4;
videoBox->videoDisplay->bTrackerEditing = 0;
}
#endif

View file

@ -76,6 +76,9 @@
FrameMain::FrameMain (wxArrayString args)
: wxFrame ((wxFrame*)NULL,-1,_T(""),wxDefaultPosition,wxSize(800,600),wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN)
{
// Set application's frame
AegisubApp::Get()->frame = this;
// Initialize flags
HasSelection = false;
menuCreated = false;
@ -510,15 +513,6 @@ void FrameMain::UpdateToolbar() {
}
//////////////////////////////////
// Append a menu item with bitmap
void FrameMain::AppendBitmapMenuItem (wxMenu* parentMenu,int id,wxString text,wxString help,wxBitmap bmp) {
wxMenuItem *cur = new wxMenuItem(parentMenu,id,text,help);
cur->SetBitmap(bmp);
parentMenu->Append(cur);
}
////////////////////////////
// Menu item enable/disable
void FrameMain::MenuItemEnable (int id, bool state,wxBitmap &bmp1,wxBitmap &bmp2) {
@ -1265,7 +1259,7 @@ void FrameMain::SetAccelerators() {
entry[i++] = Hotkeys.GetAccelerator(_T("Save Subtitles Alt"),Menu_File_Save_Subtitles);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global zoom in"),Menu_Video_Zoom_In);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global zoom out"),Menu_Video_Zoom_Out);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global play"),Video_Play);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global play"),Video_Frame_Play);
entry[i++] = Hotkeys.GetAccelerator(_T("Edit box commit"),Edit_Box_Commit);
// Medusa

View file

@ -111,24 +111,6 @@ private:
void OnStatusClear(wxTimerEvent &event);
void OnVideoPlay(wxCommandEvent &event);
void OnVideoPlayLine(wxCommandEvent &event);
void OnVideoStop(wxCommandEvent &event);
void OnVideoToggleScroll(wxCommandEvent &event);
void OnVideoTrackerMenu(wxCommandEvent &event);
void OnVideoTrackPoints(wxCommandEvent &event);
void OnVideoTrackPointAdd(wxCommandEvent &event);
void OnVideoTrackPointDel(wxCommandEvent &event);
void OnVideoTrackerMenu2(wxCommandEvent &event);
void OnVideoTrackMovement(wxCommandEvent &event);
void OnVideoTrackMovementMoveAll(wxCommandEvent &event);
void OnVideoTrackMovementMoveOne(wxCommandEvent &event);
void OnVideoTrackMovementMoveBefore(wxCommandEvent &event);
void OnVideoTrackMovementMoveAfter(wxCommandEvent &event);
void OnVideoTrackSplitLine(wxCommandEvent &event);
void OnVideoTrackLinkFile(wxCommandEvent &event);
void OnVideoTrackMovementEmpty(wxCommandEvent &event);
void OnKeyDown(wxKeyEvent &event);
void OnOpenRecentSubs (wxCommandEvent &event);
@ -249,7 +231,6 @@ private:
int TryToCloseSubs(bool enableCancel=true);
void SetDisplayMode(int mode);
void AppendBitmapMenuItem (wxMenu* parentMenu,int id,wxString text,wxString help,wxBitmap bmp);
wxMenuItem *RebuildMenuItem(wxMenu *menu,int id,wxBitmap bmp1,wxBitmap bmp2,bool state);
void MenuItemEnable(int id,bool state,wxBitmap &bmp1,wxBitmap &bmp2);
void SynchronizeProject(bool FromSubs=false);
@ -396,24 +377,7 @@ enum {
Grid_Toggle_Tags,
Edit_Box_Commit,
Video_Play,
Video_Play_Line,
Video_Stop,
Video_Auto_Scroll,
Video_Tracker_Menu,
Video_Track_Points,
Video_Track_Point_Add,
Video_Track_Point_Del,
Video_Tracker_Menu2,
Video_Track_Movement,
Video_Track_Movement_MoveAll,
Video_Track_Movement_MoveOne,
Video_Track_Movement_MoveBefore,
Video_Track_Movement_MoveAfter,
Video_Track_Split_Line,
Video_Track_Link_File,
Video_Track_Movement_Empty,
Video_Frame_Play,
Medusa_Play,
Medusa_Stop,
@ -431,7 +395,7 @@ enum {
Menu_Audio_Recent = 2400,
Menu_Timecodes_Recent = 2500,
Menu_Keyframes_Recent = 2600,
Menu_Automation_Macro = 2700,
Menu_Automation_Macro = 2700
};

View file

@ -92,27 +92,6 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_TIMER(AutoSave_Timer, FrameMain::OnAutoSave)
EVT_TIMER(StatusClear_Timer, FrameMain::OnStatusClear)
EVT_BUTTON(Video_Play, FrameMain::OnVideoPlay)
EVT_BUTTON(Video_Play_Line, FrameMain::OnVideoPlayLine)
EVT_BUTTON(Video_Stop, FrameMain::OnVideoStop)
EVT_TOGGLEBUTTON(Video_Auto_Scroll, FrameMain::OnVideoToggleScroll)
#if USE_FEXTRACKER == 1
EVT_BUTTON(Video_Tracker_Menu, FrameMain::OnVideoTrackerMenu)
EVT_MENU(Video_Track_Points, FrameMain::OnVideoTrackPoints)
EVT_MENU(Video_Track_Point_Add, FrameMain::OnVideoTrackPointAdd)
EVT_MENU(Video_Track_Point_Del, FrameMain::OnVideoTrackPointDel)
EVT_MENU(Video_Track_Movement, FrameMain::OnVideoTrackMovement)
EVT_BUTTON(Video_Tracker_Menu2, FrameMain::OnVideoTrackerMenu2)
EVT_MENU(Video_Track_Movement_MoveAll, FrameMain::OnVideoTrackMovementMoveAll)
EVT_MENU(Video_Track_Movement_MoveOne, FrameMain::OnVideoTrackMovementMoveOne)
EVT_MENU(Video_Track_Movement_MoveBefore, FrameMain::OnVideoTrackMovementMoveBefore)
EVT_MENU(Video_Track_Movement_MoveAfter, FrameMain::OnVideoTrackMovementMoveAfter)
EVT_MENU(Video_Track_Split_Line, FrameMain::OnVideoTrackSplitLine)
EVT_MENU(Video_Track_Link_File, FrameMain::OnVideoTrackLinkFile)
EVT_MENU(Video_Track_Movement_Empty, FrameMain::OnVideoTrackMovementEmpty)
#endif
EVT_CLOSE(FrameMain::OnCloseWindow)
EVT_KEY_DOWN(FrameMain::OnKeyDown)
@ -146,7 +125,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Menu_View_Zoom_100, FrameMain::OnSetZoom100)
EVT_MENU(Menu_View_Zoom_200, FrameMain::OnSetZoom200)
EVT_COMBOBOX(Toolbar_Zoom_Dropdown, FrameMain::OnSetZoom)
EVT_MENU(Video_Play, FrameMain::OnVideoPlay)
EVT_MENU(Video_Frame_Play, FrameMain::OnVideoPlay)
EVT_MENU(Menu_Video_Zoom_In, FrameMain::OnZoomIn)
EVT_MENU(Menu_Video_Zoom_Out, FrameMain::OnZoomOut)
EVT_MENU(Menu_Video_AR_Default, FrameMain::OnSetARDefault)
@ -633,6 +612,14 @@ void FrameMain::OnIRCChannel(wxCommandEvent& WXUNUSED(event)) {
}
//////////////
// Play video
void FrameMain::OnVideoPlay(wxCommandEvent &event) {
videoBox->videoDisplay->Play();
}
//////////////
// Open video
void FrameMain::OnOpenVideo(wxCommandEvent& WXUNUSED(event)) {
@ -1517,35 +1504,6 @@ void FrameMain::OnEditBoxCommit(wxCommandEvent &event) {
}
//////////////
// Play video
void FrameMain::OnVideoPlay(wxCommandEvent &event) {
videoBox->videoDisplay->Play();
}
///////////////////
// Play video line
void FrameMain::OnVideoPlayLine(wxCommandEvent &event) {
videoBox->videoDisplay->PlayLine();
}
//////////////
// Stop video
void FrameMain::OnVideoStop(wxCommandEvent &event) {
videoBox->videoDisplay->Stop();
}
/////////////////////
// Toggle autoscroll
void FrameMain::OnVideoToggleScroll(wxCommandEvent &event) {
Options.SetBool(_T("Sync video with subs"),videoBox->AutoScroll->GetValue());
Options.Save();
}
///////////////////////////////
// Choose a different language
void FrameMain::OnChooseLanguage (wxCommandEvent &event) {

View file

@ -183,3 +183,12 @@ wxString PrettySize(int bytes) {
else final = wxString::Format(_T("%.0f"),size);
return final + suffix[i];
}
//////////////////////////////////
// Append a menu item with bitmap
void AppendBitmapMenuItem (wxMenu* parentMenu,int id,wxString text,wxString help,wxBitmap bmp) {
wxMenuItem *cur = new wxMenuItem(parentMenu,id,text,help);
cur->SetBitmap(bmp);
parentMenu->Append(cur);
}

View file

@ -48,6 +48,7 @@ wxString PrettyFloat(wxString src);
wxString FloatToString(double value);
wxString IntegerToString(int value);
wxString PrettySize(int bytes);
void AppendBitmapMenuItem (wxMenu* parentMenu,int id,wxString text,wxString help,wxBitmap bmp);
//////////

View file

@ -36,6 +36,11 @@
////////////
// Includes
#include <wx/wxprec.h>
#include <wx/mimetype.h>
#include <wx/filename.h>
#include <wx/tglbtn.h>
#include <wx/rawbmp.h>
#include "video_box.h"
#include "video_display.h"
#include "video_zoom.h"
@ -43,15 +48,32 @@
#include "frame_main.h"
#include "toggle_bitmap.h"
#include "options.h"
#include "setup.h"
#include "subs_grid.h"
#include "video_provider.h"
#include "ass_file.h"
#include "ass_dialogue.h"
#include "vfr.h"
#include "subs_edit_box.h"
#include "../FexTrackerSource/FexTracker.h"
#include "../FexTrackerSource/FexTrackingFeature.h"
#include "../FexTrackerSource/FexMovement.h"
#include "dialog_progress.h"
#include "dialog_fextracker.h"
#include "utils.h"
#include "main.h"
///////////////
// Constructor
VideoBox::VideoBox(wxWindow *parent)
: wxPanel (parent,-1)
: wxPanel (parent,5000)
{
// Buttons
// Parent
videoPage = this;
frame = AegisubApp::Get()->frame;
// Buttons
wxBitmapButton *VideoPlayButton = new wxBitmapButton(videoPage,Video_Play,wxBITMAP(button_play),wxDefaultPosition,wxSize(25,-1));
VideoPlayButton->SetToolTip(_("Play video starting on this position"));
wxBitmapButton *VideoPlayLineButton = new wxBitmapButton(videoPage,Video_Play_Line,wxBITMAP(button_playline),wxDefaultPosition,wxSize(25,-1));
@ -62,10 +84,13 @@ VideoBox::VideoBox(wxWindow *parent)
AutoScroll->SetToolTip(_("Toggle autoscroll of video"));
AutoScroll->SetValue(Options.AsBool(_T("Sync video with subs")));
// Fextracker
#if USE_FEXTRACKER == 1
wxBitmapButton *VideoTrackerMenuButton = new wxBitmapButton(videoPage,Video_Tracker_Menu,wxBITMAP(button_track_points),wxDefaultPosition,wxSize(25,-1));
VideoTrackerMenuButton->SetToolTip(_("FexTracker"));
wxBitmapButton *VideoTrackerMenu2Button = new wxBitmapButton(videoPage,Video_Tracker_Menu2,wxBITMAP(button_track_trail),wxDefaultPosition,wxSize(25,-1));
VideoTrackerMenu2Button->SetToolTip(_("FexMovement"));
#endif
// Seek
videoSlider = new VideoSlider(videoPage,-1);
@ -92,11 +117,11 @@ VideoBox::VideoBox(wxWindow *parent)
// Typesetting buttons
wxSizer *typeSizer = new wxBoxSizer(wxVERTICAL);
typeSizer->Add(new wxButton(videoPage,-1,_T("a"),wxDefaultPosition,wxSize(20,20)),0,0,0);
typeSizer->Add(new wxButton(videoPage,-1,_T("b"),wxDefaultPosition,wxSize(20,20)),0,0,0);
typeSizer->Add(new wxButton(videoPage,-1,_T("c"),wxDefaultPosition,wxSize(20,20)),0,0,0);
typeSizer->Add(new wxButton(videoPage,-1,_T("d"),wxDefaultPosition,wxSize(20,20)),0,0,0);
typeSizer->Add(new wxButton(videoPage,-1,_T("e"),wxDefaultPosition,wxSize(20,20)),0,0,0);
//typeSizer->Add(new wxButton(videoPage,-1,_T("a"),wxDefaultPosition,wxSize(20,20)),0,0,0);
//typeSizer->Add(new wxButton(videoPage,-1,_T("b"),wxDefaultPosition,wxSize(20,20)),0,0,0);
//typeSizer->Add(new wxButton(videoPage,-1,_T("c"),wxDefaultPosition,wxSize(20,20)),0,0,0);
//typeSizer->Add(new wxButton(videoPage,-1,_T("d"),wxDefaultPosition,wxSize(20,20)),0,0,0);
//typeSizer->Add(new wxButton(videoPage,-1,_T("e"),wxDefaultPosition,wxSize(20,20)),0,0,0);
typeSizer->AddStretchSpacer(1);
// Top sizer
@ -113,8 +138,10 @@ VideoBox::VideoBox(wxWindow *parent)
videoBottomSizer->Add(VideoPlayLineButton,0,wxTOP|wxBOTTOM|wxALIGN_CENTER,2);
videoBottomSizer->Add(VideoStopButton,0,wxTOP|wxBOTTOM|wxALIGN_CENTER,2);
videoBottomSizer->Add(AutoScroll,0,wxTOP|wxBOTTOM|wxALIGN_CENTER|wxEXPAND,2);
#if USE_FEXTRACKER == 1
videoBottomSizer->Add(VideoTrackerMenuButton,0,wxTOP|wxBOTTOM|wxALIGN_CENTER|wxEXPAND,2);
videoBottomSizer->Add(VideoTrackerMenu2Button,0,wxTOP|wxBOTTOM|wxALIGN_CENTER|wxEXPAND,2);
#endif
videoBottomSizer->Add(VideoPosition,1,wxLEFT|wxALIGN_CENTER,5);
videoBottomSizer->Add(VideoSubsPos,1,wxALIGN_CENTER,0);
VideoSizer = new wxBoxSizer(wxVERTICAL);
@ -123,3 +150,322 @@ VideoBox::VideoBox(wxWindow *parent)
VideoSizer->Add(videoBottomSizer,0,wxEXPAND,0);
SetSizer(VideoSizer);
}
///////////////
// Event table
BEGIN_EVENT_TABLE(VideoBox, wxPanel)
EVT_BUTTON(Video_Play, VideoBox::OnVideoPlay)
EVT_BUTTON(Video_Play_Line, VideoBox::OnVideoPlayLine)
EVT_BUTTON(Video_Stop, VideoBox::OnVideoStop)
EVT_TOGGLEBUTTON(Video_Auto_Scroll, VideoBox::OnVideoToggleScroll)
#if USE_FEXTRACKER == 1
EVT_BUTTON(Video_Tracker_Menu, VideoBox::OnVideoTrackerMenu)
EVT_MENU(Video_Track_Points, VideoBox::OnVideoTrackPoints)
EVT_MENU(Video_Track_Point_Add, VideoBox::OnVideoTrackPointAdd)
EVT_MENU(Video_Track_Point_Del, VideoBox::OnVideoTrackPointDel)
EVT_MENU(Video_Track_Movement, VideoBox::OnVideoTrackMovement)
EVT_BUTTON(Video_Tracker_Menu2, VideoBox::OnVideoTrackerMenu2)
EVT_MENU(Video_Track_Movement_MoveAll, VideoBox::OnVideoTrackMovementMoveAll)
EVT_MENU(Video_Track_Movement_MoveOne, VideoBox::OnVideoTrackMovementMoveOne)
EVT_MENU(Video_Track_Movement_MoveBefore, VideoBox::OnVideoTrackMovementMoveBefore)
EVT_MENU(Video_Track_Movement_MoveAfter, VideoBox::OnVideoTrackMovementMoveAfter)
EVT_MENU(Video_Track_Split_Line, VideoBox::OnVideoTrackSplitLine)
EVT_MENU(Video_Track_Link_File, VideoBox::OnVideoTrackLinkFile)
EVT_MENU(Video_Track_Movement_Empty, VideoBox::OnVideoTrackMovementEmpty)
#endif
END_EVENT_TABLE()
//////////////
// Play video
void VideoBox::OnVideoPlay(wxCommandEvent &event) {
videoDisplay->Play();
}
///////////////////
// Play video line
void VideoBox::OnVideoPlayLine(wxCommandEvent &event) {
videoDisplay->PlayLine();
}
//////////////
// Stop video
void VideoBox::OnVideoStop(wxCommandEvent &event) {
videoDisplay->Stop();
}
/////////////////////
// Toggle autoscroll
void VideoBox::OnVideoToggleScroll(wxCommandEvent &event) {
Options.SetBool(_T("Sync video with subs"),AutoScroll->GetValue());
Options.Save();
}
/////////////////////// HERE BE DRAGONS //////////////////////////////
#if USE_FEXTRACKER == 1
///////////////////
// Tracker Menu
void VideoBox::OnVideoTrackerMenu(wxCommandEvent &event) {
wxMenu menu( _("FexTracker") );
AppendBitmapMenuItem(&menu, Video_Track_Points, _("Track points"), _T(""), wxBITMAP(button_track_points));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Point_Add, _("Add points to movement"), _T(""), wxBITMAP(button_track_point_add));
AppendBitmapMenuItem(&menu, Video_Track_Point_Del, _("Remove points from movement"), _T(""), wxBITMAP(button_track_point_del));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Movement, _("Generate movement from points"), _T(""), wxBITMAP(button_track_movement));
PopupMenu(&menu);
}
///////////////////
// Movement Menu
void VideoBox::OnVideoTrackerMenu2(wxCommandEvent &event) {
wxMenu menu( _("FexMovement") );
AppendBitmapMenuItem(&menu, Video_Track_Movement_Empty, _("Generate empty movement"), _T(""), wxBITMAP(button_track_move));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveAll, _("Move subtitle"), _T(""), wxBITMAP(button_track_move));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveBefore, _("Move subtitle (this frame and preceeding frames)"), _T(""), wxBITMAP(button_track_move));
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveOne, _("Move subtitle (this frame)"), _T(""), wxBITMAP(button_track_move));
AppendBitmapMenuItem(&menu, Video_Track_Movement_MoveAfter, _("Move subtitle (this frame and following frames)"), _T(""), wxBITMAP(button_track_move));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Split_Line, _("Split line for movement"), _T(""), wxBITMAP(button_track_split_line));
menu.AppendSeparator();
AppendBitmapMenuItem(&menu, Video_Track_Link_File, _("Link movement file"), _T(""), wxBITMAP(button_track_move));
PopupMenu(&menu);
}
///////////////////
// Track current line
void VideoBox::OnVideoTrackPoints(wxCommandEvent &event) {
videoDisplay->Stop();
// Get line
AssDialogue *curline = frame->SubsBox->GetDialogue(frame->EditBox->linen);
if (!curline) return;
FexTrackerConfig config;
DialogFexTracker configDlg( this, &config );
configDlg.ShowModal();
if( !config.FeatureNumber ) return;
// Get Video
VideoProvider *movie = VideoProvider::GetProvider(videoDisplay->videoName, wxString(_T("")));
// Create Tracker
if( curline->Tracker ) delete curline->Tracker;
curline->Tracker = new FexTracker( movie->GetWidth(), movie->GetHeight(), config.FeatureNumber );
curline->Tracker->minFeatures = config.FeatureNumber;
curline->Tracker->Cfg = config;
// Start progress
volatile bool canceled = false;
DialogProgress *progress = new DialogProgress(this,_("FexTracker"),&canceled,_("Tracking points"),0,1);
progress->Show();
// Allocate temp image
float* FloatImg = new float[ movie->GetWidth()*movie->GetHeight() ];
int StartFrame = VFR_Output.GetFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.GetFrameAtTime(curline->End.GetMS(),false);
for( int Frame = StartFrame; Frame <= EndFrame; Frame ++ )
{
progress->SetProgress( Frame-StartFrame, EndFrame-StartFrame );
if( canceled ) break;
movie->GetFloatFrame( FloatImg, Frame );
curline->Tracker->ProcessImage( FloatImg );
}
delete FloatImg;
delete movie;
// Clean up progress
if (!canceled)
progress->Destroy();
else
{
delete curline->Tracker;
curline->Tracker = 0;
}
videoDisplay->RefreshVideo();
}
///////////////////
// Track current line
void VideoBox::OnVideoTrackMovement(wxCommandEvent &event) {
videoDisplay->Stop();
// Get line
AssDialogue *curline = frame->SubsBox->GetDialogue(frame->EditBox->linen);
if (!curline) return;
if( !curline->Tracker ) return;
// Create Movement
if( curline->Movement ) DeleteMovement( curline->Movement );
curline->Movement = curline->Tracker->GetMovement();
videoDisplay->RefreshVideo();
}
///////////////////
// split current line
void VideoBox::OnVideoTrackSplitLine(wxCommandEvent &event) {
videoDisplay->Stop();
// Get line
AssDialogue *curline = frame->SubsBox->GetDialogue(frame->EditBox->linen);
if (!curline) return;
if( !curline->Movement ) return;
// Create split lines
int StartFrame = VFR_Output.GetFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.GetFrameAtTime(curline->End.GetMS(),false);
AssFile *subs = AssFile::top;
int ResXValue,ResYValue;
swscanf( subs->GetScriptInfo(_T("PlayResX")), _T("%d"), &ResXValue );
swscanf( subs->GetScriptInfo(_T("PlayResY")), _T("%d"), &ResYValue );
int SrcXValue = videoDisplay->provider->GetSourceWidth();
int SrcYValue = videoDisplay->provider->GetSourceHeight();
float sx = float(ResXValue)/float(SrcXValue);
float sy = float(ResYValue)/float(SrcYValue);
for( int Frame = StartFrame; Frame < EndFrame; Frame ++ )
{
int localframe = Frame - StartFrame;
while( curline->Movement->Frames.size() <= localframe ) localframe--;
FexMovementFrame f = curline->Movement->Frames[localframe];
// f.Pos.x /= videoDisplay->GetW
AssDialogue *cur = new AssDialogue( curline->GetEntryData() );
cur->Start.SetMS(VFR_Output.GetTimeAtFrame(Frame,true));
cur->End.SetMS(VFR_Output.GetTimeAtFrame(Frame,false));
cur->Text = wxString::Format( _T("{\\pos(%.0f,%.0f)\\fscx%.2f\\fscy%.2f}"), f.Pos.x*sx, f.Pos.y*sy, f.Scale.x*100, f.Scale.y*100 ) + cur->Text;
cur->UpdateData();
frame->SubsBox->InsertLine(cur,frame->EditBox->linen + Frame - StartFrame,true,false);
}
// Remove Movement
DeleteMovement( curline->Movement );
curline->Movement = 0;
// Remove Tracker
delete curline->Tracker;
curline->Tracker = 0;
// Remove this line
frame->SubsBox->DeleteLines(frame->SubsBox->GetRangeArray(frame->EditBox->linen, frame->EditBox->linen));
videoDisplay->RefreshVideo();
}
///////////////////
// generate empty movement
void VideoBox::OnVideoTrackMovementEmpty(wxCommandEvent &event) {
// Get line
AssDialogue *curline = frame->SubsBox->GetDialogue(frame->EditBox->linen);
if (!curline) return;
if( curline->Movement ) DeleteMovement( curline->Movement );
curline->Movement = CreateMovement();
// Create split lines
int StartFrame = VFR_Output.GetFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.GetFrameAtTime(curline->End.GetMS(),false);
FexMovementFrame f;
memset( &f, 0x00, sizeof(f) );
f.Scale.x = f.Scale.y = 1;
for( int i=StartFrame;i<EndFrame;i++ )
curline->Movement->Frames.Add( f );
}
///////////////////
// link line to move file
void VideoBox::OnVideoTrackLinkFile(wxCommandEvent &event) {
videoDisplay->Stop();
// Get line
AssDialogue *curline = frame->SubsBox->GetDialogue(frame->EditBox->linen);
if (!curline) return;
wxString link = wxGetTextFromUser(_("Link name:"), _("Link line to movement file"), curline->Movement?curline->Movement->FileName:_T(""), this);
if( link.empty() ) curline->Effect = _T("");
else curline->Effect = _T("FexMovement:")+link;
curline->UpdateData();
if( !curline->Effect.empty() && curline->Movement )
SaveMovement( curline->Movement, curline->Effect.AfterFirst(':').c_str() );
}
///////////////////
// Increase Influence
void VideoBox::OnVideoTrackPointAdd(wxCommandEvent &event) {
videoDisplay->TrackerEdit = 1;
videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Decrease Influence
void VideoBox::OnVideoTrackPointDel(wxCommandEvent &event) {
videoDisplay->TrackerEdit = -1;
videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move All
void VideoBox::OnVideoTrackMovementMoveAll(wxCommandEvent &event) {
videoDisplay->MovementEdit = 1;
videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move One
void VideoBox::OnVideoTrackMovementMoveOne(wxCommandEvent &event) {
videoDisplay->MovementEdit = 2;
videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move Before
void VideoBox::OnVideoTrackMovementMoveBefore(wxCommandEvent &event) {
videoDisplay->MovementEdit = 3;
videoDisplay->bTrackerEditing = 0;
}
///////////////////
// Move After
void VideoBox::OnVideoTrackMovementMoveAfter(wxCommandEvent &event) {
videoDisplay->MovementEdit = 4;
videoDisplay->bTrackerEditing = 0;
}
#endif

View file

@ -47,13 +47,33 @@
// Prototypes
class VideoDisplay;
class VideoSlider;
//class VideoZoomSlider;
class ToggleBitmap;
class FrameMain;
///////////////////
// Video box class
class VideoBox : public wxPanel {
private:
void OnVideoPlay(wxCommandEvent &event);
void OnVideoPlayLine(wxCommandEvent &event);
void OnVideoStop(wxCommandEvent &event);
void OnVideoToggleScroll(wxCommandEvent &event);
void OnVideoTrackerMenu(wxCommandEvent &event);
void OnVideoTrackPoints(wxCommandEvent &event);
void OnVideoTrackPointAdd(wxCommandEvent &event);
void OnVideoTrackPointDel(wxCommandEvent &event);
void OnVideoTrackerMenu2(wxCommandEvent &event);
void OnVideoTrackMovement(wxCommandEvent &event);
void OnVideoTrackMovementMoveAll(wxCommandEvent &event);
void OnVideoTrackMovementMoveOne(wxCommandEvent &event);
void OnVideoTrackMovementMoveBefore(wxCommandEvent &event);
void OnVideoTrackMovementMoveAfter(wxCommandEvent &event);
void OnVideoTrackSplitLine(wxCommandEvent &event);
void OnVideoTrackLinkFile(wxCommandEvent &event);
void OnVideoTrackMovementEmpty(wxCommandEvent &event);
public:
ToggleBitmap *AutoScroll;
wxBoxSizer *VideoSizer;
@ -63,10 +83,35 @@ public:
wxTextCtrl *VideoSubsPos;
VideoDisplay *videoDisplay;
VideoSlider *videoSlider;
//VideoZoomSlider *zoomSlider;
FrameMain *frame;
VideoBox (wxWindow *parent);
DECLARE_EVENT_TABLE()
};
///////
// IDs
enum {
Video_Play = 500,
Video_Play_Line,
Video_Stop,
Video_Auto_Scroll,
Video_Tracker_Menu,
Video_Track_Points,
Video_Track_Point_Add,
Video_Track_Point_Del,
Video_Tracker_Menu2,
Video_Track_Movement,
Video_Track_Movement_MoveAll,
Video_Track_Movement_MoveOne,
Video_Track_Movement_MoveBefore,
Video_Track_Movement_MoveAfter,
Video_Track_Split_Line,
Video_Track_Link_File,
Video_Track_Movement_Empty
};
#endif