Remove the 'audio' and 'grid' public members from VideoContext and migrate everything that used them over to Context

Originally committed to SVN as r5211.
This commit is contained in:
Thomas Goyne 2011-01-16 07:17:08 +00:00
parent 169d3cd31c
commit d84b768171
30 changed files with 173 additions and 174 deletions

View File

@ -140,7 +140,7 @@ struct tool_style_assistant : public Command {
void operator()(agi::Context *c) {
c->videoController->Stop();
if (!c->stylingAssistant) c->stylingAssistant = new DialogStyling(c->parent, c->subsGrid);
if (!c->stylingAssistant) c->stylingAssistant = new DialogStyling(c);
c->stylingAssistant->Show(true);
}
};
@ -197,7 +197,7 @@ struct tool_translation_assistant : public Command {
c->videoController->Stop();
int start = c->subsGrid->GetFirstSelRow();
if (start == -1) start = 0;
DialogTranslation(c->parent, c->ass, c->subsGrid, start, true).ShowModal();
DialogTranslation(c, start, true).ShowModal();
}
};

View File

@ -55,11 +55,10 @@
/// @brief Constructor
/// @param par FrameMain this was spawned from
/// @param initialDisplaySize Initial size of the window
DialogDetachedVideo::DialogDetachedVideo(FrameMain *par, const wxSize &initialDisplaySize)
: wxDialog(par,-1,_T("Detached Video"),wxDefaultPosition,wxSize(400,300),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxWANTS_CHARS)
DialogDetachedVideo::DialogDetachedVideo(FrameMain *parent, agi::Context *context, const wxSize &initialDisplaySize)
: wxDialog(parent,-1,_T("Detached Video"),wxDefaultPosition,wxSize(400,300),wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxWANTS_CHARS)
, parent(parent)
{
parent = par;
// Set up window
int x = OPT_GET("Video/Detached/Last/X")->GetInt();
int y = OPT_GET("Video/Detached/Last/Y")->GetInt();
@ -77,10 +76,10 @@ DialogDetachedVideo::DialogDetachedVideo(FrameMain *par, const wxSize &initialDi
wxPanel *panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN);
// Video area;
videoBox = new VideoBox(panel, true, NULL, VideoContext::Get()->grid->ass);
videoBox = new VideoBox(panel, true, NULL, context);
videoBox->videoDisplay->freeSize = true;
videoBox->videoDisplay->SetClientSize(initialDisplaySize);
videoBox->videoSlider->grid = par->SubsGrid;
videoBox->videoSlider->grid = context->subsGrid;
// Set sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
@ -97,7 +96,7 @@ DialogDetachedVideo::DialogDetachedVideo(FrameMain *par, const wxSize &initialDi
if (display_index == wxNOT_FOUND)
{
int caption_size = wxSystemSettings::GetMetric(wxSYS_CAPTION_Y, this);
Move(par->GetPosition() + wxPoint(caption_size, caption_size));
Move(parent->GetPosition() + wxPoint(caption_size, caption_size));
}
else
{
@ -130,7 +129,7 @@ DialogDetachedVideo::DialogDetachedVideo(FrameMain *par, const wxSize &initialDi
OPT_SET("Video/Detached/Enabled")->SetBool(true);
// Copy the main accelerator table to this dialog
wxAcceleratorTable *table = par->GetAcceleratorTable();
wxAcceleratorTable *table = parent->GetAcceleratorTable();
SetAcceleratorTable(*table);
}
@ -149,11 +148,10 @@ END_EVENT_TABLE()
/// @brief Close window
/// @param event UNUSED
void DialogDetachedVideo::OnClose(wxCloseEvent &WXUNUSED(event)) {
FrameMain *par = parent;
OPT_SET("Video/Detached/Enabled")->SetBool(false);
Destroy();
par->context->detachedVideo = 0;
par->SetDisplayMode(1,-1);
parent->context->detachedVideo = 0;
parent->SetDisplayMode(1,-1);
}
/// @brief Move window

View File

@ -40,9 +40,9 @@
#include <wx/dialog.h>
#endif
class VideoBox;
namespace agi { struct Context; }
class FrameMain;
class VideoBox;
/// DOCME
/// @class DialogDetachedVideo
@ -63,7 +63,7 @@ private:
void OnMinimize(wxIconizeEvent &event);
public:
DialogDetachedVideo(FrameMain *parent, const wxSize &initialDisplaySize);
DialogDetachedVideo(FrameMain *parent, agi::Context *context, const wxSize &initialDisplaySize);
~DialogDetachedVideo();
DECLARE_EVENT_TABLE()

View File

@ -43,6 +43,7 @@
#include <wx/recguard.h>
#endif
#include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h"
#include "ass_dialogue.h"
@ -66,16 +67,16 @@
/// @param parent
/// @param _grid
///
DialogStyling::DialogStyling (wxWindow *parent,SubtitlesGrid *_grid) :
wxDialog (parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX)
DialogStyling::DialogStyling(agi::Context *context)
: wxDialog(context->parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX)
{
// Set icon
SetIcon(BitmapToIcon(GETIMAGE(styling_toolbutton_24)));
// Variables
grid = _grid;
audio = VideoContext::Get()->audio;
video = VideoContext::Get();
grid = context->subsGrid;
audio = context->audioController;
video = context->videoController;
needCommit = false;
linen = -1;

View File

@ -47,18 +47,13 @@
#include <wx/textctrl.h>
#endif
//////////////
// Prototypes
namespace agi { struct Context; }
class AssFile;
class AssDialogue;
class SubtitlesGrid;
class DialogStyling;
class AudioDisplay;
class VideoContext;
class AudioController;
class DialogStyling;
class SubtitlesGrid;
class VideoContext;
/// DOCME
/// @class StyleEditBox
@ -148,7 +143,7 @@ public:
/// DOCME
VideoContext *video;
DialogStyling (wxWindow *parent,SubtitlesGrid *grid);
DialogStyling(agi::Context *context);
~DialogStyling ();
void JumpToLine(int n);

View File

@ -43,6 +43,7 @@
#include <wx/settings.h>
#endif
#include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h"
#include "ass_dialogue.h"
@ -68,19 +69,19 @@
/// @param startrow
/// @param preview
///
DialogTranslation::DialogTranslation (wxWindow *parent,AssFile *_subs,SubtitlesGrid *_grid,int startrow,bool preview)
: wxDialog(parent, -1, _("Translation Assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX, _T("TranslationAssistant"))
DialogTranslation::DialogTranslation(agi::Context *c, int startrow, bool preview)
: wxDialog(c->parent, -1, _("Translation Assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX, _T("TranslationAssistant"))
{
// Set icon
SetIcon(BitmapToIcon(GETIMAGE(translation_toolbutton_24)));
// Set variables
enablePreview = preview;
main = parent;
subs = _subs;
grid = _grid;
audio = VideoContext::Get()->audio;
video = VideoContext::Get();
main = c->parent;
subs = c->ass;
grid = c->subsGrid;
audio = c->audioController;
video = c->videoController;
// Translation controls
OrigText = new ScintillaTextCtrl(this,TEXT_ORIGINAL,_T(""),wxDefaultPosition,wxSize(320,80));

View File

@ -39,13 +39,14 @@
#include <wx/stattext.h>
#endif
class AssFile;
namespace agi { struct Context; }
class AssDialogue;
class AssFile;
class AudioController;
class AudioDisplay;
class ScintillaTextCtrl;
class SubtitlesGrid;
class VideoContext;
class AudioController;
/// DOCME
@ -111,7 +112,7 @@ public:
/// DOCME
bool enablePreview;
DialogTranslation (wxWindow *parent,AssFile *subs,SubtitlesGrid *grid,int startrow=0,bool preview=false);
DialogTranslation(agi::Context *context, int startrow=0, bool preview=false);
void OnTransBoxKey(wxKeyEvent &event);

View File

@ -144,7 +144,6 @@ FrameMain::FrameMain (wxArrayString args)
context->selectionController = 0;
context->videoController = VideoContext::Get(); // derp
context->videoController->audio = context->audioController;
context->videoController->AddVideoOpenListener(&FrameMain::OnVideoOpen, this);
StartupLog("Initializing context frames");
@ -193,6 +192,9 @@ FrameMain::FrameMain (wxArrayString args)
context->stylingAssistant = 0;
InitContents();
StartupLog("Complete context initialization");
context->videoController->SetContext(context.get());
StartupLog("Set up Auto Save");
AutoSave.SetOwner(this, ID_APP_TIMER_AUTOSAVE);
int time = OPT_GET("App/Auto/Save Every Seconds")->GetInt();
@ -290,7 +292,7 @@ void FrameMain::InitContents() {
Panel = new wxPanel(this,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL | wxCLIP_CHILDREN);
StartupLog("Create video box");
context->videoBox = videoBox = new VideoBox(Panel, false, ZoomBox, context->ass);
context->videoBox = videoBox = new VideoBox(Panel, false, ZoomBox, context.get());
wxBoxSizer *videoSizer = new wxBoxSizer(wxVERTICAL);
videoSizer->Add(videoBox , 0, wxEXPAND);
videoSizer->AddStretchSpacer(1);
@ -299,7 +301,6 @@ void FrameMain::InitContents() {
context->subsGrid = SubsGrid = new SubtitlesGrid(this,Panel,-1,context->ass,wxDefaultPosition,wxSize(600,100),wxWANTS_CHARS | wxSUNKEN_BORDER,"Subs grid");
context->selectionController = context->subsGrid;
context->videoBox->videoSlider->grid = SubsGrid;
context->videoController->grid = SubsGrid;
Search.grid = SubsGrid;
StartupLog("Create tool area splitter window");
@ -350,7 +351,6 @@ void FrameMain::DeInitContents() {
delete videoBox;
delete context->ass;
HelpButton::ClearPages();
context->videoController->audio = 0;
}
/// @brief Update toolbar
@ -650,7 +650,7 @@ void FrameMain::OpenHelp(wxString) {
void FrameMain::DetachVideo(bool detach) {
if (detach) {
if (!context->detachedVideo) {
context->detachedVideo = new DialogDetachedVideo(this, videoBox->videoDisplay->GetClientSize());
context->detachedVideo = new DialogDetachedVideo(this, context.get(), videoBox->videoDisplay->GetClientSize());
context->detachedVideo->Show();
}
}

View File

@ -43,8 +43,8 @@
#include <wx/statline.h>
#endif
#include "ass_dialogue.h"
#include "ass_file.h"
#include "include/aegisub/context.h"
#include "frame_main.h"
#include "help_button.h"
#include "libresrc/libresrc.h"
@ -64,7 +64,7 @@
/// @param parent
/// @param isDetached
///
VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, AssFile *ass)
VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, agi::Context *context)
: wxPanel (parent,-1)
{
// Parent
@ -113,7 +113,7 @@ VideoBox::VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, AssFi
visualToolBar->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
// Display
videoDisplay = new VideoDisplay(this,VideoPosition,VideoSubsPos,zoomBox,videoPage,ass);
videoDisplay = new VideoDisplay(this,VideoPosition,VideoSubsPos,zoomBox,videoPage,context);
// Set display
videoSlider->Display = videoDisplay;

View File

@ -44,15 +44,13 @@
#include <wx/toolbar.h>
#endif
class AssFile;
namespace agi { struct Context; }
class VideoDisplay;
class VideoSlider;
class ToggleBitmap;
class FrameMain;
class wxComboBox;
/// DOCME
/// @class VideoBox
/// @brief DOCME
@ -99,7 +97,7 @@ public:
/// DOCME
VideoSlider *videoSlider;
VideoBox (wxWindow *parent, bool isDetached, wxComboBox *zoomBox, AssFile *ass);
VideoBox(wxWindow *parent, bool isDetached, wxComboBox *zoomBox, agi::Context *context);
DECLARE_EVENT_TABLE()
};

View File

@ -53,8 +53,9 @@
#include <GL/glu.h>
#endif
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include <libaegisub/access.h>
#include <libaegisub/keyframe.h>
#include "ass_dialogue.h"
#include "ass_file.h"
#include "ass_style.h"
@ -63,15 +64,13 @@
#include "compat.h"
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "include/aegisub/context.h"
#include "include/aegisub/video_provider.h"
#include <libaegisub/keyframe.h>
#include <libaegisub/access.h>
#include "main.h"
#include "mkv_wrap.h"
#include "standard_paths.h"
#include "selection_controller.h"
#include "standard_paths.h"
#include "subs_edit_box.h"
#include "subs_grid.h"
#include "threaded_frame_source.h"
#include "utils.h"
#include "video_box.h"
@ -102,8 +101,6 @@ VideoContext::VideoContext()
, arType(0)
, hasSubtitles(false)
, playAudioOnStep(OPT_GET("Audio/Plays When Stepping Video"))
, grid(NULL)
, audio(NULL)
, VFR_Input(videoFPS)
, VFR_Output(ovrFPS)
{
@ -152,6 +149,12 @@ void VideoContext::Reset() {
provider.reset();
}
void VideoContext::SetContext(agi::Context *context) {
this->context = context;
context->ass->AddCommitListener(&VideoContext::OnSubtitlesCommit, this);
context->ass->AddCommitListener(&VideoContext::OnSubtitlesSave, this);
}
void VideoContext::SetVideo(const wxString &filename) {
Stop();
Reset();
@ -198,9 +201,7 @@ void VideoContext::SetVideo(const wxString &filename) {
hasSubtitles = MatroskaWrapper::HasSubtitles(filename);
}
provider->LoadSubtitles(grid->ass);
grid->ass->AddCommitListener(&VideoContext::OnSubtitlesCommit, this);
grid->ass->AddCommitListener(&VideoContext::OnSubtitlesSave, this);
provider->LoadSubtitles(context->ass);
VideoOpen();
KeyframesOpen(keyFrames);
TimecodesOpen(FPS());
@ -229,7 +230,7 @@ void VideoContext::OnSubtitlesCommit() {
bool wasPlaying = isPlaying;
Stop();
provider->LoadSubtitles(grid->ass);
provider->LoadSubtitles(context->ass);
GetFrameAsync(frame_n);
if (wasPlaying) Play();
@ -237,11 +238,11 @@ void VideoContext::OnSubtitlesCommit() {
void VideoContext::OnSubtitlesSave() {
if (!IsLoaded()) {
grid->ass->SetScriptInfo("Video File", "");
grid->ass->SetScriptInfo("Video Aspect Ratio", "");
grid->ass->SetScriptInfo("Video Position", "");
grid->ass->SetScriptInfo("VFR File", "");
grid->ass->SetScriptInfo("Keyframes File", "");
context->ass->SetScriptInfo("Video File", "");
context->ass->SetScriptInfo("Video Aspect Ratio", "");
context->ass->SetScriptInfo("Video Position", "");
context->ass->SetScriptInfo("VFR File", "");
context->ass->SetScriptInfo("Keyframes File", "");
return;
}
@ -251,11 +252,11 @@ void VideoContext::OnSubtitlesSave() {
else
ar = wxString::Format("%d", arType);
grid->ass->SetScriptInfo("Video File", MakeRelativePath(videoName, grid->ass->filename));
grid->ass->SetScriptInfo("Video Aspect Ratio", ar);
grid->ass->SetScriptInfo("Video Position", wxString::Format("%d", frame_n));
grid->ass->SetScriptInfo("VFR File", MakeRelativePath(GetTimecodesName(), grid->ass->filename));
grid->ass->SetScriptInfo("Keyframes File", MakeRelativePath(GetKeyFramesName(), grid->ass->filename));
context->ass->SetScriptInfo("Video File", MakeRelativePath(videoName, context->ass->filename));
context->ass->SetScriptInfo("Video Aspect Ratio", ar);
context->ass->SetScriptInfo("Video Position", wxString::Format("%d", frame_n));
context->ass->SetScriptInfo("VFR File", MakeRelativePath(GetTimecodesName(), context->ass->filename));
context->ass->SetScriptInfo("Keyframes File", MakeRelativePath(GetKeyFramesName(), context->ass->filename));
}
void VideoContext::JumpToFrame(int n) {
@ -327,7 +328,7 @@ void VideoContext::SaveSnapshot(bool raw) {
}
void VideoContext::GetScriptSize(int &sw,int &sh) {
grid->ass->GetResolution(sw,sh);
context->ass->GetResolution(sw,sh);
}
void VideoContext::NextFrame() {
@ -337,9 +338,9 @@ void VideoContext::NextFrame() {
JumpToFrame(frame_n + 1);
// Start playing audio
if (playAudioOnStep->GetBool()) {
audio->PlayRange(SampleRange(
audio->SamplesFromMilliseconds(TimeAtFrame(frame_n - 1)),
audio->SamplesFromMilliseconds(TimeAtFrame(frame_n))));
context->audioController->PlayRange(SampleRange(
context->audioController->SamplesFromMilliseconds(TimeAtFrame(frame_n - 1)),
context->audioController->SamplesFromMilliseconds(TimeAtFrame(frame_n))));
}
}
@ -350,9 +351,9 @@ void VideoContext::PrevFrame() {
JumpToFrame(frame_n - 1);
// Start playing audio
if (playAudioOnStep->GetBool()) {
audio->PlayRange(SampleRange(
audio->SamplesFromMilliseconds(TimeAtFrame(frame_n)),
audio->SamplesFromMilliseconds(TimeAtFrame(frame_n + 1))));
context->audioController->PlayRange(SampleRange(
context->audioController->SamplesFromMilliseconds(TimeAtFrame(frame_n)),
context->audioController->SamplesFromMilliseconds(TimeAtFrame(frame_n + 1))));
}
}
@ -367,7 +368,7 @@ void VideoContext::Play() {
endFrame = -1;
// Start playing audio
audio->PlayToEnd(audio->SamplesFromMilliseconds(TimeAtFrame(startFrame)));
context->audioController->PlayToEnd(context->audioController->SamplesFromMilliseconds(TimeAtFrame(startFrame)));
//audio->Play will override this if we put it before, so put it after.
isPlaying = true;
@ -379,18 +380,18 @@ void VideoContext::Play() {
}
void VideoContext::PlayLine() {
AssDialogue *curline = grid->GetActiveLine();
AssDialogue *curline = context->selectionController->GetActiveLine();
if (!curline) return;
// Start playing audio
audio->PlayRange(SampleRange(
audio->SamplesFromMilliseconds(curline->Start.GetMS()),
audio->SamplesFromMilliseconds(curline->End.GetMS())));
context->audioController->PlayRange(SampleRange(
context->audioController->SamplesFromMilliseconds(curline->Start.GetMS()),
context->audioController->SamplesFromMilliseconds(curline->End.GetMS())));
// Set variables
isPlaying = true;
startFrame = FrameAtTime(grid->GetActiveLine()->Start.GetMS(),agi::vfr::START);
endFrame = FrameAtTime(grid->GetActiveLine()->End.GetMS(),agi::vfr::END);
startFrame = FrameAtTime(context->selectionController->GetActiveLine()->Start.GetMS(),agi::vfr::START);
endFrame = FrameAtTime(context->selectionController->GetActiveLine()->End.GetMS(),agi::vfr::END);
// Jump to start
playNextFrame = startFrame;
@ -408,7 +409,7 @@ void VideoContext::Stop() {
if (isPlaying) {
playback.Stop();
isPlaying = false;
audio->Stop();
context->audioController->Stop();
}
}
@ -444,8 +445,8 @@ void VideoContext::OnPlayTimer(wxTimerEvent &event) {
if (nextFrame == frame_n) return;
// Next frame is before or over 2 frames ahead, so force audio resync
if (audio->IsPlaying() && keepAudioSync && (nextFrame < frame_n || nextFrame > frame_n + 2)) {
audio->ResyncPlaybackPosition(audio->SamplesFromMilliseconds(TimeAtFrame(nextFrame)));
if (context->audioController->IsPlaying() && keepAudioSync && (nextFrame < frame_n || nextFrame > frame_n + 2)) {
context->audioController->ResyncPlaybackPosition(context->audioController->SamplesFromMilliseconds(TimeAtFrame(nextFrame)));
}
// Jump to next frame
@ -454,18 +455,18 @@ void VideoContext::OnPlayTimer(wxTimerEvent &event) {
JumpToFrame(nextFrame);
// Sync audio
if (keepAudioSync && nextFrame % 10 == 0 && audio->IsPlaying()) {
int64_t audPos = audio->SamplesFromMilliseconds(TimeAtFrame(nextFrame));
int64_t curPos = audio->GetPlaybackPosition();
if (keepAudioSync && nextFrame % 10 == 0 && context->audioController->IsPlaying()) {
int64_t audPos = context->audioController->SamplesFromMilliseconds(TimeAtFrame(nextFrame));
int64_t curPos = context->audioController->GetPlaybackPosition();
int delta = int(audPos-curPos);
if (delta < 0) delta = -delta;
int maxDelta = audio->SamplesFromMilliseconds(1000);
if (delta > maxDelta) audio->ResyncPlaybackPosition(audPos);
int maxDelta = context->audioController->SamplesFromMilliseconds(1000);
if (delta > maxDelta) context->audioController->ResyncPlaybackPosition(audPos);
}
}
double VideoContext::GetARFromType(int type) const {
if (type == 0) return (double)VideoContext::Get()->GetWidth()/(double)VideoContext::Get()->GetHeight();
if (type == 0) return (double)GetWidth()/(double)GetHeight();
if (type == 1) return 4.0/3.0;
if (type == 2) return 16.0/9.0;
if (type == 3) return 2.35;

View File

@ -64,6 +64,7 @@ class VideoProviderErrorEvent;
class AudioController;
namespace agi {
struct Context;
class OptionValue;
}
@ -86,7 +87,8 @@ class VideoContext : public wxEvtHandler {
/// Aspect ratio was changed (type, value)
agi::signal::Signal<int, double> ARChange;
private:
agi::Context *context;
/// DOCME
std::tr1::shared_ptr<VideoProvider> videoProvider;
@ -159,21 +161,22 @@ private:
void OnSubtitlesSave();
public:
/// DOCME
SubtitlesGrid *grid;
/// File name of currently open video, if any
wxString videoName;
/// The audio controller for this video context
AudioController *audio;
const agi::vfr::Framerate &VFR_Input;
const agi::vfr::Framerate &VFR_Output;
VideoContext();
~VideoContext();
/// @brief Set the context that this is the video controller for
/// @param context Initialized project context
///
/// Once this is no longer a singleton this can probably be moved into
/// the constructor
void SetContext(agi::Context *context);
/// @brief Get the video provider used for the currently open video
VideoProvider *GetProvider() const { return videoProvider.get(); }
std::tr1::shared_ptr<AegiVideoFrame> GetFrame(int n, bool raw = false);

View File

@ -56,6 +56,7 @@
#include <GL/glu.h>
#endif
#include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h"
#include "video_display.h"
@ -130,10 +131,10 @@ VideoDisplay::VideoDisplay(
wxTextCtrl *SubsPosition,
wxComboBox *zoomBox,
wxWindow* parent,
AssFile *model)
agi::Context *c)
: wxGLCanvas (parent, -1, attribList, wxDefaultPosition, wxDefaultSize, 0, wxPanelNameStr)
, alwaysShowTools(OPT_GET("Tool/Visual/Always Show"))
, vc(VideoContext::Get())
, con(c)
, currentFrame(-1)
, w(8), h(8), viewport_x(0), viewport_width(0), viewport_bottom(0), viewport_top(0), viewport_height(0)
, zoomValue(OPT_GET("Video/Default Zoom")->GetInt() * .125 + .125)
@ -145,28 +146,25 @@ VideoDisplay::VideoDisplay(
, scriptW(INT_MIN)
, scriptH(INT_MIN)
, zoomBox(zoomBox)
, model(model)
, box(box)
, freeSize(false)
{
assert(vc);
assert(box);
assert(model);
if (zoomBox) zoomBox->SetValue(wxString::Format("%g%%", zoomValue * 100.));
box->Bind(wxEVT_COMMAND_TOOL_CLICKED, &VideoDisplay::OnMode, this, Video_Mode_Standard, Video_Mode_Vector_Clip);
vc->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
slots.push_back(vc->AddSeekListener(&VideoDisplay::SetFrame, this));
slots.push_back(vc->AddVideoOpenListener(&VideoDisplay::OnVideoOpen, this));
slots.push_back(vc->AddARChangeListener(&VideoDisplay::UpdateSize, this));
con->videoController->Bind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
slots.push_back(con->videoController->AddSeekListener(&VideoDisplay::SetFrame, this));
slots.push_back(con->videoController->AddVideoOpenListener(&VideoDisplay::OnVideoOpen, this));
slots.push_back(con->videoController->AddARChangeListener(&VideoDisplay::UpdateSize, this));
slots.push_back(model->AddCommitListener(&VideoDisplay::OnCommit, this));
SetCursor(wxNullCursor);
}
VideoDisplay::~VideoDisplay () {
vc->Unbind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
con->videoController->Unbind(EVT_FRAME_READY, &VideoDisplay::UploadFrameData, this);
}
bool VideoDisplay::InitContext() {
@ -194,7 +192,7 @@ void VideoDisplay::UpdateRelativeTimes(int time) {
int startOff = 0;
int endOff = 0;
if (AssDialogue *curLine = vc->grid->GetActiveLine()) {
if (AssDialogue *curLine = con->selectionController->GetActiveLine()) {
startOff = time - curLine->Start.GetMS();
endOff = time - curLine->End.GetMS();
}
@ -213,7 +211,7 @@ void VideoDisplay::SetFrame(int frameNumber) {
// Get time for frame
{
int time = vc->TimeAtFrame(frameNumber, agi::vfr::EXACT);
int time = con->videoController->TimeAtFrame(frameNumber, agi::vfr::EXACT);
int h = time / 3600000;
int m = time % 3600000 / 60000;
int s = time % 60000 / 1000;
@ -221,7 +219,7 @@ void VideoDisplay::SetFrame(int frameNumber) {
// Set the text box for frame number and time
PositionDisplay->SetValue(wxString::Format(L"%01i:%02i:%02i.%03i - %i", h, m, s, ms, frameNumber));
if (std::binary_search(vc->GetKeyFrames().begin(), vc->GetKeyFrames().end(), frameNumber)) {
if (std::binary_search(con->videoController->GetKeyFrames().begin(), con->videoController->GetKeyFrames().end(), frameNumber)) {
// Set the background color to indicate this is a keyframe
PositionDisplay->SetBackgroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour()));
PositionDisplay->SetForegroundColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Selection")->GetColour()));
@ -235,9 +233,9 @@ void VideoDisplay::SetFrame(int frameNumber) {
}
// Render the new frame
if (vc->IsLoaded()) {
if (con->videoController->IsLoaded()) {
tool->SetFrame(frameNumber);
vc->GetFrameAsync(currentFrame);
con->videoController->GetFrameAsync(currentFrame);
}
}
@ -253,7 +251,7 @@ void VideoDisplay::UploadFrameData(FrameReadyEvent &evt) {
L"programs and updating your video card drivers may fix this.\n"
L"Error message reported: %s",
err.GetMessage().c_str());
vc->Reset();
con->videoController->Reset();
}
catch (const VideoOutRenderException& err) {
wxLogError(
@ -265,24 +263,24 @@ void VideoDisplay::UploadFrameData(FrameReadyEvent &evt) {
}
void VideoDisplay::OnVideoOpen() {
if (!vc->IsLoaded()) return;
if (!con->videoController->IsLoaded()) return;
UpdateSize();
currentFrame = 0;
vc->GetFrameAsync(0);
con->videoController->GetFrameAsync(0);
UpdateRelativeTimes(0);
if (!tool.get()) tool.reset(new VisualToolCross(this, video, toolBar));
if (!tool.get()) tool.reset(new VisualToolCross(this, con, video, toolBar));
tool->Refresh();
}
void VideoDisplay::OnCommit(int type) {
if (type == AssFile::COMMIT_FULL || type == AssFile::COMMIT_UNDO)
vc->GetScriptSize(scriptW, scriptH);
con->videoController->GetScriptSize(scriptW, scriptH);
if (tool.get()) tool->Refresh();
UpdateRelativeTimes(vc->TimeAtFrame(currentFrame, agi::vfr::EXACT));
UpdateRelativeTimes(con->videoController->TimeAtFrame(currentFrame, agi::vfr::EXACT));
}
void VideoDisplay::Render() try {
if (!InitContext()) return;
if (!vc->IsLoaded()) return;
if (!con->videoController->IsLoaded()) return;
assert(wxIsMainThread());
if (!viewport_height || !viewport_width) UpdateSize();
@ -294,7 +292,7 @@ void VideoDisplay::Render() try {
E(glOrtho(0.0f, w, h, 0.0f, -1000.0f, 1000.0f));
if (OPT_GET("Video/Overscan Mask")->GetBool()) {
double ar = vc->GetAspectRatioValue();
double ar = con->videoController->GetAspectRatioValue();
// Based on BBC's guidelines: http://www.bbc.co.uk/guidelines/dq/pdf/tv/tv_standards_london.pdf
// 16:9 or wider
@ -321,27 +319,27 @@ catch (const VideoOutException &err) {
L"An error occurred trying to render the video frame on the screen.\n"
L"Error message reported: %s",
err.GetMessage().c_str());
vc->Reset();
con->videoController->Reset();
}
catch (const OpenGlException &err) {
wxLogError(
L"An error occurred trying to render visual overlays on the screen.\n"
L"Error message reported: %s",
err.GetMessage().c_str());
vc->Reset();
con->videoController->Reset();
}
catch (const wchar_t *err) {
wxLogError(
L"An error occurred trying to render the video frame on the screen.\n"
L"Error message reported: %s",
err);
vc->Reset();
con->videoController->Reset();
}
catch (...) {
wxLogError(
L"An error occurred trying to render the video frame to screen.\n"
L"No further error message given.");
vc->Reset();
con->videoController->Reset();
}
void VideoDisplay::DrawOverscanMask(int sizeH, int sizeV, wxColor color, double alpha) const {
@ -370,15 +368,15 @@ void VideoDisplay::DrawOverscanMask(int sizeH, int sizeV, wxColor color, double
}
void VideoDisplay::UpdateSize(int arType, double arValue) {
if (!vc->IsLoaded()) return;
if (!con->videoController->IsLoaded()) return;
if (!IsShownOnScreen()) return;
int vidW = vc->GetWidth();
int vidH = vc->GetHeight();
int vidW = con->videoController->GetWidth();
int vidH = con->videoController->GetHeight();
if (arType == -1) {
arType = vc->GetAspectRatioType();
arValue = vc->GetAspectRatioValue();
arType = con->videoController->GetAspectRatioType();
arValue = con->videoController->GetAspectRatioValue();
}
if (freeSize) {
@ -440,7 +438,7 @@ void VideoDisplay::UpdateSize(int arType, double arValue) {
SetEvtHandlerEnabled(true);
}
vc->GetScriptSize(scriptW, scriptH);
con->videoController->GetScriptSize(scriptW, scriptH);
video.w = w;
video.h = h;
@ -462,7 +460,7 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
assert(w > 0);
// Disable when playing
if (vc->IsPlaying()) return;
if (con->videoController->IsPlaying()) return;
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) {
wxMenu menu;
@ -546,7 +544,7 @@ double VideoDisplay::GetZoom() const {
template<class T>
void VideoDisplay::SetTool() {
tool.reset();
tool.reset(new T(this, video, toolBar));
tool.reset(new T(this, con, video, toolBar));
box->Bind(wxEVT_COMMAND_TOOL_CLICKED, &T::OnSubTool, static_cast<T*>(tool.get()), VISUAL_SUB_TOOL_START, VISUAL_SUB_TOOL_END);
}
void VideoDisplay::OnMode(const wxCommandEvent &event) {
@ -594,24 +592,24 @@ void VideoDisplay::FromScriptCoords(int *x, int *y) const {
void VideoDisplay::OnCopyToClipboard(wxCommandEvent &) {
if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxBitmapDataObject(wxBitmap(vc->GetFrame(currentFrame)->GetImage(),24)));
wxTheClipboard->SetData(new wxBitmapDataObject(wxBitmap(con->videoController->GetFrame(currentFrame)->GetImage(),24)));
wxTheClipboard->Close();
}
}
void VideoDisplay::OnCopyToClipboardRaw(wxCommandEvent &) {
if (wxTheClipboard->Open()) {
wxTheClipboard->SetData(new wxBitmapDataObject(wxBitmap(vc->GetFrame(currentFrame,true)->GetImage(),24)));
wxTheClipboard->SetData(new wxBitmapDataObject(wxBitmap(con->videoController->GetFrame(currentFrame,true)->GetImage(),24)));
wxTheClipboard->Close();
}
}
void VideoDisplay::OnSaveSnapshot(wxCommandEvent &) {
vc->SaveSnapshot(false);
con->videoController->SaveSnapshot(false);
}
void VideoDisplay::OnSaveSnapshotRaw(wxCommandEvent &) {
vc->SaveSnapshot(true);
con->videoController->SaveSnapshot(true);
}
void VideoDisplay::OnCopyCoords(wxCommandEvent &) {

View File

@ -54,7 +54,9 @@ class VideoContext;
class VideoOutGL;
class IVisualTool;
class wxToolBar;
namespace agi {
struct Context;
class OptionValue;
}
@ -74,8 +76,7 @@ class VideoDisplay : public wxGLCanvas {
const agi::OptionValue* alwaysShowTools;
/// The video context providing video to this display
VideoContext *vc;
agi::Context *con;
/// The frame number currently being displayed
int currentFrame;
@ -201,7 +202,7 @@ public:
wxTextCtrl *SubsPosition,
wxComboBox *zoomBox,
wxWindow* parent,
AssFile *model);
agi::Context *context);
~VideoDisplay();
/// @brief Render the currently visible frame

View File

@ -45,6 +45,7 @@
#include "ass_override.h"
#include "ass_style.h"
#include "ass_time.h"
#include "include/aegisub/context.h"
#include "main.h"
#include "selection_controller.h"
#include "subs_edit_box.h"
@ -62,13 +63,13 @@
const wxColour IVisualTool::colour[4] = {wxColour(106,32,19), wxColour(255,169,40), wxColour(255,253,185), wxColour(187,0,0)};
template<class FeatureType>
VisualTool<FeatureType>::VisualTool(VideoDisplay *parent, VideoState const& video)
VisualTool<FeatureType>::VisualTool(VideoDisplay *parent, agi::Context *context, VideoState const& video)
: dragStartX(0)
, dragStartY(0)
, commitId(-1)
, selChanged(false)
, selectedFeatures(selFeatures)
, grid(VideoContext::Get()->grid)
, grid(context->subsGrid)
, parent(parent)
, holding(false)
, dragging(false)
@ -80,7 +81,7 @@ VisualTool<FeatureType>::VisualTool(VideoDisplay *parent, VideoState const& vide
, ctrlDown(false)
, altDown(false)
{
frameNumber = VideoContext::Get()->GetFrameN();
frameNumber = context->videoController->GetFrameN();
curDiag = GetActiveDialogueLine();
grid->AddSelectionListener(this);
curFeature = features.begin();

View File

@ -49,11 +49,12 @@
#include "gl_wrap.h"
#include "selection_controller.h"
class VideoDisplay;
class AssDialogue;
class SubtitlesGrid;
class VideoDisplay;
struct VideoState;
namespace agi {
struct Context;
class OptionValue;
}
@ -226,7 +227,7 @@ public:
/// @brief Constructor
/// @param parent The VideoDisplay to use for coordinate conversion
/// @param video Video and mouse information passing blob
VisualTool(VideoDisplay *parent, VideoState const& video);
VisualTool(VideoDisplay *parent, agi::Context *context, VideoState const& video);
/// @brief Destructor
virtual ~VisualTool();

View File

@ -46,8 +46,8 @@
#include "video_display.h"
#include "visual_tool_clip.h"
VisualToolClip::VisualToolClip(VideoDisplay *parent, VideoState const& video, wxToolBar *)
: VisualTool<ClipCorner>(parent, video)
VisualToolClip::VisualToolClip(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *)
: VisualTool<ClipCorner>(parent, context, video)
, curX1(0)
, curY1(0)
, curX2(video.w)

View File

@ -76,5 +76,5 @@ class VisualToolClip : public VisualTool<ClipCorner> {
void Draw();
public:
VisualToolClip(VideoDisplay *parent, VideoState const& video, wxToolBar *);
VisualToolClip(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *);
};

View File

@ -42,8 +42,8 @@
#include "video_display.h"
#include "visual_tool_cross.h"
VisualToolCross::VisualToolCross(VideoDisplay *parent, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, video)
VisualToolCross::VisualToolCross(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, context, video)
, glText(new OpenGLText)
{
}

View File

@ -53,5 +53,5 @@ class VisualToolCross : public VisualTool<VisualDraggableFeature> {
void Draw();
std::tr1::shared_ptr<OpenGLText> glText;
public:
VisualToolCross(VideoDisplay *parent, VideoState const& video, wxToolBar *);
VisualToolCross(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *);
};

View File

@ -54,8 +54,8 @@ static const DraggableFeatureType DRAG_END = DRAG_BIG_CIRCLE;
/// @brief Constructor
/// @param _parent
/// @param toolBar
VisualToolDrag::VisualToolDrag(VideoDisplay *parent, VideoState const& video, wxToolBar * toolBar)
: VisualTool<VisualToolDragDraggableFeature>(parent, video)
VisualToolDrag::VisualToolDrag(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar * toolBar)
: VisualTool<VisualToolDragDraggableFeature>(parent, context, video)
, toolBar(toolBar)
, primary(NULL)
, toggleMoveOnMove(true)

View File

@ -95,7 +95,7 @@ class VisualToolDrag : public VisualTool<VisualToolDragDraggableFeature> {
void Draw();
bool Update();
public:
VisualToolDrag(VideoDisplay *parent, VideoState const& video, wxToolBar *toolbar);
VisualToolDrag(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *toolbar);
void OnSubTool(wxCommandEvent &event);
};

View File

@ -47,8 +47,8 @@
#include "video_display.h"
#include "visual_tool_rotatexy.h"
VisualToolRotateXY::VisualToolRotateXY(VideoDisplay *parent, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, video)
VisualToolRotateXY::VisualToolRotateXY(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, context, video)
{
features.resize(1);
org = &features.back();

View File

@ -56,5 +56,5 @@ class VisualToolRotateXY : public VisualTool<VisualDraggableFeature> {
void Draw();
public:
VisualToolRotateXY(VideoDisplay *parent, VideoState const& video, wxToolBar *);
VisualToolRotateXY(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *);
};

View File

@ -50,8 +50,8 @@
static const float deg2rad = 3.1415926536f / 180.f;
static const float rad2deg = 180.f / 3.1415926536f;
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *parent, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, video)
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, context, video)
{
features.resize(1);
org = &features.back();

View File

@ -61,5 +61,5 @@ class VisualToolRotateZ : public VisualTool<VisualDraggableFeature> {
void Draw();
bool Update() { return true; }
public:
VisualToolRotateZ(VideoDisplay *parent, VideoState const& video, wxToolBar *);
VisualToolRotateZ(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *);
};

View File

@ -47,8 +47,8 @@
#include "video_display.h"
#include "visual_tool_scale.h"
VisualToolScale::VisualToolScale(VideoDisplay *parent, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, video)
VisualToolScale::VisualToolScale(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *)
: VisualTool<VisualDraggableFeature>(parent, context, video)
, curScaleX(0.f)
, origScaleX(0.f)
, curScaleY(0.f)

View File

@ -56,5 +56,5 @@ class VisualToolScale : public VisualTool<VisualDraggableFeature> {
void DoRefresh();
void Draw();
public:
VisualToolScale(VideoDisplay *parent, VideoState const& video, wxToolBar *);
VisualToolScale(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *);
};

View File

@ -81,8 +81,8 @@ static void for_each_iter(C &container, O obj, M method) {
}
}
VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent, VideoState const& video, wxToolBar * toolBar)
: VisualTool<VisualToolVectorClipDraggableFeature>(parent, video)
VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar * toolBar)
: VisualTool<VisualToolVectorClipDraggableFeature>(parent, context, video)
, spline(*parent)
, toolBar(toolBar)
{

View File

@ -87,7 +87,7 @@ class VisualToolVectorClip : public VisualTool<VisualToolVectorClipDraggableFeat
void Draw();
bool Update() { return mode >= 1 && mode <= 4; }
public:
VisualToolVectorClip(VideoDisplay *parent, VideoState const& video, wxToolBar *toolbar);
VisualToolVectorClip(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *toolbar);
/// Subtoolbar button click handler
void OnSubTool(wxCommandEvent &event);