Skip to content

Commit

Permalink
Add Exp Line Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rokujyushi committed Sep 29, 2024
1 parent 1dfc0cc commit 39168b9
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions OpenUtau/Views/NoteEditStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using NWaves.Features;
using OpenUtau.App.Controls;
using OpenUtau.App.ViewModels;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;
using OpenUtau.Core.Util;
using SharpCompress;

namespace OpenUtau.App.Views {
class KeyboardPlayState {
Expand Down Expand Up @@ -615,11 +617,13 @@ public override void Update(IPointer pointer, Point point) {
}

class ExpSetValueState : NoteEditState {
private Point firstPoint;
private Point lastPoint;
private UExpressionDescriptor? descriptor;
private UTrack track;

private double startValue = 0;
private bool ctrlWasHeld = false;
private bool shiftWasHeld = false;
public ExpSetValueState(
Control control,
Expand All @@ -636,6 +640,7 @@ public ExpSetValueState(
}
public override void Begin(IPointer pointer, Point point) {
base.Begin(pointer, point);
firstPoint = point;
lastPoint = point;
}
public override void End(IPointer pointer, Point point) {
Expand All @@ -645,11 +650,12 @@ public override void Update(IPointer pointer, Point point, PointerEventArgs args
if (descriptor == null) {
return;
}
bool ctrlHeld = args.KeyModifiers == KeyModifiers.Control;
bool shiftHeld = args.KeyModifiers == KeyModifiers.Shift;
if (descriptor.type != UExpressionType.Curve) {
UpdatePhonemeExp(pointer, point, shiftHeld);
} else {
UpdateCurveExp(pointer, point);
UpdateCurveExp(pointer, point, ctrlHeld,shiftHeld);
}
double viewMax = descriptor.max + (descriptor.type == UExpressionType.Options ? 1 : 0);
double displayValue;
Expand All @@ -675,6 +681,7 @@ public override void Update(IPointer pointer, Point point, PointerEventArgs args
}
valueTip.UpdateValueTip(valueTipText);
lastPoint = point;
ctrlWasHeld = ctrlHeld;
shiftWasHeld = shiftHeld;
}
private void UpdatePhonemeExp(IPointer pointer, Point point, bool shiftHeld) {
Expand Down Expand Up @@ -714,15 +721,26 @@ private void UpdatePhonemeExp(IPointer pointer, Point point, bool shiftHeld) {
}
}
}
private void UpdateCurveExp(IPointer pointer, Point point) {
private void UpdateCurveExp(IPointer pointer, Point point, bool ctrlHeld, bool shiftHeld) {
var notesVm = vm.NotesViewModel;
int lastX = notesVm.PointToTick(lastPoint);
int x = notesVm.PointToTick(point);
if (descriptor == null || notesVm.Part == null) {
return;
}
int lastX = notesVm.PointToTick(lastPoint);
int x = notesVm.PointToTick(point);
int lastY = (int)Math.Round(descriptor.min + (descriptor.max - descriptor.min) * (1 - lastPoint.Y / control.Bounds.Height));
int y = (int)Math.Round(descriptor.min + (descriptor.max - descriptor.min) * (1 - point.Y / control.Bounds.Height));
if (shiftHeld) {
lastX = notesVm.PointToTick(lastPoint);
x = notesVm.PointToTick(point);
lastY = (int)Math.Round(descriptor.min + (descriptor.max - descriptor.min) * (1 - firstPoint.Y / control.Bounds.Height));
y = (int)Math.Round(descriptor.min + (descriptor.max - descriptor.min) * (1 - firstPoint.Y / control.Bounds.Height));
}else if (ctrlHeld) {
lastX = notesVm.PointToTick(firstPoint);
x = notesVm.PointToTick(lastPoint);
lastY = (int)Math.Round(descriptor.min + (descriptor.max - descriptor.min) * (1 - lastPoint.Y / control.Bounds.Height));
y = (int)Math.Round(descriptor.min + (descriptor.max - descriptor.min) * (1 - lastPoint.Y / control.Bounds.Height));
}
DocManager.Inst.ExecuteCmd(new SetCurveCommand(notesVm.Project, notesVm.Part, notesVm.PrimaryKey, x, y, lastX, lastY));
}
}
Expand Down

0 comments on commit 39168b9

Please sign in to comment.