Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions OpenUtau.Core/Classic/Ust.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ namespace OpenUtau.Classic {

public static class Ust {
static readonly Encoding ShiftJIS = Encoding.GetEncoding("shift_jis");
static List<string> undefinedFlags = new List<string>();
static string tool2 = string.Empty;

public static UProject Load(string[] files) {
foreach (var file in files) {
if (Formats.DetectProjectFormat(file) != ProjectFormats.Ust) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification("Multiple files must be all Ust files"));
return null;
throw new MessageCustomizableException("Multiple files must be all Ust files", "<translate:errors.failed.importustandothers>", new FileFormatException(), false);
}
}

var projects = new List<UProject>();
undefinedFlags.Clear();
foreach (var file in files) {
var encoding = DetectEncoding(file);
using (var reader = new StreamReader(file, encoding)) {
Expand All @@ -46,6 +48,11 @@ public static UProject Load(string[] files) {
}
project.AfterLoad();
project.ValidateFull();
if (undefinedFlags.Count > 0) {
var flags = string.Join(", ", undefinedFlags.Distinct());
var customEx = new MessageCustomizableException("Unable to import undefined flags within the project", $"<translate:errors.failed.importustflags>\n{flags}", new FileLoadException(), false);
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
}
return project;
}

Expand Down Expand Up @@ -171,13 +178,20 @@ private static void ParseSetting(UProject project, List<IniLine> lines) {
}
project.tracks[0].Singer = singer;
break;
case "Tool2":
tool2 = parts[1].Trim();
break;
case "Flags":
var parser = new UstFlagParser();
var track = project.tracks[0];
foreach (var flag in parser.Parse(parts[1].Trim())) {
var descriptor = project.expressions.Values.FirstOrDefault(exp => exp.flag == flag.Key).Clone();
descriptor.CustomDefaultValue = flag.Value;
track.TrackExpressions.Add(descriptor);
var descriptor = project.expressions.Values.FirstOrDefault(exp => exp.flag == flag.Key)?.Clone();
if (descriptor == null) {
undefinedFlags.Add(flag.Key);
} else {
descriptor.CustomDefaultValue = flag.Value;
track.TrackExpressions.Add(descriptor);
}
}
break;
}
Expand Down Expand Up @@ -225,8 +239,24 @@ private static void SetFlags(UProject project, UNote note, string flags) {
var parser = new UstFlagParser();
var list = parser.Parse(flags);
list.ForEach((flag) => {
if (flag.Key == "t") {
switch (tool2) {
case { } when tool2.StartsWith("resampler"):
case { } when tool2.StartsWith("doppeltler"):
case { } when tool2.StartsWith("f2resamp"):
case { } when tool2.StartsWith("moresampler"):
note.tuning = flag.Value;
break;
default: // fresamp11-14, model4, TIPS, tn_fnds, bkh01
note.tuning = flag.Value * 10;
break;
}
return;
}
var abbr = FindAbbrFromFlagKey(project.expressions, flag);
if (abbr != String.Empty) {
if (string.IsNullOrEmpty(abbr)) {
undefinedFlags.Add(flag.Key);
} else {
SetExpression(project, note, abbr, flag.Value);
}
});
Expand Down
2 changes: 2 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ OpenUtau aims to be an open source editing environment for UTAU community, with
<system:String x:Key="errors.failed.importaudio">Failed to import audio</system:String>
<system:String x:Key="errors.failed.importfiles">Failed to import files</system:String>
<system:String x:Key="errors.failed.importmidi">Failed to import midi</system:String>
<system:String x:Key="errors.failed.importustandothers">Failed to open the projects. It contains a mix of ust and other file formats.</system:String>
<system:String x:Key="errors.failed.importustflags">The following undefined flags within the project were not imported:</system:String>
<system:String x:Key="errors.failed.installsinger">Failed to install singer</system:String>
<system:String x:Key="errors.failed.load">Failed to load</system:String>
<system:String x:Key="errors.failed.loadprefs">Failed to load prefs. Initialize it.</system:String>
Expand Down
Loading