-
Notifications
You must be signed in to change notification settings - Fork 309
/
Renderers.cs
111 lines (100 loc) · 4.33 KB
/
Renderers.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using OpenUtau.Classic;
using OpenUtau.Core.Ustx;
using OpenUtau.Core.Util;
namespace OpenUtau.Core.Render {
public static class Renderers {
public const string CLASSIC = "CLASSIC";
public const string WORLDLINER = "WORLDLINE-R";
public const string ENUNU = "ENUNU";
public const string VOGEN = "VOGEN";
public const string DIFFSINGER = "DIFFSINGER";
static readonly string[] classicRenderers = new[] { WORLDLINER, CLASSIC };
static readonly string[] enunuRenderers = new[] { ENUNU };
static readonly string[] vogenRenderers = new[] { VOGEN };
static readonly string[] diffSingerRenderers = new[] { DIFFSINGER };
static readonly string[] noRenderers = new string[0];
public static string[] GetSupportedRenderers(USingerType singerType) {
switch (singerType) {
case USingerType.Classic:
return classicRenderers;
case USingerType.Enunu:
return enunuRenderers;
case USingerType.Vogen:
return vogenRenderers;
case USingerType.DiffSinger:
return diffSingerRenderers;
default:
return noRenderers;
}
}
public static List<string> getRendererOptions() {
return new List<string> {
"WORLDLINE-R",
"Classic"
};
}
public static string GetDefaultRenderer(USingerType singerType) {
if (Preferences.Default.DefaultRenderer == "Classic" && singerType == USingerType.Classic) {
return CLASSIC;
} else {
return GetSupportedRenderers(singerType)[0];
}
}
public static IRenderer CreateRenderer(string renderer) {
if (renderer == CLASSIC) {
return new ClassicRenderer();
} else if (renderer?.StartsWith(WORLDLINER.Substring(0, 9)) ?? false) {
return new WorldlineRenderer();
} else if (renderer == ENUNU) {
return new Enunu.EnunuRenderer();
} else if (renderer == VOGEN) {
return new Vogen.VogenRenderer();
} else if (renderer == DIFFSINGER) {
return new DiffSinger.DiffSingerRenderer();
}
return null;
}
readonly static ConcurrentDictionary<string, object> cacheLockMap
= new ConcurrentDictionary<string, object>();
public static object GetCacheLock(string key) {
return cacheLockMap.GetOrAdd(key, _ => new object());
}
public static void ApplyDynamics(RenderPhrase phrase, RenderResult result) {
const int interval = 5;
if (phrase.dynamics == null) {
return;
}
int startTick = phrase.position - phrase.leading;
double startMs = result.positionMs - result.leadingMs;
int startSample = 0;
for (int i = 0; i < phrase.dynamics.Length; ++i) {
int endTick = startTick + interval;
double endMs = phrase.timeAxis.TickPosToMsPos(endTick);
int endSample = Math.Min((int)((endMs - startMs) / 1000 * 44100), result.samples.Length);
float a = phrase.dynamics[i];
float b = (i + 1) == phrase.dynamics.Length ? phrase.dynamics[i] : phrase.dynamics[i + 1];
for (int j = startSample; j < endSample; ++j) {
result.samples[j] *= a + (b - a) * (j - startSample) / (endSample - startSample);
}
startTick = endTick;
startSample = endSample;
}
}
public static IReadOnlyList<IResampler> GetSupportedResamplers(IWavtool? wavtool) {
if (wavtool is SharpWavtool) {
return ToolsManager.Inst.Resamplers;
} else {
return ToolsManager.Inst.Resamplers
.Where(r => !(r is WorldlineResampler))
.ToArray();
}
}
public static IReadOnlyList<IWavtool> GetSupportedWavtools(IResampler? resampler) {
return ToolsManager.Inst.Wavtools;
}
}
}