Skip to content

Commit

Permalink
Added drawline pitch tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rokujyushi committed Sep 3, 2024
1 parent 2fe0afa commit bac4b86
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
3 changes: 3 additions & 0 deletions OpenUtau/ViewModels/NotesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class NotesViewModel : ViewModelBase, ICmdSubscriber {
[Reactive] public bool PenPlusTool { get; set; }
[Reactive] public bool EraserTool { get; set; }
[Reactive] public bool DrawPitchTool { get; set; }
[Reactive] public bool DrawLinePitchTool { get; set; }
[Reactive] public bool OverwritePitchTool { get; set; }
[Reactive] public bool KnifeTool { get; set; }
public ReactiveCommand<string, Unit> SelectToolCommand { get; }
Expand Down Expand Up @@ -204,6 +205,7 @@ public NotesViewModel() {
}
EraserTool = false;
DrawPitchTool = false;
DrawLinePitchTool = false;
OverwritePitchTool = false;
KnifeTool = false;
SelectToolCommand = ReactiveCommand.Create<string>(index => {
Expand All @@ -212,6 +214,7 @@ public NotesViewModel() {
PenPlusTool = index == "2+";
EraserTool = index == "3";
DrawPitchTool = index == "4";
DrawLinePitchTool = index == "4++";
OverwritePitchTool = index == "4+";
KnifeTool = index == "5";
});
Expand Down
50 changes: 47 additions & 3 deletions OpenUtau/Views/NoteEditStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public override void Begin(IPointer pointer, Point point) {
if (newNote == null) {
return;
}

DocManager.Inst.ExecuteCmd(new ChangeNoteLyricCommand(part, newNote, "+"));
}

Expand All @@ -436,8 +436,8 @@ public override void Update(IPointer pointer, Point point) {
maxNegDelta = (int)Math.Floor((double)maxNegDelta / snapUnit) * snapUnit;
}

int maxNoteTicks = (notesVm.IsSnapOn && snapUnit > 0)
? (oldDur-1) / snapUnit * snapUnit
int maxNoteTicks = (notesVm.IsSnapOn && snapUnit > 0)
? (oldDur-1) / snapUnit * snapUnit
: oldDur - 15;
int maxDelta = maxNoteTicks - note.duration;

Expand Down Expand Up @@ -1107,6 +1107,50 @@ public override void Update(IPointer pointer, Point point) {
}
}

class DrawLinePitchState : NoteEditState {
protected override bool ShowValueTip => false;
double? firstPitch;
Point firstPoint;
double? lastPitch;
Point lastPoint;
public DrawLinePitchState(
Control control,
PianoRollViewModel vm,
IValueTip valueTip) : base(control, vm, valueTip) { }
public override void Begin(IPointer pointer, Point point) {
base.Begin(pointer, point);
int tick = vm.NotesViewModel.PointToTick(point);
var samplePoint = vm.NotesViewModel.TickToneToPoint(
(int)Math.Round(tick / 5.0) * 5,
vm.NotesViewModel.PointToToneDouble(point));
firstPitch = vm.NotesViewModel.HitTest.SamplePitch(samplePoint);
firstPoint = point;
lastPoint = point;
}
public override void Update(IPointer pointer, Point point) {
int tick = vm.NotesViewModel.PointToTick(point);
var samplePoint = vm.NotesViewModel.TickToneToPoint(
(int)Math.Round(tick / 5.0) * 5,
vm.NotesViewModel.PointToToneDouble(point));
double? pitch = vm.NotesViewModel.HitTest.SamplePitch(samplePoint);
if (pitch == null || vm.NotesViewModel.Part == null) {
return;
}
double tone = vm.NotesViewModel.PointToToneDouble(point);
DocManager.Inst.ExecuteCmd(new SetCurveCommand(
vm.NotesViewModel.Project,
vm.NotesViewModel.Part,
Core.Format.Ustx.PITD,
vm.NotesViewModel.PointToTick(lastPitch == null ? point : lastPoint),
(int)Math.Round(tone * 100 - (lastPitch ?? pitch.Value)),
vm.NotesViewModel.PointToTick(firstPoint),
(int)Math.Round(tone * 100 - (firstPitch == null ? pitch.Value : firstPitch.Value))
));
lastPitch = pitch;
lastPoint = point;
}
}

class OverwritePitchState : NoteEditState {
protected override bool ShowValueTip => false;
double? lastPitch;
Expand Down
19 changes: 17 additions & 2 deletions OpenUtau/Views/PianoRollWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
</Style>
</Style>
</Menu.Styles>

<MenuItem Header="{DynamicResource menu.edit}">
<MenuItem Header="{DynamicResource menu.edit.undo}" InputGesture="Ctrl+Z" Command="{Binding Undo}"/>
<MenuItem Header="{DynamicResource menu.edit.redo}" InputGesture="Ctrl+Y" Command="{Binding Redo}"/>
Expand Down Expand Up @@ -227,7 +227,7 @@
</MenuItem>
</MenuItem>
</MenuItem>

<MenuItem Header="{DynamicResource menu.view}">
<MenuItem Header="{DynamicResource prefs.appearance.showportrait}" Click="OnMenuShowPortrait">
<MenuItem.Icon>
Expand Down Expand Up @@ -421,6 +421,21 @@
</Path>
</Grid>
</ToggleButton>
<ToggleButton Classes="toolbar" Margin="0" Padding="1" Height="20" Width="20"
IsChecked="{Binding NotesViewModel.DrawLinePitchTool, Mode=OneWay}"
Command="{Binding NotesViewModel.SelectToolCommand}" CommandParameter="4++"
ToolTip.Tip="{DynamicResource pianoroll.tool.drawpitch}">
<Grid Width="18" Height="18">
<Path Classes="filled" Data="m 1.9654432,15.883124 a 0.74547489,0.74547489 0 0 0 -0.00284,1.052361 l 4.9071522,4.946703 a 0.74547489,0.74547489 0 0 0 1.0555507,0.0035 L 22.513776,7.3542255 a 0.74547489,0.74547489 0 0 0 0.0024,-1.053823 L 17.585453,1.3481852 a 0.74547489,0.74547489 0 0 0 -1.05524,-0.00189 L 13.795097,4.077798 a 0.74547489,0.74547489 0 0 0 -0.01235,0.00583 l -2.970023,2.9664092 a 0.74547489,0.74547489 0 0 0 -0.0019,0.00148 L 7.8078572,10.05092 a 0.74547489,0.74547489 0 0 0 -4.549e-4,7.9e-5 l -2.9880739,2.98446 a 0.74547489,0.74547489 0 0 0 5.6e-5,3.19e-4 0.74547489,0.74547489 0 0 0 -8.034e-4,2.32e-4 z m 1.5792305,0.530266 1.8022733,-1.799373 1.4875429,1.472969 9.4e-5,9.4e-5 a 0.74547489,0.74547489 0 0 0 1.0491324,-1.059188 l -1.879e-4,-1.87e-4 -0.00182,-0.0019 -1.4792147,-1.465706 1.9335572,-1.930656 1.5071022,1.492572 A 0.74547489,0.74547489 0 0 0 10.89214,12.062682 l -1.5009923,-1.48671 1.9421273,-1.9392277 1.470447,1.4883567 0.0033,0 2.85e-4,2.87e-4 A 0.74547489,0.74547489 0 0 0 13.868294,9.0814325 L 13.868009,9.0811469 12.38859,7.5827533 14.310718,5.6635241 15.799339,7.1434007 A 0.74547489,0.74547489 0 0 0 16.85022,6.0859614 l -1.480921,-1.472178 1.687093,-1.6841938 3.878195,3.89507 L 7.4011867,20.301022 Z" >
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX=".7" ScaleY=".7" />
<TranslateTransform X="-2" Y="-2"/>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
</ToggleButton>
<ToggleButton Classes="toolbar" Margin="0" Padding="1" Height="20" Width="20"
IsChecked="{Binding NotesViewModel.OverwritePitchTool, Mode=OneWay}"
Command="{Binding NotesViewModel.SelectToolCommand}" CommandParameter="4+"
Expand Down
13 changes: 8 additions & 5 deletions OpenUtau/Views/PianoRollWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ await MessageBox.ShowProcessing(this, $"{name} - ? / ?",
var customEx = new MessageCustomizableException("Failed to run editing macro", "<translate:errors.failed.runeditingmacro>", e);
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
}
});
ViewModel.NoteBatchEdits.AddRange(new List<BatchEdit>() {
new LoadRenderedPitch(),
Expand Down Expand Up @@ -218,7 +218,7 @@ void OnMenuShowGhostNotes(object sender, RoutedEventArgs args) {
Preferences.Save();
ViewModel.RaisePropertyChanged(nameof(ViewModel.ShowGhostNotes));
MessageBus.Current.SendMessage(new PianorollRefreshEvent("Part"));

}
void OnMenuUseTrackColor(object sender, RoutedEventArgs args) {
Preferences.Default.UseTrackColor = !Preferences.Default.UseTrackColor;
Expand Down Expand Up @@ -497,14 +497,16 @@ public void NotesCanvasPointerPressed(object sender, PointerPressedEventArgs arg
}

private void NotesCanvasLeftPointerPressed(Control control, PointerPoint point, PointerPressedEventArgs args) {
if (ViewModel.NotesViewModel.DrawPitchTool || ViewModel.NotesViewModel.OverwritePitchTool) {
if (ViewModel.NotesViewModel.DrawPitchTool || ViewModel.NotesViewModel.DrawLinePitchTool || ViewModel.NotesViewModel.OverwritePitchTool) {
ViewModel.NotesViewModel.DeselectNotes();
if (args.KeyModifiers == KeyModifiers.Alt) {
editState = new SmoothenPitchState(control, ViewModel, this);
return;
} else if (args.KeyModifiers != cmdKey) {
if (ViewModel.NotesViewModel.DrawPitchTool) {
editState = new DrawPitchState(control, ViewModel, this);
} else if (ViewModel.NotesViewModel.DrawLinePitchTool) {
editState = new DrawLinePitchState(control, ViewModel, this);
} else {
editState = new OverwritePitchState(control, ViewModel, this);
}
Expand Down Expand Up @@ -584,6 +586,7 @@ private void NotesCanvasLeftPointerPressed(Control control, PointerPoint point,
ViewModel.NotesViewModel.PenTool && args.KeyModifiers == cmdKey ||
ViewModel.NotesViewModel.PenPlusTool && args.KeyModifiers == cmdKey ||
ViewModel.NotesViewModel.DrawPitchTool && args.KeyModifiers == cmdKey ||
ViewModel.NotesViewModel.DrawLinePitchTool && args.KeyModifiers == cmdKey ||
ViewModel.NotesViewModel.OverwritePitchTool && args.KeyModifiers == cmdKey) {
if (args.KeyModifiers == KeyModifiers.None) {
// New selection.
Expand All @@ -608,7 +611,7 @@ private void NotesCanvasLeftPointerPressed(Control control, PointerPoint point,

private void NotesCanvasRightPointerPressed(Control control, PointerPoint point, PointerPressedEventArgs args) {
var selectedNotes = ViewModel.NotesViewModel.Selection.ToList();
if (ViewModel.NotesViewModel.DrawPitchTool || ViewModel.NotesViewModel.OverwritePitchTool) {
if (ViewModel.NotesViewModel.DrawPitchTool || ViewModel.NotesViewModel.DrawLinePitchTool || ViewModel.NotesViewModel.OverwritePitchTool) {
editState = new ResetPitchState(control, ViewModel, this);
return;
}
Expand Down Expand Up @@ -729,7 +732,7 @@ public void NotesCanvasPointerMoved(object sender, PointerEventArgs args) {
if (ViewModel?.NotesViewModel?.HitTest == null) {
return;
}
if(((ViewModel.NotesViewModel.DrawPitchTool || ViewModel.NotesViewModel.OverwritePitchTool) && args.KeyModifiers != cmdKey) || ViewModel.NotesViewModel.EraserTool) {
if(((ViewModel.NotesViewModel.DrawPitchTool || ViewModel.NotesViewModel.DrawLinePitchTool || ViewModel.NotesViewModel.OverwritePitchTool) && args.KeyModifiers != cmdKey) || ViewModel.NotesViewModel.EraserTool) {
Cursor = null;
return;
}
Expand Down

0 comments on commit bac4b86

Please sign in to comment.