beffroi-tools/companion-modules/media-player-classic/src/definitions.js

84 lines
2.7 KiB
JavaScript

import { commands } from './commands.js'
import { colors } from './feedbacks.js'
export function actions(send) {
return Object.fromEntries(
Object.entries(commands).map(([id, name]) => [
id,
{
name,
options: [],
callback: async () => send(id),
},
]),
)
}
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: {} }], 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: colors.white, ...(text ? { text } : {}) },
})
const button = (name, text, id, feedback = []) => ({
type: 'simple',
name,
style: { text, size: '18', color: colors.white, bgcolor: colors.dark, show_topbar: false },
steps: [{ down: id ? [{ actionId: id, options: {} }] : [], up: [] }],
feedbacks: [...feedback, offline],
})
const transport = {
transport_play: button('Play — green while playing', '▶\nPLAY', '887', [
active('playing', colors.green),
active('paused', colors.amber, 'Ⅱ\nPAUSED'),
]),
transport_stop: button('Stop — red while stopped', '■\nSTOP', '890', [active('stopped', colors.red)]),
// Verified against MPC-HC 2.8.5's /commands.json: 918 is an after-playback setting.
transport_previous: button('Previous playlist item', '◀◀\nPREV', '919'),
transport_next: button('Next playlist item', '▶▶\nNEXT', '920'),
transport_mute: button('Toggle mute — red while muted', 'MUTE', '909', [active('muted', colors.red, 'MUTED')]),
transport_pause: button('Pause — amber while paused', 'Ⅱ\nPAUSE', '888', [active('paused', colors.amber)]),
transport_remaining: button('Remaining time and progress', `LEFT\n$(${label}:remaining)`, null, [
{ feedbackId: 'progress_bar', options: {} },
]),
transport_elapsed: button('Elapsed time and progress', `ELAPSED\n$(${label}:elapsed)`, null, [
{ feedbackId: 'progress_bar', options: {} },
]),
transport_state: button('Playback state', `$(${label}:state)`, null, [
active('playing', colors.green),
active('paused', colors.amber),
active('stopped', colors.red),
]),
}
return { ...transport, ...catalog }
}
export function presetSections(buttons) {
return [
{
id: 'transport',
name: 'Transport & timing',
definitions: Object.keys(buttons).filter((id) => id.startsWith('transport_')),
},
{ id: 'commands', name: 'All commands', definitions: Object.keys(commands) },
]
}