Skip to content

Commit

Permalink
Merge pull request #6 from oxygen-dioxide/PhonemizerOnUtau
Browse files Browse the repository at this point in the history
fix for hasprev/hasnext, check if the user haven't selected any note
  • Loading branch information
oxygen-dioxide authored Dec 13, 2023
2 parents e62a2c8 + 18e062f commit 167e469
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion PhonemizerOnUtau/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
var singer = new ClassicSinger(voicebank);
singer.EnsureLoaded();

//Check if the user has selected any note
if(IsEmptyProject(plugin)) {
Console.WriteLine("Please select some notes before running this plugin.");
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
return;
}

//Parse notes and tempos
var myNotes = UtauUtil.PluginNotesToMyNotes(plugin);
var tempos = UtauUtil.GetTempoList(plugin, myNotes);
Expand Down Expand Up @@ -181,7 +189,7 @@
bool hasPrev = plugin.note[0].GetNum() == "PREV";
bool hasNext = plugin.note[^1].GetNum() == "NEXT";
int insertLocation = hasPrev ? 1 : 0;
foreach (var pluginNoteIndex in Enumerable.Range(insertLocation, originalPluginNoteCount - (hasNext ? 1 : 0))) {
foreach (var pluginNoteIndex in Enumerable.Range(insertLocation, originalPluginNoteCount - insertLocation - (hasNext ? 1 : 0))) {
plugin.DeleteNote(pluginNoteIndex);
}
currTick = 0;
Expand Down Expand Up @@ -213,6 +221,18 @@
return;
}

bool IsEmptyProject(UtauPlugin plugin){
if(plugin.note.Count == 0){
return true;
}
bool hasPrev = plugin.note[0].GetNum() == "PREV";
bool hasNext = plugin.note[^1].GetNum() == "NEXT";
if(plugin.note.Count - (hasPrev ? 1 : 0) - (hasNext ? 1 : 0) == 0) {
return true;
}
return false;
}

bool TryParsePhonemizerGroup(
List<IGrouping<string, PhonemizerFactory>> phonemizerGroups,
string input,
Expand Down

0 comments on commit 167e469

Please sign in to comment.