From 41b813e2bbab8624e8e63e0401f3f73151db4e73 Mon Sep 17 00:00:00 2001 From: routersys Date: Sat, 22 Aug 2026 19:29:49 +0900 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E7=A8=8B=E3=81=AE=E4=BC=B8=E3=81=B0?= =?UTF-8?q?=E3=81=97=E3=82=92=E5=8F=A5=E3=81=AE=E5=88=87=E3=82=8C=E7=9B=AE?= =?UTF-8?q?=E3=81=A7=E6=B1=BA=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UTAU.Tests/SynthesisTests.cs | 14 ++++++++++++++ UTAU/Synthesis/PitchTrack.cs | 22 +++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/UTAU.Tests/SynthesisTests.cs b/UTAU.Tests/SynthesisTests.cs index 6db0bb4..be67760 100644 --- a/UTAU.Tests/SynthesisTests.cs +++ b/UTAU.Tests/SynthesisTests.cs @@ -530,6 +530,20 @@ public sealed class PitchTrackTests Assert.Equal(6000.0, track.CentsAt(24), 9); } + [Fact] + public void APhraseOpeningNoteExtendsItsFirstPointBackToItsAudioStart() + { + var second = Unit(300.0, 200.0, 72, 80.0, 40.0); + second.Note.LengthTicks = 240; + second.Note.PitchPoints.Add(new PitchPoint(-50, 500.0)); + second.Note.PitchPoints.Add(new PitchPoint(0, 0.0)); + var track = Track(Unit(0.0, 200.0, 60, 0.0, 0.0), second); + + Assert.Equal(7200.0, track.CentsAt(43), 9); + Assert.Equal(7700.0, track.CentsAt(44), 9); + Assert.Equal(7200.0, track.CentsAt(60), 9); + } + [Fact] public void APortamentoReachesAcrossThePreviousNote() { diff --git a/UTAU/Synthesis/PitchTrack.cs b/UTAU/Synthesis/PitchTrack.cs index 80d2854..8e54f14 100644 --- a/UTAU/Synthesis/PitchTrack.cs +++ b/UTAU/Synthesis/PitchTrack.cs @@ -4,7 +4,7 @@ namespace UTAU.Synthesis; internal sealed class PitchTrack { - readonly record struct TrackNote(UTAUNote Note, double StartMilliseconds, double LengthMilliseconds, int Tone) + readonly record struct TrackNote(UTAUNote Note, double StartMilliseconds, double LengthMilliseconds, int Tone, double AudioStartMilliseconds) { public double EndMilliseconds => StartMilliseconds + LengthMilliseconds; @@ -41,7 +41,7 @@ internal sealed class PitchTrack var unit = timing.Unit; if (unit.Note.IsRest) continue; - notes.Add(new TrackNote(unit.Note, unit.NoteStartMilliseconds, unit.NoteLengthMilliseconds, unit.Tone)); + notes.Add(new TrackNote(unit.Note, unit.NoteStartMilliseconds, unit.NoteLengthMilliseconds, unit.Tone, timing.AudioStartMilliseconds)); } notes.Sort((left, right) => left.StartMilliseconds.CompareTo(right.StartMilliseconds)); @@ -49,8 +49,14 @@ internal sealed class PitchTrack var distinct = new List(notes.Count); foreach (var note in notes) { - if (distinct.Count > 0 && distinct[^1] == note) + if (distinct.Count > 0 && distinct[^1].StartMilliseconds == note.StartMilliseconds && ReferenceEquals(distinct[^1].Note, note.Note)) + { + distinct[^1] = distinct[^1] with + { + AudioStartMilliseconds = Math.Min(distinct[^1].AudioStartMilliseconds, note.AudioStartMilliseconds), + }; continue; + } distinct.Add(note); } return distinct; @@ -105,10 +111,12 @@ internal sealed class PitchTrack foreach (var point in note.Note.PitchPoints) points.Add((note.StartMilliseconds + point.Ticks * scale, note.Cents + point.Cents, point.Shape)); - if (n == 0 && points[0].X > startMilliseconds) - points.Insert(0, (startMilliseconds, points[0].Y, points[0].Shape)); - else if (points[0].X > note.StartMilliseconds) - points.Insert(0, (note.StartMilliseconds, points[0].Y, points[0].Shape)); + var opensPhrase = n == 0 || notes[n - 1].EndMilliseconds < note.StartMilliseconds; + var lead = opensPhrase + ? Math.Max(startMilliseconds, note.AudioStartMilliseconds) + : note.StartMilliseconds; + if (points[0].X > lead) + points.Insert(0, (lead, points[0].Y, points[0].Shape)); if (points[^1].X < note.EndMilliseconds) points.Add((note.EndMilliseconds, points[^1].Y, points[^1].Shape));