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.

(feat) Tempo tap

Egor Khindikaynenf95f00b43bb9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9246cc37..40318f58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **Tap tempo.** A **TAP** cell beside the BPM in the transport bar: tap the beat on it and the
+ project tempo follows from the second tap, averaged over the last eight. Four dots count the
+ beats as you tap. Change pace mid-series and it picks up the new tempo at once; pause for
+ three seconds to start over. Also in the command palette as **Tap Tempo**.
- **Edit MPE in the piano roll.** The lane under the notes now switches between **VEL**,
**BEND**, **PRES** and **SLIDE**. Pick a note and draw its bend, pressure or slide right over
its span — hold ⌥ for a straight line — drag a point to reshape it, double-click to add or
diff --git a/FEATURES.md b/FEATURES.md
index f980ba03..ac898898 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -66,6 +66,8 @@ JUCE module; the engine core is JUCE-free.
- **Position**: clicking the readout toggles bars ↔ time (mm:ss.ms).
- **Tempo (BPM)** and **time signature** (edited by dragging; the denominator snaps to a
power of two), grid and quantization.
+- **Tap tempo**: a TAP cell beside the BPM (and *Tap Tempo* in the command palette) sets the
+ tempo from tapped beats — mean of the last eight gaps, restarts on a pace change or a 3 s pause.
- **Loop region** (on/off and range; Cmd/Ctrl+L loops the selection).
- **Metronome** and **count-in** before recording.
- **Transport shortcuts** (Space play/stop, Enter stop, R/M/A, clip copy-paste, typing
diff --git a/src/managed/Nota.App/MainWindow.Commands.cs b/src/managed/Nota.App/MainWindow.Commands.cs
index 82b3d547..6afe1075 100644
--- a/src/managed/Nota.App/MainWindow.Commands.cs
+++ b/src/managed/Nota.App/MainWindow.Commands.cs
@@ -89,6 +89,7 @@ public partial class MainWindow
B("transport.record", () => OnMenuRecord(this, e));
B("transport.loop", () => OnMenuLoop(this, e));
B("transport.metronome", () => OnMenuMetronome(this, e));
+ B("transport.tapTempo", TapTempoBeat);
// ---- Track
B("track.newInstrument", () => AddTrack(NewTrackKind.Instrument));
diff --git a/src/managed/Nota.App/MainWindow.TransportFit.cs b/src/managed/Nota.App/MainWindow.TransportFit.cs
index a389da77..3969ade8 100644
--- a/src/managed/Nota.App/MainWindow.TransportFit.cs
+++ b/src/managed/Nota.App/MainWindow.TransportFit.cs
@@ -27,6 +27,7 @@ public partial class MainWindow
new Control[] { CpuMeter, CpuSep }, // informative only
new Control[] { ProjectNameText }, // moves to the title-bar caption
new Control[] { RemoteLabel }, // Remote keeps its glyph, count and dot
+ new Control[] { TapChip }, // palette ▸ Tap Tempo; the BPM field stays
new Control[] { KeyChip }, // set once per project
new Control[] { RemoteBtn }, // View ▸ Connect Phone…
new Control[] { FollowBtn }, // View ▸ Follow playhead
diff --git a/src/managed/Nota.App/MainWindow.axaml b/src/managed/Nota.App/MainWindow.axaml
index 57fe9146..cf1f93d8 100644
--- a/src/managed/Nota.App/MainWindow.axaml
+++ b/src/managed/Nota.App/MainWindow.axaml
@@ -200,6 +200,21 @@
<Panel x:Name="BpmHost" Width="52" Height="18"/>
<TextBlock Classes="CellLabel" Text="BPM" HorizontalAlignment="Center"/>
</StackPanel>
+ <!-- Tap tempo: fires on press (a release lags the beat). The dots count the beats
+ of the current series, brass as each one lands; they clear when it times out. -->
+ <Button x:Name="TapChip" Classes="cell" ClickMode="Press" Click="OnTapTempo"
+ ToolTip.Tip="Tap the beat to set the tempo">
+ <StackPanel Spacing="2">
+ <StackPanel x:Name="TapDots" Orientation="Horizontal" Spacing="3" Height="16"
+ HorizontalAlignment="Center" VerticalAlignment="Center">
+ <Ellipse Width="4" Height="4" Fill="{DynamicResource Brush.BorderStrong}"/>
+ <Ellipse Width="4" Height="4" Fill="{DynamicResource Brush.BorderStrong}"/>
+ <Ellipse Width="4" Height="4" Fill="{DynamicResource Brush.BorderStrong}"/>
+ <Ellipse Width="4" Height="4" Fill="{DynamicResource Brush.BorderStrong}"/>
+ </StackPanel>
+ <TextBlock Classes="CellLabel" Text="TAP" HorizontalAlignment="Center"/>
+ </StackPanel>
+ </Button>
<!-- Time signature (drag ↕ each field) -->
<StackPanel x:Name="TimeSigCell" Spacing="2" VerticalAlignment="Center" Margin="7,0" ToolTip.Tip="Set the time signature — drag each field">
<StackPanel Orientation="Horizontal" Spacing="1" Height="18">
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 3dad01fe..33a28da8 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -599,6 +599,45 @@ public partial class MainWindow : Window
f.ShowAt(MetronomeBtn);
}
+ private readonly TapTempo _tap = new();
+ private readonly System.Diagnostics.Stopwatch _tapClock = System.Diagnostics.Stopwatch.StartNew();
+ private DispatcherTimer? _tapIdle;
+
+ private void OnTapTempo(object? sender, RoutedEventArgs e) => TapTempoBeat();
+
+ // One beat of tap tempo, from the TAP cell or the palette. The tempo follows from the
+ // second tap on; the dots fill 1–4 and wrap, and clear once the series times out.
+ private void TapTempoBeat()
+ {
+ if (_vm is null) return;
+ double? bpm = _tap.Tap(_tapClock.Elapsed.TotalMilliseconds);
+ if (bpm is { } b)
+ {
+ _vm.Transport.Bpm = (decimal)b;
+ _vm.StatusText = $"Tempo: {NotaNum.Bpm(b)} BPM (tapped)";
+ }
+ ShowTapDots(_tap.Count);
+ _tapIdle ??= new DispatcherTimer { Interval = TimeSpan.FromSeconds(3) };
+ _tapIdle.Tick -= OnTapIdle;
+ _tapIdle.Tick += OnTapIdle;
+ _tapIdle.Stop();
+ _tapIdle.Start();
+ }
+
+ private void OnTapIdle(object? sender, EventArgs e)
+ {
+ _tapIdle?.Stop();
+ _tap.Reset();
+ ShowTapDots(0);
+ }
+
+ private void ShowTapDots(int taps)
+ {
+ int lit = taps == 0 ? 0 : (taps - 1) % TapDots.Children.Count + 1;
+ for (int i = 0; i < TapDots.Children.Count; i++)
+ ((Ellipse)TapDots.Children[i]).BindResource(Shape.FillProperty, i < lit ? "Brush.Accent" : "Brush.BorderStrong");
+ }
+
private void OnCycleSnap(object? sender, RoutedEventArgs e)
{
_snapIndex = (_snapIndex + 1) % SnapSteps.Length;
diff --git a/src/managed/Nota.Application/Palette/CommandCatalog.cs b/src/managed/Nota.Application/Palette/CommandCatalog.cs
index 346d45a0..47ae6176 100644
--- a/src/managed/Nota.Application/Palette/CommandCatalog.cs
+++ b/src/managed/Nota.Application/Palette/CommandCatalog.cs
@@ -70,6 +70,7 @@ public static class CommandCatalog
C("transport.record", "Record", "Transport", "⌘R", "arm capture"),
C("transport.loop", "Toggle Loop", "Transport", "⌘L", "cycle repeat"),
C("transport.metronome", "Metronome", "Transport", "⌘M", "click"),
+ C("transport.tapTempo", "Tap Tempo", "Transport", "", "bpm beat tap"),
// ---- Track ------------------------------------------------------------------------
C("track.newInstrument", "New MIDI Track", "Track", "", "add instrument track"),
diff --git a/src/managed/Nota.Application/TapTempo.cs b/src/managed/Nota.Application/TapTempo.cs
new file mode 100644
index 00000000..2e0fed48
--- /dev/null
+++ b/src/managed/Nota.Application/TapTempo.cs
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Tap tempo: the tempo from a series of taps. The estimate is the mean interval over the
+// last eight gaps (first-to-last span / gap count, so one late tap shifts it once, not
+// twice). A pause longer than a 20 BPM beat starts a new series; a gap far off the running
+// mean means the player changed tempo, so the series restarts from the previous tap; a
+// gap shorter than a 300 BPM sixteenth is a switch bounce and is ignored.
+
+using System;
+using System.Collections.Generic;
+
+namespace Nota.Application;
+
+public sealed class TapTempo
+{
+ public const double MinBpm = 20, MaxBpm = 300;
+ private const int MaxGaps = 8;
+ private const double ResetMs = 60000.0 / MinBpm; // 3 s: a longer pause is a new series
+ private const double BounceMs = 50;
+ private const double Deviation = 0.25; // ±25 % off the mean = a new tempo
+
+ private readonly List<double> _taps = new();
+
+ /// <summary>Taps in the current series (1 after the first tap, 0 when idle).</summary>
+ public int Count => _taps.Count;
+
+ public void Reset() => _taps.Clear();
+
+ /// <summary>Registers a tap at <paramref name="nowMs"/> (any monotonic clock, in ms).
+ /// Returns the tempo once there are two taps, else null. Whole BPM: a tapped series
+ /// isn't accurate past that, and a round number is what the player meant.</summary>
+ public double? Tap(double nowMs)
+ {
+ if (_taps.Count > 0)
+ {
+ double gap = nowMs - _taps[^1];
+ if (gap < 0 || gap > ResetMs) _taps.Clear();
+ else if (gap < BounceMs) return Estimate();
+ else if (_taps.Count >= 3)
+ {
+ double mean = (_taps[^1] - _taps[0]) / (_taps.Count - 1);
+ if (Math.Abs(gap - mean) > mean * Deviation) _taps.RemoveRange(0, _taps.Count - 1);
+ }
+ }
+ _taps.Add(nowMs);
+ if (_taps.Count > MaxGaps + 1) _taps.RemoveAt(0);
+ return Estimate();
+ }
+
+ private double? Estimate()
+ {
+ if (_taps.Count < 2) return null;
+ double mean = (_taps[^1] - _taps[0]) / (_taps.Count - 1);
+ return Math.Clamp(Math.Round(60000.0 / mean), MinBpm, MaxBpm);
+ }
+}
diff --git a/tests/Nota.SmokeTest/PaletteTests.cs b/tests/Nota.SmokeTest/PaletteTests.cs
index 88d10f2c..dc8f757f 100644
--- a/tests/Nota.SmokeTest/PaletteTests.cs
+++ b/tests/Nota.SmokeTest/PaletteTests.cs
@@ -98,7 +98,7 @@ internal static class PaletteTests
("dark reverb", "Nota Chamber"), ("acid bass", "Preset:*acid"), ("pluck", "Preset:*pluck"),
// actions & tracks (CP-6a)
("quant", "Quantize Notes"), (">quant", "Quantize Notes"), ("export", "Export Audio…"), ("render", "Export Audio…"),
- ("settings audio", "Settings: Audio"), ("hotkeys", "Settings: Shortcuts"), ("metronome", "Metronome"),
+ ("settings audio", "Settings: Audio"), ("hotkeys", "Settings: Shortcuts"), ("metronome", "Metronome"), ("tap tempo", "Tap Tempo"),
("@vox", "Lead Vox"), ("bass", "Bass"), ("phaser", "Nota Phaser"),
};
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index e0d7ae35..780e142e 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -199,6 +199,14 @@ if (args.Length >= 1 && args[0] == "--bundle")
return failures == 0 ? 0 : 1;
}
+// Tap tempo alone: `--tap`. Also part of the full run.
+if (args.Length >= 1 && args[0] == "--tap")
+{
+ Console.WriteLine("-- tap tempo --");
+ foreach (var (ok, label) in TapTempoTests.Run()) Check(ok, label);
+ Console.WriteLine(failures == 0 ? "TAP PASSED" : $"TAP FAILED ({failures})");
+ return failures == 0 ? 0 : 1;
+}
// Nota Keys alone (fast iteration): `--keys`. Also part of the full run.
if (args.Length >= 1 && args[0] == "--keys")
{
@@ -14220,6 +14228,9 @@ foreach (var (ok, label) in MpeTests.Run()) Check(ok, label);
Console.WriteLine("-- nota keys --");
foreach (var (ok, label) in KeysTests.Run()) Check(ok, label);
+Console.WriteLine("-- tap tempo --");
+foreach (var (ok, label) in TapTempoTests.Run()) Check(ok, label);
+
// --- command palette: descriptors, golden queries, context table, undo, speed ---
Console.WriteLine("-- command palette --");
foreach (var (ok, label) in PaletteTests.Run()) Check(ok, label);
diff --git a/tests/Nota.SmokeTest/TapTempoTests.cs b/tests/Nota.SmokeTest/TapTempoTests.cs
new file mode 100644
index 00000000..1d29fca8
--- /dev/null
+++ b/tests/Nota.SmokeTest/TapTempoTests.cs
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Tap tempo: steady taps land on the tempo, jitter averages out, a pause or a tempo change
+// starts a new series, a switch bounce is ignored, and the result stays in 20–300 BPM.
+// Also runnable alone: `dotnet run --project tests/Nota.SmokeTest -- --tap`.
+
+using Nota.Application;
+
+namespace Nota.SmokeTest;
+
+internal static class TapTempoTests
+{
+ private static double? Series(TapTempo t, double start, double gapMs, int taps)
+ {
+ double? bpm = null;
+ for (int i = 0; i < taps; i++) bpm = t.Tap(start + i * gapMs);
+ return bpm;
+ }
+
+ public static IEnumerable<(bool Ok, string Label)> Run()
+ {
+ var t = new TapTempo();
+ yield return (t.Tap(0) is null && t.Count == 1, "one tap gives no tempo yet");
+ yield return (t.Tap(500) == 120, "a second tap 500 ms later reads 120 BPM");
+
+ t = new TapTempo();
+ yield return (Series(t, 0, 60000.0 / 128, 8) == 128, "eight steady taps at 128 BPM read 128");
+
+ // ±15 ms of jitter around 500 ms: the mean over the series still lands on 120.
+ t = new TapTempo();
+ double[] jitter = { 0, 512, 988, 1510, 1995, 2508, 2991, 3500 };
+ double? j = null;
+ foreach (var ms in jitter) j = t.Tap(ms);
+ yield return (j == 120, $"jittered taps average to 120 BPM (got {j})");
+
+ // A pause longer than 3 s starts over: the next tap alone gives no tempo.
+ t = new TapTempo();
+ Series(t, 0, 500, 4);
+ yield return (t.Tap(1500 + 3500) is null && t.Count == 1, "a pause over 3 s starts a new series");
+
+ // Switching from 120 to 90 BPM mid-series: the old taps are dropped at once.
+ t = new TapTempo();
+ Series(t, 0, 500, 6); // last tap at 2500
+ double? changed = t.Tap(2500 + 60000.0 / 90);
+ yield return (changed == 90 && t.Count == 2, $"a tempo change restarts the series from the previous tap (got {changed})");
+
+ // A bounce 20 ms after a tap is ignored and doesn't count as a beat.
+ t = new TapTempo();
+ Series(t, 0, 500, 4);
+ double? bounced = t.Tap(1520);
+ yield return (bounced == 120 && t.Count == 4, "a 20 ms bounce is ignored");
+
+ // Only the last eight gaps count, so a long run doesn't anchor the tempo forever.
+ t = new TapTempo();
+ double now = 0;
+ for (int i = 0; i < 12; i++) { t.Tap(now); now += 600; }
+ yield return (t.Count == 9, "the series keeps the last nine taps (eight gaps)");
+
+ // Clamp: very fast taps (80 ms ≈ 750 BPM) read the 300 BPM ceiling.
+ t = new TapTempo();
+ yield return (Series(t, 0, 80, 5) == TapTempo.MaxBpm, "taps faster than 300 BPM clamp to 300");
+
+ t.Reset();
+ yield return (t.Count == 0 && t.Tap(10000) is null, "Reset clears the series");
+ }
+}