diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index 0b33251e0..d7642794e 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -110,6 +110,7 @@ FrameMain::FrameMain (wxArrayString args) , showVideo(true) , showAudio(true) , blockVideoLoad(false) +, blockAudioLoad(false) { StartupLog("Entering FrameMain constructor"); @@ -433,6 +434,23 @@ void FrameMain::OnVideoOpen() { if (OPT_GET("Video/Detached/Enabled")->GetBool() && !context->dialog->Get()) cmd::call("video/detach", context.get()); Thaw(); + + if (!blockAudioLoad && OPT_GET("Video/Open Audio")->GetBool()) { + try { + context->audioController->OpenAudio(context->videoController->GetVideoName()); + } + // Opening a video with no audio data isn't an error, so just log + // and move on + catch (agi::FileNotAccessibleError const&) { + LOG_D("video/open/audio") << "File " << context->videoController->GetVideoName() << " found by video provider but not audio provider"; + } + catch (agi::AudioDataNotFoundError const& e) { + LOG_D("video/open/audio") << "File " << context->videoController->GetVideoName() << " has no audio data: " << e.GetChainedMessage(); + } + catch (agi::AudioOpenError const& err) { + wxMessageBox(lagi_wxString(err.GetMessage()), "Error loading audio", wxICON_ERROR | wxOK); + } + } } void FrameMain::OnVideoDetach(agi::OptionValue const& opt) { @@ -448,84 +466,92 @@ void FrameMain::StatusTimeout(wxString text,int ms) { StatusClear.Start(ms,true); } +#define countof(array) (sizeof(array) / sizeof(array[0])) bool FrameMain::LoadList(wxArrayString list) { - wxArrayString List; - for (size_t i=0;ivideoController->SetVideo(video); } - if (!audio.empty()) - context->audioController->OpenAudio(audio); + + if (blockAudioLoad) { + blockAudioLoad = false; + try { + context->audioController->OpenAudio(audio); + } catch (agi::UserCancelException const&) { } + } bool loaded_any = subs.size() || audio.size() || video.size(); if (loaded_any) @@ -615,71 +641,69 @@ void FrameMain::OnSubtitlesOpen() { /// prompting for each file loaded/unloaded // Load stuff from the new script - wxString curSubsVideo = DecodeRelativePath(context->ass->GetScriptInfo("Video File"),context->ass->filename); - wxString curSubsVFR = DecodeRelativePath(context->ass->GetScriptInfo("VFR File"),context->ass->filename); - wxString curSubsKeyframes = DecodeRelativePath(context->ass->GetScriptInfo("Keyframes File"),context->ass->filename); + wxString curSubsVideo = DecodeRelativePath(context->ass->GetScriptInfo("Video File"), context->ass->filename); + wxString curSubsVFR = DecodeRelativePath(context->ass->GetScriptInfo("VFR File"), context->ass->filename); + wxString curSubsKeyframes = DecodeRelativePath(context->ass->GetScriptInfo("Keyframes File"), context->ass->filename); wxString curSubsAudio = context->ass->GetScriptInfo("Audio URI"); + bool videoChanged = !blockVideoLoad && curSubsVideo != context->videoController->GetVideoName(); + bool timecodesChanged = curSubsVFR != context->videoController->GetTimecodesName(); + bool keyframesChanged = curSubsKeyframes != context->videoController->GetKeyFramesName(); + bool audioChanged = !blockAudioLoad && curSubsAudio != context->audioController->GetAudioURL(); + // Check if there is anything to change int autoLoadMode = OPT_GET("App/Auto/Load Linked Files")->GetInt(); - bool doLoad = false; - if (curSubsAudio != context->audioController->GetAudioURL() || - curSubsVFR != context->videoController->GetTimecodesName() || - curSubsVideo != context->videoController->GetVideoName() || - curSubsKeyframes != context->videoController->GetKeyFramesName() - ) - { - if (autoLoadMode == 1) { - doLoad = true; - } - else if (autoLoadMode == 2) { - doLoad = wxMessageBox(_("Do you want to load/unload the associated files?"), _("(Un)Load files?"), wxYES_NO) == wxYES; + if (autoLoadMode == 0 || (!videoChanged && !timecodesChanged && !keyframesChanged && !audioChanged)) { + SetDisplayMode(1, 1); + return; + } + + if (autoLoadMode == 2) { + if (wxMessageBox(_("Do you want to load/unload the associated files?"), _("(Un)Load files?"), wxYES_NO) != wxYES) { + SetDisplayMode(1, 1); + return; } } - if (doLoad) { - // Video - if (!blockVideoLoad && curSubsVideo != context->videoController->GetVideoName()) { - context->videoController->SetVideo(curSubsVideo); - if (context->videoController->IsLoaded()) { - context->videoController->JumpToFrame(context->ass->GetScriptInfoAsInt("Video Position")); + // Video + if (videoChanged) { + context->videoController->SetVideo(curSubsVideo); + if (context->videoController->IsLoaded()) { + context->videoController->JumpToFrame(context->ass->GetScriptInfoAsInt("Video Position")); - long videoAr = 0; - double videoArValue = 0.; - wxString arString = context->ass->GetScriptInfo("Video Aspect Ratio"); - if (arString.Left(1) == "c") { - videoAr = 4; - arString = arString.Mid(1); - arString.ToDouble(&videoArValue); - } - else if (arString.IsNumber()) { - arString.ToLong(&videoAr); - } - context->videoController->SetAspectRatio(videoAr,videoArValue); - - double videoZoom = 0.; - if (context->ass->GetScriptInfo("Video Zoom Percent").ToDouble(&videoZoom)) - context->videoDisplay->SetZoom(videoZoom); + long videoAr = 0; + double videoArValue = 0.; + wxString arString = context->ass->GetScriptInfo("Video Aspect Ratio"); + if (arString.StartsWith("c")) { + videoAr = 4; + arString.Mid(1).ToDouble(&videoArValue); } - } + else + arString.ToLong(&videoAr); - context->videoController->LoadTimecodes(curSubsVFR); - context->videoController->LoadKeyframes(curSubsKeyframes); + context->videoController->SetAspectRatio(videoAr, videoArValue); - // Audio - if (curSubsAudio != context->audioController->GetAudioURL()) { - try { - if (!curSubsAudio) - context->audioController->CloseAudio(); - else - context->audioController->OpenAudio(curSubsAudio); - } - catch (agi::UserCancelException const&) { } + double videoZoom = 0.; + if (context->ass->GetScriptInfo("Video Zoom Percent").ToDouble(&videoZoom)) + context->videoDisplay->SetZoom(videoZoom); } } - // Display - SetDisplayMode(1,1); + context->videoController->LoadTimecodes(curSubsVFR); + context->videoController->LoadKeyframes(curSubsKeyframes); + + // Audio + if (audioChanged) { + try { + if (!curSubsAudio) + context->audioController->CloseAudio(); + else + context->audioController->OpenAudio(curSubsAudio); + } + catch (agi::UserCancelException const&) { } + } + + SetDisplayMode(1, 1); } void FrameMain::OnKeyDown(wxKeyEvent &event) { @@ -701,8 +725,6 @@ wxString FrameMain::GetScriptFileName() const { return _("untitled"); #endif } - else { - wxFileName file (context->ass->filename); - return file.GetFullName(); - } + else + return wxFileName(context->ass->filename).GetFullName(); } diff --git a/aegisub/src/frame_main.h b/aegisub/src/frame_main.h index 13c5d1314..baab8a795 100644 --- a/aegisub/src/frame_main.h +++ b/aegisub/src/frame_main.h @@ -88,6 +88,7 @@ class FrameMain: public wxFrame { /// the same time, so that the video associated with the subtitles (if any) /// isn't loaded bool blockVideoLoad; + bool blockAudioLoad; void InitToolbar(); void InitContents(); diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index a6763cfc2..7e4677c05 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -212,20 +212,6 @@ void VideoContext::SetVideo(const wxString &filename) { VideoOpen(); KeyframesOpen(keyFrames); TimecodesOpen(FPS()); - - if (OPT_GET("Video/Open Audio")->GetBool()) { - try { - context->audioController->OpenAudio(filename); - } - // Opening a video with no audio data isn't an error, so just log - // and move on - catch (agi::FileNotAccessibleError const&) { - LOG_D("video/open/audio") << "File " << filename << " found by video provider but not audio provider"; - } - catch (agi::AudioDataNotFoundError const& e) { - LOG_D("video/open/audio") << "File " << filename << " has no audio data: " << e.GetChainedMessage(); - } - } } catch (agi::UserCancelException const&) { } catch (agi::FileNotAccessibleError const& err) { @@ -235,9 +221,6 @@ void VideoContext::SetVideo(const wxString &filename) { catch (VideoProviderError const& err) { wxMessageBox(lagi_wxString(err.GetMessage()), "Error setting video", wxICON_ERROR | wxOK); } - catch (agi::AudioOpenError const& err) { - wxMessageBox(lagi_wxString(err.GetMessage()), "Error loading audio", wxICON_ERROR | wxOK); - } } void VideoContext::Reload() {