327 lines
9.0 KiB
JavaScript
327 lines
9.0 KiB
JavaScript
import { commands } from './commands.js'
|
|
import { colors } from './feedbacks.js'
|
|
|
|
export function actions(send, loadNext, loadPrevious, loadPlaylistItem, playPlaylistItem) {
|
|
const definitions = Object.fromEntries(
|
|
Object.entries(commands).map(([id, name]) => [
|
|
id,
|
|
{
|
|
name,
|
|
options: [
|
|
{
|
|
type: 'dropdown',
|
|
id: 'target',
|
|
label: 'Player target',
|
|
default: 'both',
|
|
choices: [
|
|
{ id: 'both', label: 'Both players' },
|
|
{ id: 'main', label: 'Main only' },
|
|
{ id: 'backup', label: 'Backup only' },
|
|
],
|
|
disableAutoExpression: true,
|
|
},
|
|
],
|
|
callback: async (action) => send(id, action?.options?.target ?? 'both'),
|
|
},
|
|
]),
|
|
)
|
|
for (const [direction, callback] of [
|
|
['next', loadNext],
|
|
['previous', loadPrevious],
|
|
]) {
|
|
if (callback)
|
|
definitions[`load_${direction}`] = {
|
|
name: `Load ${direction}`,
|
|
options: definitions['887'].options,
|
|
callback: (action) => callback(action?.options?.target ?? 'both'),
|
|
}
|
|
}
|
|
for (const [id, name, callback] of [
|
|
['load_playlist_item', 'Load playlist item', loadPlaylistItem],
|
|
['play_playlist_item', 'Play playlist item', playPlaylistItem],
|
|
]) {
|
|
if (callback)
|
|
definitions[id] = {
|
|
name,
|
|
options: [
|
|
{
|
|
type: 'number',
|
|
id: 'item',
|
|
label: 'Playlist item number (1 = first)',
|
|
default: 1,
|
|
min: 1,
|
|
max: 10000,
|
|
step: 1,
|
|
},
|
|
...definitions['887'].options,
|
|
],
|
|
callback: (action) => callback(action?.options?.item ?? 1, action?.options?.target ?? 'both'),
|
|
}
|
|
}
|
|
return definitions
|
|
}
|
|
|
|
export function presets(label = 'MPC_DEV') {
|
|
const catalog = Object.fromEntries(
|
|
Object.entries(commands).map(([id, name]) => [
|
|
id,
|
|
{
|
|
type: 'simple',
|
|
name,
|
|
style: { text: name, size: 'auto', color: 0xffffff, bgcolor: 0 },
|
|
steps: [{ down: [{ actionId: id, options: { target: 'both' } }], up: [] }],
|
|
feedbacks: [],
|
|
},
|
|
]),
|
|
)
|
|
|
|
const offline = {
|
|
feedbackId: 'offline',
|
|
options: {},
|
|
style: { text: 'OFFLINE', bgcolor: colors.dark, color: 0x889099 },
|
|
}
|
|
const active = (feedbackId, bgcolor, text) => ({
|
|
feedbackId,
|
|
options: {},
|
|
style: { bgcolor, color: bgcolor === colors.amber ? colors.dark : colors.white, ...(text ? { text } : {}) },
|
|
})
|
|
const button = (name, text, id, feedback = [], size = '18', bgcolor = colors.dark) => ({
|
|
type: 'simple',
|
|
name,
|
|
style: { text, size, color: colors.white, bgcolor, show_topbar: true },
|
|
steps: [{ down: id ? [{ actionId: id, options: { target: 'both' } }] : [], up: [] }],
|
|
feedbacks: [...feedback, offline],
|
|
})
|
|
const transport = {
|
|
transport_redundancy: {
|
|
type: 'simple',
|
|
name: 'Backup sync status',
|
|
style: { text: 'No\nbackup', size: '14', color: 0x99a4af, bgcolor: colors.dark, show_topbar: true },
|
|
steps: [{ down: [], up: [] }],
|
|
feedbacks: [{ feedbackId: 'redundancy', options: {} }],
|
|
},
|
|
transport_load_result: {
|
|
type: 'simple',
|
|
name: 'Last load result',
|
|
style: { text: 'NO LOAD\nYET', size: 'auto', color: colors.white, bgcolor: colors.dark, show_topbar: true },
|
|
steps: [{ down: [], up: [] }],
|
|
feedbacks: [{ feedbackId: 'load_result', options: {} }],
|
|
},
|
|
transport_load_next: button(
|
|
'Load next',
|
|
'↦\nLOAD\nNEXT',
|
|
'load_next',
|
|
[{ feedbackId: 'load_next_status', options: {} }],
|
|
12,
|
|
0x243b50,
|
|
),
|
|
transport_load_previous: button(
|
|
'Load previous',
|
|
'↤\nLOAD\nPREV',
|
|
'load_previous',
|
|
[{ feedbackId: 'load_previous_status', options: {} }],
|
|
12,
|
|
0x243b50,
|
|
),
|
|
transport_play: button(
|
|
'Play — green while playing',
|
|
'▶\nPLAY',
|
|
'887',
|
|
[active('playing', colors.green), active('paused', colors.amber, 'Ⅱ\nPAUSED')],
|
|
'18',
|
|
0x243b50,
|
|
),
|
|
transport_stop: button(
|
|
'Stop — red while stopped',
|
|
'■\nSTOP',
|
|
'890',
|
|
[active('stopped', colors.red)],
|
|
'18',
|
|
0x502d34,
|
|
),
|
|
// Verified against MPC-HC 2.8.5's /commands.json: 918 is an after-playback setting.
|
|
transport_previous: button('Previous playlist item', '◀◀\nPREV', '919', [], '18', 0x243b50),
|
|
transport_next: button('Next playlist item', '▶▶\nNEXT', '920', [], '18', 0x243b50),
|
|
transport_mute: button(
|
|
'Toggle mute — red while muted',
|
|
'MUTE',
|
|
'909',
|
|
[active('muted', colors.red, 'MUTED')],
|
|
'18',
|
|
),
|
|
transport_pause: button('Pause — amber while paused', 'Ⅱ\nPAUSE', '888', [active('paused', colors.amber)], '18'),
|
|
transport_remaining: button(
|
|
'Remaining time and progress',
|
|
`LEFT\n$(${label}:remaining)`,
|
|
null,
|
|
[{ feedbackId: 'progress_bar', options: {} }],
|
|
'18',
|
|
),
|
|
transport_elapsed: button(
|
|
'Elapsed time and progress',
|
|
`ELAPSED\n$(${label}:elapsed)`,
|
|
null,
|
|
[{ feedbackId: 'progress_bar', options: {} }],
|
|
12,
|
|
),
|
|
transport_state: button(
|
|
'Playback state',
|
|
`$(${label}:state_label)`,
|
|
null,
|
|
[active('playing', colors.green), active('paused', colors.amber), active('stopped', colors.red)],
|
|
'14',
|
|
),
|
|
}
|
|
const playlist = Object.fromEntries(
|
|
Array.from({ length: 10 }, (_, index) => {
|
|
const item = index + 1
|
|
return [
|
|
`transport_load_item_${item}`,
|
|
{
|
|
type: 'layered',
|
|
name: `Load playlist item ${item}`,
|
|
canvas: { decoration: 'topbar' },
|
|
elements: [
|
|
{ id: 'background', type: 'box', x: 0, y: 0, width: 100, height: 100, color: 0x243b50 },
|
|
{
|
|
id: 'title',
|
|
type: 'text',
|
|
text: '↓ LOAD',
|
|
x: 5,
|
|
y: 3,
|
|
width: 90,
|
|
height: 20,
|
|
fontsize: 80,
|
|
fontsizeAllowShrink: true,
|
|
color: colors.white,
|
|
halign: 'center',
|
|
valign: 'center',
|
|
},
|
|
{
|
|
id: 'number',
|
|
type: 'text',
|
|
text: String(item),
|
|
x: 5,
|
|
y: 24,
|
|
width: 90,
|
|
height: 74,
|
|
fontsize: 100,
|
|
fontsizeAllowShrink: true,
|
|
color: colors.white,
|
|
halign: 'center',
|
|
valign: 'center',
|
|
},
|
|
],
|
|
steps: [{ down: [{ actionId: 'load_playlist_item', options: { item, target: 'both' } }], up: [] }],
|
|
feedbacks: [
|
|
...['loading', 'ready', 'failed'].map((state) => ({
|
|
feedbackId: 'load_playlist_item_state',
|
|
options: { item, state },
|
|
styleOverrides: [
|
|
{
|
|
elementId: 'title',
|
|
elementProperty: 'text',
|
|
override: { loading: 'LOADING', ready: 'LOADED', failed: 'FAILED' }[state],
|
|
},
|
|
{
|
|
elementId: 'background',
|
|
elementProperty: 'color',
|
|
override: { loading: colors.amber, ready: colors.blue, failed: colors.red }[state],
|
|
},
|
|
...['title', 'number'].map((elementId) => ({
|
|
elementId,
|
|
elementProperty: 'color',
|
|
override: state === 'loading' ? colors.dark : colors.white,
|
|
})),
|
|
],
|
|
})),
|
|
{
|
|
feedbackId: 'offline',
|
|
options: {},
|
|
styleOverrides: [
|
|
{ elementId: 'title', elementProperty: 'text', override: 'OFFLINE' },
|
|
{ elementId: 'background', elementProperty: 'color', override: colors.dark },
|
|
...['title', 'number'].map((elementId) => ({
|
|
elementId,
|
|
elementProperty: 'color',
|
|
override: 0x889099,
|
|
})),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
]
|
|
}),
|
|
)
|
|
const playPlaylist = Object.fromEntries(
|
|
Array.from({ length: 10 }, (_, index) => {
|
|
const item = index + 1
|
|
return [
|
|
`playlist_play_item_${item}`,
|
|
{
|
|
type: 'simple',
|
|
name: `Play item ${item}`,
|
|
style: { text: `▶\nPLAY\n${item}`, size: 12, color: colors.white, bgcolor: 0x243b50, show_topbar: true },
|
|
steps: [{ down: [{ actionId: 'play_playlist_item', options: { item, target: 'both' } }], up: [] }],
|
|
feedbacks: [offline],
|
|
},
|
|
]
|
|
}),
|
|
)
|
|
const timers = Object.fromEntries(
|
|
['remaining', 'elapsed'].flatMap((mode) =>
|
|
['hh', 'mm', 'ss'].map((part, index) => [
|
|
`timer_${mode}_${part}`,
|
|
{
|
|
type: 'simple',
|
|
name: `${mode === 'remaining' ? 'Remaining' : 'Elapsed'} ${part.toUpperCase()} (${index + 1}/3)`,
|
|
style: {
|
|
text: `$(${label}:${mode}_${part})`,
|
|
size: 'auto',
|
|
color: colors.white,
|
|
bgcolor: colors.dark,
|
|
show_topbar: true,
|
|
alignment: 'center:center',
|
|
},
|
|
steps: [{ down: [], up: [] }],
|
|
feedbacks: [{ feedbackId: 'split_timer_color', options: { mode } }],
|
|
},
|
|
]),
|
|
),
|
|
)
|
|
return { ...transport, ...playlist, ...playPlaylist, ...timers, ...catalog }
|
|
}
|
|
|
|
export function presetSections(buttons) {
|
|
return [
|
|
{
|
|
id: 'transport',
|
|
name: 'Transport & timing',
|
|
definitions: Object.keys(buttons).filter(
|
|
(id) => id.startsWith('transport_') && !id.startsWith('transport_load_'),
|
|
),
|
|
},
|
|
{
|
|
id: 'experimental',
|
|
name: 'Experimental',
|
|
definitions: [
|
|
'transport_load_previous',
|
|
'transport_load_next',
|
|
'transport_load_result',
|
|
...Object.keys(buttons).filter((id) => id.startsWith('transport_load_item_')),
|
|
],
|
|
},
|
|
{
|
|
id: 'playlist',
|
|
name: 'Playlist',
|
|
definitions: Object.keys(buttons).filter((id) => id.startsWith('playlist_play_item_')),
|
|
},
|
|
{
|
|
id: 'timers',
|
|
name: 'Timers — large HH / MM / SS',
|
|
definitions: Object.keys(buttons).filter((id) => id.startsWith('timer_')),
|
|
},
|
|
{ id: 'commands', name: 'All commands', definitions: Object.keys(commands) },
|
|
]
|
|
}
|