From 02fa5bee3e3d2c510ff0100a4b28fe271daa7157 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 8 Jan 2012 01:33:47 +0000 Subject: [PATCH] Add option to automatically open audio when opening video. Closes #1134. Originally committed to SVN as r6224. --- aegisub/src/libresrc/default_config.json | 1 + aegisub/src/preferences.cpp | 2 +- aegisub/src/video_context.cpp | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index 3a009c081..6aa57914f 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -541,6 +541,7 @@ }, "Pattern" : false }, + "Open Audio" : false, "Overscan Mask" : false, "Provider" : "ffmpegsource", "Slider" : { diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index ed42cb523..2daecc122 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -184,7 +184,7 @@ Video::Video(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _( OptionAdd(general, _("Show keyframes in slider"), "Video/Slider/Show Keyframes"); OptionAdd(general, _("Always show visual tools"), "Tool/Visual/Always Show"); OptionAdd(general, _("Seek video to line start on selection change"), "Video/Subtitle Sync"); - CellSkip(general); + OptionAdd(general, _("Automatically open audio when opening video"), "Video/Open Audio"); const wxString czoom_arr[24] = { "12.5%", "25%", "37.5%", "50%", "62.5%", "75%", "87.5%", "100%", "112.5%", "125%", "137.5%", "150%", "162.5%", "175%", "187.5%", "200%", "212.5%", "225%", "237.5%", "250%", "262.5%", "275%", "287.5%", "300%" }; wxArrayString choice_zoom(24, czoom_arr); diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 9318f6d58..ef4c0ca5a 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -48,6 +48,7 @@ #include #include +#include #include "ass_dialogue.h" #include "ass_file.h" @@ -55,8 +56,6 @@ #include "ass_time.h" #include "audio_controller.h" #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 "main.h" @@ -207,6 +206,20 @@ 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) { @@ -216,6 +229,9 @@ 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() {