Skip to content

Commit

Permalink
Merge branch 'master' into solfege
Browse files Browse the repository at this point in the history
  • Loading branch information
oxygen-dioxide authored Oct 10, 2023
2 parents 6a9a867 + 0895b44 commit 8cddfbb
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 65 deletions.
2 changes: 1 addition & 1 deletion OpenUtau.Core/Classic/ResamplerItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ResamplerItem(RenderPhrase phrase, RenderPhone phone) {
int tempoPitchSkip = (int)Math.Floor(MusicMath.TempoMsToTick(tempo, startMs - phoneStartMs) / 5.0);
tempoPitchCount = Math.Min(tempoPitchCount, pitches.Length - tempoPitchSkip);
int phrasePitchSkip = (int)Math.Floor(phrase.timeAxis.TicksBetweenMsPos(phraseStartMs, startMs) / 5.0);
double intervalPitchMs = phrase.timeAxis.TickPosToMsPos(5);
double intervalPitchMs = 120 / tempo * 500 / 480 * 5;
double diffPitchMs = startMs - phraseStartMs - phrase.timeAxis.TickPosToMsPos(phrasePitchSkip * 5);
double tempoRatio = phone.tempos[i].bpm / tempo;
for (int j = 0; j < tempoPitchCount; j++) {
Expand Down
29 changes: 24 additions & 5 deletions OpenUtau.Core/Commands/ExpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,35 @@ public ResetPitchPointsCommand(UVoicePart part, UNote note) : base(part) {
}

public class SetPitchPointsCommand : PitchExpCommand {
UPitch oldPitch;
UPitch[] oldPitch;
UNote[] Notes;
UPitch newPitch;
public SetPitchPointsCommand(UVoicePart part, UNote note, UPitch pitch) : base(part) {
Note = note;
oldPitch = note.pitch;
Notes = new UNote[] { note };
oldPitch = Notes.Select(note => note.pitch).ToArray();
newPitch = pitch;
}

public SetPitchPointsCommand(UVoicePart part, IEnumerable<UNote> notes, UPitch pitch) : base(part) {
Notes = notes.ToArray();
oldPitch = Notes.Select(note => note.pitch).ToArray();
newPitch = pitch;
}
public override string ToString() => "Set pitch points";
public override void Execute() => Note.pitch = newPitch;
public override void Unexecute() => Note.pitch = oldPitch;
public override void Execute(){
lock (Part) {
for (var i=0; i<Notes.Length; i++) {
Notes[i].pitch = newPitch.Clone();
}
}
}
public override void Unexecute() {
lock (Part) {
for (var i = 0; i < Notes.Length; i++) {
Notes[i].pitch = oldPitch[i];
}
}
}
}

public class SetCurveCommand : ExpCommand {
Expand Down
23 changes: 23 additions & 0 deletions OpenUtau.Core/Editing/NoteBatchEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,29 @@ public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, Do
}
}

public class ResetAliases : BatchEdit {
public virtual string Name => name;

private string name;

public ResetAliases() {
name = "pianoroll.menu.notes.reset.aliases";
}

public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, DocManager docManager) {
var notes = selectedNotes.Count > 0 ? selectedNotes : part.notes.ToList();
docManager.StartUndoGroup(true);
foreach (var note in notes) {
foreach (var o in note.phonemeOverrides) {
if (o.phoneme!=null) {
docManager.ExecuteCmd(new ChangePhonemeAliasCommand(part, note, o.index, null));
}
}
}
docManager.EndUndoGroup();
}
}

public class LengthenCrossfade : BatchEdit {
public virtual string Name => name;
private string name;
Expand Down
3 changes: 3 additions & 0 deletions OpenUtau/Controls/WaveformImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public override void Render(DrawingContext context) {
private WriteableBitmap? GetBitmap() {
int desiredWidth = (int)Bounds.Width;
int desiredHeight = (int)Bounds.Height;
if (desiredWidth == 0 || desiredHeight == 0) {
return null;
}
if (bitmap == null || bitmap.Size.Width < desiredWidth) {
bitmap?.Dispose();
var size = new PixelSize(desiredWidth, desiredHeight);
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<system:String x:Key="pianoroll.menu.notes.quantize15">Quantize to 1/128</system:String>
<system:String x:Key="pianoroll.menu.notes.quantize30">Quantize to 1/64</system:String>
<system:String x:Key="pianoroll.menu.notes.autolegato">Auto Legato</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.aliases">Reset phoneme aliases</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.exps">Reset all expressions</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.phonemetimings">Reset phoneme timings</system:String>
<system:String x:Key="pianoroll.menu.notes.reset.pitchbends">Reset pitch bends</system:String>
Expand Down
8 changes: 2 additions & 6 deletions OpenUtau/ViewModels/NotePropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ private void SetValueChanges() {
var pitch = new UPitch() { snapFirst = true };
pitch.AddPoint(new PitchPoint(PortamentoStart, 0));
pitch.AddPoint(new PitchPoint(PortamentoStart + PortamentoLength, 0));
foreach (UNote note in selectedNotes) {
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, note, pitch));
}
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, selectedNotes, pitch));
}
}
});
Expand All @@ -280,9 +278,7 @@ private void SetValueChanges() {
var pitch = new UPitch() { snapFirst = true };
pitch.AddPoint(new PitchPoint(PortamentoStart, 0));
pitch.AddPoint(new PitchPoint(PortamentoStart + PortamentoLength, 0));
foreach (UNote note in selectedNotes) {
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, note, pitch));
}
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, selectedNotes, pitch));
}
}
});
Expand Down
33 changes: 23 additions & 10 deletions OpenUtau/ViewModels/NotesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,27 @@ private void LoadPart(UPart part, UProject project) {
UpdateKey();
}

