Skip to content

Commit

Permalink
Merge pull request #73 from oxygen-dioxide/diffsinger
Browse files Browse the repository at this point in the history
Diffsinger
  • Loading branch information
oxygen-dioxide authored Oct 22, 2023
2 parents c94d72f + 282a583 commit 3dad88c
Show file tree
Hide file tree
Showing 27 changed files with 217 additions and 31 deletions.
1 change: 1 addition & 0 deletions OpenUtau.Core/Classic/ClassicSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace OpenUtau.Classic {
public class ClassicSinger : USinger {
public override string Id => voicebank.Id;
public override string Name => voicebank.Name;
public override Dictionary<string, string> LocalizedNames => voicebank.LocalizedNames;
public override USingerType SingerType => voicebank.SingerType;
public override string BasePath => voicebank.BasePath;
public override string Author => voicebank.Author;
Expand Down
2 changes: 2 additions & 0 deletions OpenUtau.Core/Classic/VoiceBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Voicebank {
public string BasePath;
public string File;
public string Name;
public Dictionary<string, string> LocalizedNames = new Dictionary<string, string>();
public string Image;
public string Portrait;
public float PortraitOpacity;
Expand All @@ -27,6 +28,7 @@ public class Voicebank {

public void Reload() {
Name = null;
LocalizedNames.Clear();
Image = null;
Portrait = null;
PortraitOpacity = 0;
Expand Down
4 changes: 3 additions & 1 deletion OpenUtau.Core/Classic/VoicebankConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Text;
using OpenUtau.Core;

Expand Down Expand Up @@ -36,6 +37,7 @@ public class Subbank {

public class VoicebankConfig {
public string Name;
public Dictionary<string, string> LocalizedNames;
public string SingerType;
public string TextFileEncoding;
public string Image;
Expand Down
5 changes: 5 additions & 0 deletions OpenUtau.Core/Classic/VoicebankLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public static void ApplyConfig(Voicebank bank, VoicebankConfig bankConfig) {
if (!string.IsNullOrWhiteSpace(bankConfig.Name)) {
bank.Name = bankConfig.Name;
}
if (bankConfig.LocalizedNames != null) {
foreach (var kv in bankConfig.LocalizedNames) {
bank.LocalizedNames[kv.Key] = kv.Value;
}
}
if (!string.IsNullOrWhiteSpace(bankConfig.Image)) {
bank.Image = bankConfig.Image;
}
Expand Down
12 changes: 12 additions & 0 deletions OpenUtau.Core/Commands/ProjectCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ public override void Unexecute() {
}
}

public class KeyCommand : ProjectCommand{
public readonly int oldKey;
public readonly int newKey;
public KeyCommand(UProject project, int key) : base(project) {
oldKey = project.key;
newKey = key;
}
public override string ToString() => $"Change key from {oldKey} to {newKey}";
public override void Execute() => project.key = newKey;
public override void Unexecute() => project.key = oldKey;
}

public class ConfigureExpressionsCommand : ProjectCommand {
readonly UExpressionDescriptor[] oldDescriptors;
readonly UExpressionDescriptor[] newDescriptors;
Expand Down
22 changes: 7 additions & 15 deletions OpenUtau.Core/DiffSinger/DiffSingerPitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,13 @@ public RenderPitchResult Process(RenderPhrase phrase){
.Prepend((float)phrase.notes[0].tone)
.ToArray();
//get the index of groups of consecutive rest notes
int restGroupStart = 0;
var restGroups = new List<Tuple<int,int>>{};
foreach(int noteIndex in Enumerable.Range(1,note_rest.Count - 1)) {
if(!note_rest[noteIndex-1] && note_rest[noteIndex]) {
//start a new rest group
restGroupStart = noteIndex;
}
if(note_rest[noteIndex-1] && !note_rest[noteIndex]) {
//end the current rest group
restGroups.Add(new Tuple<int,int>(restGroupStart,noteIndex));
}
}
if(!note_rest[^1]) {
//end the last rest group
restGroups.Add(new Tuple<int,int>(restGroupStart,note_rest.Count));
var restGroups = new List<Tuple<int,int>>();
for (var i = 0; i < note_rest.Count; ++i) {
if (!note_rest[i]) continue;
var j = i + 1;
for (; j < note_rest.Count && note_rest[j]; ++j) { }
restGroups.Add(new Tuple<int, int>(i, j));
i = j;
}
//Set tone for each rest group
foreach(var restGroup in restGroups){
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/DiffSinger/DiffSingerSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace OpenUtau.Core.DiffSinger {
class DiffSingerSinger : USinger {
public override string Id => voicebank.Id;
public override string Name => voicebank.Name;
public override Dictionary<string, string> LocalizedNames => voicebank.LocalizedNames;
public override USingerType SingerType => voicebank.SingerType;
public override string BasePath => voicebank.BasePath;
public override string Author => voicebank.Author;
Expand Down
5 changes: 3 additions & 2 deletions OpenUtau.Core/DiffSinger/DiffSingerSpeakerEmbedManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public NDArray getSpeakerEmbeds() {
if(dsConfig.speakers == null) {
return null;
} else {
speakerEmbeds = np.zeros<float>(dsConfig.hiddenSize, dsConfig.speakers.Count);
var embeds = np.zeros<float>(dsConfig.hiddenSize, dsConfig.speakers.Count);
foreach(var spkId in Enumerable.Range(0, dsConfig.speakers.Count)) {
speakerEmbeds[":", spkId] = loadSpeakerEmbed(dsConfig.speakers[spkId]);
embeds[":", spkId] = loadSpeakerEmbed(dsConfig.speakers[spkId]);
}
speakerEmbeds = embeds;
}
}
return speakerEmbeds;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Enunu/EnunuSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace OpenUtau.Core.Enunu {
public class EnunuSinger : USinger {
public override string Id => voicebank.Id;
public override string Name => voicebank.Name;
public override Dictionary<string, string> LocalizedNames => voicebank.LocalizedNames;
public override USingerType SingerType => voicebank.SingerType;
public override string BasePath => voicebank.BasePath;
public override string Author => voicebank.Author;
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau.Core/SingerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void SearchAllSingers() {
.ToDictionary(g => g.Key, g => g.First());
SingerGroups = singers
.GroupBy(s => s.SingerType)
.ToDictionary(s => s.Key, s => s.LocalizedOrderBy(singer => singer.Name).ToList());
.ToDictionary(s => s.Key, s => s.LocalizedOrderBy(singer => singer.LocalizedName).ToList());
stopWatch.Stop();
Log.Information($"Search all singers: {stopWatch.Elapsed}");
} catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Ustx/UProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class UProject {
public string[] expSelectors = new string[] { Format.Ustx.DYN, Format.Ustx.PITD, Format.Ustx.CLR, Format.Ustx.ENG, Format.Ustx.VEL };
public int expPrimary = 0;
public int expSecondary = 1;
public int key = 0;//Music key of the project, 0 = C, 1 = C#, 2 = D, ..., 11 = B
public List<UTimeSignature> timeSignatures;
public List<UTempo> tempos;
public List<UTrack> tracks;
Expand Down
19 changes: 19 additions & 0 deletions OpenUtau.Core/Ustx/USinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Text;
using OpenUtau.Classic;
using OpenUtau.Core.Util;

namespace OpenUtau.Core.Ustx {
public class UOto : INotifyPropertyChanged {
Expand Down Expand Up @@ -191,6 +192,7 @@ public class USinger : INotifyPropertyChanged {

public virtual string Id { get; }
public virtual string Name => name;
public virtual Dictionary<string, string> LocalizedNames { get; }
public virtual USingerType SingerType { get; }
public virtual string BasePath { get; }
public virtual string Author { get; }
Expand Down Expand Up @@ -231,6 +233,23 @@ public bool OtoDirty {

public string DisplayName { get { return Found ? name : $"[Missing] {name}"; } }

public string LocalizedName {
get {
if(LocalizedNames == null) {
return Name;
}
string language = Preferences.Default.SortingOrder;
if(String.IsNullOrEmpty(language)){
language = Preferences.Default.Language;
}
if(LocalizedNames.TryGetValue(language, out var localizedName)){
return localizedName;
} else {
return Name;
}
}
}

public virtual void EnsureLoaded() { }
public virtual void Reload() { }
public virtual void Save() { }
Expand Down
30 changes: 30 additions & 0 deletions OpenUtau.Core/Util/MusicMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@ public enum KeyColor { White, Black }
{ "B", 11 },
};

public static readonly string[] Solfeges = {
"do",
"",
"re",
"",
"mi",
"fa",
"",
"sol",
"",
"la",
"",
"ti",
};

public static readonly string[] NumberedNotations = {
"1",
"",
"2",
"",
"3",
"4",
"",
"5",
"",
"6",
"",
"7",
};

public static string GetToneName(int noteNum) {
return noteNum < 0 ? string.Empty : KeysInOctave[noteNum % 12].Item1 + (noteNum / 12 - 1).ToString();
}
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Util/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class SerializablePreferences {
public bool ShowPrefs = true;
public bool ShowTips = true;
public int Theme;
public int DegreeStyle;
public bool UseTrackColor = false;
public bool ClearCacheOnQuit = false;
public bool PreRender = true;
Expand Down
1 change: 1 addition & 0 deletions OpenUtau.Core/Vogen/VogenSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace OpenUtau.Core.Vogen {
class VogenSinger : USinger {
public override string Id => meta.id;
public override string Name => meta.name;
public override Dictionary<string, string> LocalizedNames => new Dictionary<string, string>();
public override USingerType SingerType => USingerType.Vogen;
public override string BasePath => basePath;
public override string Author => meta.builtBy;
Expand Down
38 changes: 33 additions & 5 deletions OpenUtau/Controls/TrackBackground.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Linq;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using OpenUtau.Core;
using OpenUtau.Core.Util;
using ReactiveUI;

namespace OpenUtau.App.Controls {
Expand Down Expand Up @@ -65,12 +67,29 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
}
}

int mod(int a, int b){
return (a % b + b) % b;
}

public override void Render(DrawingContext context) {
if (TrackHeight == 0) {
return;
}
int track = (int)TrackOffset;
double top = TrackHeight * (track - TrackOffset);
int key = DocManager.Inst.Project == null ? 0 : DocManager.Inst.Project.key;
string[] degreeNames;
switch(Preferences.Default.DegreeStyle){
case 1:
degreeNames = MusicMath.Solfeges;
break;
case 2:
degreeNames = MusicMath.NumberedNotations;
break;
default:
degreeNames = Enumerable.Repeat("", 12).ToArray();
break;
}
while (top < Bounds.Height) {
bool isAltTrack = IsAltTrack(track) ^ (ThemeManager.IsDarkMode && !IsKeyboard);
bool isCenterKey = IsKeyboard && IsCenterKey(track);
Expand All @@ -85,11 +104,20 @@ public override void Render(DrawingContext context) {
brush = isCenterKey ? ThemeManager.CenterKeyNameBrush
: isAltTrack ? ThemeManager.BlackKeyNameBrush
: ThemeManager.WhiteKeyNameBrush;
string toneName = MusicMath.GetToneName(ViewConstants.MaxTone - 1 - track);
var textLayout = TextLayoutCache.Get(toneName, brush, 12);
var textPosition = new Point(Bounds.Width - 4 - (int)textLayout.Width, (int)(top + (TrackHeight - textLayout.Height) / 2));
using (var state = context.PushTransform(Matrix.CreateTranslation(textPosition))) {
textLayout.Draw(context, new Point());
int tone = ViewConstants.MaxTone - 1 - track;
string toneName = MusicMath.GetToneName(tone);
var toneTextLayout = TextLayoutCache.Get(toneName, brush, 12);
var toneTextPosition = new Point(Bounds.Width - 4 - (int)toneTextLayout.Width, (int)(top + (TrackHeight - toneTextLayout.Height) / 2));
using (var state = context.PushTransform(Matrix.CreateTranslation(toneTextPosition))) {
toneTextLayout.Draw(context, new Point());
}
//scale degree display
int degree = mod(tone - key, 12);
string degreeName = degreeNames[degree];
var degreeTextLayout = TextLayoutCache.Get(degreeName, brush, 12);
var degreeTextPosition = new Point(4, (int)(top + (TrackHeight - degreeTextLayout.Height) / 2));
using (var state = context.PushTransform(Matrix.CreateTranslation(degreeTextPosition))) {
degreeTextLayout.Draw(context, new Point());
}
}
track++;
Expand Down
7 changes: 6 additions & 1 deletion OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<system:String x:Key="dialogs.installdependency.message">Installing </system:String>
<system:String x:Key="dialogs.installdll.caption">Installing phonemizer</system:String>
<system:String x:Key="dialogs.installdll.message">Installing </system:String>
<system:String x:Key="dialogs.key.caption">Key</system:String>
<system:String x:Key="dialogs.messagebox.cancel">Cancel</system:String>
<system:String x:Key="dialogs.messagebox.no">No</system:String>
<system:String x:Key="dialogs.messagebox.ok">Ok</system:String>
Expand Down Expand Up @@ -290,10 +291,14 @@
<system:String x:Key="prefs.advanced.stable">Stable</system:String>
<system:String x:Key="prefs.advanced.vlabelerpath">vLabeler Path</system:String>
<system:String x:Key="prefs.appearance">Appearance</system:String>
<system:String x:Key="prefs.appearance.degree">Scale degree display style</system:String>
<system:String x:Key="prefs.appearance.degree.numbered">Numbered (1 2 3 4 5 6 7)</system:String>
<system:String x:Key="prefs.appearance.degree.off">Off</system:String>
<system:String x:Key="prefs.appearance.degree.solfege">Solfège (do re mi fa sol la ti)</system:String>
<system:String x:Key="prefs.appearance.lang">Language</system:String>
<system:String x:Key="prefs.appearance.showghostnotes">Show other tracks' notes on piano roll</system:String>
<system:String x:Key="prefs.appearance.showportrait">Show portrait on piano roll</system:String>
<system:String x:Key="prefs.appearance.sortorder">Singer sorting order</system:String>
<system:String x:Key="prefs.appearance.sortorder">Singer name display language</system:String>
<system:String x:Key="prefs.appearance.theme">Theme</system:String>
<system:String x:Key="prefs.appearance.theme.dark">Dark</system:String>
<system:String x:Key="prefs.appearance.theme.light">Light</system:String>
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/Strings/Strings.zh-CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
<system:String x:Key="prefs.appearance.lang">语言</system:String>
<system:String x:Key="prefs.appearance.showghostnotes">在钢琴窗上显示其他音轨的音符</system:String>
<system:String x:Key="prefs.appearance.showportrait">在钢琴窗上显示歌手背景图</system:String>
<system:String x:Key="prefs.appearance.sortorder">歌手排序方式</system:String>
<system:String x:Key="prefs.appearance.sortorder">歌手名称显示语言</system:String>
<system:String x:Key="prefs.appearance.theme">主题</system:String>
<system:String x:Key="prefs.appearance.theme.dark">暗</system:String>
<system:String x:Key="prefs.appearance.theme.light">亮</system:String>
Expand Down
Loading

0 comments on commit 3dad88c

Please sign in to comment.