Procházet zdrojové kódy

Fluidity, big projects: the tempo integration reads the tempo clips only (an edit while a 1,728-bar song plays: 1.6-1.9 s -> 65-77 ms)

Song::secondsForTicks integrates the tempo every 16th, and each step's tempoAt walked every clip of the song: 27,648
steps x 17,928 clips on the 1,728-bar FL project (Thief tiled 12 times). With a tempo automation it ran at every edit
while the song played (a mute click, a clip drag): tempoAtIn was 81 % of the message thread's samples (perf). Each step
now reads tempomap::tempoClips (the clips tempoAt can read, in playlist order; tempoAtIn over them == tempoAt), so the
values and their sum are the same to the bit (test against the old integration). The video tempo map's two loops
(VideoTrack.cpp) do the same.

Linux, --uiperf on the 1,728-bar project while it plays (3 runs each, interleaved, outside a quiet window): mute click
-> paint p50 1,482-1,867 -> 65-77 ms; a clip-drag step 1,580-1,684 -> 57-63 ms. Gold 7 / 7 identical.
Ka1-S před 1 týdnem
rodič
revize
9435aed80e
3 změnil soubory, kde provedl 47 přidání a 5 odebrání
  1. 6 2
      src/core/Song.cpp
  2. 6 3
      src/core/VideoTrack.cpp
  3. 35 0
      tests/Q3190ryTests.inc

+ 6 - 2
src/core/Song.cpp

@@ -1651,14 +1651,18 @@ double Song::secondsForTicks (std::int64_t ticks) const
     if (! tempomap::active (*this))
         return (double) ticks * 60.0 / (std::max (1.0, bpm) * ppq);
 
-    // integrate in 1/16 steps (playback changes tempo block by block; the difference is minimal)
+    // integrate in 1/16 steps (playback changes tempo block by block; the difference is minimal). Round 190ry (Q3): each
+    // step's lookup reads the playlist's tempo clips only (tempomap::tempoClips: tempoAtIn over them is tempoAt, the same
+    // value): it walked every clip of the song per 16th, 1.6-1.8 s per call on a 1,728-bar project of 17,928 clips, paid
+    // by the message thread at every edit while the song played
     double seconds = 0.0;
     constexpr std::int64_t step = ticksPerStep;
+    const auto clips = tempomap::tempoClips (*this);
 
     for (std::int64_t t = 0; t < ticks; t += step)
     {
         const auto n = std::min (step, ticks - t);
-        seconds += (double) n * 60.0 / (std::max (1.0, tempoAt ((double) t)) * ppq);
+        seconds += (double) n * 60.0 / (std::max (1.0, tempomap::tempoAtIn (*this, clips, (double) t)) * ppq);
     }
 
     return seconds;

+ 6 - 3
src/core/VideoTrack.cpp

@@ -1,4 +1,5 @@
 #include "core/VideoTrack.h"
+#include "core/TempoMap.h"
 
 #include <cctype>
 
@@ -91,12 +92,13 @@ double ticksForSeconds (const Song& song, double seconds)
                                           [] (const Automation& a) { return a.target.kind == AutomationTargetKind::tempo; });
     if (! hasTempo)
         return seconds * std::max (1.0, song.bpm) * ppq / 60.0;
-    // the same 1/16 steps as Song::secondsForTicks
+    // the same 1/16 steps as Song::secondsForTicks (round 190ry: over the tempo clips only, the same values)
     constexpr std::int64_t step = ticksPerStep;
+    const auto clips = tempomap::tempoClips (song);
     double at = 0.0;
     for (std::int64_t t = 0;; t += step)
     {
-        const auto perTick = 60.0 / (std::max (1.0, song.tempoAt ((double) t)) * ppq);
+        const auto perTick = 60.0 / (std::max (1.0, tempomap::tempoAtIn (song, clips, (double) t)) * ppq);
         const auto span = perTick * (double) step;
         if (at + span >= seconds || t > (std::int64_t) 1 << 40)
             return (double) t + (seconds - at) / perTick;
@@ -113,11 +115,12 @@ TempoMap::TempoMap (const Song& song, double maxSeconds)
     if (! hasTempo)
         return;
     constexpr std::int64_t step = ticksPerStep;
+    const auto clips = tempomap::tempoClips (song); // (round 190ry: as Song::secondsForTicks)
     double at = 0.0;
     stepStarts.push_back (0.0);
     for (std::int64_t t = 0; at <= maxSeconds && stepStarts.size() < 4000000; t += step)
     {
-        secondsPerTick = 60.0 / (std::max (1.0, song.tempoAt ((double) t)) * ppq);
+        secondsPerTick = 60.0 / (std::max (1.0, tempomap::tempoAtIn (song, clips, (double) t)) * ppq);
         at += secondsPerTick * (double) step;
         stepStarts.push_back (at);
     }

+ 35 - 0
tests/Q3190ryTests.inc

@@ -158,3 +158,38 @@ TEST (q3190ry_availability_memo)
     const auto copy = fl;
     CHECK (natives::available (*engine, copy) == first && *looks == once);
 }
+
+TEST (q3190ry_seconds_for_ticks_reads_the_tempo_clips_only)
+{
+    using namespace lynx;
+    // the automation project (a tempo automation clip among 528 clips) and the 1,728-bar case's shape: many more clips
+    Song song;
+    perfprojects::Samples samples;
+    CHECK (perfprojects::make ("automation", song, samples));
+    const auto copies = song.playlist;
+    for (int k = 1; k < 8; ++k)
+        for (auto c : copies)
+            if (c.kind != ClipKind::automation)
+            {
+                c.start += (std::int64_t) k * 32 * 4 * ppq;
+                song.playlist.push_back (c);
+            }
+    CHECK (tempomap::active (song));
+    // the integration as it was: every step's tempo through tempoAt (every clip)
+    const auto reference = [&song] (std::int64_t ticks) {
+        double seconds = 0.0;
+        for (std::int64_t t = 0; t < ticks; t += ticksPerStep)
+        {
+            const auto n = std::min<std::int64_t> (ticksPerStep, ticks - t);
+            seconds += (double) n * 60.0 / (std::max (1.0, tempomap::tempoAt (song, (double) t)) * ppq);
+        }
+        return seconds;
+    };
+    for (const std::int64_t ticks : { (std::int64_t) 0, (std::int64_t) 1, (std::int64_t) (7 * ppq + 5), (std::int64_t) (32 * 4 * ppq),
+                                      (std::int64_t) (256 * 4 * ppq + 3) })
+        CHECK (song.secondsForTicks (ticks) == reference (ticks)); // (bit for bit)
+    // pattern mode: the integration only when the pattern has a Tempo lane (else the constant tempo's formula, unchanged)
+    song.mode = PlayMode::pattern;
+    if (tempomap::active (song))
+        CHECK (song.secondsForTicks (64 * ppq) == reference (64 * ppq));
+}