//If PortraitHeight is 0, the default behaviour is resizing any image taller than 800px to 800px,
//and keeping the sizes of images shorter than 800px unchanged.
//If PortraitHeight isn't 0, then the image will be resized to the specified height.
private Bitmap ResizePortrait(Bitmap Portrait, int PortraitHeight) {
int targetHeight;
if (PortraitHeight == 0) {
if (Portrait.Size.Height > 800) {
targetHeight = 800;
} else {
return Portrait;
}
} else {
targetHeight = PortraitHeight;
}
int targetWidth = (int)Math.Round(targetHeight * Portrait.Size.Width / Portrait.Size.Height);
if(targetWidth == 0){
targetWidth = 1;
}
return Portrait.CreateScaledBitmap(new PixelSize(targetWidth, targetHeight));
}

private void LoadPortrait(UPart? part, UProject? project) {
if (part == null || project == null) {
lock (portraitLock) {
Expand Down Expand Up @@ -452,16 +473,8 @@ private void LoadPortrait(UPart? part, UProject? project) {
Portrait = null;
portraitSource = null;
} else {
using (var stream = new MemoryStream(data)) {
var portrait = new Bitmap(stream);
if (portrait.Size.Height > 800 && singer.PortraitHeight == 0) {
int width = (int)Math.Round(800 * portrait.Size.Width / portrait.Size.Height);
portrait = portrait.CreateScaledBitmap(new PixelSize(width, 800));
} else {
int width = (int)Math.Round(singer.PortraitHeight * portrait.Size.Width / portrait.Size.Height);
portrait = portrait.CreateScaledBitmap(new PixelSize(width, singer.PortraitHeight));
}
Portrait = portrait;
using (var stream = new MemoryStream(data)) {
Portrait = ResizePortrait(new Bitmap(stream), singer.PortraitHeight);
portraitSource = singer.Portrait;
}
}
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/ViewModels/PianoRollViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public PianoRollViewModel() {
new ClearVibratos(),
new ResetVibratos(),
new ClearTimings(),
new ResetAliases(),
new BakePitch(),
}.Select(edit => new MenuItemViewModel() {
Header = ThemeManager.GetString(edit.Name),
Expand Down
9 changes: 8 additions & 1 deletion OpenUtau/ViewModels/SingersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,14 @@ public void Refresh() {
public void OpenLocation() {
try {
if (Singer != null) {
OS.OpenFolder(Singer.Location);
var location = Singer.Location;
if(File.Exists(location)) {
//Vogen voicebank is a singlefile
OS.GotoFile(location);
} else {
//classic or ENUNU voicebank is a folder
OS.OpenFolder(location);
}
}
} catch (Exception e) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(e));
Expand Down
5 changes: 2 additions & 3 deletions OpenUtau/Views/EditSubbanksDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia.Controls;
using Avalonia.Interactivity;
using OpenUtau.App.ViewModels;
Expand Down Expand Up @@ -70,7 +69,7 @@ async void OnImportMap(object sender, RoutedEventArgs args) {
var file = await FilePicker.OpenFile(this, "singers.subbanks.import", ViewModel.Singer.Location, FilePicker.PrefixMap);
if (!string.IsNullOrEmpty(file)) {
try {
using (var reader = new StreamReader(file, Encoding.GetEncoding("shift_jis"))) {
using (var reader = new StreamReader(file, ViewModel.Singer.TextFileEncoding)) {
while (reader.Peek() != -1) {
var line = reader.ReadLine()!.Trim();
var s = line.Split('\t');
Expand All @@ -97,7 +96,7 @@ async void OnExportMap(object sender, RoutedEventArgs args) {
var file = await FilePicker.SaveFile(this, "singers.subbanks.export", ViewModel.Singer.Location, "prefix.map", FilePicker.PrefixMap);
if (!string.IsNullOrEmpty(file)) {
try {
using (var writer = new StreamWriter(file, false, Encoding.GetEncoding("shift_jis"))) {
using (var writer = new StreamWriter(file, false, ViewModel.Singer.TextFileEncoding)) {
foreach (var row in main.Rows) {
writer.WriteLine($"{row.Tone}\t{row.Prefix}\t{row.Suffix}");
}
Expand Down
1 change: 1 addition & 0 deletions OpenUtau/Views/PasteParamDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ListBox.Styles>
<Style Selector="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
<Setter Property="Focusable" Value="False"/>
</Style>
</ListBox.Styles>
</ListBox>
Expand Down
15 changes: 7 additions & 8 deletions OpenUtau/Views/PianoRollWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,20 +848,19 @@ void IValueTip.UpdateValueTip(string text) {
#endregion

void OnKeyDown(object sender, KeyEventArgs args) {
if (LyricBox != null && LyricBox.IsVisible) {
args.Handled = false;
return;
}
if (SearchBar != null && SearchBar.IsVisible && SearchBar.box.IsFocused) {
args.Handled = false;
return;
}
var notesVm = ViewModel.NotesViewModel;
if (notesVm.Part == null) {
args.Handled = false;
return;
}

if (FocusManager != null && FocusManager.GetFocusedElement() is TextBox focusedTextBox) {
if (focusedTextBox.IsEnabled && focusedTextBox.IsEffectivelyVisible && focusedTextBox.IsFocused) {
args.Handled = false;
return;
}
}

// returns true if handled
args.Handled = OnKeyExtendedHandler(args);
}
Expand Down
71 changes: 40 additions & 31 deletions OpenUtau/Views/SingersDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,43 +230,52 @@ void OnOpenReadme(object sender, RoutedEventArgs e) {
}
}

string? FindSample(USinger singer){
var sample = singer.Sample;
if(sample!=null && File.Exists(sample)){
return sample;
} else if (singer.SingerType == USingerType.Classic) {
var path = singer.Location;
if(!Directory.Exists(path)){
return null;
}
string[] files = Directory.EnumerateFiles(path, "*.wav", SearchOption.AllDirectories)
.Union(Directory.EnumerateFiles(path, "*.mp3", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.flac", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.aiff", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.ogg", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.opus", SearchOption.AllDirectories))
.ToArray();
if(files.Length==0){
return null;
}
Random rnd = new Random(Guid.NewGuid().GetHashCode());
int choice = rnd.Next(0, files.Length - 1);
string soundFile = files[choice];
return soundFile;
}
return null;
}

public void OnPlaySample(object sender, RoutedEventArgs e) {
var viewModel = (DataContext as SingersViewModel)!;
var playBack = PlaybackManager.Inst.AudioOutput;
var playbackState = playBack.PlaybackState;
if (viewModel.Singer != null) {
var sample = viewModel.Singer.Sample;
if (sample != null && File.Exists(sample)) {
var playSample = Wave.OpenFile(sample);
playBack.Init(playSample.ToSampleProvider());
playBack.Play();
if (playbackState == PlaybackState.Playing) {
playBack.Stop();
}
} else if (viewModel.Singer.SingerType == USingerType.Classic) {
var path = viewModel.Singer.Location;
if(!Directory.Exists(path)){
return;
}
string[] files = Directory.EnumerateFiles(path, "*.wav", SearchOption.AllDirectories)
.Union(Directory.EnumerateFiles(path, "*.mp3", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.flac", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.aiff", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.ogg", SearchOption.AllDirectories))
.Union(Directory.EnumerateFiles(path, "*.opus", SearchOption.AllDirectories))
.ToArray();
if(files.Length==0){
return;
}
Random rnd = new Random(Guid.NewGuid().GetHashCode());
int choice = rnd.Next(0, files.Length - 1);
string soundFile = files[choice];
var playSound = Wave.OpenFile(soundFile);
var sample = FindSample(viewModel.Singer);
if(sample == null){
return;
}
try{
var playSound = Wave.OpenFile(sample);
playBack.Init(playSound.ToSampleProvider());
playBack.Play();
if (playbackState == PlaybackState.Playing) {
playBack.Stop();
}
} catch (Exception ex) {
Log.Error(ex, $"Failed to load sample {sample}.");
return;
}
playBack.Play();
if (playbackState == PlaybackState.Playing) {
playBack.Stop();
}
}
}
Expand Down

0 comments on commit 8cddfbb

Please sign in to comment.