From b275399fb1befec9ffe25d6b581f19daefe0b161 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 27 Apr 2012 19:07:29 +0000 Subject: [PATCH] Add option to draw lines at each second in the audio display Originally committed to SVN as r6721. --- aegisub/src/audio_marker.cpp | 28 ++++++++++++++++++++ aegisub/src/audio_marker.h | 33 ++++++++++++++++++++++++ aegisub/src/audio_timing_dialogue.cpp | 6 +++++ aegisub/src/libresrc/default_config.json | 2 ++ aegisub/src/preferences.cpp | 3 +++ 5 files changed, 72 insertions(+) diff --git a/aegisub/src/audio_marker.cpp b/aegisub/src/audio_marker.cpp index 787a46aed..c00116053 100644 --- a/aegisub/src/audio_marker.cpp +++ b/aegisub/src/audio_marker.cpp @@ -141,3 +141,31 @@ void VideoPositionMarkerProvider::GetMarkers(const TimeRange &range, AudioMarker if (marker && range.contains(*marker)) out.push_back(marker.get()); } + +SecondsMarkerProvider::SecondsMarkerProvider() +: pen(new Pen("Colour/Audio Display/Seconds Line", 1, wxPENSTYLE_DOT)) +, enabled(OPT_GET("Audio/Display/Draw/Seconds")) +, enabled_opt_changed(OPT_SUB("Audio/Display/Draw/Seconds", &SecondsMarkerProvider::EnabledOptChanged, this)) +{ +} + +void SecondsMarkerProvider::EnabledOptChanged() { + AnnounceMarkerMoved(); +} + +void SecondsMarkerProvider::GetMarkers(TimeRange const& range, AudioMarkerVector &out) const { + if (!enabled->GetBool()) return; + + if ((range.length() + 999) / 1000 > (int)markers.size()) + markers.resize((range.length() + 999) / 1000, Marker(pen.get())); + + size_t i = 0; + for (int time = ((range.begin() + 999) / 1000) * 1000; time < range.end(); time += 1000) { + markers[i].position = time; + out.push_back(&markers[i++]); + } +} + +wxPen SecondsMarkerProvider::Marker::GetStyle() const { + return *style; +} diff --git a/aegisub/src/audio_marker.h b/aegisub/src/audio_marker.h index ac4f39614..ce97dad99 100644 --- a/aegisub/src/audio_marker.h +++ b/aegisub/src/audio_marker.h @@ -176,3 +176,36 @@ public: void GetMarkers(const TimeRange &range, AudioMarkerVector &out) const; }; + +/// Marker provider for lines every second +class SecondsMarkerProvider : public AudioMarkerProvider { + struct Marker : public AudioMarker { + Pen *style; + int position; + + Marker(Pen *style) : style(style) { } + int GetPosition() const { return position; } + FeetStyle GetFeet() const { return Feet_None; } + bool CanSnap() const { return false; } + wxPen GetStyle() const; + operator int() const { return position; } + }; + + /// Pen used by all seconds markers, here for performance + agi::scoped_ptr pen; + + /// Markers returned from last call to GetMarkers + mutable std::vector markers; + + /// Cached reference to the option to enable/disable seconds markers + const agi::OptionValue *enabled; + + /// Enabled option change connection + agi::signal::Connection enabled_opt_changed; + + void EnabledOptChanged(); + +public: + SecondsMarkerProvider(); + void GetMarkers(TimeRange const& range, AudioMarkerVector &out) const; +}; diff --git a/aegisub/src/audio_timing_dialogue.cpp b/aegisub/src/audio_timing_dialogue.cpp index cd9dfd8b1..be6d12787 100644 --- a/aegisub/src/audio_timing_dialogue.cpp +++ b/aegisub/src/audio_timing_dialogue.cpp @@ -308,6 +308,9 @@ class AudioTimingControllerDialogue : public AudioTimingController, private Sele /// Marker provider for video playback position VideoPositionMarkerProvider video_position_provider; + /// Marker provider for seconds lines + SecondsMarkerProvider seconds_provider; + /// The set of lines which have been modified and need to have their /// changes applied on commit std::set modified_lines; @@ -425,6 +428,7 @@ AudioTimingControllerDialogue::AudioTimingControllerDialogue(agi::Context *c) c->selectionController->AddSelectionListener(this); keyframes_provider.AddMarkerMovedListener(std::tr1::bind(std::tr1::ref(AnnounceMarkerMoved))); video_position_provider.AddMarkerMovedListener(std::tr1::bind(std::tr1::ref(AnnounceMarkerMoved))); + seconds_provider.AddMarkerMovedListener(std::tr1::bind(std::tr1::ref(AnnounceMarkerMoved))); sel = context->selectionController->GetSelectedSet(); Revert(); @@ -441,6 +445,8 @@ void AudioTimingControllerDialogue::GetMarkers(const TimeRange &range, AudioMark // The order matters here; later markers are painted on top of earlier // markers, so the markers that we want to end up on top need to appear last + seconds_provider.GetMarkers(range, out_markers); + // Copy inactive line markers in the range copy( lower_bound(markers.begin(), markers.end(), range.begin(), marker_ptr_cmp()), diff --git a/aegisub/src/libresrc/default_config.json b/aegisub/src/libresrc/default_config.json index 22c38a057..57822d5f9 100644 --- a/aegisub/src/libresrc/default_config.json +++ b/aegisub/src/libresrc/default_config.json @@ -42,6 +42,7 @@ "Inactive Comments" : true, "Keyframes in Dialogue Mode" : true, "Keyframes in Karaoke Mode" : true, + "Seconds" : false, "Video Position" : false }, "Waveform Style" : 1 @@ -101,6 +102,7 @@ "Line boundary End" : "rgb(0, 0, 216)", "Line boundary Start" : "rgb(216, 0, 0)", "Play Cursor" : "rgb(255,255,255)", + "Seconds Line" : "rgb(0,100,255)", "Spectrum" : "Icy Blue", "Syllable Boundaries" : "rgb(255,255,0)", "Waveform" : "Green" diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index 1d4937b12..9b8b43833 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -150,6 +150,8 @@ Audio::Audio(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _( OptionAdd(display, _("Keyframes in karaoke mode"), "Audio/Display/Draw/Keyframes in Karaoke Mode"); OptionAdd(display, _("Cursor time"), "Audio/Display/Draw/Cursor Time"); OptionAdd(display, _("Video position"), "Audio/Display/Draw/Video Position"); + OptionAdd(display, _("Seconds boundaries"), "Audio/Display/Draw/Seconds"); + CellSkip(display); OptionChoice(display, _("Waveform Style"), AudioWaveformRenderer::GetWaveformStyles(), "Audio/Display/Waveform Style"); wxFlexGridSizer *label = PageSizer(_("Audio labels")); @@ -224,6 +226,7 @@ Interface_Colours::Interface_Colours(wxTreebook *book, Preferences *parent): Opt OptionAdd(audio, _("Line boundary end"), "Colour/Audio Display/Line boundary End"); OptionAdd(audio, _("Line boundary inactive line"), "Colour/Audio Display/Line Boundary Inactive Line"); OptionAdd(audio, _("Syllable boundaries"), "Colour/Audio Display/Syllable Boundaries"); + OptionAdd(audio, _("Seconds boundaries"), "Colour/Audio Display/Seconds Line"); wxFlexGridSizer *color_schemes = PageSizer(_("Audio Color Schemes")); wxArrayString schemes = vec_to_arrstr(OPT_GET("Audio/Colour Schemes")->GetListString());