Просмотр исходного кода

Tempo: before the first tempo clip keep 178a's first-clip value (unverified against FL); the #97 rule inside and after clips

Ka1-S 4 недель назад
Родитель
Сommit
5de25f2879
3 измененных файлов с 13 добавлено и 5 удалено
  1. 10 2
      src/core/TempoMap.h
  2. 2 1
      tests/Issue97Tests.inc
  3. 1 2
      tests/Issues178aTests.inc

+ 10 - 2
src/core/TempoMap.h

@@ -126,20 +126,26 @@ inline double tempoAt (const Song& song, double tick) noexcept
 
     // the tempo automations (issue #97, the rule of every target, RackRenderer's automationValueAt): inside clips the
     // one that started last wins (same start: the lowest automation); after them, the value the clip that ended last
-    // ended with (written at its end); before the first clip, none (the project's tempo)
+    // ended with (written at its end); before the first clip, the first clip's first value (round 178a, lowest priority;
+    // unverified against FL for the tempo: the other targets have their own value there)
     Write automation;
     if (tempoAutomation (song) >= 0)
     {
         const Clip* inside = nullptr;
         const Clip* ended = nullptr;
+        const Clip* first = nullptr;
         for (const auto& c : song.playlist)
         {
             if (c.kind != ClipKind::automation || c.automation < 0 || c.automation >= (int) song.automations.size() || c.length <= 0
-                || c.muted || song.isTrackMuted (c.track) || tick < (double) c.start)
+                || c.muted || song.isTrackMuted (c.track))
                 continue;
             const auto& a = song.automations[(std::size_t) c.automation];
             if (a.target.kind != AutomationTargetKind::tempo || a.isLive())
                 continue;
+            if (first == nullptr || c.start < first->start || (c.start == first->start && c.automation < first->automation))
+                first = &c;
+            if (tick < (double) c.start)
+                continue;
             if (tick < (double) c.end())
             {
                 if (inside == nullptr || c.start > inside->start || (c.start == inside->start && c.automation < inside->automation))
@@ -152,6 +158,8 @@ inline double tempoAt (const Song& song, double tick) noexcept
             return tempoFromValue (song.automations[(std::size_t) inside->automation].valueAt (tick - (double) inside->start + (double) inside->offset));
         if (ended != nullptr)
             automation = { (double) ended->end(), song.automations[(std::size_t) ended->automation].valueAt ((double) (ended->length + ended->offset)) };
+        else if (first != nullptr)
+            automation.value = song.automations[(std::size_t) first->automation].valueAt ((double) first->offset);
     }
 
     Write events;

+ 2 - 1
tests/Issue97Tests.inc

@@ -163,7 +163,8 @@ TEST (issue97_two_tempo_clips)
     }
     issue97::addClip (s, 0, 2, 2, 1);
     issue97::addClip (s, 1, 6, 2, 2);
-    CHECK (s.tempoAt ((double) issue97::bar) == s.bpm); // before: the project's tempo
+    // before the first clip: the first clip's value (178a's rule for the tempo, unverified against FL)
+    CHECK (std::abs (s.tempoAt ((double) issue97::bar) - lynx::tempoFromValue (0.2f)) < 1.0e-3);
     const auto first = s.tempoAt ((double) issue97::bar * 3), second = s.tempoAt ((double) issue97::bar * 7);
     CHECK (first < second);
     CHECK (s.tempoAt ((double) issue97::bar * 5) == first);

+ 1 - 2
tests/Issues178aTests.inc

@@ -325,8 +325,7 @@ TEST (issues178a_tempo_events_in_song_mode)
     e.track = 4;
     song.playlist.push_back (e);
     CHECK (issues178a::near (song.tempoAt (26 * ppq), 100.0));            // a later event writes over it
-    CHECK (issues178a::near (song.tempoAt (2 * ppq), 120.0));             // before anything: the project's tempo (issue #97: a
-                                                                           // control has its own value before its first clip)
+    CHECK (issues178a::near (song.tempoAt (2 * ppq), 60.0));              // before anything: the first tempo clip's value
 }
 
 // #86: FL's .flp keeps the Tempo events as BPM × 1000 (0x40000005 events) and the initialized tempo in 0xD8; both go