Skip to content

Commit

Permalink
makes pitd to pitch bend conversion one command group
Browse files Browse the repository at this point in the history
  • Loading branch information
stakira committed Apr 23, 2023
1 parent 9d4b4a3 commit 3568714
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 4 additions & 2 deletions OpenUtau.Core/Commands/ExpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void Execute() {
}
public override void Unexecute() {
phoneme.SetExpression(project, track, Key, oldValue);
}
}
}

public class ResetExpressionsCommand : ExpCommand {
Expand Down Expand Up @@ -245,7 +245,9 @@ public override void Unexecute() {
curve.ys.AddRange(oldYs);
}
}
public override bool Mergeable => true;
public override bool CanMerge(IList<UCommand> commands) {
return commands.All(c => c is SetCurveCommand);
}
public override UCommand Merge(IList<UCommand> commands) {
var first = commands.First() as SetCurveCommand;
var last = commands.Last() as SetCurveCommand;
Expand Down
9 changes: 5 additions & 4 deletions OpenUtau.Core/Commands/UCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;

namespace OpenUtau.Core {
Expand All @@ -7,8 +8,8 @@ public abstract class UCommand {
public virtual ValidateOptions ValidateOptions => default;
public abstract void Execute();
public abstract void Unexecute();
public virtual bool Mergeable => false;
public virtual UCommand Merge(IList<UCommand> commands) => null;
public virtual bool CanMerge(IList<UCommand> commands) => false;
public virtual UCommand Merge(IList<UCommand> commands) => throw new NotImplementedException();
public abstract override string ToString();
}

Expand All @@ -20,7 +21,7 @@ public UCommandGroup(bool deferValidate) {
Commands = new List<UCommand>();
}
public void Merge() {
if (Commands.Count > 0 && Commands.Last().Mergeable) {
if (Commands.Count > 0 && Commands.Last().CanMerge(Commands)) {
var merged = Commands.Last().Merge(Commands);
Commands.Clear();
Commands.Add(merged);
Expand Down
2 changes: 0 additions & 2 deletions OpenUtau.Core/Editing/NoteBatchEdits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ public void Run(UProject project, UVoicePart part, List<UNote> selectedNotes, Do

}
}
docManager.EndUndoGroup();
docManager.StartUndoGroup(true);
foreach(var note in selectedNotes) {
if (pitchPointsPerNote.TryGetValue(note.position, out var tickRangeAndPitch)) {
docManager.ExecuteCmd(new SetCurveCommand(project, part, Format.Ustx.PITD,
Expand Down

0 comments on commit 3568714

Please sign in to comment.