Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Each `## x.y.z` section is the release notes of that version, word for word.

## Unreleased

- A **MIDI Message** action, also in the layout builder: a key sends a program change or a
control change to any MIDI output (a switcher, an amp, other gear) or to the unit, or toggles a
control change between two values. It takes a name and a colour of its own.

- A name and a colour for any block (PEQ 2 as "Cut" in red), in the new **Blocks** section of the
Control Center or from a block key's settings. Every key that shows the block uses them, on
every page and in every preset. Pick a colour from a colour field, the system picker or a hex
Expand Down
8 changes: 8 additions & 0 deletions docs/design/03-ux.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ page. Mockups of the deck pages come before M3 and M4 build them.
| Looper | record/play/overdub/stop per key | undo | looper state |
| Status | open the Control Center (without one: read everything again) | switch Updates: Auto, Polling, Real time | connected unit, firmware, Polling or Real time |
| Open Riglight | open the Riglight profile for this deck, from any profile | — | the Riglight mark, and the unit's model once it answers |
| MIDI message | send a program change or a control change to any MIDI output (or the unit's port); a toggle sends its on and off values in turn | — | the port and channel, the name given to it (else the message), the message; a toggle lit while on, a one-shot lit for a moment; NO PORT when the output is gone |
| Bank (layout) | next bank | previous bank | the row's range, e.g. "1–12 of 15" |
| Page (layout) | next page | previous page; on the first page, leave the Riglight profile | the page it goes to |
| Page (action, or a layout key with a target) | the next or previous page, Home, or a set page | — | the page it goes to; HOME on the Home page |
Expand Down Expand Up @@ -56,6 +57,13 @@ of every hue (across) from light to dark (down), with a strength slider for mute
system colour picker or a hex code. Lit keys fill with the colour; on the dark themes an unlit
scene or preset key shows it in its small title, and a bypassed block in its icon.

MIDI message keys (issue #28) reach other gear: a switcher, an amp, a second unit. Each key
names an output port (none: the unit's own), a channel, and a program change, a control change
with a value, or a control change that toggles between an on and an off value. Riglight cannot
read the other gear, so a toggle shows what it last sent, shared by every key that toggles the
same controller on the same port and channel, and starts off. Ports open on first use, one per
output, and open again after a failed send.

## Later

Stream Deck+ fits this device well: dials for preset and scene browsing and tempo, the touch
Expand Down
128 changes: 124 additions & 4 deletions packages/control-center/ui/pages/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
swapKeys,
withLayout,
} from '../edits.ts';
import { useLive } from '../live.ts';
import { useLive, useTopic } from '../live.ts';
import type { Rpc } from '../rpc.ts';

const DRAG_KEY = 'application/x-riglight-key';
Expand Down Expand Up @@ -71,6 +71,7 @@ export function LayoutPage(props: PageProps): JSX.Element {
const shown = layout ? Math.min(page, layout.pages.length - 1) : 0;
const images = usePreviews(props.rpc, layout, shown);
const decks = useDecks(props.rpc);
const outputs = useTopic(props.rpc, 'connection')?.report.ports.outputs ?? [];
if (!state || !layout || !m) return <></>;
const current = layout.pages[shown];
if (!current) return <></>;
Expand Down Expand Up @@ -300,6 +301,7 @@ export function LayoutPage(props: PageProps): JSX.Element {
spec={spec}
pages={pageNames}
blocks={blocks}
outputs={outputs}
onChange={(next) => {
place(selected, next);
}}
Expand Down Expand Up @@ -633,6 +635,8 @@ function baseLabel(
return 'Status';
case 'open':
return 'Open Riglight';
case 'midi':
return `${spec.message === 'pc' ? 'PC' : 'CC'} ${String(spec.number)}${spec.message === 'toggle' ? ' toggle' : ''}, ch ${String(spec.channel)}`;
case 'slot':
return `${ROW_WORD[spec.row]} ${String(spec.n + 1)}`;
case 'bank':
Expand Down Expand Up @@ -674,6 +678,10 @@ function paletteGroups(
{ label: 'Status', spec: { type: 'status' } },
],
},
{
title: 'Other gear',
items: [{ label: 'MIDI message', spec: MIDI_KEY }],
},
{
title: 'Banks',
items: [
Expand Down Expand Up @@ -761,8 +769,19 @@ const KINDS: readonly Choice<Kind>[] = [
{ value: 'looper', label: 'Looper' },
{ value: 'status', label: 'Status' },
{ value: 'page', label: 'Page key' },
{ value: 'midi', label: 'MIDI message' },
];

/** A new MIDI message key: program change 0 on channel 1, to the unit's port. */
const MIDI_KEY: KeySpec = {
type: 'midi',
channel: 1,
message: 'pc',
number: 0,
value: 127,
off: 0,
};

/** What a key becomes when its kind is picked. */
function specOfKind(kind: Kind): KeySpec {
switch (kind) {
Expand All @@ -789,6 +808,8 @@ function specOfKind(kind: Kind): KeySpec {
return { type: kind };
case 'page':
return { type: 'page' };
case 'midi':
return MIDI_KEY;
case 'open':
case 'detail':
return EMPTY_KEY;
Expand All @@ -808,8 +829,100 @@ const KIND_HELP: Partial<Record<Kind, string>> = {
presetStep: 'Hold to scroll; the preset loads on release.',
block: 'A tap bypasses or engages it, a hold opens its channels.',
blockChannel: 'Picks one channel, or steps to the next one.',
midi: 'Sends a MIDI message to other gear, or to the unit. A toggle shows what it last sent: Riglight can’t read the other gear.',
};

type MidiSpec = Extract<KeySpec, { type: 'midi' }>;

const SEVEN_BIT: readonly Choice<string>[] = Array.from({ length: 128 }, (_, i) => ({
value: String(i),
label: String(i),
}));

/** Where a MIDI message key sends, and what. */
function MidiFields(props: {
readonly spec: MidiSpec;
readonly outputs: readonly string[];
readonly onChange: (spec: KeySpec) => void;
}): JSX.Element {
const { spec, onChange } = props;
const ports: Choice<string>[] = [
{ value: '', label: 'The unit (its own port)' },
...props.outputs.map((p) => ({ value: p, label: p })),
];
if (spec.port !== undefined && !props.outputs.includes(spec.port)) {
ports.push({ value: spec.port, label: `${spec.port} (not connected)` });
}
const number = (key: 'number' | 'value' | 'off', label: string, help?: string) => (
<Field label={label} help={help}>
<Select
label={label}
value={String(spec[key])}
choices={SEVEN_BIT}
onChange={(v) => {
onChange({ ...spec, [key]: Number(v) });
}}
/>
</Field>
);
return (
<>
<Field label="Port" help="Any MIDI output this computer has.">
<Select
label="Port"
value={spec.port ?? ''}
choices={ports}
onChange={(v) => {
const rest = Object.fromEntries(Object.entries(spec).filter(([k]) => k !== 'port'));
onChange((v === '' ? rest : { ...rest, port: v }) as KeySpec);
}}
/>
</Field>
<Field label="Channel">
<Select
label="Channel"
value={String(spec.channel)}
choices={Array.from({ length: 16 }, (_, i) => ({
value: String(i + 1),
label: String(i + 1),
}))}
onChange={(v) => {
onChange({ ...spec, channel: Number(v) });
}}
/>
</Field>
<Field label="Message">
<Select
label="Message"
value={spec.message}
choices={[
{ value: 'pc', label: 'Program change' },
{ value: 'cc', label: 'Control change' },
{ value: 'toggle', label: 'Control change, on and off' },
]}
onChange={(message) => {
onChange({ ...spec, message });
}}
/>
</Field>
{spec.message === 'pc'
? number(
'number',
'Program',
'As it goes out: 0 to 127. Gear that counts from 1 shows one more.',
)
: number('number', 'Controller')}
{spec.message === 'cc' && number('value', 'Value')}
{spec.message === 'toggle' && (
<>
{number('value', 'On value')}
{number('off', 'Off value')}
</>
)}
</>
);
}

function BlockFields(props: {
readonly block: BlockRef;
readonly blocks: readonly BlockChoice[];
Expand Down Expand Up @@ -860,11 +973,14 @@ function BlockFields(props: {
/** The longest custom name (LABEL_MAX in packages/deck). */
const LABEL_MAX = 16;

type CustomSpec = Extract<KeySpec, { type: 'preset' | 'scene' }>;
type CustomSpec = Extract<KeySpec, { type: 'preset' | 'scene' | 'midi' }>;

/** Preset and scene keys take a name and colour of their own; blocks keep theirs in Blocks. */
/**
* Preset, scene and MIDI message keys take a name and colour of their own; blocks keep theirs
* in Blocks.
*/
function hasCustom(spec: KeySpec): spec is CustomSpec {
return spec.type === 'preset' || spec.type === 'scene';
return spec.type === 'preset' || spec.type === 'scene' || spec.type === 'midi';
}

/** The key's name and colour of its own: a text box and a row of swatches. */
Expand Down Expand Up @@ -910,6 +1026,7 @@ function KeySettings(props: {
readonly spec: KeySpec;
readonly pages: readonly string[];
readonly blocks: readonly BlockChoice[];
readonly outputs: readonly string[];
readonly onChange: (spec: KeySpec) => void;
}): JSX.Element {
const { spec } = props;
Expand Down Expand Up @@ -1064,6 +1181,9 @@ function KeySettings(props: {
/>
</Field>
)}
{spec.type === 'midi' && (
<MidiFields spec={spec} outputs={props.outputs} onChange={onChange} />
)}
{hasCustom(spec) && <CustomFields spec={spec} onChange={props.onChange} />}
{(spec.type === 'block' || spec.type === 'blockChannel') && (
<p class="field-help">
Expand Down
7 changes: 7 additions & 0 deletions packages/deck/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ActionKind =
| 'status'
| 'open'
| 'page'
| 'midi'
| 'test-image';

export interface ActionInfo {
Expand Down Expand Up @@ -88,6 +89,12 @@ export const ACTIONS: readonly ActionInfo[] = [
tooltip:
'Flips the pages of the Riglight profile: next, previous, Home or a page you pick. Put it on any key of the Riglight profile.',
},
{
kind: 'midi',
name: 'MIDI Message',
tooltip:
'Sends a program change or a control change to any MIDI output (a switcher, an amp, other gear), or toggles a control change between two values.',
},
{
kind: 'test-image',
name: 'Test Images',
Expand Down
84 changes: 82 additions & 2 deletions packages/deck/src/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
// from the commands: everything comes in through the KeyContext.

import type { UpdatesMode } from '@riglight/axefx';
import type { LooperButton as MidiLooperButton } from '@riglight/midi';
import {
controlChange,
programChange,
type LooperButton as MidiLooperButton,
} from '@riglight/midi';
import { T, type RigStore } from '@riglight/model';
import type {
BankKey,
Expand All @@ -12,6 +16,7 @@ import type {
KeyView,
LooperButton,
LooperState,
MidiKey,
PageKey,
PresetKey,
PresetStepKey,
Expand All @@ -24,7 +29,7 @@ import { blockLabel, hasBlock, presetChain } from './chain.ts';
import type { Gesture, GestureOptions } from './gestures.ts';
import type { RigControl } from './rig.ts';
import { blockLook, UPDATES_SETTINGS, type GlobalSettings } from './settings.ts';
import type { BankRow, BlockRef, Direction, KeySpec } from './specs.ts';
import type { BankRow, BlockRef, Direction, KeySpec, MidiSend } from './specs.ts';

/** Where a bank of the page shown is, and how far it can go. */
export interface BankState {
Expand Down Expand Up @@ -70,6 +75,8 @@ export interface KeyContext {
readonly held: boolean;
/** State kept for this key across gestures (the preset a held step key went to). */
readonly memo: Record<string, unknown>;
/** What MIDI message toggles last sent, by `toggleId`: on or off. */
readonly toggles: Map<string, boolean>;
readonly nav: Navigator;
/** Shows the app's "did not work" mark on the key. */
alert(): void;
Expand Down Expand Up @@ -239,6 +246,40 @@ export function bankRange(b: BankState): { first: number; last: number; total: n

const updatesMode = (mode: UpdatesMode | undefined): StatusKey['updates'] => mode;

/** How long a MIDI message key stays lit after it sent. */
export const MIDI_FLASH_MS = 250;

/** What a MIDI message key shows as its message: "PC 5", "CC 64". */
export function midiMessageText(m: MidiSend): string {
return `${m.message === 'pc' ? 'PC' : 'CC'} ${String(m.number)}`;
}

/**
* A port name short enough for the top line of a key: the words that tell ports apart, in
* capitals, without the driver's port numbers ("MIDISPORT 2x2 Anniversary Port 1" ->
* "MIDISPORT 2X2 ANNIVERSARY 1").
*/
export function shortPort(port: string): string {
return port
.replace(/\s*\[.*?\]|\s*\(.*?\)/g, '')
.replace(/\bport\b/gi, '')
.replace(/\s+/g, ' ')
.trim()
.toUpperCase();
}

/** Toggles that send the same control change to the same port share their state. */
export const toggleId = (m: MidiSend): string =>
`${m.port ?? ''}|${String(m.channel)}|${String(m.number)}`;

/** The bytes a MIDI message key sends; `on` picks the value of a toggle. */
export function midiBytes(m: MidiSend, on: boolean): Uint8Array {
const channel = m.channel - 1;
if (m.message === 'pc') return programChange(m.number, channel);
if (m.message === 'cc') return controlChange(m.number, m.value, channel);
return controlChange(m.number, on ? m.value : m.off, channel);
}

/** Fires on key down: the key has no other gesture. */
const TAP: GestureOptions = {};

Expand Down Expand Up @@ -520,6 +561,45 @@ export const CONTROLLERS: ControllerMap = {
},
},

midi: {
options: () => TAP,
view(spec, ctx): MidiKey {
const unit = spec.port === undefined;
const offline = unit && !isOnline(ctx.rig.store);
const noPort = !unit && !ctx.rig.outputPorts().includes(spec.port);
const sentAt = ctx.memo.sentAt;
return {
kind: 'midi',
name: spec.label,
message: midiMessageText(spec),
target: `${unit ? ctx.rig.profile.model.toUpperCase() : shortPort(spec.port)} · CH ${String(spec.channel)}`,
on: spec.message === 'toggle' ? ctx.toggles.get(toggleId(spec)) === true : undefined,
sent:
spec.message !== 'toggle' &&
typeof sentAt === 'number' &&
ctx.now - sentAt < MIDI_FLASH_MS,
noPort,
offline,
tint: spec.color,
};
},
gesture(spec, g, ctx) {
if (g.type !== 'tap') return;
// A toggle goes on from off; Riglight cannot read the other gear, so it keeps what it sent.
const on = spec.message === 'toggle' ? ctx.toggles.get(toggleId(spec)) !== true : true;
if (!ctx.rig.sendMidi(spec.port, midiBytes(spec, on))) {
ctx.alert();
return;
}
if (spec.message === 'toggle') ctx.toggles.set(toggleId(spec), on);
else ctx.memo.sentAt = ctx.now;
},
animated: (spec, ctx) =>
spec.message !== 'toggle' &&
typeof ctx.memo.sentAt === 'number' &&
ctx.now - ctx.memo.sentAt < MIDI_FLASH_MS * 2,
},

slot: {
// Resolved by the runtime into the key the bank shows; never drawn as such.
options: () => TAP,
Expand Down
Loading