Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(fix) Dragging the BPM field up or down now changes the tempo in whole numbers only

Egor Khindikaynenf9fed85a20ae
diff --git a/src/managed/Nota.App/Controls/DragNumber.cs b/src/managed/Nota.App/Controls/DragNumber.cs
index 1b41e42f..11983765 100644
--- a/src/managed/Nota.App/Controls/DragNumber.cs
+++ b/src/managed/Nota.App/Controls/DragNumber.cs
@@ -19,7 +19,7 @@ public sealed class DragNumber : UserControl
{
private readonly TextBlock _display = new() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
private readonly TextBox _editor;
- private readonly double _min, _max, _step;
+ private readonly double _min, _max, _step, _dragSnap;
private readonly string _format;
private double _value;
private bool _drag, _editing;
@@ -30,9 +30,10 @@ public sealed class DragNumber : UserControl
public event Action? GestureBegin;
public event Action? GestureEnd;
- public DragNumber(double value, double min, double max, double step, string format = "0", double fontSize = 12)
+ /// <param name="dragSnap">When &gt; 0, a drag lands only on multiples of this (typing stays exact).</param>
+ public DragNumber(double value, double min, double max, double step, string format = "0", double fontSize = 12, double dragSnap = 0)
{
- _min = min; _max = max; _step = step; _format = format;
+ _min = min; _max = max; _step = step; _format = format; _dragSnap = dragSnap;
_value = Math.Clamp(value, min, max);
_display.FontSize = fontSize;
@@ -78,7 +79,15 @@ public sealed class DragNumber : UserControl
{
if (!_drag) return;
double dy = _startY - e.GetPosition(this).Y; // up = increase
- double v = Math.Clamp(_startValue + dy * _step, _min, _max);
+ double v = _startValue + dy * _step;
+ if (_dragSnap > 0)
+ {
+ // Hold a typed-in fraction until the drag has travelled half a snap, so a
+ // click's jitter doesn't round it away.
+ if (Math.Abs(dy * _step) < _dragSnap / 2) return;
+ v = Math.Round(v / _dragSnap) * _dragSnap;
+ }
+ v = Math.Clamp(v, _min, _max);
if (Math.Abs(v - _value) < 1e-9) return;
_value = v; Refresh(); ValueChanged?.Invoke(_value);
}
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 3e314a7f..c94c3c32 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -208,8 +208,9 @@ public partial class MainWindow : Window
MidiLearn.Bind(masterVol, MidiTarget.MasterVolume, "Master Volume");
// BPM as a drag/type field (HANDOFF §4).
- // Tempo reads with two decimals (almanac § Numbers); a drag moves in half-BPM steps.
- var bpmField = new DragNumber((double)vm.Transport.Bpm, 20, 300, 0.5, "0.00", fontSize: 14);
+ // Tempo reads with two decimals (almanac § Numbers); a drag lands on whole BPM
+ // (half a BPM per pixel), the hundredths come from double-click-to-type.
+ var bpmField = new DragNumber((double)vm.Transport.Bpm, 20, 300, 0.5, "0.00", fontSize: 14, dragSnap: 1);
bpmField.ValueChanged += v => vm.Transport.Bpm = (decimal)Math.Round(v, 2);
BpmHost.Children.Add(bpmField);