Add direct Play item presets in a regular Playlist folder
Beffroi/beffroi-tools/pipeline/head There was a failure building this commit
Details
Beffroi/beffroi-tools/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
290511c23c
commit
116b67e51f
|
|
@ -97,6 +97,25 @@ with the player, follows seeks, and does not predict wall-clock completion at
|
|||
nonstandard playback speeds. Playback state is MPC's reported state, not proof
|
||||
that frames or audio are physically reaching an output device.
|
||||
|
||||
## Playlist — direct playback
|
||||
|
||||
**Presets → MPC_DEV → Playlist** contains **Play item 1–10**. Each sends MPC-HC's
|
||||
normal indexed playlist selection command, which opens and plays that item.
|
||||
These presets do **not** mute, stop, retry Stop, or run the experimental loading
|
||||
sequence. Existing mute remains unchanged. Even the currently selected item is
|
||||
sent through MPC-HC's normal open/play path.
|
||||
|
||||
The reusable **Play playlist item** action accepts a 1-based item number from
|
||||
1–10000. Duplicate a preset, change its action number and button text to create
|
||||
additional positions. The action checks `/playlist.json` before sending selection;
|
||||
missing items send no playback command. Positions follow the current playlist
|
||||
order, so keep main/backup playlists aligned. Player target defaults to Both.
|
||||
|
||||
The buttons stay muted blue with a play icon; they do not claim individual-item
|
||||
playing feedback. Normal player feedback updates after selection. These actions
|
||||
leave **Last load result** unchanged because they are not experimental loads.
|
||||
Like other transport actions, they are ignored while an experimental load is running.
|
||||
|
||||
## EXPERIMENTAL — Load next / previous / playlist item: not a guaranteed cue/preload
|
||||
|
||||
> **EXPERIMENTAL: these buttons deliberately start the next or previous video,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,14 @@ while playing, full red while stopped, and amber while paused. Timers stay dark
|
|||
with progress bars; backup sync keeps its original status colors.
|
||||
Re-add copied presets to apply styling updates; linked presets update automatically.
|
||||
|
||||
## Playlist — direct playback
|
||||
|
||||
The **Playlist** folder has **Play item 1–10** presets. These directly select and
|
||||
play the numbered item using MPC-HC's normal command; there is no mute/Stop
|
||||
sequence. Mute remains unchanged. Duplicate a preset and change the action's item
|
||||
number and button text for other positions. Numbers follow current playlist order;
|
||||
keep backup order aligned. Missing items are rejected before selection.
|
||||
|
||||
## EXPERIMENTAL — Load next / Load previous
|
||||
|
||||
Find **Load previous** and **Load next** in the separate **Experimental** preset
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { commands } from './commands.js'
|
||||
import { colors } from './feedbacks.js'
|
||||
|
||||
export function actions(send, loadNext, loadPrevious, loadPlaylistItem) {
|
||||
export function actions(send, loadNext, loadPrevious, loadPlaylistItem, playPlaylistItem) {
|
||||
const definitions = Object.fromEntries(
|
||||
Object.entries(commands).map(([id, name]) => [
|
||||
id,
|
||||
|
|
@ -36,23 +36,28 @@ export function actions(send, loadNext, loadPrevious, loadPlaylistItem) {
|
|||
callback: (action) => callback(action?.options?.target ?? 'both'),
|
||||
}
|
||||
}
|
||||
if (loadPlaylistItem)
|
||||
definitions.load_playlist_item = {
|
||||
name: 'Load playlist item',
|
||||
options: [
|
||||
{
|
||||
type: 'number',
|
||||
id: 'item',
|
||||
label: 'Playlist item number (1 = first)',
|
||||
default: 1,
|
||||
min: 1,
|
||||
max: 10000,
|
||||
step: 1,
|
||||
},
|
||||
...definitions['887'].options,
|
||||
],
|
||||
callback: (action) => loadPlaylistItem(action?.options?.item ?? 1, 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
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +187,22 @@ export function presets(label = 'MPC_DEV') {
|
|||
]
|
||||
}),
|
||||
)
|
||||
return { ...transport, ...playlist, ...catalog }
|
||||
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],
|
||||
},
|
||||
]
|
||||
}),
|
||||
)
|
||||
return { ...transport, ...playlist, ...playPlaylist, ...catalog }
|
||||
}
|
||||
|
||||
export function presetSections(buttons) {
|
||||
|
|
@ -204,6 +224,11 @@ export function presetSections(buttons) {
|
|||
...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: 'commands', name: 'All commands', definitions: Object.keys(commands) },
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export default class MpcInstance extends InstanceBase {
|
|||
(target) => this.loadItem('next', target),
|
||||
(target) => this.loadItem('previous', target),
|
||||
(item, target) => this.loadItem(`item_${item}`, target),
|
||||
(item, target) => this.playPlaylistItem(item, target),
|
||||
),
|
||||
)
|
||||
this.setFeedbackDefinitions(
|
||||
|
|
@ -172,6 +173,16 @@ export default class MpcInstance extends InstanceBase {
|
|||
}
|
||||
}
|
||||
|
||||
async playPlaylistItem(item, target = 'both') {
|
||||
if (this.loadingItem) {
|
||||
this.log('warn', 'Command ignored while experimental loading is running')
|
||||
return
|
||||
}
|
||||
if (!['both', 'main', 'backup'].includes(target)) return
|
||||
const players = target === 'main' ? [this.main] : target === 'backup' ? [this.backup] : [this.main, this.backup]
|
||||
await Promise.allSettled(players.filter(Boolean).map((player) => player.playPlaylistItem(item)))
|
||||
}
|
||||
|
||||
async send(id, target = 'both') {
|
||||
if (this.loadingItem) {
|
||||
this.log('warn', 'Command ignored while experimental loading is running')
|
||||
|
|
|
|||
|
|
@ -107,17 +107,32 @@ export class Player {
|
|||
return this.loading
|
||||
}
|
||||
|
||||
playPlaylistItem(item) {
|
||||
return this.runCommand(async () => {
|
||||
const number = Number(item)
|
||||
if (!Number.isInteger(number) || number < 1 || number > 10000) throw new Error('Invalid playlist item number')
|
||||
const playlist = await this.client.playlist()
|
||||
if (number > playlist.items.length)
|
||||
throw new Error(`Playlist item ${number} does not exist (${playlist.items.length} items)`)
|
||||
await this.client.selectPlaylistItem(number - 1)
|
||||
})
|
||||
}
|
||||
|
||||
send(id) {
|
||||
return this.runCommand(() => this.client.command(id))
|
||||
}
|
||||
|
||||
runCommand(command) {
|
||||
if (this.loading) return Promise.resolve(false)
|
||||
const pending = this.sendCommand(id)
|
||||
const pending = this.sendCommand(command)
|
||||
this.commands.add(pending)
|
||||
return pending.finally(() => this.commands.delete(pending))
|
||||
}
|
||||
|
||||
async sendCommand(id) {
|
||||
async sendCommand(command) {
|
||||
if (!this.active) return
|
||||
try {
|
||||
await this.client.command(id)
|
||||
await command()
|
||||
await this.pending
|
||||
if (this.active) await this.refresh()
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ test('initialization registers API 2 presets; successful actions recover failed
|
|||
await module.init({ host: '127.0.0.1', port: server.address().port })
|
||||
await module.send('887')
|
||||
assert.equal(state.statuses.at(-1), InstanceStatus.Ok)
|
||||
assert.equal(Object.keys(state.actions).length, 141)
|
||||
assert.equal(Object.keys(state.actions).length, 142)
|
||||
assert.deepEqual(state.sections.flatMap((section) => section.definitions).sort(), Object.keys(state.presets).sort())
|
||||
assert.equal(state.variables.remaining, '00:48')
|
||||
assert.equal(state.feedbacks.playing.callback(), true)
|
||||
|
|
|
|||
|
|
@ -150,3 +150,46 @@ test('modular action, first ten presets and load-result feedback agree on item n
|
|||
assert.equal(fb.load_playlist_item_status.callback({ options: { item: 1 } }).text, '↓\nLOAD\n1')
|
||||
assert.equal(fb.load_result.callback().text, 'LAST\nLOADED\n#12')
|
||||
})
|
||||
|
||||
test('direct playlist play sends only selection, leaves mute alone, and does not record an experimental load', async (t) => {
|
||||
for (const muted of [true, false]) {
|
||||
const { player, data, commands } = await mock(t)
|
||||
data.muted = muted
|
||||
await player.playPlaylistItem(3)
|
||||
assert.deepEqual(commands, ['/command.html?wm_command=-3&index=2'])
|
||||
assert.equal(data.state, 2)
|
||||
assert.equal(data.muted, muted)
|
||||
assert.equal(player.loadResult.status, 'idle')
|
||||
assert.equal(player.state.file, 'Clip 3.mp4')
|
||||
}
|
||||
})
|
||||
|
||||
test('direct playlist play rejects missing items without a playback command', async (t) => {
|
||||
const { player, commands } = await mock(t)
|
||||
await player.playPlaylistItem(13)
|
||||
assert.deepEqual(commands, [])
|
||||
assert.match(player.error, /does not exist/)
|
||||
})
|
||||
|
||||
test('direct playlist action and presets expose selection independently of experimental loads', async () => {
|
||||
let sent
|
||||
const definitions = actions(
|
||||
() => {},
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
(item, target) => {
|
||||
sent = { item, target }
|
||||
},
|
||||
)
|
||||
await definitions.play_playlist_item.callback({ options: { item: 7, target: 'main' } })
|
||||
assert.deepEqual(sent, { item: 7, target: 'main' })
|
||||
for (let item = 1; item <= 10; item++) {
|
||||
const button = presets()[`playlist_play_item_${item}`]
|
||||
assert.deepEqual(button.steps[0].down, [{ actionId: 'play_playlist_item', options: { item, target: 'both' } }])
|
||||
assert.deepEqual(
|
||||
button.feedbacks.map((f) => f.feedbackId),
|
||||
['offline'],
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue