From fb19ebf65bbdaf5ef448fe0f28a12cbbedc6411d Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Sun, 28 Oct 2018 12:01:13 -0700 Subject: [PATCH] Audio/timing: minor style, comment A bit more clarification of code logic. Follow predominant if/else style --- src/audio_karaoke.cpp | 13 +++++++------ src/audio_karaoke.h | 4 ++-- src/audio_timing_dialogue.cpp | 12 ++++++++---- src/audio_timing_karaoke.cpp | 23 +++++++++++++---------- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/audio_karaoke.cpp b/src/audio_karaoke.cpp index 4643d500c..41721a645 100644 --- a/src/audio_karaoke.cpp +++ b/src/audio_karaoke.cpp @@ -221,14 +221,15 @@ void AudioKaraoke::RenderText() { // Draw each character in the line int y = (bmp_size.GetHeight() - char_height) / 2; for (size_t i = 0; i < spaced_text.size(); ++i) { - if (!(marked_syl_start <= i && i < marked_syl_end)) { + if (!(tap_syl_start <= i && i < tap_syl_end)) { + // Only draw with normal color if _not_ the tap syllable dc.DrawText(spaced_text[i], char_x[i], y); } } // Draw marked syllable dc.SetTextForeground(*wxGREEN); - for (size_t i = marked_syl_start; i < marked_syl_end; ++i) + for (size_t i = tap_syl_start; i < tap_syl_end; ++i) dc.DrawText(spaced_text[i], char_x[i], y); // Draw the lines between each syllable @@ -343,15 +344,15 @@ void AudioKaraoke::OnScrollTimer(wxTimerEvent&) { } void AudioKaraoke::OnTapMarkerChanged() { - marked_syl_start = 0; - marked_syl_end = 0; + tap_syl_start = 0; + tap_syl_end = 0; if (OPT_GET("Timing/Tap To Time")->GetBool() && kara->size() > 0) { const AudioTimingController *tc = c->audioController->GetTimingController(); const size_t marker_idx = tc->GetTapMarkerIndex(); if (marker_idx > 0) { - marked_syl_start = syl_start_points[marker_idx - 1]; - marked_syl_end = + tap_syl_start = syl_start_points[marker_idx - 1]; + tap_syl_end = (marker_idx < syl_start_points.size() ? syl_start_points[marker_idx] : spaced_text.size()); diff --git a/src/audio_karaoke.h b/src/audio_karaoke.h index c9a071d40..b7bb482bf 100644 --- a/src/audio_karaoke.h +++ b/src/audio_karaoke.h @@ -106,8 +106,8 @@ class AudioKaraoke final : public wxWindow { wxFont split_font; ///< Font used in the split/join interface - size_t marked_syl_start = 0; - size_t marked_syl_end = 0; + size_t tap_syl_start = 0; ///< Tap-to-time syllable start character index + size_t tap_syl_end = 0; ///< Tap-to-time syllable end character index bool enabled = false; ///< Is karaoke mode enabled? diff --git a/src/audio_timing_dialogue.cpp b/src/audio_timing_dialogue.cpp index dce66b1ac..2c913cba1 100644 --- a/src/audio_timing_dialogue.cpp +++ b/src/audio_timing_dialogue.cpp @@ -464,7 +464,8 @@ int AudioTimingControllerDialogue::GetTapMarkerPosition() const if (tap_marker_idx == 0) { return *active_line.GetLeftMarker(); - } else { + } + else { return *active_line.GetRightMarker(); } } @@ -612,7 +613,8 @@ void AudioTimingControllerDialogue::MoveTapMarker(int ms) { // Moving left marker (start time of the line) if (ms > *right) SetMarkers({ right }, ms, 0); SetMarkers({ left }, ms, 0); - } else { + } + else { // Moving right marker (end time of the line) if (ms < *left) SetMarkers({ left }, ms, 0); SetMarkers({ right }, ms, 0); @@ -705,10 +707,12 @@ std::vector AudioTimingControllerDialogue::OnLeftClick(int ms, boo std::vector AudioTimingControllerDialogue::OnRightClick(int ms, bool ctrl_down, int sensitivity, int snap_range) { if (ctrl_down) { + // Ctrl-right-click: play audio context->audioController->PlayToEnd(ms); return {}; - - } else { + } + else { + // Normal right-click: move right marker clicked_ms = INT_MIN; std::vector ret = GetRightMarkers(); SetMarkers(ret, ms, snap_range); diff --git a/src/audio_timing_karaoke.cpp b/src/audio_timing_karaoke.cpp index 41f0e3b3c..788cd8096 100644 --- a/src/audio_timing_karaoke.cpp +++ b/src/audio_timing_karaoke.cpp @@ -365,11 +365,11 @@ void AudioTimingControllerKaraoke::MoveTapMarker(int ms) { // Get syllable this time falls within const size_t syl = distance(markers.begin(), lower_bound(markers.begin(), markers.end(), ms)); - // Tapping automatically all of the necessary markers for the tap marker to - // land at the current audio position. Intuitively, it "pushes" or - // "compresses" all of the markers in front of the tap marker. The - // expectation is that the markers will reach their proper position once the - // user finishes tapping to the line + // Tapping automatically moves all of the necessary markers for the tap + // marker to land at the current audio position. Intuitively, it "pushes" or + // "compresses" the markers blocking the tap marker's way so they all end up + // in the same position. The expectation is that the markers will reach their + // proper position once the user finishes tapping to the line if (tap_marker_idx == 0) { // Moving the start time of first syllable (i.e. start time of the line) if (ms > end_marker) MoveEndMarker(ms); @@ -381,11 +381,11 @@ void AudioTimingControllerKaraoke::MoveTapMarker(int ms) { if (ms < start_marker) MoveStartMarker(ms); else if (ms > end_marker) MoveEndMarker(ms); if (syl < tap_marker_idx) { - // Moving marker left + // Moving markers left CompressMarkers(syl, tap_marker_idx-1, ms); } else { - // Moving marker right + // Moving markers right CompressMarkers(syl-1, tap_marker_idx-1, ms); } } @@ -455,9 +455,11 @@ std::vector AudioTimingControllerKaraoke::OnLeftClick(int ms, bool std::vector AudioTimingControllerKaraoke::OnRightClick(int ms, bool ctrl_down, int, int) { if (ctrl_down) { + // Ctrl-right-click: play audio c->audioController->PlayToEnd(ms); - - } else { + } + else { + // Normal right-click: select new syllable and play range cur_syl = distance(markers.begin(), lower_bound(markers.begin(), markers.end(), ms)); AnnounceUpdatedPrimaryRange(); AnnounceUpdatedStyleRanges(); @@ -531,7 +533,8 @@ void AudioTimingControllerKaraoke::CompressMarkers(size_t from, size_t to, int n MoveMarker(&markers[i], new_position); if (i == to) { break; - } else { + } + else { i += incr; } }