Skip to content

Commit

Permalink
optimize portamento update
Browse files Browse the repository at this point in the history
  • Loading branch information
lennyservant committed Oct 10, 2023
1 parent 3de2759 commit 81603a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
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
20 changes: 8 additions & 12 deletions OpenUtau/ViewModels/NotePropertiesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,21 @@ private void SetValueChanges() {
.Subscribe(value => {
if (value >= 2 && value <= 320) {
if (AllowNoteEdit && Part != null && selectedNotes.Count > 0) {
foreach (UNote note in selectedNotes) {
var pitch = new UPitch() { snapFirst = true };
pitch.AddPoint(new PitchPoint(PortamentoStart, 0));
pitch.AddPoint(new PitchPoint(PortamentoStart + PortamentoLength, 0));
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, note, pitch));
}
var pitch = new UPitch() { snapFirst = true };
pitch.AddPoint(new PitchPoint(PortamentoStart, 0));
pitch.AddPoint(new PitchPoint(PortamentoStart + PortamentoLength, 0));
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, selectedNotes, pitch));
}
}
});
this.WhenAnyValue(vm => vm.PortamentoStart)
.Subscribe(value => {
if (value >= -200 && value <= 200) {
if (AllowNoteEdit && Part != null && selectedNotes.Count > 0) {
foreach (UNote note in selectedNotes) {
var pitch = new UPitch() { snapFirst = true };
pitch.AddPoint(new PitchPoint(PortamentoStart, 0));
pitch.AddPoint(new PitchPoint(PortamentoStart + PortamentoLength, 0));
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, note, pitch));
}
var pitch = new UPitch() { snapFirst = true };
pitch.AddPoint(new PitchPoint(PortamentoStart, 0));
pitch.AddPoint(new PitchPoint(PortamentoStart + PortamentoLength, 0));
DocManager.Inst.ExecuteCmd(new SetPitchPointsCommand(Part, selectedNotes, pitch));
}
}
});
Expand Down

0 comments on commit 81603a7

Please sign in to comment.