-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathDiffSingerRetake.cs
More file actions
52 lines (50 loc) · 2.29 KB
/
Copy pathDiffSingerRetake.cs
File metadata and controls
52 lines (50 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
}
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;
}
// paddedToRealNoteIndex must be the same length as paddedNoteDurations.
// Each entry is the real-note index the padded segment should follow for retake purposes,
// or -1 for a segment that is never retaken regardless of selection.
public static bool[] BuildRetakeFrameMask(
IReadOnlyList<int> paddedNoteDurations,
IReadOnlyList<int> paddedToRealNoteIndex,
IReadOnlyCollection<int>? retakeNoteIndexes,
int totalFrames) {
var mask = new bool[totalFrames];
if (retakeNoteIndexes == null || retakeNoteIndexes.Count == 0 || paddedNoteDurations.Count == 0) {
return mask;
}
var lookup = retakeNoteIndexes as ISet<int> ?? new HashSet<int>(retakeNoteIndexes);
int padded = paddedNoteDurations.Count;
int frameOffset = 0;
for (int segIdx = 0; segIdx < padded; segIdx++) {
int realIdx = paddedToRealNoteIndex[segIdx];
bool shouldRetake = realIdx >= 0 && lookup.Contains(realIdx);
int dur = paddedNoteDurations[segIdx];
for (int f = 0; f < dur; f++) {
int fi = frameOffset + f;
if (fi < totalFrames) {
mask[fi] = shouldRetake;
}
}
frameOffset += dur;
}
return mask;
}
}
}