diff --git a/slab/menuband/Info.plist b/slab/menuband/Info.plist
index 53f0ec5790..de23b4b675 100644
--- a/slab/menuband/Info.plist
+++ b/slab/menuband/Info.plist
@@ -20,6 +20,13 @@
1.4.1
CFBundleVersion
141
+
+ ITSAppUsesNonExemptEncryption
+
+ LSApplicationCategoryType
+ public.app-category.music
LSMinimumSystemVersion
11.0
LSUIElement
diff --git a/slab/menuband/MenuBand-AppStore.entitlements b/slab/menuband/MenuBand-AppStore.entitlements
new file mode 100644
index 0000000000..d7ba0616c2
--- /dev/null
+++ b/slab/menuband/MenuBand-AppStore.entitlements
@@ -0,0 +1,31 @@
+
+
+
+
+
+ com.apple.security.app-sandbox
+
+
+
+ com.apple.security.device.audio-input
+
+
+
+ com.apple.security.network.client
+
+
+
+
+
diff --git a/slab/menuband/STORE-APP-STORE.md b/slab/menuband/STORE-APP-STORE.md
new file mode 100644
index 0000000000..355782e167
--- /dev/null
+++ b/slab/menuband/STORE-APP-STORE.md
@@ -0,0 +1,195 @@
+# Menu Band — Mac App Store submission plan
+
+Companion to `STORE.md` (which covers the direct-download DMG). This file is
+the App Store-specific plan: what must change in the code, the sandbox audit,
+the signing/archive steps, and the runtime checks only a signed build can
+answer. Prepared 2026-05-29 against v1.4.1 (build 141).
+
+The App Store build ships as a **reduced, sandboxed subset** of the
+direct-download version. The full version stays at prompt.ac/menuband.
+
+---
+
+## 0. Status of prep (done before handoff)
+
+- [x] `MenuBand-AppStore.entitlements` created — app-sandbox + audio-input + network.client.
+- [x] `Info.plist` — added `ITSAppUsesNonExemptEncryption=false` (skips the per-submission export question).
+- [x] Privacy policy already live at **https://aesthetic.computer/menuband/privacy.html** — use this as the App Store Connect Privacy Policy URL (resolves the STORE.md TODO). It accurately describes the full app; the sandboxed build collects strictly less.
+- [x] **`#if MAC_APP_STORE` source fork APPLIED + compile-verified** (see §2). Both
+ `swift build` (direct-download) and `swift build -Xswiftc -DMAC_APP_STORE`
+ (sandboxed subset) link clean. Files touched: `GlobalHotkey.swift`,
+ `MenuBandController.swift` (enableTypeMode), `AppDelegate.swift` (stickies
+ start), `MenuBandPopover.swift` (picker), `UpdateChecker.swift`,
+ `CrashLogReader.swift`. Decision locked: **Pointer + focused typing**
+ (Notepat/Ableton layouts work while Menu Band is frontmost via
+ `LocalKeyCapture`; no global typing).
+- [ ] Xcode app target + archive — see §3 (needs Jeffrey: Apple ID, certs).
+- [ ] Screenshots — see §4 (best captured from the signed sandboxed build).
+
+### Environment prerequisites discovered on this Mac (Jeffrey — do these first)
+
+1. **Activate full Xcode** — `xcode-select` currently points at the Command
+ Line Tools, so `xcodebuild`/archiving won't run. Xcode.app IS installed:
+ ```
+ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
+ ```
+2. **Mac App Store signing cert is missing.** The keychain has *Developer ID
+ Application* (`FB5948YR3S`, used for the notarized DMG) and an *Apple
+ Development* cert — but **no Apple Distribution / 3rd Party Mac cert**, which
+ App Store submission needs. Easiest: let Xcode "Automatically manage signing"
+ create the Apple Distribution cert + Mac App Store provisioning profile on
+ first archive (requires being signed into the Apple ID in Xcode ▸ Settings ▸
+ Accounts).
+3. **Team-ID check.** Developer ID is team `FB5948YR3S`; the Apple Development
+ cert is under `88649MN8MK`. Create the App Store Connect app record and sign
+ under **the team that owns the bundle id `computer.aestheticcomputer.menuband`**
+ (the FB5948YR3S team, per STORE.md). Pick that team in the Xcode signing pane.
+
+---
+
+## 1. The one hard fact
+
+Mac App Store mandates the **App Sandbox**. Several Menu Band features use APIs
+or file paths the sandbox forbids. The App Store build must compile-gate them
+out behind `#if MAC_APP_STORE` and ship without them.
+
+---
+
+## 2. Sandbox audit — what to gate, what survives
+
+### Must gate OUT (`#if !MAC_APP_STORE` around the code + its call sites)
+
+| Feature | File(s) | Why it's illegal under sandbox |
+| --- | --- | --- |
+| Global keystroke capture (Notepat/Ableton **global** typing) | `KeyEventTap.swift` + wiring in `MenuBandController.swift` (~L37, L1167, L1783) | `CGEventTap` is forbidden by the sandbox. |
+| System-wide hotkeys (⌃⌥⌘P etc., right-⌘ toggle) | `GlobalHotkey.swift` + 5 instances in `AppDelegate.swift` (L16–20, L874–934) | Carbon `RegisterEventHotKey` is forbidden. |
+| Stickies typing bridge | `StickiesBridge.swift` (L13 init, L161–180) | Apple Events to another app + its own event tap. App Review rejects this for an instrument. |
+| Cmd-cmd launcher daemon | `Sources/MenuBandLauncher/` (separate target) | Background daemon tapping global keys. Drop the target from the App Store build entirely. |
+| Auto-update checker + "New Menu Band Available" banner | `UpdateChecker.swift` + banner UI in `MenuBandPopover.swift`/`AboutWindow.swift` | App Review §2.4.5 / 3.2.2: apps must not steer users to update outside the App Store. The App Store handles updates. |
+| Crash-log reader + manual upload | `CrashLogReader.swift`, `CrashViewer.swift` | Reads `~/Library/Logs/DiagnosticReports/` — outside the sandbox container; not readable. |
+| GarageBand patch picker (the GM/GarageBand toggle) | `GarageBandLibrary.swift`, `GarageBandPatchView.swift` | Would scan `/Library/Application Support/GarageBand` + `~/Music/Audio Music Apps` (outside the container) — **but this is already dormant code** ("deprecated for now", `GarageBandPatchView` is never instantiated), so it never runs and needs no gate. The **built-in GM synth stays** (see below). Left as-is; revisit only if the picker is ever re-surfaced. |
+
+### Keeps working under sandbox (entitlements already in `MenuBand-AppStore.entitlements`)
+
+| Feature | Note |
+| --- | --- |
+| Pointer mode — click the menubar piano | Core. No special API. |
+| **Typing while Menu Band is focused** (`LocalKeyCapture.swift`) | Its own header calls it "MAS-safe": invisible key panel + local `NSEvent` monitor, no CGEventTap, no Accessibility. This lets the App Store build keep **Notepat + Ableton layouts** as long as Menu Band is the active app — a much better product than Pointer-only. **Recommended to keep** (see §2a). |
+| Trackpad pitch-bend gesture | Local indirect-touch via `LocalKeyCapture`'s sensor view. Sandbox-legal. |
+| Built-in General MIDI synth | Loads Apple's system soundbank `/System/Library/Components/CoreAudio.component/.../gs_instruments.dls` — the same file GarageBand uses; sandboxed apps may read it. **Must verify on a signed run (§5).** |
+| Virtual CoreMIDI source ("Menu Band") + MIDI out to DAWs | CoreMIDI virtual sources are sandbox-legal, no entitlement. |
+| Microphone sampler (hold `` ` ``) | `com.apple.security.device.audio-input` + the existing `NSMicrophoneUsageDescription`. |
+| MIDI-file drag-and-drop (`MidiDropTargetView`/`MidiFilePlayer`) | Dragging a file in is a user-intent gesture; the sandbox grants temporary read access to dropped files. No entitlement needed. |
+| KidLisp TV feed, KPBJ radio stream, web window | Outbound HTTPS only → `com.apple.security.network.client`. |
+
+### Needs a judgment call
+
+- **`AestheticWebWindow` (WKWebView loading aesthetic.computer).** Sandbox-legal
+ with network.client, but App Review scrutinizes apps that embed web content —
+ if the web window is prominent it can trigger a "this is just a web wrapper"
+ rejection. For a menubar instrument with an *optional* web panel it's likely
+ fine. Be ready to gate it out if review pushes back.
+
+### 2a. Product decision: keep local-focus typing, or strict Pointer-only?
+
+Because `LocalKeyCapture` already exists and is sandbox-safe, the App Store
+build does **not** have to be Pointer-only. Two options:
+
+- **Recommended — Pointer + local-focus typing.** Keep Notepat/Ableton layouts
+ active while Menu Band is the frontmost app. Loses only *global* typing
+ (playing while another app is focused). Far more useful; the code already
+ exists. Bigger fork (must reroute the mode wiring from `KeyEventTap` to
+ `LocalKeyCapture` for the App Store build).
+- **Simplest — strict Pointer-only.** Gate out all typing; mouse + synth + MIDI
+ out only. Smallest, safest, fastest-to-submit fork. Ship local typing as a
+ fast-follow update.
+
+---
+
+## 3. Build + sign + archive (Jeffrey — needs Apple ID + certs)
+
+The project is SwiftPM-only with **no `.xcodeproj`**. App Store submission
+requires the Xcode archive → Organizer flow with **Apple Distribution** signing
+and a **Mac App Store provisioning profile** (not the Developer ID cert used for
+notarized direct download).
+
+The Xcode app target is pre-specified in **`project.yml`** (XcodeGen) — it wraps
+the same `Sources/MenuBand/*.swift`, flattens `Resources/` + ships
+`WaveformShaders.metal` as a raw resource + `AppIcon.icns`, sets the
+`MAC_APP_STORE` + `XCODE_APP_TARGET` compilation conditions, points at
+`MenuBand-AppStore.entitlements` and the repo `Info.plist`, links IOKit, and
+selects automatic signing under team `FB5948YR3S`. The `MenuBandLauncher`
+target is intentionally omitted. (`Bundle.module` is supplied for this target by
+`MASBundleShim.swift`, guarded so it never collides with SwiftPM's accessor.)
+
+1. `brew install xcodegen` (one-time).
+2. `cd slab/menuband && xcodegen generate` → writes `MenuBand.xcodeproj`
+ (already git-ignored via `*.xcodeproj/`).
+3. `open MenuBand.xcodeproj`.
+4. **Xcode ▸ Settings ▸ Accounts** — sign in to the Apple ID that owns the
+ `FB5948YR3S` team. With automatic signing on, Xcode creates the **Apple
+ Distribution** cert + **Mac App Store** provisioning profile on first
+ archive (neither exists in the keychain yet — see §0 prereqs).
+5. **Product ▸ Archive**, then **Distribute App ▸ App Store Connect ▸ Upload**.
+
+> **Verify in Xcode** (things only a real build confirms): that the flattened
+> resources resolve (`sheet.html`, the fonts, the keymaps PDF), that
+> `WaveformShaders.metal` is in Copy Bundle Resources (not Compile Sources),
+> and that the build picks up `Info.plist` rather than a generated one. If the
+> visualizer renders black, the `.metal` got compiled instead of copied.
+>
+> Alternative without XcodeGen: **File ▸ New ▸ Project ▸ macOS App**, add the
+> sources/resources/entitlements manually, set the same two compilation
+> conditions. The `project.yml` is just the same recipe, reproducibly.
+
+---
+
+## 4. App Store Connect record
+
+- Create the app record (bundle id `computer.aestheticcomputer.menuband`, name
+ "Menu Band", category Music).
+- Metadata is ready in `STORE.md` (description, subtitle, keywords, support +
+ marketing URLs). **Privacy Policy URL → https://aesthetic.computer/menuband/privacy.html**.
+- **App Privacy nutrition label: "Data Not Collected."** (The app collects
+ nothing; the update-check + crash-upload are gated out of this build anyway.)
+- **What's New:** rewrite for the subset — see §6.
+- ≥1 screenshot required (§4 of STORE.md has the shot list; `bin/app-store-screenshots.mjs` exists).
+
+---
+
+## 5. Runtime checks only a signed sandboxed build can answer
+
+Run these on the archived/signed App Store build before submitting — they
+cannot be verified by `swift build` or an unsigned binary:
+
+1. **Does sound play?** Confirm the GM synth loads `gs_instruments.dls` inside
+ the sandbox (almost certainly yes — GarageBand does it — but verify). If it
+ fails, bundle a fallback `.sf2`/`.dls` in `Resources/` and load from the
+ bundle instead.
+2. **Virtual MIDI source appears** in a DAW's input list and receives notes.
+3. **Mic permission prompt** fires on first `` ` `` and recording works.
+4. **Local-focus typing** (if kept) plays notes while Menu Band is frontmost and
+ silently stops when another app is focused (no Accessibility prompt).
+5. **No sandbox violations** in Console.app (filter: `Sandbox` + process
+ `MenuBand`) during a full play session.
+6. **MIDI file drag-drop** still reads the dropped file.
+
+---
+
+## 6. What's New (App Store, subset)
+
+> Menu Band for the Mac App Store — the built-in macOS instruments in your menu
+> bar. Click the little piano to play, or type to play while Menu Band is
+> focused. Publishes a virtual MIDI source so any DAW can receive your notes,
+> with a built-in General MIDI synth when no DAW is running. (For system-wide
+> typing from any app, the full version is a free download at prompt.ac/menuband.)
+
+---
+
+## 7. Realistic timeline
+
+- **Submitting by Sunday night: realistic** if the fork (§2) goes cleanly and
+ the signed build passes §5.
+- **Live this weekend: no.** Apple review is 1–7 days.
+- Biggest risks: the Xcode-target/provisioning setup (§3, first time), and a
+ §5 surprise (synth or MIDI behaving differently sandboxed).
diff --git a/slab/menuband/STORE.md b/slab/menuband/STORE.md
index 756abc54d1..4a7ae5f669 100644
--- a/slab/menuband/STORE.md
+++ b/slab/menuband/STORE.md
@@ -51,7 +51,7 @@ First release. Three-state input picker (Pointer / Notepat / Ableton) with hover
- **Support URL:** `https://aesthetic.computer`
- **Marketing URL:** `https://notepat.com`
-- **Privacy Policy URL:** TODO — needed for App Store; for direct download, optional.
+- **Privacy Policy URL:** `https://aesthetic.computer/menuband/privacy.html` (live).
## Screenshot checklist
diff --git a/slab/menuband/Sources/MenuBand/AppDelegate.swift b/slab/menuband/Sources/MenuBand/AppDelegate.swift
index 26fccc9350..f8f2547d6e 100644
--- a/slab/menuband/Sources/MenuBand/AppDelegate.swift
+++ b/slab/menuband/Sources/MenuBand/AppDelegate.swift
@@ -552,9 +552,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
// forwards them through the same keymap the physical
// keyboard uses. Requires Accessibility permission; on
// first launch the system will prompt.
+ #if !MAC_APP_STORE
+ // The Stickies bridge taps global keystrokes and drives the
+ // Stickies app via Apple Events — both forbidden by the App
+ // Sandbox, so it's absent from the Mac App Store build. (Gating
+ // the access here also means the lazy `stickiesBridge` is never
+ // constructed in that build.)
if stickiesBridge.isEnabled {
stickiesBridge.start()
}
+ #endif
// Dev affordance: post the
// `computer.aestheticcomputer.menuband.showPopover`
@@ -737,16 +744,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
guard let self = self else { return }
self.trackpadTouchActive = active
guard !active else { return }
- // Last finger lifted off the trackpad. This is the
- // authoritative "stop driving the fx" signal: begin the
- // hold→linear-ramp now even if a note is still sounding.
- // If no notes are held either, also tear the gesture
- // down fully — onLitChanged already skipped that while
- // the finger was down so the fx could ride note changes.
+ // Last finger lifted off the trackpad. If no notes are
+ // held either, this IS the end of the gesture — close
+ // out the cursor lock and let the fx ramp naturally.
+ // If notes ARE still held, the user is mid-phrase and
+ // just resting their finger; leave bend/space/echo at
+ // whatever values they set so pitch + ambience don't
+ // drift on their own. The next finger touch (or note
+ // release) is the right time to change them.
if !self.menuBand.keyboardNotesHeld {
self.endPitchBendSession()
- } else if self.pitchBendCursorLocked {
- self.startFxRelease()
}
}
@@ -1750,12 +1757,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
// here — overriding them on every note-event redraw would
// erase the smoothing.
statusItem.length = KeyboardIconRenderer.imageSize.width
- // While the sample backend is active, the voice subscript
- // shows the literal `\`` glyph instead of a numeric program
- // slot — visually marks "this voice is your recording, not a
- // GM patch." Otherwise the existing 1-based digit logic
- // continues to render the GM program number.
- let voiceLabel: String? = (menuBand.instrumentBackend == .sample) ? "`" : nil
+ // Voice-subscript override: backends that don't map to a GM
+ // program get a glyph instead of a digit. Sample voice → "`"
+ // (the record key); KPBJ radio → "−1" (its conceptual slot —
+ // matches the "−1 KPBJ" title the popover uses). Everything
+ // else falls through to the 1-based GM program number.
+ let voiceLabel: String?
+ switch menuBand.instrumentBackend {
+ case .sample: voiceLabel = "`"
+ case .kpbj: voiceLabel = "−1"
+ default: voiceLabel = nil
+ }
button.image = KeyboardIconRenderer.image(
litNotes: menuBand.litNotes,
playbackLitNotes: menuBand.playbackLitNotes,
diff --git a/slab/menuband/Sources/MenuBand/CrashLogReader.swift b/slab/menuband/Sources/MenuBand/CrashLogReader.swift
index fec717e7ba..92aec11dd8 100644
--- a/slab/menuband/Sources/MenuBand/CrashLogReader.swift
+++ b/slab/menuband/Sources/MenuBand/CrashLogReader.swift
@@ -16,6 +16,13 @@ enum CrashLogReader {
/// builds (very common during heavy dev iteration) don't pollute
/// the count surfaced to the user.
static func recentLogs() -> [URL] {
+ #if MAC_APP_STORE
+ // Mac App Store build: crash logs live in
+ // ~/Library/Logs/DiagnosticReports — outside the sandbox
+ // container, so they're unreadable. Report none; the About
+ // window's crash count + manual upload UI stay hidden.
+ return []
+ #else
let dirURL = URL(fileURLWithPath: directoryPath)
guard let entries = try? FileManager.default.contentsOfDirectory(
at: dirURL,
@@ -42,6 +49,7 @@ enum CrashLogReader {
.contentModificationDate ?? .distantPast
return ad > bd
}
+ #endif
}
/// mtime of the running executable. install.sh `cp`s the new binary
diff --git a/slab/menuband/Sources/MenuBand/GlobalHotkey.swift b/slab/menuband/Sources/MenuBand/GlobalHotkey.swift
index 0c7395d01a..6fd77c9f2d 100644
--- a/slab/menuband/Sources/MenuBand/GlobalHotkey.swift
+++ b/slab/menuband/Sources/MenuBand/GlobalHotkey.swift
@@ -22,6 +22,15 @@ final class GlobalHotkey {
/// `modifiers` uses the Carbon mask (`cmdKey | optionKey | controlKey | shiftKey`).
@discardableResult
func register(keyCode: UInt32, modifiers: UInt32) -> Bool {
+ #if MAC_APP_STORE
+ // Mac App Store build: system-wide hotkeys via Carbon
+ // RegisterEventHotKey are forbidden by the App Sandbox. No-op so
+ // every global shortcut is simply absent — the popover controls
+ // and focused LocalKeyCapture cover the App Store feature set.
+ // Callers guard on this return value, so the hotkey ivars stay
+ // nil and `unregister()` remains safe.
+ return false
+ #else
unregister()
let hotKeyID = EventHotKeyID(signature: signature, id: id)
var ref: EventHotKeyRef?
@@ -65,6 +74,7 @@ final class GlobalHotkey {
return false
}
return true
+ #endif
}
func unregister() {
diff --git a/slab/menuband/Sources/MenuBand/KidLispTVView.swift b/slab/menuband/Sources/MenuBand/KidLispTVView.swift
index b9d77b5094..702738756f 100644
--- a/slab/menuband/Sources/MenuBand/KidLispTVView.swift
+++ b/slab/menuband/Sources/MenuBand/KidLispTVView.swift
@@ -30,6 +30,13 @@ final class KidLispTVView: NSView {
/// before the evaluator runs the next frame so pieces that read
/// `amp` see the freshest reading.
var ampProvider: (() -> Double)?
+ /// Returns true while the app is in a latency-critical state
+ /// (notes lit, pitch-bend gesture engaged, etc.). The TV skips
+ /// its render tick while busy — kidlisp.mjs treats frames as a
+ /// monotonic clock so a handful of dropped frames is invisible
+ /// to most pieces and the user gets the main-thread time back
+ /// for audio scheduling.
+ var busyProvider: (() -> Bool)?
// Persistent across frames — kidlisp.mjs's canonical model. Pieces that
// don't wipe accumulate, timing tokens remember their last fire time,
// the frame counter advances. We allocate the evaluator once and call
@@ -78,20 +85,39 @@ final class KidLispTVView: NSView {
needsDisplay = true
}
- static let targetFPS: Double = 60.0
+ /// Target frame rate when the main thread has slack. Adaptive
+ /// throttling (see `tick`) drops below this when the timer is
+ /// being scheduled late — which is the cheap signal that the
+ /// main run loop is overcommitted.
+ static let targetFPS: Double = 30.0
+ /// Floor for the adaptive throttler. Below this the TV would
+ /// read as a slideshow; keep it animated even at the cost of
+ /// a frame or two of audio attention.
+ private static let minFPS: Double = 8.0
+ /// When the measured frame interval exceeds the scheduled
+ /// interval by this ratio (smoothed), we're being scheduled
+ /// late → step the FPS down to give the main loop slack.
+ private static let lagThreshold: Double = 1.6
+ /// Headroom ratio under which we step the FPS back up toward
+ /// target. Slightly above 1.0 so a single fast frame doesn't
+ /// undo a multi-frame throttle decision.
+ private static let headroomThreshold: Double = 1.05
+
+ private var currentFPS: Double = targetFPS
+ private var lastTickAt: CFTimeInterval = 0
+ private var smoothedInterval: Double = 0
+ /// Sticky-decay flag for the on-canvas "BUSY" indicator. Pure
+ /// busy bool flickers at the tick rate; latch for a few frames
+ /// so the badge is readable.
+ private var busyHoldFrames: Int = 0
func start() {
guard !running else { return }
running = true
- timer?.invalidate()
- timer = Timer.scheduledTimer(withTimeInterval: 1.0 / Self.targetFPS,
- repeats: true) { [weak self] _ in
- self?.tick()
- }
- // Keep firing while popover scrolls/resizes.
- if let t = timer {
- RunLoop.current.add(t, forMode: .common)
- }
+ currentFPS = Self.targetFPS
+ smoothedInterval = 1.0 / currentFPS
+ lastTickAt = 0
+ scheduleTimer(fps: currentFPS)
}
func stop() {
@@ -100,6 +126,18 @@ final class KidLispTVView: NSView {
timer = nil
}
+ private func scheduleTimer(fps: Double) {
+ timer?.invalidate()
+ let t = Timer.scheduledTimer(withTimeInterval: 1.0 / fps,
+ repeats: true) { [weak self] _ in
+ self?.tick()
+ }
+ // Keep firing while popover scrolls/resizes.
+ RunLoop.current.add(t, forMode: .common)
+ timer = t
+ currentFPS = fps
+ }
+
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
if window != nil {
@@ -112,6 +150,46 @@ final class KidLispTVView: NSView {
}
private func tick() {
+ let now = CACurrentMediaTime()
+ // Adaptive throttle: EMA the scheduled-to-fired interval
+ // and compare to the configured tick interval. The Timer
+ // class fires LATE (never early) when the main run loop is
+ // saturated, so a consistently elevated ratio is the
+ // cheapest possible "main thread is overcommitted" signal.
+ if lastTickAt > 0 {
+ let actual = now - lastTickAt
+ smoothedInterval = smoothedInterval * 0.8 + actual * 0.2
+ let expected = 1.0 / currentFPS
+ let ratio = smoothedInterval / expected
+ if ratio > Self.lagThreshold, currentFPS > Self.minFPS {
+ let next = max(Self.minFPS, currentFPS - 6)
+ if next < currentFPS - 0.5 {
+ scheduleTimer(fps: next)
+ smoothedInterval = 1.0 / next
+ NSLog("MenuBand TV: throttle %.1f → %.1f fps (lag %.2fx)",
+ currentFPS, next, ratio)
+ }
+ } else if ratio < Self.headroomThreshold, currentFPS < Self.targetFPS {
+ let next = min(Self.targetFPS, currentFPS + 2)
+ if next > currentFPS + 0.5 {
+ scheduleTimer(fps: next)
+ smoothedInterval = 1.0 / next
+ }
+ }
+ }
+ lastTickAt = now
+
+ // Yield while the app is doing latency-critical work. The
+ // framebuffer is left as-is — the TV reads as briefly
+ // paused, which is far less distracting than the audio
+ // glitching because the KidLisp eval ate the main thread.
+ if busyProvider?() == true {
+ busyHoldFrames = 8
+ needsDisplay = true // repaint to flip BUSY badge on
+ return
+ }
+ if busyHoldFrames > 0 { busyHoldFrames -= 1 }
+
renderOneFrame()
needsDisplay = true
}
@@ -132,6 +210,53 @@ final class KidLispTVView: NSView {
NSColor.black.setFill()
bounds.fill()
}
+ drawPerformanceBadge()
+ }
+
+ /// Tiny bottom-right corner readout: current effective FPS, plus
+ /// a "BUSY" pill when the TV is skipping ticks for the audio
+ /// path. Latched for a few frames after the last skip so the
+ /// indicator is readable instead of flickering at the tick rate.
+ private func drawPerformanceBadge() {
+ let fpsAttrs: [NSAttributedString.Key: Any] = [
+ .font: NSFont.monospacedDigitSystemFont(ofSize: 9, weight: .semibold),
+ .foregroundColor: currentFPS >= Self.targetFPS - 0.5
+ ? NSColor.white.withAlphaComponent(0.55)
+ : NSColor(srgbRed: 1.0, green: 0.7, blue: 0.3, alpha: 0.85),
+ ]
+ let fps = NSAttributedString(
+ string: String(format: "%2.0f", currentFPS), attributes: fpsAttrs)
+ let pad: CGFloat = 4
+ let fpsSize = fps.size()
+ let fpsOrigin = NSPoint(x: bounds.maxX - fpsSize.width - pad,
+ y: bounds.maxY - fpsSize.height - pad)
+ // Subtle dark scrim so the digits stay legible against any
+ // KidLisp output (incl. all-white frames).
+ let scrim = NSRect(x: fpsOrigin.x - 2,
+ y: fpsOrigin.y - 1,
+ width: fpsSize.width + 4,
+ height: fpsSize.height + 1)
+ NSColor.black.withAlphaComponent(0.5).setFill()
+ NSBezierPath(roundedRect: scrim, xRadius: 2, yRadius: 2).fill()
+ fps.draw(at: fpsOrigin)
+
+ if busyHoldFrames > 0 {
+ let busyAttrs: [NSAttributedString.Key: Any] = [
+ .font: NSFont.systemFont(ofSize: 8, weight: .heavy),
+ .foregroundColor: NSColor(srgbRed: 1.0, green: 0.4, blue: 0.4, alpha: 0.9),
+ ]
+ let busy = NSAttributedString(string: "BUSY", attributes: busyAttrs)
+ let bSize = busy.size()
+ let bOrigin = NSPoint(x: bounds.maxX - bSize.width - pad,
+ y: fpsOrigin.y - bSize.height - 1)
+ let bScrim = NSRect(x: bOrigin.x - 2,
+ y: bOrigin.y - 1,
+ width: bSize.width + 4,
+ height: bSize.height + 1)
+ NSColor.black.withAlphaComponent(0.6).setFill()
+ NSBezierPath(roundedRect: bScrim, xRadius: 2, yRadius: 2).fill()
+ busy.draw(at: bOrigin)
+ }
}
private func makeCGImage(from fb: KLFramebuffer) -> CGImage? {
diff --git a/slab/menuband/Sources/MenuBand/MASBundleShim.swift b/slab/menuband/Sources/MenuBand/MASBundleShim.swift
new file mode 100644
index 0000000000..dcd44816f0
--- /dev/null
+++ b/slab/menuband/Sources/MenuBand/MASBundleShim.swift
@@ -0,0 +1,22 @@
+import Foundation
+
+// SwiftPM synthesizes `Bundle.module` (via a generated
+// resource_bundle_accessor.swift) for the package build. The hand-built
+// Xcode "Menu Band MAS" target — the one used for Mac App Store archiving —
+// does NOT get that accessor, and its resources live directly in the app's
+// main bundle instead of a nested `MenuBand_MenuBand.bundle`. This shim
+// supplies `Bundle.module` for that target so the six existing
+// `Bundle.module.url(...)` lookups (fonts, sheet.html, the keymaps PDF, the
+// WaveformShaders.metal source) keep working unchanged.
+//
+// Guarded on XCODE_APP_TARGET — a flag set ONLY by project.yml's Xcode
+// target — NOT on MAC_APP_STORE. That distinction matters: the
+// compile-verification `swift build -Xswiftc -DMAC_APP_STORE` still runs
+// under SwiftPM, where the generated `Bundle.module` accessor is present;
+// defining this shim there too would be a duplicate-declaration error. Only
+// the Xcode target (which lacks the SwiftPM accessor) gets the shim.
+#if XCODE_APP_TARGET
+extension Bundle {
+ static var module: Bundle { Bundle.main }
+}
+#endif
diff --git a/slab/menuband/Sources/MenuBand/MenuBandController.swift b/slab/menuband/Sources/MenuBand/MenuBandController.swift
index c438c39c6f..9e48f23759 100644
--- a/slab/menuband/Sources/MenuBand/MenuBandController.swift
+++ b/slab/menuband/Sources/MenuBand/MenuBandController.swift
@@ -1159,6 +1159,16 @@ final class MenuBandController {
// MARK: - TYPE mode (global keyboard capture + letter overlays)
private func enableTypeMode(promptForPermission: Bool, playFeedback: Bool = false) {
+ #if MAC_APP_STORE
+ // Mac App Store build: global keystroke capture (CGEventTap) is
+ // forbidden by the App Sandbox, so there is no global TYPE mode.
+ // Typing-to-play is served instead by LocalKeyCapture while Menu
+ // Band is the focused app (armed on piano-click / popover-open);
+ // the selected keymap is still honored via handleLocalKey. Keep
+ // typeMode persisted false so the UI never claims global capture.
+ UserDefaults.standard.set(false, forKey: typeModeKey)
+ return
+ #else
if !ensureAccessibility(prompt: promptForPermission) {
UserDefaults.standard.set(false, forKey: typeModeKey)
onChange?()
@@ -1180,6 +1190,7 @@ final class MenuBandController {
NSSound(named: NSSound.Name("Submarine"))?.play()
}
onChange?()
+ #endif
}
private func disableTypeMode(playFeedback: Bool = false) {
@@ -1747,6 +1758,12 @@ final class MenuBandController {
/// `voiceDigitFlushInterval` means the user is picking a new voice,
/// not continuing a multi-digit number.
private var voiceDigitLastPress: CFTimeInterval = 0
+ /// True after the `-` key was pressed and the next digit will be
+ /// read as part of a negative voice slot (currently only `-1`
+ /// = KPBJ radio). Same `voiceDigitFlushInterval` timeout as the
+ /// digit buffer so a stray `-` doesn't hijack the next typed
+ /// voice number.
+ private var voiceDigitNegative: Bool = false
/// Burst window for multi-digit voice entry. Tuned so "128" typed
/// at a normal pace stays one number, while a re-pick after a beat
/// starts clean.
@@ -1867,16 +1884,19 @@ final class MenuBandController {
break
}
- // Minus key (`-`, keyCode 27) toggles the live KPBJ radio backend
- // — conceptually "voice −1": the piano plays the live stream
- // pitched by 2^((note−60)/12), with stalls fading into AM-style
- // static. Consumed in both directions so it never leaks to the
- // focused app, but only the down-event flips the mode.
+ // Minus key (`-`, keyCode 27) primes a negative voice slot —
+ // the trigger sequence is `-1`, NOT a bare `-`. Typing `-1`
+ // toggles the live KPBJ radio backend ("voice −1": the piano
+ // plays the live stream pitched by 2^((note−60)/12), with
+ // stalls fading into AM-style static). Standalone `-` is a
+ // no-op so the negative-prefix UX matches how positive voices
+ // are typed (number row commits the pick). Consumed in both
+ // directions so the key never leaks to the focused app.
if keyCode == 27 {
if isDown && !isRepeat {
- DispatchQueue.main.async { [weak self] in
- self?.toggleRadioBackend()
- }
+ voiceDigitBuffer = ""
+ voiceDigitNegative = true
+ voiceDigitLastPress = CACurrentMediaTime()
}
return true
}
@@ -1926,6 +1946,26 @@ final class MenuBandController {
let now = CACurrentMediaTime()
let staleGap = now - voiceDigitLastPress
> Self.voiceDigitFlushInterval
+ // Negative-voice slot, primed by a preceding `-`.
+ // `-1` is the only negative voice today (KPBJ radio);
+ // it toggles, so a second `-1` switches back to the
+ // last GM voice. Other digits after `-` are no-ops —
+ // we consume them so they don't quietly pick a GM
+ // voice the user wasn't aiming for.
+ if voiceDigitNegative && !staleGap {
+ voiceDigitNegative = false
+ voiceDigitLastPress = now
+ if digit == 1 {
+ DispatchQueue.main.async { [weak self] in
+ self?.toggleRadioBackend()
+ }
+ }
+ return true
+ }
+ // A stale `-` doesn't get to hijack the next typed
+ // voice number — clear the prefix and fall through to
+ // normal positive-digit handling.
+ voiceDigitNegative = false
if voiceDigitBuffer.count >= 3 || staleGap {
voiceDigitBuffer = ""
}
diff --git a/slab/menuband/Sources/MenuBand/MenuBandPopover.swift b/slab/menuband/Sources/MenuBand/MenuBandPopover.swift
index ab57c7b89d..f8b479a537 100644
--- a/slab/menuband/Sources/MenuBand/MenuBandPopover.swift
+++ b/slab/menuband/Sources/MenuBand/MenuBandPopover.swift
@@ -2231,10 +2231,14 @@ final class MenuBandPopoverViewController: NSViewController {
switch sender.tag {
case 0: // Notepat.com
m.keymap = .notepat
+ #if !MAC_APP_STORE
if !m.typeMode { m.toggleTypeMode() }
+ #endif
case 1: // Ableton MIDI Keys
m.keymap = .ableton
+ #if !MAC_APP_STORE
if !m.typeMode { m.toggleTypeMode() }
+ #endif
default: break
}
}
diff --git a/slab/menuband/Sources/MenuBand/SheetMusicView.swift b/slab/menuband/Sources/MenuBand/SheetMusicView.swift
index eed3d0b824..dedca33f40 100644
--- a/slab/menuband/Sources/MenuBand/SheetMusicView.swift
+++ b/slab/menuband/Sources/MenuBand/SheetMusicView.swift
@@ -45,6 +45,15 @@ final class SheetMusicView: NSView, WKNavigationDelegate, WKScriptMessageHandler
private var pdfRefreshTimer: Timer?
private static let pdfRefreshDebounce: TimeInterval = 0.25
+ /// Click-to-arm: the sheet starts disarmed so opening the popover
+ /// doesn't immediately start spraying held notes onto the staff
+ /// (which then have to be cleared by dragging the page to the
+ /// trash). A click anywhere on the page surface toggles this; the
+ /// page dims visibly while disarmed so the user can tell at a
+ /// glance whether their playing is being inscribed.
+ private(set) var inscriptionEnabled: Bool = false
+ private static let disarmedAlpha: CGFloat = 0.35
+
// MARK: - "Menu Band PDF" embedded-score format
//
// A Menu Band PDF is a regular PDF whose standard Info
@@ -208,6 +217,39 @@ final class SheetMusicView: NSView, WKNavigationDelegate, WKScriptMessageHandler
overlay.autoresizingMask = [.width, .height]
addSubview(overlay)
self.overlay = overlay
+ // Apply the initial disarmed dim so the page reads as
+ // "tap to start inscribing" the moment the popover opens.
+ applyInscriptionAppearance(animated: false)
+ }
+
+ /// Reflect `inscriptionEnabled` onto the visible page chrome.
+ /// Webview + overlay get dimmed individually (not via self.alphaValue
+ /// or layer.opacity) so the crumple-out drag animation still owns
+ /// the parent layer's opacity track without fighting this state.
+ private func applyInscriptionAppearance(animated: Bool) {
+ let target: CGFloat = inscriptionEnabled ? 1.0 : Self.disarmedAlpha
+ let apply: () -> Void = { [weak self] in
+ guard let self = self else { return }
+ self.webView?.alphaValue = target
+ self.overlay?.alphaValue = target
+ }
+ if animated {
+ NSAnimationContext.runAnimationGroup { ctx in
+ ctx.duration = 0.18
+ ctx.allowsImplicitAnimation = true
+ apply()
+ }
+ } else {
+ apply()
+ }
+ }
+
+ /// Flip arm state. Public so the popover can mirror the state in
+ /// (e.g.) a focus-ring or status label if it ever wants to; for now
+ /// the only caller is the click handler below.
+ func toggleInscription() {
+ inscriptionEnabled.toggle()
+ applyInscriptionAppearance(animated: true)
}
// MARK: - Hit testing
@@ -238,7 +280,15 @@ final class SheetMusicView: NSView, WKNavigationDelegate, WKScriptMessageHandler
}
override func mouseUp(with event: NSEvent) {
+ // A `dragMouseDownAt` that survived mouseUp means the press
+ // never crossed the 4pt threshold in `mouseDragged` — it was
+ // a click, not a drag-out. Use it as the toggle for the
+ // inscription armed state.
+ let wasClick = dragMouseDownAt != nil
dragMouseDownAt = nil
+ if wasClick {
+ toggleInscription()
+ }
}
// MARK: - Drag SOURCE — page → PDF on desktop
@@ -1084,6 +1134,10 @@ final class SheetMusicView: NSView, WKNavigationDelegate, WKScriptMessageHandler
// so Verovio's renderToMIDI replays at the same tempo the user
// performed at, with rests preserving inter-note silences.
func recordNote(pitch: UInt8) {
+ // Disarmed sheets eat onsets silently so the user can warm
+ // up / noodle without the page filling. Click the page to
+ // arm; see `toggleInscription`.
+ guard inscriptionEnabled else { return }
// Capture wall-clock at the moment Swift sees the input,
// not when the JS bridge delivers our message. The bridge
// latency is variable (5–50ms) — without an explicit time
@@ -1095,6 +1149,7 @@ final class SheetMusicView: NSView, WKNavigationDelegate, WKScriptMessageHandler
}
func releaseNote(pitch: UInt8) {
+ guard inscriptionEnabled else { return }
let t = CACurrentMediaTime()
send("Sheet.noteOff(\(pitch), \(t))")
}
@@ -1110,6 +1165,14 @@ final class SheetMusicView: NSView, WKNavigationDelegate, WKScriptMessageHandler
func clearScore() {
send("Sheet.clear()")
overlay.reset()
+ // A cleared page is a fresh page — disarm so the next batch
+ // of notes is intentional. Matches the just-opened popover
+ // state so the UI affordance ("dimmed = tap to inscribe") is
+ // consistent.
+ if inscriptionEnabled {
+ inscriptionEnabled = false
+ applyInscriptionAppearance(animated: true)
+ }
}
func printScore() {
diff --git a/slab/menuband/Sources/MenuBand/UpdateChecker.swift b/slab/menuband/Sources/MenuBand/UpdateChecker.swift
index 67462a740e..a1efa3119c 100644
--- a/slab/menuband/Sources/MenuBand/UpdateChecker.swift
+++ b/slab/menuband/Sources/MenuBand/UpdateChecker.swift
@@ -34,6 +34,14 @@ enum UpdateChecker {
/// nil on network/parse failure (silent fallback — we don't want to
/// pester the user when their wi-fi is down).
static func fetchLatest(completion: @escaping (VersionInfo?) -> Void) {
+ #if MAC_APP_STORE
+ // Mac App Store build: the App Store handles updates. App Review
+ // forbids steering users to a self-hosted update outside the
+ // store, so we never check and never surface the "New version"
+ // banner. Report "no update" so all callers stay quiet.
+ completion(nil)
+ return
+ #else
if let info = cached, let ts = lastCheck, Date().timeIntervalSince(ts) < 3600 {
completion(info)
return
@@ -52,6 +60,7 @@ enum UpdateChecker {
}
DispatchQueue.main.async { completion(parsed) }
}.resume()
+ #endif
}
/// `true` iff `latest > current` under naive dotted-integer ordering.
diff --git a/slab/menuband/project.yml b/slab/menuband/project.yml
new file mode 100644
index 0000000000..b472b623fd
--- /dev/null
+++ b/slab/menuband/project.yml
@@ -0,0 +1,93 @@
+# XcodeGen spec for the Mac App Store build of Menu Band.
+#
+# This generates the Xcode app target needed for App Store archiving WITHOUT
+# committing a hand-authored .xcodeproj. SwiftPM (Package.swift) remains the
+# source of truth for the direct-download build; this is a parallel wrapper
+# that compiles the SAME Sources/MenuBand/*.swift into a signable .app with
+# the App Sandbox.
+#
+# Usage:
+# brew install xcodegen # one-time
+# cd slab/menuband
+# xcodegen generate # writes MenuBand.xcodeproj (git-ignore it)
+# open MenuBand.xcodeproj
+# # then: sign in to your Apple ID, pick the FB5948YR3S team with automatic
+# # signing, Product > Archive, Distribute App > App Store Connect.
+#
+# See STORE-APP-STORE.md for the full submission checklist + runtime tests.
+
+name: MenuBand
+
+options:
+ bundleIdPrefix: computer.aestheticcomputer
+ deploymentTarget:
+ macOS: "11.0"
+ createIntermediateGroups: true
+
+settings:
+ base:
+ SWIFT_VERSION: "5.9"
+ # The fork flag (gates global keystroke capture / hotkeys / stickies /
+ # update-checker / crash-upload) AND the bundle-shim flag (supplies
+ # Bundle.module for this non-SwiftPM target). See MASBundleShim.swift.
+ SWIFT_ACTIVE_COMPILATION_CONDITIONS: MAC_APP_STORE XCODE_APP_TARGET
+
+targets:
+ MenuBand:
+ type: application
+ platform: macOS
+ deploymentTarget: "11.0"
+
+ sources:
+ # All Swift under Sources/MenuBand (incl. KidLisp/ + PianoWaveformWindow/
+ # subdirs). Resources + the .metal are handled separately below so they
+ # land FLATTENED in the app's Resources root — matching SwiftPM's
+ # `.process("Resources")` behavior, which is what the existing
+ # `Bundle.module.url(forResource:withExtension:)` (no subdirectory:)
+ # lookups rely on.
+ - path: Sources/MenuBand
+ excludes:
+ - "KidLisp/README.md"
+ - "Resources/**"
+ - "WaveformShaders.metal"
+
+ # Resource files → Copy Bundle Resources (flattened). verovio/sheet.html
+ # + verovio-toolkit-wasm.js flatten into the same Resources root, so the
+ # relative