From c33f6ecd3cf12f577eadbadbcc477da36c2f198b Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 12 Nov 2026 19:31:18 +0100 Subject: [PATCH] Show loaded filenames and emphasize numbered Load buttons --- .../media-player-classic/README.md | 20 +++-- .../media-player-classic/companion/HELP.md | 12 ++- .../media-player-classic/src/definitions.js | 74 ++++++++++++++++++- .../media-player-classic/src/feedbacks.js | 32 +++++++- .../test/lifecycle.test.js | 4 +- .../test/playlist.test.js | 2 +- .../media-player-classic/test/state.test.js | 16 +++- 7 files changed, 142 insertions(+), 18 deletions(-) diff --git a/companion-modules/media-player-classic/README.md b/companion-modules/media-player-classic/README.md index 7aeca53..cec76a8 100644 --- a/companion-modules/media-player-classic/README.md +++ b/companion-modules/media-player-classic/README.md @@ -200,7 +200,7 @@ Each navigation button shows **LOADING**, then **LOADED** or **FAILED** with or erase the result. Offline still overrides the navigation buttons. Add the passive **Last load result** preset from **Experimental** for a retained -record. It shows **NO LOAD YET** initially, amber **LOADING**, blue **LAST LOADED**, +record. It shows **NO LOAD YET** initially, amber **LOADING**, blue **LOADED** plus the start of the video name, or red **LAST FAILED**, with the direction. The latest result stays until the next load attempt, even after Play, Stop, a file change, or a disconnect. This is **history, not confirmation that the player is still stopped or connected**. @@ -209,6 +209,10 @@ Connection reconfiguration or module restart resets it. Pressing it does nothing `load_result_status`, `load_result_direction`, `load_result_file`, and `load_result_detail` expose the retained result; add `backup_` for the backup. The filename is recorded on success; failure details explain the problem. +The result button displays up to 16 visible characters of the basename (extension +omitted), split over two lines and ending with an ellipsis when truncated. The +full filename remains in `load_result_file`; `file` is the current player filename. +The display uses the retained successful-load filename, not a later playing file. `load_next_status` / `load_next_detail` and `load_previous_status` / `load_previous_detail` retain their existing operation/current-state behavior. Starting one direction resets the other direction's result to idle. These @@ -241,13 +245,19 @@ playback still requires an MPC-HC open-paused API or a helper on the player PC. **Load playlist item 1–10** presets are in **Experimental**. They use the same experimental mute → select → Stop → verify → restore-mute sequence and the same two-second result display. **Last load result** retains the outcome as **#1**, **#2**, -and so on; `load_result_direction` contains `item_1`, `item_2`, etc. +on failures/in-progress; successful results show the video name. +`load_result_direction` contains `item_1`, `item_2`, etc. + +Numbered Load presets use Companion 5 layered graphics: a small **↓ LOAD** title +above a large item number. Re-add existing copied presets to get this layout; +linked presets update automatically. The action is reusable, not limited to ten items. Duplicate a numbered preset -and edit **Playlist item number (1 = first)** in its action and **Load playlist -item status** feedback to the same number. Update its base label too if desired. +and edit **Playlist item number (1 = first)** in its action and all three **Load +playlist item state** feedbacks to the same number. Set the large number text +layer to match. The small title and large number are separate editable layers. Numbers from 1 to 10000 are supported, subject to the actual playlist length. -The feedback renders the chosen number; preserve it when customizing the button. +The title changes for loading, loaded, failed, or offline; the large number stays visible. These are **playlist positions, not saved file identities**. Reordering a playlist changes what a numbered button loads. Presets remain available even if the diff --git a/companion-modules/media-player-classic/companion/HELP.md b/companion-modules/media-player-classic/companion/HELP.md index ff8b722..2a9d554 100644 --- a/companion-modules/media-player-classic/companion/HELP.md +++ b/companion-modules/media-player-classic/companion/HELP.md @@ -78,7 +78,8 @@ Re-add existing copied presets to remove the EXP label; linked presets update. The **Experimental** folder also contains ten numbered **Load playlist item** presets. To make another, duplicate one and set its action's item number and -**Load playlist item status** feedback's item number to match (1 = first). +**Load playlist item state** feedbacks' item numbers to match (1 = first), +and update the large number text layer. A small title sits above the large number. The action accepts 1–10000, but checks the actual playlist before muting. Missing items or unavailable `/playlist.json` abort without navigation. @@ -86,19 +87,22 @@ Numbers follow playlist order, not file identity; keep main/backup orders aligne The same experimental brief-playback limitation applies. Selection is verified by index, changed filename, and stable stopped state; playlist changes abort. An already selected, loaded item is stopped without reopening. Duplicate reported -filenames across different entries cannot be confirmed. Last load result shows -**#N**, and `load_result_direction` uses `item_N`. Results reset after two seconds +filenames across different entries cannot be confirmed. Last load result shows the video name on success and **#N** on failure, and `load_result_direction` uses `item_N`. Results reset after two seconds on the numbered buttons and remain on the last-result display. ### Load status display Load previous/next show their result for two seconds, then return to their normal labels. Add **Last load result** from **Experimental** to keep the latest result: -neutral **NO LOAD YET**, amber **LOADING**, blue **LAST LOADED**, or red **LAST FAILED**, +neutral **NO LOAD YET**, amber **LOADING**, blue **LOADED** with the video name, or red **LAST FAILED**, with NEXT/PREV. This passive button keeps the result until the next load attempt, even after playback changes or disconnection. It records history, not current player readiness. Reconfiguration/restart clears it. +Successful results show the first 16 characters of the filename without its +extension; the full name is in `load_result_file`. Re-add copied numbered Load +presets for the new layered layout. + Use `load_result_status`, `load_result_direction`, `load_result_file`, and `load_result_detail` for details; backup equivalents have a `backup_` prefix. diff --git a/companion-modules/media-player-classic/src/definitions.js b/companion-modules/media-player-classic/src/definitions.js index bdee22b..6d5b79c 100644 --- a/companion-modules/media-player-classic/src/definitions.js +++ b/companion-modules/media-player-classic/src/definitions.js @@ -103,7 +103,7 @@ export function presets(label = 'MPC_DEV') { transport_load_result: { type: 'simple', name: 'Last load result', - style: { text: 'NO LOAD\nYET', size: 12, color: colors.white, bgcolor: colors.dark, show_topbar: true }, + style: { text: 'NO LOAD\nYET', size: 'auto', color: colors.white, bgcolor: colors.dark, show_topbar: true }, steps: [{ down: [], up: [] }], feedbacks: [{ feedbackId: 'load_result', options: {} }], }, @@ -178,11 +178,77 @@ export function presets(label = 'MPC_DEV') { return [ `transport_load_item_${item}`, { - type: 'simple', + type: 'layered', name: `Load playlist item ${item}`, - style: { text: `↓\nLOAD\n${item}`, size: 12, color: colors.white, bgcolor: 0x243b50, show_topbar: true }, + 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: [{ feedbackId: 'load_playlist_item_status', options: { item } }, offline], + 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, + })), + ], + }, + ], }, ] }), diff --git a/companion-modules/media-player-classic/src/feedbacks.js b/companion-modules/media-player-classic/src/feedbacks.js index 4ea7c3b..5009f70 100644 --- a/companion-modules/media-player-classic/src/feedbacks.js +++ b/companion-modules/media-player-classic/src/feedbacks.js @@ -7,6 +7,20 @@ export const colors = { white: 0xffffff, } +export function shortFilename(file) { + const name = String(file ?? '') + .split(/[\\/]/) + .at(-1) + .replace(/\.[^.]+$/, '') + .replace(/\s+/g, ' ') + .trim() + const characters = [...new Intl.Segmenter(undefined, { granularity: 'grapheme' }).segment(name)].map( + (part) => part.segment, + ) + const visible = characters.length > 16 ? [...characters.slice(0, 15), '…'] : characters + return visible.length > 8 ? `${visible.slice(0, 8).join('')}\n${visible.slice(8).join('')}` : visible.join('') +} + export function progressBar(state, image) { if (!image) return {} const width = Math.max(1, Math.min(2048, Math.floor(image.width))) @@ -107,6 +121,22 @@ export function feedbacks(getState, getSync = () => null, getLoadStatus = () => }, ]), ), + load_playlist_item_state: { + type: 'boolean', + name: 'Load playlist item state', + options: [ + { type: 'number', id: 'item', label: 'Playlist item number', default: 1, min: 1, max: 10000, step: 1 }, + { + type: 'dropdown', + id: 'state', + label: 'State', + default: 'loading', + choices: ['loading', 'ready', 'failed'].map((id) => ({ id, label: id })), + }, + ], + defaultStyle: { bgcolor: colors.blue }, + callback: (feedback) => getLoadStatus(`item_${feedback.options.item}`) === feedback.options.state, + }, load_playlist_item_status: { type: 'advanced', name: 'Load playlist item status', @@ -138,7 +168,7 @@ export function feedbacks(getState, getSync = () => null, getLoadStatus = () => text: { loading: `LOADING\n${direction}`, - ready: `LAST\nLOADED\n${direction}`, + ready: `LOADED\n${shortFilename(result.file) || direction}`, failed: `LAST\nFAILED\n${direction}`, }[result?.status] ?? 'NO LOAD\nYET', bgcolor: { loading: colors.amber, ready: colors.blue, failed: colors.red }[result?.status] ?? colors.dark, diff --git a/companion-modules/media-player-classic/test/lifecycle.test.js b/companion-modules/media-player-classic/test/lifecycle.test.js index 9397cbd..a141788 100644 --- a/companion-modules/media-player-classic/test/lifecycle.test.js +++ b/companion-modules/media-player-classic/test/lifecycle.test.js @@ -51,7 +51,7 @@ test('initialization registers API 2 presets; successful actions recover failed 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) - assert.ok(Object.values(state.presets).every((preset) => preset.type === 'simple')) + assert.ok(Object.values(state.presets).every((preset) => ['simple', 'layered'].includes(preset.type))) status = 503 await module.send('887') assert.equal(state.statuses.at(-1), InstanceStatus.ConnectionFailure) @@ -199,7 +199,7 @@ for (const direction of ['next', 'previous']) { assert.equal(state.variables.load_result_status, 'ready') assert.equal(state.variables.load_result_direction, direction) assert.equal(state.variables.load_result_file, 'Next.mp4') - const resultText = direction === 'next' ? 'LAST\nLOADED\nNEXT' : 'LAST\nLOADED\nPREV' + const resultText = 'LOADED\nNext' assert.equal(state.feedbacks.load_result.callback().text, resultText) data.state = 2 await module.refresh() diff --git a/companion-modules/media-player-classic/test/playlist.test.js b/companion-modules/media-player-classic/test/playlist.test.js index 100925d..068fd2d 100644 --- a/companion-modules/media-player-classic/test/playlist.test.js +++ b/companion-modules/media-player-classic/test/playlist.test.js @@ -148,7 +148,7 @@ test('modular action, first ten presets and load-result feedback agree on item n ) assert.equal(fb.load_playlist_item_status.callback({ options: { item: 12 } }).text, '↓\nLOADED\n12') 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') + assert.equal(fb.load_result.callback().text, 'LOADED\n#12') }) test('direct playlist play sends only selection, leaves mute alone, and does not record an experimental load', async (t) => { diff --git a/companion-modules/media-player-classic/test/state.test.js b/companion-modules/media-player-classic/test/state.test.js index 95a4f16..dd9f448 100644 --- a/companion-modules/media-player-classic/test/state.test.js +++ b/companion-modules/media-player-classic/test/state.test.js @@ -1,7 +1,7 @@ import assert from 'node:assert/strict' import { test } from 'node:test' import { normalizeStatus, parseVariables, variables, clock } from '../src/state.js' -import { feedbacks, progressBar, transportBorder } from '../src/feedbacks.js' +import { feedbacks, progressBar, transportBorder, shortFilename } from '../src/feedbacks.js' import { presets } from '../src/definitions.js' import { status, htmlStatus } from './fixture.js' @@ -147,3 +147,17 @@ test('split timer presets are passive and countdown urgency follows remaining ti } assert.equal(feedbacks(() => null).split_timer_color.callback({ options: { mode: 'remaining' } }).color, 0x889099) }) + +test('loaded filename preview uses the basename, wraps and truncates without splitting Unicode characters', () => { + assert.equal(shortFilename('C:\\Videos\\Opening film.mp4'), 'Opening \nfilm') + assert.equal(shortFilename('/media/12345678901234567890.mp4'), '12345678\n9012345…') + assert.equal(shortFilename('é👨‍👩‍👧‍👦.mp4'), 'é👨‍👩‍👧‍👦') + assert.equal(shortFilename(''), '') + const fb = feedbacks( + () => null, + () => null, + () => 'idle', + () => ({ status: 'ready', file: '/media/Intro.mp4', direction: 'item_1' }), + ) + assert.equal(fb.load_result.callback().text, 'LOADED\nIntro') +})