Skip to content

Commit

Permalink
move MsToTickAt to TimeAxis
Browse files Browse the repository at this point in the history
  • Loading branch information
oxygen-dioxide committed May 30, 2024
1 parent 5a3e9e3 commit 1c5b8f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
12 changes: 12 additions & 0 deletions OpenUtau.Core/Util/TimeAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ public double MsBetweenTickPos(double tickPos, double tickEnd) {
return TickPosToMsPos(tickEnd) - TickPosToMsPos(tickPos);
}

/// <summary>
/// Convert ms duration to tick at a given reference tick position
/// </summary>
/// <param name="durationMs">Duration in ms, positive value means starting from refTickPos, negative value means ending at refTickPos</param>
/// <param name="refTickPos">Reference tick position</param>
/// <returns>Duration in ticks</returns>
public int MsToTickAt(double offsetMs, int refTickPos) {
return TicksBetweenMsPos(
TickPosToMsPos(refTickPos),
TickPosToMsPos(refTickPos) + offsetMs);
}

public void TickPosToBarBeat(int tick, out int bar, out int beat, out int remainingTicks) {
var segment = timeSigSegments.First(seg => seg.tickPos == tick || seg.tickEnd > tick); // TODO: optimize
bar = segment.barPos + (tick - segment.tickPos) / segment.ticksPerBar;
Expand Down
17 changes: 2 additions & 15 deletions OpenUtau.Plugin.Builtin/ChineseCVVCPhonemizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
int vcLen = 120;
int endTick = notes[^1].position + notes[^1].duration;
if (singer.TryGetMappedOto(lyric, notes[0].tone + attr1.toneShift, attr1.voiceColor, out var cvOto)) {
vcLen = -MsToTickAt(-cvOto.Preutter, endTick);
vcLen = -timeAxis.MsToTickAt(-cvOto.Preutter, endTick);
if (cvOto.Overlap == 0 && vcLen < 120) {
vcLen = Math.Min(120, vcLen * 2); // explosive consonant with short preutter.
}
if (cvOto.Overlap < 0) {
vcLen = -MsToTickAt(-(cvOto.Preutter - cvOto.Overlap), endTick);
vcLen = -timeAxis.MsToTickAt(-(cvOto.Preutter - cvOto.Overlap), endTick);
}
}

Expand Down Expand Up @@ -176,19 +176,6 @@ public override Result Process(Note[] notes, Note? prev, Note? next, Note? prevN
}
return MakeSimpleResult(cvOtoSimple?.Alias ?? lyric);
}

/// <summary>
/// Convert ms to tick at a given reference tick position
/// </summary>
/// <param name="durationMs">Duration in ms</param>
/// <param name="refTick">Reference tick position</param>
/// <returns>Duration in ticks</returns>
public int MsToTickAt(double offsetMs, int refTick) {
return timeAxis.TicksBetweenMsPos(
timeAxis.TickPosToMsPos(refTick),
timeAxis.TickPosToMsPos(refTick)+ offsetMs);
}


public override void SetSinger(USinger singer) {
if (this.singer == singer) {
Expand Down

0 comments on commit 1c5b8f4

Please sign in to comment.