Skip to content

Commit

Permalink
Some minor changes (#752)
Browse files Browse the repository at this point in the history
* Use SetPhonemeExpressionCommand instead of ChangeVoiceColorCommand

* Min value of vibrato shift slider set to 0 in NoteDefaultsDialog

* Fix RomajiToHiragana fallback
  • Loading branch information
maiko3tattun committed Jun 28, 2023
1 parent cbc6eb4 commit 7003524
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 91 deletions.
73 changes: 0 additions & 73 deletions OpenUtau.Core/Commands/NoteCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,77 +462,4 @@ public override void Unexecute() {
}
public override string ToString() => "Change phoneme alias";
}

public class ChangeVoiceColorCommand : NoteCommand {
readonly int[] NewColors;
readonly int[] OldColors;
readonly UTrack Track;
public ChangeVoiceColorCommand(UVoicePart part, UNote note, int newColor, UTrack track) : base(part, note) {
NewColors = new int[] { newColor };
if (note.phonemeExpressions.Any(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0)) {
OldColors = new int[] { (int)note.phonemeExpressions.FirstOrDefault(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0).value };
} else {
OldColors = new int[] { 0 };
}
Track = track;
}
public ChangeVoiceColorCommand(UVoicePart part, UNote[] notes, int[] newColors, UTrack track) : base(part, notes) {
if (notes.Length != newColors.Length) {
throw new ArgumentException($"notes count {notes.Length} and colors count {newColors.Length} does not match.");
}
NewColors = newColors;
OldColors = notes.Select(note => {
if (note.phonemeExpressions.Any(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0)) {
return (int)note.phonemeExpressions.FirstOrDefault(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0).value;
} else {
return 0;
}
}).ToArray();
Track = track;
}
public override string ToString() => "Change notes color";

public override void Execute() {
lock (Part) {
if (Track.VoiceColorExp != null) {
for (var i = 0; i < Notes.Length; i++) {
var note = Notes[i];
var exp = note.phonemeExpressions.FirstOrDefault(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0);

if (exp != null) {
exp.descriptor = Track.VoiceColorExp;
exp.value = NewColors[i];
} else {
note.phonemeExpressions.Add(new UExpression(Track.VoiceColorExp) {
descriptor = Track.VoiceColorExp,
index = 0,
value = NewColors[i]
});
}
}
}
}
}
public override void Unexecute() {
lock (Part) {
if (Track.VoiceColorExp != null) {
for (var i = 0; i < Notes.Length; i++) {
var note = Notes[i];
var exp = note.phonemeExpressions.FirstOrDefault(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0);

if (exp != null) {
exp.descriptor = Track.VoiceColorExp;
exp.value = OldColors[i];
} else {
note.phonemeExpressions.Add(new UExpression(Track.VoiceColorExp) {
descriptor = Track.VoiceColorExp,
index = 0,
value = OldColors[i]
});
}
}
}
}
}
}
}
27 changes: 10 additions & 17 deletions OpenUtau.Core/Editing/LyricBatchEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public class RomajiToHiragana : SingleNoteLyricEdit {
private WanaKanaOptions option = new WanaKanaOptions() { CustomKanaMapping = mapping };
public override string Name => "pianoroll.menu.lyrics.romajitohiragana";
protected override string Transform(string lyric) {
return WanaKana.ToHiragana(lyric, option);
string hiragana = WanaKana.ToHiragana(lyric, option).Replace('ゔ','ヴ');
if(Regex.IsMatch(hiragana, "[ぁ-んァ-ヴ]")) {
return hiragana;
} else {
return lyric;
}
}
}

Expand Down Expand Up @@ -133,23 +138,11 @@ public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, Do
docManager.ExecuteCmd(new ChangeNoteLyricCommand(part, note, lyric));

int index = colors.FirstOrDefault(c => c.Value == suffix).Key;
docManager.ExecuteCmd(new ChangeVoiceColorCommand(part, note, index, track));

/*if(track.VoiceColorExp != null) {
int index = colors.FirstOrDefault(c => c.Value == suffix).Key;
var exp = note.phonemeExpressions.FirstOrDefault(exp => exp.descriptor?.abbr == Format.Ustx.CLR && exp.index == 0);
if (exp != null) {
exp.descriptor = track.VoiceColorExp;
exp.value = index;
} else {
note.phonemeExpressions.Add(new UExpression(track.VoiceColorExp) {
descriptor = track.VoiceColorExp,
index = 0,
value = index,
});
foreach (UPhoneme phoneme in part.phonemes) {
if (phoneme.Parent == note) {
docManager.ExecuteCmd(new SetPhonemeExpressionCommand(project, track, part, phoneme, Format.Ustx.CLR, index));
}
}*/
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenUtau/Views/NoteDefaultsDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<Grid ColumnDefinitions="180,20,50,20,*">
<Label Content="{DynamicResource notedefaults.vibrato.shift}"/>
<TextBox Grid.Column="2" Text="{Binding CurrentVibratoShift}" />
<Slider Grid.Column="4" Classes="fader" Value="{Binding CurrentVibratoShift}" Minimum="1" Maximum="100"
<Slider Grid.Column="4" Classes="fader" Value="{Binding CurrentVibratoShift}" Minimum="0" Maximum="100"
TickPlacement="BottomRight" TickFrequency="0.1" IsSnapToTickEnabled="true" />
</Grid>
<Grid ColumnDefinitions="173,20,*">
Expand Down

0 comments on commit 7003524

Please sign in to comment.