diff --git a/CLAUDE.md b/CLAUDE.md
index a51687c..6dab54e 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1522,7 +1522,7 @@ Two independent apps that talk over HTTP:
position jogs that wrap; `detectEncoding` guesses from what a control sent
while learning: relative REPEATS and jitters inside its zones, absolute
progresses), `actions.ts` (the vocabulary: deck buttons = the deck keys'
- actions, plus pitch, jog, jog touch, fast scrub, load, SYNC, keylock,
+ actions, plus pitch, jog, jog touch, fast scrub, load, SYNC, MASTER, keylock,
loops; mixer; browse / tree; performance mode; `shiftDefault` = the
keyboard's Shift meaning), `mapping.ts` (per controller, keyed by SOURCE;
each control a normal + a FREE Shift binding; learning REPLACES an
@@ -1535,7 +1535,9 @@ Two independent apps that talk over HTTP:
encoder wins only where it has an action for the layer. A CC learned for
a button waits 400 ms: one message, or any 0, = a button; several
non-zero = a turn (so a two's-complement encoder's 127s are not a press).
- **`router.ts`**: Shift is a learned control (an unbound Shift
+ **`router.ts`**: Shift is a learned control — up to TWO per controller
+ (`Mapping.shifts`, many have one per deck; either held = the Shift layer;
+ the old single `shift` field still loads) (an unbound Shift
binding falls back to normal); deck B and the mixer act only in
performance mode; positions JUMP (no soft takeover — "the controller
always wins"); a held control releases where it was pressed; Learn sees
diff --git a/frontend/src/components/MidiSettings.tsx b/frontend/src/components/MidiSettings.tsx
index 4fd980b..01e49f8 100644
--- a/frontend/src/components/MidiSettings.tsx
+++ b/frontend/src/components/MidiSettings.tsx
@@ -5,6 +5,7 @@ import { ENCODING_LABELS, ENCODINGS } from '../lib/midi/encoding'
import {
DEFAULT_JOG_SENSITIVITY,
DEFAULT_SCRUB_SPEED,
+ bindShift,
emptyMapping,
sanitizeMapping,
setBinding,
@@ -24,8 +25,8 @@ import { Modal } from './Modal'
const section = 'text-[11px] font-semibold uppercase tracking-wider text-faint'
const MAPPING_SUFFIX = '.konduktor-midi.json'
-const sameTarget = (a: LearnTarget | null, b: LearnTarget) =>
- a != null && a.action === b.action && ('layer' in a ? a.layer : null) === ('layer' in b ? b.layer : null)
+const which = (t: LearnTarget) => ('layer' in t ? t.layer : t.slot)
+const sameTarget = (a: LearnTarget | null, b: LearnTarget) => a != null && a.action === b.action && which(a) === which(b)
/**
* Settings ▸ MIDI Controllers… (decided 2026-11-03): every controller is
@@ -169,7 +170,7 @@ export function MidiSettings({ onClose }: { onClose: () => void }) {
try {
const m = sanitizeMapping((await api.midiImport(path)).mapping)
if (!m) throw new Error('That file is not a MIDI mapping')
- if (Object.keys(mapping.bindings).length > 0 || mapping.shift) {
+ if (Object.keys(mapping.bindings).length > 0 || mapping.shifts.some(Boolean)) {
const ok = await askConfirm({
title: `Replace ${port}'s mapping?`,
body: 'The imported mapping replaces every control learned on this controller.',
@@ -253,29 +254,41 @@ export function MidiSettings({ onClose }: { onClose: () => void }) {
{note &&
{note.text}
}
-
Shift button
-
- {sameTarget(armed, { action: 'shift' }) ? (
- armLearn(null)} className="animate-pulse rounded-md bg-accent/25 px-2 py-1 text-[11px] text-text ring-1 ring-accent">
- Press the controller's Shift…
-
- ) : mapping.shift ? (
- <>
- {describeSource(mapping.shift)}
- learn({ action: 'shift' })} className="text-[11px] text-faint hover:text-text">
- Learn again
-
- edit((m) => ({ ...m, shift: null }))} className="text-[11px] text-faint hover:text-pink">
- Clear
-
- >
- ) : (
- learn({ action: 'shift' })} className="rounded-md px-2 py-1 text-[11px] text-faint hover:bg-ink-800 hover:text-text">
- Learn
-
- )}
- Hold it while moving a control to learn its Shift action.
-
+ {([0, 1] as const).map((slot) => {
+ const src = mapping.shifts[slot]
+ const t: LearnTarget = { action: 'shift', slot }
+ return (
+
+
{slot === 0 ? 'Shift button' : 'Second Shift'}
+
+ {sameTarget(armed, t) ? (
+ armLearn(null)} className="animate-pulse rounded-md bg-accent/25 px-2 py-1 text-[11px] text-text ring-1 ring-accent">
+ Press the controller's Shift…
+
+ ) : src ? (
+ <>
+ {describeSource(src)}
+ learn(t)} className="text-[11px] text-faint hover:text-text">
+ Learn again
+
+ edit((m) => bindShift(m, null, slot))} className="text-[11px] text-faint hover:text-pink">
+ Clear
+
+ >
+ ) : (
+ learn(t)} className="rounded-md px-2 py-1 text-[11px] text-faint hover:bg-ink-800 hover:text-text">
+ Learn
+
+ )}
+
+ {slot === 0
+ ? 'Hold it while moving a control to learn its Shift action.'
+ : 'Optional — many controllers have one per deck. Either one gives the Shift layer.'}
+
+
+
+ )
+ })}
Jog sensitivity
{
+ if (performance && d.track) makeMaster(id)
+ },
toggleKeylock: () => d.setKeylock(!d.keylock),
pitch: d.pitch,
setPitch: (v) => {
diff --git a/frontend/src/components/deck/DeckTempo.tsx b/frontend/src/components/deck/DeckTempo.tsx
index fe4de34..5acd960 100644
--- a/frontend/src/components/deck/DeckTempo.tsx
+++ b/frontend/src/components/deck/DeckTempo.tsx
@@ -62,6 +62,7 @@ export function DeckTempo({ deck, master, synced, syncBlocked, onSync, onMaster,
SYNC
{
it('the Shift control does nothing else', () => {
let m = bind(emptyMapping(), 'note:1:63', 'button', 'normal', 'deck.A.play')
m = bindShift(m, 'note:1:63')
- expect(m.shift).toBe('note:1:63')
+ expect(m.shifts).toEqual(['note:1:63', null])
expect(m.bindings['note:1:63']).toBeUndefined()
m = bind(m, 'note:1:63', 'button', 'normal', 'deck.A.cue')
- expect(m.shift).toBeNull()
+ expect(m.shifts).toEqual([null, null])
+ })
+ it('two Shift controls, each in its own slot', () => {
+ let m = bindShift(emptyMapping(), 'note:1:63')
+ m = bindShift(m, 'note:2:63', 1)
+ expect(m.shifts).toEqual(['note:1:63', 'note:2:63'])
+ // Learning one into the other slot moves it, never doubles it.
+ m = bindShift(m, 'note:1:63', 1)
+ expect(m.shifts).toEqual([null, 'note:1:63'])
+ m = bindShift(m, null, 1)
+ expect(m.shifts).toEqual([null, null])
+ })
+ it("reads the single-Shift form mappings had before", () => {
+ expect(sanitizeMapping({ version: 1, shift: 'note:1:63', bindings: {} })?.shifts).toEqual(['note:1:63', null])
+ expect(sanitizeMapping({ version: 1, shifts: ['note:1:63', 'note:1:63'] })?.shifts).toEqual(['note:1:63', null])
})
it('the LSB half of a 14-bit pair reaches its MSB', () => {
const m = bind(emptyMapping(), 'cc:1:0', 'abs14', 'normal', 'deck.A.pitch')
@@ -73,7 +87,7 @@ describe('mapping', () => {
'nonsense': { encoding: 'button', normal: 'deck.A.play' },
},
})
- expect(m?.shift).toBe('note:1:63')
+ expect(m?.shifts).toEqual(['note:1:63', null])
expect(m?.jogSensitivity).toBe(10)
expect(Object.keys(m!.bindings)).toEqual(['note:1:0'])
expect(sanitizeMapping({ version: 2 })).toBeNull()
diff --git a/frontend/src/lib/midi/mapping.ts b/frontend/src/lib/midi/mapping.ts
index 348da30..53bc6da 100644
--- a/frontend/src/lib/midi/mapping.ts
+++ b/frontend/src/lib/midi/mapping.ts
@@ -19,8 +19,10 @@ export interface Binding {
export interface Mapping {
version: 1
- /** The control acting as Shift (itself a learned control). */
- shift: SourceKey | null
+ /** The controls acting as Shift (learned controls), up to two — many
+ * controllers have one per deck. Either held = the Shift layer. Slot order
+ * is only the editor's; a mapping from before two were allowed had `shift`. */
+ shifts: [SourceKey | null, SourceKey | null]
bindings: Record
/** Jog: scratch / nudge / scrub sensitivity (1 = the default feel). */
jogSensitivity: number
@@ -34,7 +36,7 @@ export const DEFAULT_JOG_SENSITIVITY = 1
export const DEFAULT_SCRUB_SPEED = 8
export function emptyMapping(): Mapping {
- return { version: 1, shift: null, bindings: {}, jogSensitivity: DEFAULT_JOG_SENSITIVITY, scrubSpeed: DEFAULT_SCRUB_SPEED }
+ return { version: 1, shifts: [null, null], bindings: {}, jogSensitivity: DEFAULT_JOG_SENSITIVITY, scrubSpeed: DEFAULT_SCRUB_SPEED }
}
const num = (v: unknown, lo: number, hi: number, fallback: number) =>
@@ -46,7 +48,10 @@ export function sanitizeMapping(raw: unknown): Mapping | null {
const r = raw as Record
if (r.version !== 1) return null
const out = emptyMapping()
- if (typeof r.shift === 'string' && parseSource(r.shift)) out.shift = r.shift
+ const shift = (v: unknown) => (typeof v === 'string' && parseSource(v) ? v : null)
+ if (Array.isArray(r.shifts)) out.shifts = [shift(r.shifts[0]), shift(r.shifts[1])]
+ else out.shifts = [shift(r.shift), null] // the single-Shift form
+ if (out.shifts[0] && out.shifts[0] === out.shifts[1]) out.shifts[1] = null
out.jogSensitivity = num(r.jogSensitivity, 0.05, 10, DEFAULT_JOG_SENSITIVITY)
out.scrubSpeed = num(r.scrubSpeed, 1, 64, DEFAULT_SCRUB_SPEED)
const bindings = r.bindings && typeof r.bindings === 'object' ? (r.bindings as Record) : {}
@@ -116,14 +121,25 @@ export function bind(m: Mapping, source: SourceKey, encoding: Encoding, layer: L
const { base, dir } = splitSource(source)
const other = dir && bindings[turnSource(base, dir === '+' ? '-' : '+')]
if (dir && other) bindings[turnSource(base, dir === '+' ? '-' : '+')] = { ...other, encoding }
- return { ...cleared, shift: cleared.shift === source ? null : cleared.shift, bindings }
+ return { ...cleared, shifts: withoutShift(cleared.shifts, source), bindings }
}
-/** Make `source` the Shift control (it then does nothing else). */
-export function bindShift(m: Mapping, source: SourceKey): Mapping {
+const withoutShift = (s: Mapping['shifts'], source: SourceKey): Mapping['shifts'] => [
+ s[0] === source ? null : s[0],
+ s[1] === source ? null : s[1],
+]
+
+/** Whether `source` is one of the mapping's Shift controls. */
+export const isShift = (m: Mapping, source: SourceKey) => m.shifts[0] === source || m.shifts[1] === source
+
+/** Make `source` Shift control `slot` (it then does nothing else; it leaves
+ * the other slot if it was there). `null` clears the slot. */
+export function bindShift(m: Mapping, source: SourceKey | null, slot: 0 | 1 = 0): Mapping {
const bindings = { ...m.bindings }
- delete bindings[source]
- return { ...m, shift: source, bindings }
+ const shifts = source ? withoutShift(m.shifts, source) : ([...m.shifts] as Mapping['shifts'])
+ shifts[slot] = source
+ if (source) delete bindings[source]
+ return { ...m, shifts, bindings }
}
export function setBinding(m: Mapping, source: SourceKey, patch: Partial): Mapping {
diff --git a/frontend/src/lib/midi/router.test.ts b/frontend/src/lib/midi/router.test.ts
index 03ec9a8..7e6cf64 100644
--- a/frontend/src/lib/midi/router.test.ts
+++ b/frontend/src/lib/midi/router.test.ts
@@ -29,6 +29,7 @@ function fakeDeck(): DeckMidi & { calls: string[] } {
loopOut: log('loopOut'),
toggleLoop: log('toggleLoop'),
toggleSync: log('sync'),
+ makeMaster: log('master'),
toggleKeylock: log('keylock'),
setPitch: log('pitch'),
jogTouch: log('jogTouch'),
@@ -72,6 +73,14 @@ beforeEach(() => {
})
describe('router', () => {
+ it('MASTER is a mappable button on each deck', () => {
+ map((m) => bind(m, 'note:2:20', 'button', 'normal', 'deck.B.master'))
+ router.receive(PORT, [0x91, 20, 127])
+ expect(B.calls).toEqual([]) // deck B: performance mode only
+ targets.performance = true
+ router.receive(PORT, [0x91, 20, 127])
+ expect(B.calls).toEqual(['master'])
+ })
it('runs a button on press only', () => {
note(11, 127)
note(11, 0)
@@ -91,6 +100,17 @@ describe('router', () => {
note(0, 0)
expect(A.calls).toEqual(['slotPress 0', 'slotRelease 0'])
})
+ it('with two Shift buttons, either one held gives the Shift layer', () => {
+ map((m) => bindShift(bindShift(bind(m, 'note:1:0', 'button', 'normal', 'deck.A.hotcue.1'), 'note:1:63', 0), 'note:2:63', 1))
+ router.receive(PORT, [0x91, 63, 127]) // the second Shift (deck B's side)
+ note(0, 127)
+ note(63, 127) // both held…
+ router.receive(PORT, [0x91, 63, 0]) // …one let go: still shifted
+ note(0, 127)
+ note(63, 0)
+ note(0, 127)
+ expect(A.calls).toEqual(['deleteSlot 0', 'deleteSlot 0', 'slotPress 0'])
+ })
it('an unbound Shift layer falls back to the normal action', () => {
note(63, 127)
note(11, 127)
@@ -244,8 +264,8 @@ describe('learning', () => {
}
})
it('the Shift control itself', () => {
- armLearn({ action: 'shift' })
+ armLearn({ action: 'shift', slot: 1 })
note(70, 127)
- expect(getMidiState().mappings[PORT].shift).toBe('note:1:70')
+ expect(getMidiState().mappings[PORT].shifts).toEqual(['note:1:63', 'note:1:70'])
})
})
diff --git a/frontend/src/lib/midi/router.ts b/frontend/src/lib/midi/router.ts
index 4bcdf45..291bc5b 100644
--- a/frontend/src/lib/midi/router.ts
+++ b/frontend/src/lib/midi/router.ts
@@ -14,7 +14,7 @@
import { actionDef, actionDeck, performanceOnly, type ActionKind, type DeckId } from './actions'
import { Decoder, detectEncoding, type Decoded, type Encoding, type LearnKind } from './encoding'
-import { bind, bindShift, resolveBinding, type Binding, type Layer, type Mapping } from './mapping'
+import { bind, bindShift, isShift, resolveBinding, type Binding, type Layer, type Mapping } from './mapping'
import { parseMessage, sourceKey, splitSource, turnSource, type MidiMessage, type SourceKey } from './messages'
import { armLearn, getMidiState, patchMidi, updateMapping, type LearnTarget } from './store'
import type { Track } from '../../api'
@@ -29,6 +29,8 @@ export interface DeckMidi extends DeckShortcuts {
loopOut(): void
toggleLoop(): void
toggleSync(): void
+ /** Make this deck the tempo master (performance mode). */
+ makeMaster(): void
toggleKeylock(): void
/** The pitch fader, -1..1. */
pitch: number
@@ -90,7 +92,8 @@ interface Capture {
}
export class MidiRouter {
- private shiftHeld = new Map()
+ /** Per port, the Shift controls held now (two may be mapped). */
+ private shiftHeld = new Map>()
private decoders = new Map()
private held = new Map()
private capture: Capture | null = null
@@ -120,8 +123,11 @@ export class MidiRouter {
const mapping = st.mappings[port]
// Shift: tracked always, and never an action of its own.
- if (mapping?.shift === key && !(st.armed?.action === 'shift')) {
- this.shiftHeld.set(port, m.value > 0)
+ if (mapping && isShift(mapping, key) && !(st.armed?.action === 'shift')) {
+ const held = this.shiftHeld.get(port) ?? new Set()
+ if (m.value > 0) held.add(key)
+ else held.delete(key)
+ this.shiftHeld.set(port, held)
return
}
if (st.armed) {
@@ -129,7 +135,7 @@ export class MidiRouter {
return
}
if (!mapping) return
- const shift = !!this.shiftHeld.get(port)
+ const shift = this.isShifted(port)
const hit = resolveBinding(mapping, key)
// An encoder whose turns are bound by direction. The plain binding wins
// where it has an action for this layer; else the turns do.
@@ -188,6 +194,10 @@ export class MidiRouter {
}
}
+ private isShifted(port: string): boolean {
+ return (this.shiftHeld.get(port)?.size ?? 0) > 0
+ }
+
/** Forget held controls and decoder state (a controller unplugged). */
forget(port: string): void {
this.shiftHeld.delete(port)
@@ -253,6 +263,8 @@ export class MidiRouter {
return deck.toggle()
case 'sync':
return deck.toggleSync()
+ case 'master':
+ return deck.makeMaster()
case 'keylock':
return deck.toggleKeylock()
case 'jumpBack':
@@ -318,7 +330,7 @@ export class MidiRouter {
let c = this.capture
if (!c || c.target !== target) {
if (c?.timer) clearTimeout(c.timer)
- const layer: Layer = 'layer' in target ? (this.shiftHeld.get(port) ? 'shift' : target.layer) : 'normal'
+ const layer: Layer = 'layer' in target ? (this.isShifted(port) ? 'shift' : target.layer) : 'normal'
c = this.capture = { target, kind, port: null, source: null, samples: [], layer, timer: null }
}
if (c.port && c.port !== port) return // one controller at a time
@@ -395,7 +407,7 @@ export class MidiRouter {
if (this.capture !== c) return
this.capture = null
const t = c.target
- if (t.action === 'shift') updateMapping(port, (m) => bindShift(m, source))
+ if ('slot' in t) updateMapping(port, (m) => bindShift(m, source, t.slot))
else {
updateMapping(port, (m) => bind(m, source, encoding, c.layer, t.action))
patchMidi({ learned: { port, action: t.action, layer: c.layer, at: performance.now() } })
diff --git a/frontend/src/lib/midi/store.ts b/frontend/src/lib/midi/store.ts
index 04aec4f..2a8fad3 100644
--- a/frontend/src/lib/midi/store.ts
+++ b/frontend/src/lib/midi/store.ts
@@ -12,7 +12,7 @@ import { emptyMapping } from './mapping'
import type { SourceKey } from './messages'
/** What Learn is waiting for: an action in a layer, or the Shift control itself. */
-export type LearnTarget = { action: string; layer: Layer } | { action: 'shift' }
+export type LearnTarget = { action: string; layer: Layer } | { action: 'shift'; slot: 0 | 1 }
export interface MidiState {
/** Whether this build can read MIDI at all (desktop app, or a Web MIDI browser). */