From 58a6cf4793963b23026222b8086faf7846bbb698 Mon Sep 17 00:00:00 2001 From: Asada shinon Date: Thu, 24 Dec 2020 17:01:33 +0800 Subject: [PATCH 1/6] Added new hotkey command to reload current font provider. --- src/command/video.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/command/video.cpp b/src/command/video.cpp index d3ffaf7fe..cb1254596 100644 --- a/src/command/video.cpp +++ b/src/command/video.cpp @@ -236,6 +236,23 @@ struct video_cycle_subtitles_provider final : public cmd::Command { } }; +struct video_reload_subtitles_provider final : public cmd::Command { + CMD_NAME("video/subtitles_provider/reload") + STR_MENU("Reload active subtitles provider") + STR_DISP("Reload active subtitles provider") + STR_HELP("Reloads the current subtitles provider") + + void operator()(agi::Context* c) override { + auto providers = SubtitlesProviderFactory::GetClasses(); + if (providers.empty()) return; + + auto it = find(begin(providers), end(providers), OPT_GET("Subtitle/Provider")->GetString()); + + OPT_SET("Subtitle/Provider")->SetString(*it); + c->frame->StatusTimeout(fmt_tl("Subtitles provider set to %s", *it), 5000); + } +}; + struct video_detach final : public validator_video_loaded { CMD_NAME("video/detach") CMD_ICON(detach_video_menu) @@ -746,6 +763,7 @@ namespace cmd { reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); + reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); reg(agi::make_unique()); From d0efa0494a51ef2953cc7cea65ad3c3ff90c99e3 Mon Sep 17 00:00:00 2001 From: Asada shinon Date: Fri, 29 Jul 2022 21:50:10 +0200 Subject: [PATCH 2/6] Save vector clips with two decimal places Co-authored-by: arch1t3cht --- src/spline.cpp | 10 +++++----- src/utils.cpp | 5 +++-- src/utils.h | 2 +- src/vector2d.cpp | 2 +- src/visual_tool.cpp | 10 +++++----- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/spline.cpp b/src/spline.cpp index 395bac084..ed7353f1c 100644 --- a/src/spline.cpp +++ b/src/spline.cpp @@ -71,7 +71,7 @@ std::string Spline::EncodeToAss() const { result += "m "; last = 'm'; } - result += ToScript(pt.p1).DStr(' '); + result += ToScript(pt.p1).Str(' '); break; case SplineCurve::LINE: @@ -79,7 +79,7 @@ std::string Spline::EncodeToAss() const { result += "l "; last = 'l'; } - result += ToScript(pt.p2).DStr(' '); + result += ToScript(pt.p2).Str(' '); break; case SplineCurve::BICUBIC: @@ -87,9 +87,9 @@ std::string Spline::EncodeToAss() const { result += "b "; last = 'b'; } - result += ToScript(pt.p2).DStr(' ') + " "; - result += ToScript(pt.p3).DStr(' ') + " "; - result += ToScript(pt.p4).DStr(' '); + result += ToScript(pt.p2).Str(' ') + " "; + result += ToScript(pt.p3).Str(' ') + " "; + result += ToScript(pt.p4).Str(' '); break; default: break; diff --git a/src/utils.cpp b/src/utils.cpp index a014b0a29..f6a705fa7 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -76,8 +76,9 @@ wxString PrettySize(int bytes) { return agi::wxformat(fmt, size) + " " + suffix[i]; } -std::string float_to_string(double val) { - std::string s = agi::format("%.3f", val); +std::string float_to_string(double val, int precision) { + std::string fmt = "%." + std::to_string(precision) + "f"; + std::string s = agi::format(fmt, val); size_t pos = s.find_last_not_of("0"); if (pos != s.find(".")) ++pos; s.erase(begin(s) + pos, end(s)); diff --git a/src/utils.h b/src/utils.h index 02ef78aac..bb82570d6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -44,7 +44,7 @@ class wxWindow; wxString PrettySize(int bytes); -std::string float_to_string(double val); +std::string float_to_string(double val, int precision = 3); /// @brief Get the smallest power of two that is greater or equal to x /// diff --git a/src/vector2d.cpp b/src/vector2d.cpp index 8bb81de3c..92dca1fd8 100644 --- a/src/vector2d.cpp +++ b/src/vector2d.cpp @@ -88,5 +88,5 @@ std::string Vector2D::DStr(char sep) const { } std::string Vector2D::Str(char sep) const { - return float_to_string(x) + sep + float_to_string(y); + return float_to_string(x,2) + sep + float_to_string(y,2); } diff --git a/src/visual_tool.cpp b/src/visual_tool.cpp index 61d320722..965c2956a 100644 --- a/src/visual_tool.cpp +++ b/src/visual_tool.cpp @@ -504,11 +504,11 @@ std::string VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, boo tag = find_tag(blocks, "\\clip"); if (tag && tag->size() == 4) { - return agi::format("m %d %d l %d %d %d %d %d %d" - , (*tag)[0].Get(), (*tag)[1].Get() - , (*tag)[2].Get(), (*tag)[1].Get() - , (*tag)[2].Get(), (*tag)[3].Get() - , (*tag)[0].Get(), (*tag)[3].Get()); + return agi::format("m %.2f %.2f l %.2f %.2f %.2f %.2f %.2f %.2f" + , (*tag)[0].Get(), (*tag)[1].Get() + , (*tag)[2].Get(), (*tag)[1].Get() + , (*tag)[2].Get(), (*tag)[3].Get() + , (*tag)[0].Get(), (*tag)[3].Get()); } if (tag) { scale = std::max((*tag)[0].Get(scale), 1); From dabd9f699f4c4b6e3402ecb7c06f5b9518f08937 Mon Sep 17 00:00:00 2001 From: wangqr Date: Thu, 26 Dec 2019 17:31:59 -0500 Subject: [PATCH 3/6] Add option to downmix FFMS audio When enabled, restore FFMS to old behavior, downmixing auduo to S16 mono. This can reduce cache usage. Fix wangqr/Aegisub#31 --- src/audio_provider_ffmpegsource.cpp | 22 ++++++++++++---------- src/libresrc/default_config.json | 3 ++- src/preferences.cpp | 1 + src/project.cpp | 1 + 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/audio_provider_ffmpegsource.cpp b/src/audio_provider_ffmpegsource.cpp index 0a201855a..176a0ad81 100644 --- a/src/audio_provider_ffmpegsource.cpp +++ b/src/audio_provider_ffmpegsource.cpp @@ -165,17 +165,19 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) { throw agi::AudioProviderError("unknown or unsupported sample format"); } - if (channels > 1 || bytes_per_sample != 2) { - std::unique_ptr - opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions); - opt->ChannelLayout = FFMS_CH_FRONT_CENTER; - opt->SampleFormat = FFMS_FMT_S16; + if (OPT_GET("Provider/Audio/FFmpegSource/Downmix")->GetBool()) { + if (channels > 1 || bytes_per_sample != 2 || float_samples) { + std::unique_ptr + opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions); + opt->ChannelLayout = FFMS_CH_FRONT_CENTER; + opt->SampleFormat = FFMS_FMT_S16; - // Might fail if FFMS2 wasn't built with libavresample - if (!FFMS_SetOutputFormatA(AudioSource, opt.get(), nullptr)) { - channels = 1; - bytes_per_sample = 2; - float_samples = false; + // Might fail if FFMS2 wasn't built with libavresample + if (!FFMS_SetOutputFormatA(AudioSource, opt.get(), nullptr)) { + channels = 1; + bytes_per_sample = 2; + float_samples = false; + } } } } diff --git a/src/libresrc/default_config.json b/src/libresrc/default_config.json index 318f8d3ee..f5d26761b 100644 --- a/src/libresrc/default_config.json +++ b/src/libresrc/default_config.json @@ -331,7 +331,8 @@ "Sample Rate" : 0 }, "FFmpegSource" : { - "Decode Error Handling" : "ignore" + "Decode Error Handling" : "ignore", + "Downmix" : false } }, "Avisynth" : { diff --git a/src/preferences.cpp b/src/preferences.cpp index f6320dd75..91ebacee7 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -401,6 +401,7 @@ void Advanced_Audio(wxTreebook *book, Preferences *parent) { p->OptionChoice(ffms, _("Audio indexing error handling mode"), error_modes_choice, "Provider/Audio/FFmpegSource/Decode Error Handling"); p->OptionAdd(ffms, _("Always index all audio tracks"), "Provider/FFmpegSource/Index All Tracks"); + p->OptionAdd(ffms, _("Downmix to 16bit mono audio"), "Provider/Audio/FFmpegSource/Downmix"); #endif #ifdef WITH_PORTAUDIO diff --git a/src/project.cpp b/src/project.cpp index e01dd3749..b6230af23 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -53,6 +53,7 @@ Project::Project(agi::Context *c) : context(c) { OPT_SUB("Audio/Cache/Type", &Project::ReloadAudio, this); OPT_SUB("Audio/Provider", &Project::ReloadAudio, this); OPT_SUB("Provider/Audio/FFmpegSource/Decode Error Handling", &Project::ReloadAudio, this); + OPT_SUB("Provider/Audio/FFmpegSource/Downmix", &Project::ReloadAudio, this); OPT_SUB("Provider/Avisynth/Allow Ancient", &Project::ReloadVideo, this); OPT_SUB("Provider/Avisynth/Memory Max", &Project::ReloadVideo, this); OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", &Project::ReloadVideo, this); From f06e42a82e6b1ec7505d7b74de95030e88bf8a13 Mon Sep 17 00:00:00 2001 From: Ristellise Date: Fri, 1 Oct 2021 22:21:41 +0800 Subject: [PATCH 4/6] [Shinon] Change Mono Downmixing to Stereo Downmixing --- src/audio_provider_ffmpegsource.cpp | 5 +++-- src/preferences.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/audio_provider_ffmpegsource.cpp b/src/audio_provider_ffmpegsource.cpp index 176a0ad81..405116b05 100644 --- a/src/audio_provider_ffmpegsource.cpp +++ b/src/audio_provider_ffmpegsource.cpp @@ -166,10 +166,11 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) { } if (OPT_GET("Provider/Audio/FFmpegSource/Downmix")->GetBool()) { - if (channels > 1 || bytes_per_sample != 2 || float_samples) { + if (channels > 2 || bytes_per_sample != 2 || float_samples) { std::unique_ptr opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions); - opt->ChannelLayout = FFMS_CH_FRONT_CENTER; + if (channels > 2) + opt->ChannelLayout = FFMS_CH_FRONT_LEFT | FFMS_CH_FRONT_RIGHT; opt->SampleFormat = FFMS_FMT_S16; // Might fail if FFMS2 wasn't built with libavresample diff --git a/src/preferences.cpp b/src/preferences.cpp index 91ebacee7..703937324 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -401,7 +401,8 @@ void Advanced_Audio(wxTreebook *book, Preferences *parent) { p->OptionChoice(ffms, _("Audio indexing error handling mode"), error_modes_choice, "Provider/Audio/FFmpegSource/Decode Error Handling"); p->OptionAdd(ffms, _("Always index all audio tracks"), "Provider/FFmpegSource/Index All Tracks"); - p->OptionAdd(ffms, _("Downmix to 16bit mono audio"), "Provider/Audio/FFmpegSource/Downmix"); + wxControl* stereo = p->OptionAdd(ffms, _("Downmix to stereo"), "Provider/Audio/FFmpegSource/Downmix"); + stereo->SetToolTip("Reduces memory usage on surround audio, but may cause audio tracks to sound blank in specific circumstances. This will not affect audio with two channels or less."); #endif #ifdef WITH_PORTAUDIO From aeaab655eb70dae3af4ca28fe9a369aadbac01c2 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sat, 30 Jul 2022 00:45:49 +0200 Subject: [PATCH 5/6] Fix segfault when stereo downmixing --- src/audio_provider_ffmpegsource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio_provider_ffmpegsource.cpp b/src/audio_provider_ffmpegsource.cpp index 405116b05..46e1412f5 100644 --- a/src/audio_provider_ffmpegsource.cpp +++ b/src/audio_provider_ffmpegsource.cpp @@ -175,7 +175,7 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) { // Might fail if FFMS2 wasn't built with libavresample if (!FFMS_SetOutputFormatA(AudioSource, opt.get(), nullptr)) { - channels = 1; + channels = channels > 2 ? 2 : channels; bytes_per_sample = 2; float_samples = false; } From ba3a3dc80a5152c474c33ea9804df997b975312f Mon Sep 17 00:00:00 2001 From: Asada shinon Date: Sat, 30 Jul 2022 00:57:15 +0200 Subject: [PATCH 6/6] Parse mixin lines as template lines --- src/subs_edit_ctrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index 9d1fc6a01..8edc9b561 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -250,7 +250,7 @@ void SubsTextEditCtrl::SetStyles() { void SubsTextEditCtrl::UpdateStyle() { AssDialogue *diag = context ? context->selectionController->GetActiveLine() : nullptr; - bool template_line = diag && diag->Comment && boost::istarts_with(diag->Effect.get(), "template"); + bool template_line = diag && diag->Comment && (boost::istarts_with(diag->Effect.get(), "template") || boost::istarts_with(diag->Effect.get(), "mixin")); tokenized_line = agi::ass::TokenizeDialogueBody(line_text, template_line); agi::ass::SplitWords(line_text, tokenized_line);