{item.title}
{item.description}
From 5c95dceb5840f4465f62dc3154d3b643161e9405 Mon Sep 17 00:00:00 2001
From: karigardarsson <10534568+karigardarsson@users.noreply.github.com>
Date: Fri, 4 Dec 2026 20:15:49 +0000
Subject: [PATCH 1/8] Preview Digitakt II Try and Undo with a mock device
---
.../2026-12-04-digitakt-ii-trial-preview.md | 1 +
src/dev/Dt2TrialPreview.test.ts | 108 +++++++++++++
src/dev/Dt2TrialPreview.tsx | 142 ++++++++++++++++++
src/dev/dt2-trial-mock.ts | 55 +++++++
src/dev/dt2-trial-preview.css | 29 ++++
src/main.tsx | 6 +-
6 files changed, 340 insertions(+), 1 deletion(-)
create mode 100644 changelog/2026-12-04-digitakt-ii-trial-preview.md
create mode 100644 src/dev/Dt2TrialPreview.test.ts
create mode 100644 src/dev/Dt2TrialPreview.tsx
create mode 100644 src/dev/dt2-trial-mock.ts
create mode 100644 src/dev/dt2-trial-preview.css
diff --git a/changelog/2026-12-04-digitakt-ii-trial-preview.md b/changelog/2026-12-04-digitakt-ii-trial-preview.md
new file mode 100644
index 0000000000..e55829e802
--- /dev/null
+++ b/changelog/2026-12-04-digitakt-ii-trial-preview.md
@@ -0,0 +1 @@
+Digitakt II: a local mock preview shows the running modules, tries a module in RAM and restores the previous set with Undo. If USB drops during Undo, the panel shows the last confirmed set and checks it again on reconnect. Keep stays disabled.
diff --git a/src/dev/Dt2TrialPreview.test.ts b/src/dev/Dt2TrialPreview.test.ts
new file mode 100644
index 0000000000..d572412864
--- /dev/null
+++ b/src/dev/Dt2TrialPreview.test.ts
@@ -0,0 +1,108 @@
+// @vitest-environment jsdom
+import { act, createElement } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import Dt2TrialPreview from './Dt2TrialPreview'
+import { createMockDt2Device } from './dt2-trial-mock'
+
+let container: HTMLElement
+let root: Root
+const text = () => container.textContent
+const button = (name: string) => [...container.querySelectorAll('button')].find(item => item.textContent === name)!
+const click = (name: string) => act(() => button(name).click())
+const settle = () => act(() => vi.runAllTimersAsync())
+const modules = () => [...container.querySelectorAll('.hub-unit-modules strong')].map(item => item.textContent)
+
+beforeEach(() => {
+ vi.useFakeTimers()
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
+ container = document.createElement('div')
+ document.body.append(container)
+ root = createRoot(container)
+})
+
+afterEach(async () => {
+ await act(() => root.unmount())
+ container.remove()
+ vi.useRealTimers()
+ vi.unstubAllGlobals()
+})
+
+async function open() {
+ const device = createMockDt2Device()
+ const read = vi.spyOn(device, 'read')
+ const undo = vi.spyOn(device, 'undo')
+ await act(() => root.render(createElement(Dt2TrialPreview, { makeDevice: () => device })))
+ expect(text()).toContain('Reading the box')
+ expect(button('Try').disabled).toBe(true)
+ await settle()
+ return { read, undo }
+}
+
+describe('Digitakt II trial preview', () => {
+ it('reads the box, tries in RAM and verifies that Undo restores the prior set', async () => {
+ const { read } = await open()
+ expect(text()).toContain('DT2-MOCK-01')
+ expect(text()).toContain('1.17')
+ expect(text()).toContain('7f31c2a0')
+ expect(modules()).toEqual(['Track Names'])
+ expect(button('Keep').disabled).toBe(true)
+ expect(button('Undo').disabled).toBe(true)
+
+ await click('Try')
+ expect(text()).toContain('Starting trial')
+ expect(modules()).toEqual(['Track Names'])
+ await settle()
+ expect(modules()).toEqual(['Track Names', 'Chord Arp'])
+ expect(text()).toContain('Trial in RAM')
+ expect(text()).toContain('Undo restores the previous set: Track Names')
+ expect(button('Keep').disabled).toBe(true)
+
+ await click('Undo')
+ expect(button('Undo').disabled).toBe(true)
+ expect(text()).toContain('Undoing trial')
+ await settle()
+ expect(read).toHaveBeenCalledTimes(3)
+ expect(modules()).toEqual(['Track Names'])
+ expect(text()).toContain('Previous set restored')
+ expect(button('Try').disabled).toBe(false)
+ })
+
+ it.each([
+ ['drop-before-restore', ['Track Names', 'Chord Arp'], 'Box checked.', false],
+ ['drop-after-restore', ['Track Names'], 'Previous set restored', true],
+ ] as const)('reads actual mock state after %s without replaying Undo', async (scenario, expected, message, undoDisabled) => {
+ const { read, undo } = await open()
+ await click('Try')
+ await settle()
+ const picker = container.querySelector('select')!
+ await act(() => {
+ picker.value = scenario
+ picker.dispatchEvent(new Event('change', { bubbles: true }))
+ })
+ await click('Undo')
+ await settle()
+ expect(read).toHaveBeenCalledTimes(2)
+ expect(text()).toContain('USB disconnected')
+ expect(text()).toContain('Last confirmed set')
+ expect(text()).toContain('Undo result unknown')
+ expect(text()).toContain('Last read base')
+ expect(modules()).toEqual(['Track Names', 'Chord Arp'])
+ expect(button('Undo')).toBeUndefined()
+ expect(button('Keep').disabled).toBe(true)
+
+ await click('Reconnect')
+ expect(button('Reconnect').disabled).toBe(true)
+ expect(text()).toContain('Undo result unknown')
+ expect(modules()).toEqual(['Track Names', 'Chord Arp'])
+ await settle()
+ expect(read).toHaveBeenCalledTimes(3)
+ expect(undo).toHaveBeenCalledTimes(1)
+ expect(text()).toContain('On the box')
+ expect(text()).toContain(message)
+ expect(text()).not.toContain('Undo result unknown')
+ expect(modules()).toEqual(expected)
+ expect(button('Undo').disabled).toBe(undoDisabled)
+ expect(button('Keep').disabled).toBe(true)
+ })
+})
diff --git a/src/dev/Dt2TrialPreview.tsx b/src/dev/Dt2TrialPreview.tsx
new file mode 100644
index 0000000000..04f7303ee9
--- /dev/null
+++ b/src/dev/Dt2TrialPreview.tsx
@@ -0,0 +1,142 @@
+import { useEffect, useState } from 'react'
+import { DeviceImage } from '../devices/DeviceImage'
+import { DEVICES_BY_ID } from '../devices/registry'
+import { createMockDt2Device, TRIAL_MODULE, UNDO_SCENARIOS, type Dt2Snapshot, type UndoScenario } from './dt2-trial-mock'
+import '../devices/devices.css'
+import '../components/octatrack-link.css'
+import './dt2-trial-preview.css'
+
+type Phase = 'reading' | 'ready' | 'trying' | 'undoing' | 'undo-unknown' | 'reconnecting'
+type Review = 'restored' | 'reread'
+type Control = {
+ phase: Phase
+ confirmed: Dt2Snapshot | null
+ review?: Review
+}
+
+function trialMessage({ phase, confirmed, review }: Control): [title: string, detail: string] {
+ switch (phase) {
+ case 'reading': return ['Reading the box…', 'Checking the build and active modules.']
+ case 'trying': return ['Starting trial…', `Loading ${TRIAL_MODULE} into RAM.`]
+ case 'undoing': return ['Undoing trial…', 'Restoring the previous set and checking what is running.']
+ case 'undo-unknown': return ['Undo result unknown', 'USB disconnected during Undo. Reconnect to check what’s on the box.']
+ case 'reconnecting': return ['Undo result unknown', 'Reading the box again to check what’s running…']
+ case 'ready': {
+ const trial = confirmed?.trial
+ if (trial) return ['Trial active', `${review === 'reread' ? 'Box checked. ' : ''}${trial.module} is running from RAM. Undo restores the previous set: ${trial.previous.join(', ') || 'no modules'}.`]
+ if (review === 'restored') return ['Previous set restored', 'The box confirmed that the previous set is running.']
+ return [`Try ${TRIAL_MODULE}`, `Load ${TRIAL_MODULE} into RAM. You can undo the trial to restore the current set.`]
+ }
+ }
+}
+
+export function Dt2TrialPanel({ control, scenario, setScenario, onTry, onUndo, onReconnect }: {
+ control: Control
+ scenario: UndoScenario
+ setScenario: (scenario: UndoScenario) => void
+ onTry: () => void
+ onUndo: () => void
+ onReconnect: () => void
+}) {
+ const { phase, confirmed } = control
+ const stale = phase === 'undo-unknown' || phase === 'reconnecting'
+ const pending = phase === 'trying' || phase === 'undoing'
+ const trial = confirmed?.trial
+ const [title, detail] = trialMessage(control)
+ const linkLabel = phase === 'undo-unknown' ? 'USB disconnected'
+ : phase === 'reconnecting' ? 'Reconnecting…'
+ : phase === 'reading' ? 'Reading over USB…' : 'Connected via USB'
+ const led = phase === 'undo-unknown' ? 'leaving' : phase === 'reading' || phase === 'reconnecting' ? 'load' : 'on'
+
+ return Digitakt II mock preview {linkLabel} {confirmed ? 'No modules running.' : 'Reading active modules…'} {detail} Keep requires a base that supports saving the set.Try, Keep and Undo
Digitakt II
+
+
}
+ {confirmed.build}{stale || pending ? 'Last confirmed set' : 'On the box'}
+ {confirmed.modules.map(module => {
+ const inTrial = module === trial?.module
+ return
: {title}
+
Digitakt II mock preview
{confirmed.build}{confirmed.hello.base.slice(0, 8)}{confirmed ? 'No modules running.' : 'Reading active modules…'}
} + :{confirmed ? 'No modules running.' : stale ? 'No confirmed inventory.' : 'Reading active modules…'}
}{linkLabel}
- {confirmed &&{confirmed.hello.base.slice(0, 8)}{build.digest.slice(0, 8)}{confirmed ? 'No modules running.' : stale ? 'No confirmed inventory.' : 'Reading active modules…'}
} @@ -97,9 +110,9 @@ export function Dt2TrialPanel({ control, scenario, setScenario, onTry, onUndo, o{detail}
Keep requires a base that supports saving the set.
@@ -114,54 +127,50 @@ export function Dt2TrialPanel({ control, scenario, setScenario, onTry, onUndo, o{item.description}
{pausedModule ? pausedModule.name + ' is temporarily unavailable.' : 'This module or page is not in the current catalog.'}
Open module library{pausedModule ? pausedModule.name + ' is temporarily unavailable.' : 'This module or page is not in the current catalog.'}
Open module libraryConnecting your {device.name} needs Chrome or Edge on a computer.
{line}
- {error &&{error}
} -{modules ? 'No modules loaded. Modules kept over USB show here until the next power cycle.' : 'This base loads no modules over USB.'}
:{line}{hint && (!screenView || connected) && {hint}}
+ {/* While not connected, Screen gives its own detail beside the preview, so the hint stays off it. */} +{identity!.base.slice(0, 8)}}