-
Notifications
You must be signed in to change notification settings - Fork 519
Support DiffSinger pitch local retaking #2183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KakaruHayate
wants to merge
4
commits into
openutau:master
Choose a base branch
from
KakaruHayate:ds-pitch-retake
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fda71f1
Support DiffSinger pitch local retaking
yqzhishen c54b388
Extract retake mask + note-index helpers for testability
KakaruHayate 6e3289d
Address Copilot review feedback on pitch retake
KakaruHayate 381d588
Show LoadRenderedPitch shortcut hint (Ctrl+R) in Notes menu
KakaruHayate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace OpenUtau.Core.DiffSinger { | ||
| public static class DiffSingerRetake { | ||
| public static HashSet<int> MapSelectedPositionsToNoteIndexes( | ||
| int phrasePosition, | ||
| IReadOnlyList<int> noteRelativePositions, | ||
| IReadOnlyCollection<int> selectedAbsolutePositions) { | ||
| var result = new HashSet<int>(); | ||
| if (selectedAbsolutePositions == null || selectedAbsolutePositions.Count == 0) { | ||
| return result; | ||
| } | ||
|
KakaruHayate marked this conversation as resolved.
|
||
| var lookup = selectedAbsolutePositions as ISet<int> ?? new HashSet<int>(selectedAbsolutePositions); | ||
| for (int i = 0; i < noteRelativePositions.Count; i++) { | ||
| if (lookup.Contains(phrasePosition + noteRelativePositions[i])) { | ||
| result.Add(i); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public static bool[] BuildRetakeFrameMask( | ||
| IReadOnlyList<int> paddedNoteDurations, | ||
| int realNoteCount, | ||
| IReadOnlyCollection<int> retakeNoteIndexes, | ||
| int totalFrames) { | ||
| var mask = new bool[totalFrames]; | ||
| if (retakeNoteIndexes == null || retakeNoteIndexes.Count == 0 || paddedNoteDurations.Count == 0) { | ||
| return mask; | ||
| } | ||
|
KakaruHayate marked this conversation as resolved.
|
||
| var lookup = retakeNoteIndexes as ISet<int> ?? new HashSet<int>(retakeNoteIndexes); | ||
| int padded = paddedNoteDurations.Count; | ||
| int frameOffset = 0; | ||
| for (int noteIdx = 0; noteIdx < padded; noteIdx++) { | ||
| int realIdx; | ||
| if (noteIdx == 0) { | ||
| realIdx = 0; | ||
| } else if (noteIdx == padded - 1) { | ||
| realIdx = realNoteCount - 1; | ||
| } else { | ||
| realIdx = noteIdx - 1; | ||
| } | ||
| bool shouldRetake = lookup.Contains(realIdx); | ||
| int dur = paddedNoteDurations[noteIdx]; | ||
| for (int f = 0; f < dur; f++) { | ||
| int fi = frameOffset + f; | ||
| if (fi < totalFrames) { | ||
| mask[fi] = shouldRetake; | ||
| } | ||
| } | ||
| frameOffset += dur; | ||
| } | ||
| return mask; | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using OpenUtau.Core.DiffSinger; | ||
| using Xunit; | ||
|
|
||
| namespace OpenUtau.Core { | ||
| public class DiffSingerRetakeTest { | ||
|
KakaruHayate marked this conversation as resolved.
Outdated
|
||
| [Fact] | ||
| public void MapSelectedPositionsToNoteIndexes_PicksMatchingNotes() { | ||
| var noteRel = new[] { 0, 480, 960, 1440 }; | ||
| var selected = new HashSet<int> { 100 + 480, 100 + 1440 }; | ||
|
|
||
| var result = DiffSingerRetake.MapSelectedPositionsToNoteIndexes(100, noteRel, selected); | ||
|
|
||
| Assert.Equal(new HashSet<int> { 1, 3 }, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MapSelectedPositionsToNoteIndexes_ReturnsEmptyWhenNoneSelected() { | ||
| var noteRel = new[] { 0, 480 }; | ||
| var result = DiffSingerRetake.MapSelectedPositionsToNoteIndexes(0, noteRel, new HashSet<int>()); | ||
| Assert.Empty(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MapSelectedPositionsToNoteIndexes_HandlesNullSelected() { | ||
| var noteRel = new[] { 0, 480 }; | ||
| var result = DiffSingerRetake.MapSelectedPositionsToNoteIndexes(0, noteRel, null); | ||
| Assert.Empty(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_AllSelected_AllTrue() { | ||
| var paddedDurations = new[] { 2, 5, 5, 2 }; | ||
| var totalFrames = paddedDurations.Sum(); | ||
| var indexes = new HashSet<int> { 0, 1 }; | ||
|
|
||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(paddedDurations, 2, indexes, totalFrames); | ||
|
|
||
| Assert.Equal(totalFrames, mask.Length); | ||
| Assert.All(mask, b => Assert.True(b)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_NoneSelected_AllFalse() { | ||
| var paddedDurations = new[] { 2, 5, 5, 2 }; | ||
| var totalFrames = paddedDurations.Sum(); | ||
| var indexes = new HashSet<int>(); | ||
|
|
||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(paddedDurations, 2, indexes, totalFrames); | ||
|
|
||
| Assert.Equal(totalFrames, mask.Length); | ||
| Assert.All(mask, b => Assert.False(b)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_PartialSelected_RespectsHeadTailPaddingShift() { | ||
| // 3 real notes, padded with head + tail → 5 padded "note durations". | ||
| // Mapping: padded[0] → real 0 (head), padded[1] → real 0, padded[2] → real 1, | ||
| // padded[3] → real 2, padded[4] → real 2 (tail). | ||
| var paddedDurations = new[] { 2, 3, 4, 3, 2 }; // 14 frames total | ||
| int totalFrames = paddedDurations.Sum(); | ||
| var indexes = new HashSet<int> { 1 }; // retake only middle real note | ||
|
|
||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(paddedDurations, 3, indexes, totalFrames); | ||
|
|
||
| // padded[0] (frames 0-1, head→real 0) → false | ||
| Assert.False(mask[0]); | ||
| Assert.False(mask[1]); | ||
| // padded[1] (frames 2-4, real 0) → false | ||
| Assert.False(mask[2]); | ||
| Assert.False(mask[4]); | ||
| // padded[2] (frames 5-8, real 1) → true | ||
| Assert.True(mask[5]); | ||
| Assert.True(mask[8]); | ||
| // padded[3] (frames 9-11, real 2) → false | ||
| Assert.False(mask[9]); | ||
| Assert.False(mask[11]); | ||
| // padded[4] (frames 12-13, tail→real 2) → false | ||
| Assert.False(mask[12]); | ||
| Assert.False(mask[13]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_FirstRealNoteSelected_HeadPadIncluded() { | ||
| // Selecting real note 0 should mark both head (padded[0]) and padded[1] frames. | ||
| var paddedDurations = new[] { 2, 3, 4, 3, 2 }; | ||
| int totalFrames = paddedDurations.Sum(); | ||
| var indexes = new HashSet<int> { 0 }; | ||
|
|
||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(paddedDurations, 3, indexes, totalFrames); | ||
|
|
||
| Assert.True(mask[0]); | ||
| Assert.True(mask[1]); // head padded → real 0 | ||
| Assert.True(mask[2]); | ||
| Assert.True(mask[4]); // padded[1] → real 0 | ||
| Assert.False(mask[5]); // padded[2] → real 1, not selected | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_LastRealNoteSelected_TailPadIncluded() { | ||
| var paddedDurations = new[] { 2, 3, 4, 3, 2 }; | ||
| int totalFrames = paddedDurations.Sum(); | ||
| var indexes = new HashSet<int> { 2 }; // last real note | ||
|
|
||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(paddedDurations, 3, indexes, totalFrames); | ||
|
|
||
| Assert.False(mask[8]); | ||
| Assert.True(mask[9]); // padded[3] → real 2 | ||
| Assert.True(mask[11]); | ||
| Assert.True(mask[12]); // padded[4] tail → real 2 | ||
| Assert.True(mask[13]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_ClampsFramesPastTotal() { | ||
| // paddedDurations sum to 10 but totalFrames is 8 (simulating FitDurationSum trim). | ||
| var paddedDurations = new[] { 2, 4, 4 }; | ||
| var indexes = new HashSet<int> { 0 }; | ||
|
|
||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(paddedDurations, 1, indexes, 8); | ||
|
|
||
| Assert.Equal(8, mask.Length); | ||
| // Should not throw; frames past totalFrames silently dropped. | ||
| Assert.True(mask[0]); | ||
| Assert.True(mask[5]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildRetakeFrameMask_EmptyDurations_ReturnsAllFalse() { | ||
| var mask = DiffSingerRetake.BuildRetakeFrameMask(new int[0], 0, new HashSet<int> { 0 }, 4); | ||
| Assert.Equal(4, mask.Length); | ||
| Assert.All(mask, b => Assert.False(b)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.