diff --git a/crates/ui/src/player/equalizer.rs b/crates/ui/src/player/equalizer.rs index 1b219e145..cab1bc253 100644 --- a/crates/ui/src/player/equalizer.rs +++ b/crates/ui/src/player/equalizer.rs @@ -1516,6 +1516,7 @@ impl Editor { let weak = Rc::downgrade(self); glib::spawn_future_local(async move { let Some(root) = root.upgrade() else { return }; + crate::widgets::popup::hide_popover_while_open(&confirm, &root); if confirm.choose_future(Some(&root)).await != "accept" { return; } diff --git a/crates/ui/src/widgets/popup.rs b/crates/ui/src/widgets/popup.rs index a062f789b..aa95febab 100644 --- a/crates/ui/src/widgets/popup.rs +++ b/crates/ui/src/widgets/popup.rs @@ -7,9 +7,29 @@ where D: IsA + Clone + 'static, { install_light_dismiss(dialog); + hide_popover_while_open(dialog, parent); dialog.present(Some(parent)); } +/// Dialogs draw inside the window, under any open popover: the popover holding `parent` hides +/// while `dialog` is open and comes back when it closes. +pub fn hide_popover_while_open(dialog: &impl IsA, parent: &impl IsA) { + let Some(popover) = parent + .ancestor(gtk::Popover::static_type()) + .and_downcast::() + .filter(|popover| popover.is_visible()) + else { + return; + }; + popover.popdown(); + let popover = popover.downgrade(); + dialog.connect_closed(move |_| { + if let Some(popover) = popover.upgrade() { + popover.popup(); + } + }); +} + /// Presents a page's Customize display dialog as tall as its rows, up to the large popup height. pub fn present_settings_dialog(dialog: &adw::PreferencesDialog, window: &impl IsA) { let width = crate::widgets::layout::large_popup_content_width(560); diff --git a/crates/ui/src/widgets/settings/mod.rs b/crates/ui/src/widgets/settings/mod.rs index cc4058838..0e9a8345b 100644 --- a/crates/ui/src/widgets/settings/mod.rs +++ b/crates/ui/src/widgets/settings/mod.rs @@ -37,6 +37,7 @@ pub fn connect_confirmed_reset( dialog.set_default_response(Some("cancel")); dialog.set_close_response("cancel"); let reset = Rc::clone(&reset); + crate::widgets::popup::hide_popover_while_open(&dialog, button); dialog.choose( Some(button), None::<>k::gio::Cancellable>, diff --git a/crates/web/src/equalizer.rs b/crates/web/src/equalizer.rs index 0b3a25d13..b99e913af 100644 --- a/crates/web/src/equalizer.rs +++ b/crates/web/src/equalizer.rs @@ -7,6 +7,27 @@ pub(super) fn routes() -> Router { .route("/api/equalizer/presets", get(presets)) .route("/api/equalizer/events", get(events)) .route("/api/equalizer/response", get(response)) + .route("/api/playback/outputs", get(outputs)) +} +/// This host's audio devices, as GTK's Audio output lists them, and the receiver's name while casting. +async fn outputs(State(products): State) -> Result, Error> { + let playback = products.playback.clone(); + let selected = products.settings.load().playback.audio_output.clone(); + let value = tokio::task::spawn_blocking(move || { + let devices: Vec<_> = playback + .available_audio_outputs() + .into_iter() + .map(|output| json!({"id": output.id, "name": output.name})) + .collect(); + let casting = match playback.playback_output() { + playback::PlaybackOutput::Remote(output) => Some(output.name), + _ => None, + }; + json!({"devices": devices, "selected": selected, "casting": casting}) + }) + .await + .map_err(internal)?; + Ok(json_response(StatusCode::OK, value)) } #[derive(Default, Deserialize)] struct Target { diff --git a/crates/web/src/help.json b/crates/web/src/help.json index f6002d68f..2965a78d7 100644 --- a/crates/web/src/help.json +++ b/crates/web/src/help.json @@ -326,7 +326,8 @@ "POST /api/equalizer": "Shared EQ operations: preview {output,edit}, commit {output}, select {output,preset:null or ID}, save {output,name:null or text}, duplicate {output,name}, rename {id,name}, delete {id}, import {output,text,format:Json|Apo}, export {output,format}, assign {output,assigned}, apply {output}. Edits use enum objects such as {BandGain:{index:0,value:6}} and {Enabled:{value:true}}. Preview does not write settings; commit persists the final editor. Cast previews await apply except discrete bypass/format changes.", "GET /api/equalizer/presets": "Built-in and named custom preset identities and names. Custom is the retained draft, selected with preset:null.", "GET /api/equalizer/events": "Equalizer server-sent events. Optional output, meter=true and spectrum=true. Measurement stops when the connection closes.", - "GET /api/equalizer/response": "Calculated response from the shared filter model, with frequency and dB arrays. Uses actual stream sample rate or 48 kHz for preview." + "GET /api/equalizer/response": "Calculated response from the shared filter model, with frequency and dB arrays. Uses actual stream sample rate or 48 kHz for preview.", + "GET /api/playback/outputs": "This host's audio devices as {devices:[{id,name}], selected:null or a device id, casting:null or the receiver's name}. Choose one with the /playback/audio_output preference (null is the system default)." }, "commands": "Playback and queue commands return 202 when received. Check playback status or follow playback updates to see the result or any error. Source and playlist changes return when finished. Use IDs exactly as returned, including negative numbers. Positions and offsets start at zero. Each copy of a track in a playlist or queue has its own ID.", "login": "Keep the login connection open until sign-in finishes. Closing it cancels sign-in. Updates use event: login with JSON {event,data}, or {error}. Plex also accepts {method: password, data: {username,password,verification_code:null}}; Emby accepts {method: password, data: {username,password}}. Use the returned login details unchanged when adding the source.", diff --git a/crates/web/src/preferences.rs b/crates/web/src/preferences.rs index 65005023b..655a9faca 100644 --- a/crates/web/src/preferences.rs +++ b/crates/web/src/preferences.rs @@ -94,6 +94,7 @@ const SETTINGS: &[&str] = &[ "/external_site_links/lastfm", "/external_site_links/musicbrainz", "/external_site_links/server", + "/playback/audio_output", "/playback/transition_mode", "/playback/crossfade_seconds", "/playback/skip_same_album_crossfade", diff --git a/locales/rufin.pot b/locales/rufin.pot index 1812dac4c..d19b037db 100644 --- a/locales/rufin.pot +++ b/locales/rufin.pot @@ -676,9 +676,6 @@ msgstr "" msgid "Auto DJ" msgstr "" -msgid "Auto" -msgstr "" - msgid "AutoEQ / APO" msgstr "" @@ -747,12 +744,6 @@ msgstr "" msgid "Band" msgstr "" -msgid "Bands" -msgstr "" - -msgid "Bandwidth" -msgstr "" - msgid "Bar count" msgstr "" @@ -1230,10 +1221,6 @@ msgstr "" msgid "Copy link" msgstr "" -#, rust-format -msgid "Copy of {name}" -msgstr "" - msgid "Copy" msgstr "" @@ -1757,9 +1744,6 @@ msgstr "" msgid "Enable" msgstr "" -msgid "Enabled" -msgstr "" - msgid "Encoding peak" msgstr "" @@ -3571,9 +3555,6 @@ msgstr "" msgid "Preserve pitch" msgstr "" -msgid "Preset name" -msgstr "" - msgid "Preset text" msgstr "" @@ -4937,9 +4918,6 @@ msgstr "" msgid "Toggle Fullscreen" msgstr "" -msgid "Tone and channels" -msgstr "" - msgid "Tools" msgstr "" @@ -5093,9 +5071,6 @@ msgstr "" msgid "Unplayed" msgstr "" -msgid "Unsaved" -msgstr "" - msgid "Untitled" msgstr "" diff --git a/web/equalizer.js b/web/equalizer.js index 38e09707f..50d7f0079 100644 --- a/web/equalizer.js +++ b/web/equalizer.js @@ -1,10 +1,11 @@ import { api } from "./connection.js"; -import { tr, notice, openPopup } from "./ui.js"; +import { tr, notice, openPopup, setIcon } from "./ui.js"; const $ = (id) => document.getElementById(`eq-${id}`); -let view, stream, sending, response, deferredView, clipTimer, nameAction, responseSending, signature = "", latestProfile = ""; +let view, stream, sending, response, deferredView, clipTimer, nameAction, responseSending, signature = "", latestProfile = "", selected = 0; const pending = new Map(); let writes = Promise.resolve(); const number = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 }); +const signed = (db) => `${db >= 0 ? "+" : ""}${db.toFixed(1)} dB`; function element(tag, text) { const el = document.createElement(tag); if (text) el.textContent = text; return el; } function mode() { return document.querySelector("#eq-mode input:checked").value; } function checked(id, value) { $(id).checked = value; } @@ -15,7 +16,7 @@ function request(operation, extra = {}) { writes = result.catch(() => {}); return result; } -function report(error) { notice(error.message); $("status").textContent = error.message; } +function report(error) { notice(error.message); } function queue(type, data, key = type) { pending.set(`${view.output}:${key}:${data?.index ?? ""}`, { output: view.output, edit: { [type]: data } }); if (!sending) sending = drain().finally(() => { sending = null; if (deferredView) { const next = deferredView; deferredView = null; render(next); } }); @@ -27,9 +28,9 @@ async function drain() { async function flush() { while (sending) await sending; } async function commit() { await flush(); await request("commit"); } async function operation(name, extra) { const output = view.output; await flush(); const result = await request(name, { output, ...extra }); await refreshPresets(); render(await api("/equalizer")); return result; } -// Preamp, bass, treble and balance each show their Reset while away from 0, as GTK's entries. +// Preamp, bass, treble and balance: a slider and a field, with Reset while away from 0, as GTK's entries. const tones = [["preamp", "Preamp"], ["bass", "Bass"], ["treble", "Treble"], ["balance", "Balance"]]; -function showResets() { for (const [id] of tones) $(`${id}-reset`).style.visibility = Number($(id).value) === 0 ? "hidden" : ""; } +function showResets() { for (const [id] of tones.slice(1)) $(`${id}-reset`).style.visibility = Number($(id).value) === 0 ? "hidden" : ""; } function action(fn) { return () => Promise.resolve().then(fn).catch(report); } // The one equalizer body sits in its dialog (Preferences), on the playback settings popover's page, // or in the fullscreen player as one of its views. @@ -48,45 +49,90 @@ function watch() { stream = new EventSource(`/api/equalizer/events?meter=true&spectrum=${$("spectrum").checked}`); stream.addEventListener("equalizer", event => render(JSON.parse(event.data))); } -async function refreshPresets() { - const list = await api("/equalizer/presets"); - $("preset").replaceChildren(...list.map(p => { const o = element("option", p.builtin ? tr(p.name) : p.name); o.value = p.id; return o; }), Object.assign(element("option", tr("Custom")), { value: "" })); +// This host's audio devices, as GTK's Audio output: System default, the devices, and a chosen +// device that is away. While casting the bar's picker is insensitive and the equalizer names the receiver. +// A host that lists no devices, as Android whose system routes the sound, shows no picker. +export async function showOutputs() { + const { devices, selected, casting } = await api("/playback/outputs"); + const choice = devices.length > 0 || selected !== null; + const options = [[null, tr("System default")], ...devices.map(device => [device.id, device.name])]; + if (!options.some(([id]) => id === selected)) options.push([selected, tr("Unavailable output")]); + for (const select of document.querySelectorAll("select.audio-output")) { + select.replaceChildren(...options.map(([id, name]) => Object.assign(element("option", name), { value: JSON.stringify(id) }))); + select.value = JSON.stringify(selected); select.title = select.selectedOptions[0]?.textContent ?? ""; + select.disabled = !!casting; + } + document.querySelector("#playback-settings-main select.audio-output").parentElement.hidden = !choice; + $("output").hidden = !!casting || !choice; $("output-name").hidden = !casting; $("output-name").textContent = casting ?? ""; +} +// Custom first, then the presets, as GTK's Saved preset row; a changed preset's name ends in " *". +let presets = []; +async function refreshPresets() { presets = await api("/equalizer/presets"); showPresets(); } +function showPresets() { + if (document.activeElement === $("preset")) return; + const title = (p) => (p.builtin ? tr(p.name) : p.name) + (view?.modified && view.preset_id === p.id ? " *" : ""); + $("preset").replaceChildren(Object.assign(element("option", tr("Custom")), { value: "" }), ...presets.map(p => Object.assign(element("option", title(p)), { value: p.id }))); if (view) $("preset").value = view.preset_id || ""; } function render(next) { if (!shown()) return; const busy = document.activeElement?.closest("#eq-body") && (pending.size || sending); - if (busy && view && view.output === next.output) { deferredView = next; view.peak_db = next.peak_db; view.spectrum_db = next.spectrum_db; draw(); return; } + if (busy && view && view.output === next.output) { deferredView = next; view.peak_db = next.peak_db; view.spectrum_db = next.spectrum_db; showPeak(); draw(); return; } + const previous = view; view = next; - checked("enabled", view.enabled); checked("auto", view.profile.automatic_preamp); checked("crossfeed", view.crossfeed); checked("mono", view.mono); checked("assigned", view.assigned); - value("preset", view.preset_id || ""); value("layout", view.profile.layout); value("preamp", view.preamp_db); value("preamp-number", view.preamp_db); - value("bass", view.profile.bass_db); value("treble", view.profile.treble_db); value("balance", view.balance); value("cast-format", view.cast_format); - $("bass-value").textContent = `${number.format(view.profile.bass_db)} dB`; $("treble-value").textContent = `${number.format(view.profile.treble_db)} dB`; showResets(); - $("rename").disabled = view.preset_builtin || !(view.preset_id || view.save_target); $("delete").disabled = $("rename").disabled; - $("apply").hidden = !view.cast || !view.pending; $("cast-format").hidden = !view.cast; $("spectrum").disabled = view.cast; - for (const input of document.querySelectorAll("#eq-body input, #eq-body select")) input.disabled = !view.available; + if (previous && previous.cast !== view.cast) void showOutputs().catch(report); + const profile = view.profile; + checked("enabled", view.enabled); checked("auto", profile.automatic_preamp); checked("crossfeed", view.crossfeed); checked("mono", view.mono); checked("assigned", view.assigned); + if (!previous || previous.preset_id !== view.preset_id || previous.name !== view.name || previous.modified !== view.modified) showPresets(); + value("layout", profile.layout); + for (const id of ["preamp", "parametric-preamp"]) value(id, profile.manual_preamp_db); + value("preamp-scale", profile.manual_preamp_db); + for (const [id, current] of [["bass", profile.bass_db], ["treble", profile.treble_db], ["balance", view.balance]]) { value(id, current); value(`${id}-scale`, current); } + showResets(); + $("headroom").textContent = signed(view.enabled && profile.automatic_preamp ? view.preamp_db : 0); + $("output-gain").textContent = signed(view.enabled ? view.preamp_db : 0); + $("unavailable").hidden = view.available; + for (const control of document.querySelectorAll("#eq-body :is(input, select, .eq-actions button, #eq-editor button, #eq-cast button)")) control.disabled = !view.available; + const saved = !!view.preset_id && !view.preset_builtin; + $("save").disabled ||= !(view.modified || !view.preset_id); + $("rename").disabled ||= !saved; $("delete").disabled ||= !saved; + $("cast").hidden = !view.cast; value("cast-format", view.cast_format); $("apply").disabled ||= !view.pending; $("spectrum").disabled = view.cast || !view.available; - $("clip").textContent = view.cast ? tr("Encoding peak") : tr("Clipping"); - $("peak").textContent = view.cast && view.peak_db.length ? `${number.format(Math.max(...view.peak_db))} dBFS` : ""; - $("status").textContent = !view.available ? tr("Equalizer is controlled by the receiver") : view.error || (view.modified ? tr("Unsaved") : ""); - if (view.profile.layout === "Parametric") document.querySelector('#eq-mode input[value="parametric"]').checked = true; - const nextSignature = `${mode()}:${JSON.stringify(view.profile.bands.map(b => [mode() === "graphic" ? b.frequency_hz : null, b.kind, Object.keys(b.width)[0]]))}`; + $("add").disabled = !view.available || profile.bands.length >= 64; + $("error").hidden = !view.error; $("error").textContent = view.error || ""; + showPeak(); + if (!previous || previous.profile.layout !== profile.layout) document.querySelector(`#eq-mode input[value="${profile.layout === "Parametric" ? "parametric" : "graphic"}"]`).checked = true; + const nextSignature = `${mode()}:${JSON.stringify(profile.bands.map(b => [b.frequency_hz, b.kind, Object.keys(b.width)[0]]))}`; if (signature !== nextSignature) { signature = nextSignature; buildBands(); } + selected = Math.min(selected, Math.max(0, profile.bands.length - 1)); + value("band-picker", selected); value("band-gain", profile.bands[selected]?.gain_db ?? 0); for (const input of document.querySelectorAll("[data-eq-band]")) { - const b = view.profile.bands[Number(input.dataset.eqBand)]; if (document.activeElement === input && input.type === "number") continue; - if (input.dataset.field === "gain") input.value = b.gain_db; + const b = profile.bands[Number(input.dataset.eqBand)]; if (document.activeElement === input && input.type === "number") continue; + if (input.dataset.field === "gain") { input.value = b.gain_db; if (input.type === "range") input.title = `${number.format(b.frequency_hz)} Hz: ${b.gain_db >= 0 ? "+" : ""}${number.format(b.gain_db)} dB`; } if (input.dataset.field === "frequency") input.value = b.frequency_hz; if (input.dataset.field === "width") input.value = Object.values(b.width)[0].value; if (input.dataset.field === "enabled") input.checked = b.enabled; if (input.dataset.field === "kind") input.value = b.kind; if (input.dataset.field === "unit") input.value = Object.keys(b.width)[0]; + if (input.dataset.field === "inactive") input.hidden = !view.sample_rate || b.frequency_hz < view.sample_rate / 2; } draw(); - const stamp = JSON.stringify([view.output, view.enabled, view.sample_rate, view.profile]); + const stamp = JSON.stringify([view.output, view.enabled, view.sample_rate, profile]); if (stamp !== latestProfile) { latestProfile = stamp; void loadResponse(stamp).catch(report); } } -function bandInput(index, field, min, max, step = .1) { - const input = element("input"); Object.assign(input, { type: "number", min, max, step: "any" }); input.dataset.eqBand = index; input.dataset.field = field; +// Sample peak, or Encoding peak while casting; Clipping shows for a second after a peak at 0 dBFS. +function showPeak() { + const title = $("peak-title"); + title.dataset.local ??= title.textContent; + title.textContent = view.cast ? title.dataset.cast : title.dataset.local; + $("peak").textContent = view.peak_db.map(db => `${db.toFixed(1)} dBFS`).join(" / "); + if (view.peak_db.some(db => db >= 0)) { + $("clip").hidden = false; clearTimeout(clipTimer); + clipTimer = setTimeout(() => { $("clip").hidden = true; }, 1000); + } +} +function bandInput(index, field) { + const input = element("input"); Object.assign(input, { type: "number", step: "any" }); input.dataset.eqBand = index; input.dataset.field = field; return input; } function bindNumber(input, type, payload, reflect = () => {}) { @@ -100,46 +146,64 @@ function bindNumber(input, type, payload, reflect = () => {}) { input.addEventListener("blur", action(commit)); input.addEventListener("keydown", event => { if (event.key === "Enter") { preview(); void commit().catch(report); } }); } +function bindSlider(slider, type, payload, reflect) { + slider.addEventListener("input", () => { const value = Number(slider.value); reflect(value); queue(type, payload(value)); draw(); }); + slider.addEventListener("change", action(commit)); +} +const frequency = (hz) => (hz >= 1000 ? `${number.format(hz / 1000)}k` : number.format(hz)); function buildBands() { - const parametric = mode() === "parametric"; - $("bands").replaceChildren(); $("filters").replaceChildren(); $("bands").hidden = parametric; $("add").hidden = !parametric; $("layout").hidden = parametric; - $("graph").style.minWidth = `${parametric ? 350 : Math.max(350, view.profile.bands.length * parseFloat(getComputedStyle($("graph")).getPropertyValue("--eq-band-min")) + 48)}px`; - view.profile.bands.forEach((band, index) => { + const parametric = mode() === "parametric", bands = view.profile.bands, dense = bands.length > 10; + $("bands").replaceChildren(); $("filters").replaceChildren(); + $("bands").classList.toggle("dense", dense); + for (const id of ["layout"]) $(id).hidden = parametric; + $("band-value").hidden = parametric || !dense; + $("add").hidden = !parametric; $("parametric-preamp-field").hidden = !parametric; $("filters").hidden = !parametric; + $("preamp-column").hidden = parametric; $("bands").hidden = parametric; + $("graph").style.minWidth = `${parametric ? 0 : bands.length * (dense ? 10 : 26)}px`; + $("band-picker").replaceChildren(...bands.map((band, index) => Object.assign(element("option", `${number.format(band.frequency_hz)} Hz`), { value: index }))); + bands.forEach((band, index) => { if (!parametric) { const column = element("div"); column.className = "eq-band"; - const gain = bandInput(index, "gain", -24, 12); gain.ariaLabel = `${number.format(band.frequency_hz)} Hz, dB`; - const slider = bandInput(index, "gain", -24, 12); slider.type = "range"; slider.step = ".1"; slider.ariaLabel = `${number.format(band.frequency_hz)} Hz`; - slider.addEventListener("input", () => { view.profile.bands[index].gain_db = Number(slider.value); gain.value = slider.value; queue("BandGain", { index, value: Number(slider.value) }, `gain:${index}`); draw(); }); - slider.addEventListener("change", action(commit)); - bindNumber(gain, "BandGain", value => ({ index, value }), value => { view.profile.bands[index].gain_db = value; slider.value = value; }); - const reset = () => { queue("BandGain", { index, value: 0 }, `gain:${index}`); void commit().catch(report); }; - slider.addEventListener("dblclick", reset); - const label = element("button", band.frequency_hz >= 1000 ? `${number.format(band.frequency_hz / 1000)}k` : number.format(band.frequency_hz)); label.type = "button"; label.title = tr("Reset"); label.addEventListener("click", reset); - column.append(gain, slider, label); $("bands").append(column); + const gain = bandInput(index, "gain"); gain.min = -24; gain.max = 12; gain.ariaLabel = tr("Gain"); gain.hidden = dense; + const slider = bandInput(index, "gain"); Object.assign(slider, { type: "range", min: -24, max: 12, step: ".1" }); slider.ariaLabel = `${number.format(band.frequency_hz)} Hz`; + const reflect = value => { view.profile.bands[index].gain_db = value; gain.value = value; slider.value = value; if (selected === index) $("band-gain").value = value; }; + bindSlider(slider, "BandGain", value => ({ index, value }), reflect); + bindNumber(gain, "BandGain", value => ({ index, value }), reflect); + slider.addEventListener("focus", () => selectBand(index)); + slider.addEventListener("pointerdown", () => selectBand(index)); + slider.addEventListener("dblclick", () => { reflect(0); queue("BandGain", { index, value: 0 }, `gain:${index}`); void commit().catch(report); }); + column.append(gain, slider); $("bands").append(column); } else { const row = element("div"); row.className = "eq-filter"; - const enabled = bandInput(index, "enabled", 0, 1); enabled.type = "checkbox"; enabled.ariaLabel = tr("Enabled"); enabled.addEventListener("change", action(async () => { queue("BandEnabled", { index, value: enabled.checked }); await commit(); })); + const enabled = bandInput(index, "enabled"); enabled.type = "checkbox"; enabled.ariaLabel = tr("Band"); + enabled.addEventListener("change", action(async () => { queue("BandEnabled", { index, value: enabled.checked }); await commit(); })); + const toggle = element("label"); toggle.className = "checkbox"; toggle.append(enabled, element("span", String(index + 1))); const kind = element("select"); kind.dataset.eqBand = index; kind.dataset.field = "kind"; kind.ariaLabel = tr("Filter type"); for (const [id, name] of [["Peak", tr("Peak")], ["LowShelf", tr("Low shelf")], ["HighShelf", tr("High shelf")]]) kind.append(Object.assign(element("option", name), { value: id })); kind.addEventListener("change", action(async () => { queue("BandKind", { index, value: kind.value }); await commit(); })); - const frequency = bandInput(index, "frequency", 0, 100000); frequency.ariaLabel = tr("Frequency"); - const gain = bandInput(index, "gain", -24, 12); gain.ariaLabel = tr("Gain"); - const unit = Object.keys(band.width)[0]; const width = bandInput(index, "width", 0, unit === "Q" ? "" : 100000, .01); width.ariaLabel = unit === "Q" ? "Q" : tr("Bandwidth"); - for (const [input, type] of [[frequency, "BandFrequency"], [gain, "BandGain"], [width, "BandWidth"]]) bindNumber(input, type, value => ({ index, value: type === "BandWidth" ? { [unit]: { value } } : value })); + const hz = bandInput(index, "frequency"); hz.min = 0; hz.title = hz.ariaLabel = tr("Frequency · Hz"); + const gain = bandInput(index, "gain"); gain.min = -24; gain.max = 12; gain.title = gain.ariaLabel = tr("Gain · dB"); + const unit = Object.keys(band.width)[0]; + const width = bandInput(index, "width"); width.min = 0; width.title = width.ariaLabel = tr("Width"); + for (const [input, type] of [[hz, "BandFrequency"], [gain, "BandGain"], [width, "BandWidth"]]) bindNumber(input, type, value => ({ index, value: type === "BandWidth" ? { [unit]: { value } } : value })); const units = element("select"); units.ariaLabel = tr("Width unit"); units.dataset.eqBand = index; units.dataset.field = "unit"; - for (const id of ["Q", "Hertz"]) units.append(Object.assign(element("option", id === "Q" ? "Q" : "Hz"), { value: id })); - units.value = unit; + for (const id of ["Q", "Hertz"]) units.append(Object.assign(element("option", id === "Q" ? tr("Q") : tr("Hz")), { value: id })); units.addEventListener("change", action(async () => { queue("BandWidthUnit", { index, q: units.value === "Q" }); await commit(); })); - const remove = element("button", tr("Delete")); remove.type = "button"; remove.addEventListener("click", action(async () => { await flush(); queue("RemoveBand", { index }); await commit(); })); - row.append(enabled, kind, frequency, element("span", "Hz"), gain, element("span", "dB"), width, units, remove); $("filters").append(row); + const inactive = element("span"); inactive.className = "icon"; inactive.dataset.eqBand = index; inactive.dataset.field = "inactive"; inactive.title = tr("Inactive at this sample rate"); setIcon(inactive, "rufin-dialog-information-symbolic"); + const remove = element("button"); remove.type = "button"; remove.className = "icon-button"; remove.title = remove.ariaLabel = tr("Remove band"); remove.append(Object.assign(element("span"), { className: "icon" })); setIcon(remove.firstElementChild, "rufin-list-remove-symbolic"); + remove.addEventListener("click", action(async () => { await flush(); queue("RemoveBand", { index }); await commit(); })); + row.append(toggle, kind, hz, gain, width, units, inactive, remove); $("filters").append(row); } }); } +function selectBand(index) { selected = index; $("band-picker").value = index; value("band-gain", view.profile.bands[index]?.gain_db ?? 0); } +// The response curve shows when asked for, and always in the parametric editor, as GTK's. +const wantsResponse = () => $("response").checked || mode() === "parametric"; async function loadResponse() { - if (responseSending || !$("response").checked || !view) return; + if (responseSending || !wantsResponse() || !view) return; responseSending = true; try { - while (shown() && $("response").checked) { + while (shown() && wantsResponse()) { const stamp = latestProfile; const next = await api(`/equalizer/response?output=${encodeURIComponent(view.output)}`); if (stamp === latestProfile) { response = next; draw(); break; } @@ -147,52 +211,90 @@ async function loadResponse() { } finally { responseSending = false; } } +// The plot sits under the band sliders: a slider starts below its 26 px gain field and 6 px gap, and +// its knob's centre stops 8 px inside either end, so 12 dB is 40 px down and the travel is 196 px. +const PLOT_TOP = 40, PLOT_HEIGHT = 196, AXIS = 28; function draw() { if (!view) return; - const svg = $("plot"), width = $("graph").clientWidth || 400, height = 265; + const svg = $("plot"), width = $("graph").clientWidth || 400, height = $("graph").clientHeight || 264; svg.setAttribute("viewBox", `0 0 ${width} ${height}`); svg.replaceChildren(); const node = (tag, attrs) => { const n = document.createElementNS("http://www.w3.org/2000/svg", tag); for (const [k, v] of Object.entries(attrs)) n.setAttribute(k, v); svg.append(n); return n; }; - const responseGains = $("response").checked && response ? response.gain_db.filter(Number.isFinite) : []; + const showResponse = wantsResponse() && view.enabled && response; + const responseGains = showResponse ? response.gain_db.filter(Number.isFinite) : []; const low = Math.min(-24, ...responseGains), high = Math.max(12, ...responseGains); - const y = gain => 48 + (high - gain) / (high - low) * 168; + const y = gain => PLOT_TOP + (high - gain) / (high - low) * PLOT_HEIGHT; + const knob = $("bands").classList.contains("dense") ? 10 : 16; for (const slider of document.querySelectorAll("#eq-bands input[type=range]")) { - slider.style.height = `${y(-24) - y(12) + 16}px`; - slider.style.marginTop = `${y(12) - 48}px`; + slider.style.height = `${y(-24) - y(12) + knob}px`; + slider.style.marginTop = `${y(12) - knob / 2 - (PLOT_TOP - 8)}px`; } - for (const db of [...new Set([Math.ceil(high), 12, 0, -12, -24, Math.floor(low)])]) { node("line", { x1: 40, x2: width - 20, y1: y(db), y2: y(db), class: "eq-grid" }); node("text", { x: 2, y: y(db) + 4, class: "eq-axis" }).textContent = `${db > 0 ? "+" : ""}${number.format(db)}`; } - node("text", { x: 2, y: 28, class: "eq-axis" }).textContent = "dB"; - const bands = view.profile.bands, parametric = mode() === "parametric"; - const x = i => 48 + (width - 48) * (i + .5) / Math.max(1, bands.length); + const parametric = mode() === "parametric", bands = view.profile.bands; + const left = parametric ? AXIS : 0; + for (const db of [...new Set([Math.ceil(high), 12, 0, -12, -24, Math.floor(low)])]) { node("line", { x1: left, x2: width, y1: y(db), y2: y(db), class: "eq-grid" }); if (parametric) node("text", { x: 2, y: y(db) + 4, class: "eq-axis" }).textContent = number.format(db); } + const columns = [...document.querySelectorAll("#eq-bands .eq-band")].map(column => column.offsetLeft + column.offsetWidth / 2); + const x = i => columns[i] ?? (width * (i + .5) / Math.max(1, bands.length)); + if (!parametric) for (let i = 0; i < bands.length; i++) node("line", { x1: x(i), x2: x(i), y1: y(12), y2: y(-24), class: "eq-track" }); function freqX(f) { - if (parametric || !bands.length) return 48 + (width - 68) * Math.log(f / 20) / Math.log(1000); + if (parametric || !bands.length) return AXIS + (width - AXIS - 8) * Math.log(f / 20) / Math.log(1000); if (f <= bands[0].frequency_hz) return x(0); for (let i = 1; i < bands.length; i++) if (f < bands[i].frequency_hz) return x(i - 1) + (x(i) - x(i - 1)) * Math.log(f / bands[i - 1].frequency_hz) / Math.log(bands[i].frequency_hz / bands[i - 1].frequency_hz); return x(bands.length - 1); } if ($("spectrum").checked && !view.cast && view.spectrum_db.length) { const rate = view.sample_rate || 48000, n = view.spectrum_db.length; - const points = view.spectrum_db.map((db, i) => [i * rate / (2 * (n - 1)), db]).filter(([f]) => f >= 20 && f <= 20000).map(([f, db]) => `${freqX(f)},${216 - Math.max(0, Math.min(1, (db + 90) / 90)) * 168}`).join(" "); - node("polyline", { points, class: "eq-spectrum" }); node("text", { x: width - 70, y: 28, class: "eq-axis" }).textContent = "dBFS"; + const points = view.spectrum_db.map((db, i) => [i * rate / (2 * (n - 1)), db]).filter(([f]) => f >= 20 && f <= 20000).map(([f, db]) => `${freqX(f)},${PLOT_TOP + PLOT_HEIGHT - Math.max(0, Math.min(1, (db + 90) / 90)) * PLOT_HEIGHT}`).join(" "); + node("polyline", { points, class: "eq-spectrum" }); } - if ($("response").checked && response) node("polyline", { points: response.frequencies.map((f, i) => `${freqX(f)},${y(response.gain_db[i])}`).join(" "), class: "eq-response" }); - if (!parametric) node("polyline", { points: bands.map((b, i) => `${x(i)},${y(b.gain_db)}`).join(" "), class: "eq-curve" }); - if (view.peak_db.some(db => db >= 0)) { - $("clip").classList.add("clipped"); clearTimeout(clipTimer); - clipTimer = setTimeout(() => $("clip").classList.remove("clipped"), 1000); + if (showResponse) node("polyline", { points: response.frequencies.map((f, i) => `${freqX(f)},${y(response.gain_db[i])}`).join(" "), class: parametric ? "eq-curve" : "eq-response" }); + if (!parametric && bands.length) node("path", { d: smooth(bands.map((b, i) => [x(i), y(b.gain_db)])), class: "eq-curve" }); + if (parametric) for (const b of bands) node("circle", { cx: freqX(b.frequency_hz), cy: y(b.gain_db), r: 5, class: b.enabled ? "eq-point" : "eq-point off" }); + // Every band's frequency up to 10 bands, else as many as fit a label each 40 px, spread over the bands. + if (!parametric && bands.length) { + const labels = bands.length <= 10 ? bands.length : Math.min(bands.length, Math.max(2, Math.floor(width / 40))); + for (let tick = 0; tick < labels; tick++) { + const index = labels === 1 ? 0 : Math.floor(tick * (bands.length - 1) / (labels - 1)); + node("text", { x: x(index), y: height - 4, class: "eq-axis", "text-anchor": tick === 0 && labels > 1 ? "start" : tick === labels - 1 && labels > 1 ? "end" : "middle" }).textContent = frequency(bands[index].frequency_hz); + } } + if ($("spectrum").checked && !view.cast) for (const db of [0, -30, -60, -90]) node("text", { x: width - 2, y: PLOT_TOP + -db / 90 * PLOT_HEIGHT + 4, class: "eq-axis", "text-anchor": "end" }).textContent = db; + if (parametric) for (const f of [20, 100, 1000, 10000, 20000]) node("text", { x: freqX(f), y: height - 4, class: "eq-axis", "text-anchor": "middle" }).textContent = frequency(f); } -function askName(operation, title) { +// A curve through every knob, as GTK's plot draws it. +function smooth(points) { + let d = `M${points[0][0]},${points[0][1]}`; + for (let i = 0; i < points.length - 1; i++) { + const [p0, p1, p2, p3] = [points[i - 1] ?? points[i], points[i], points[i + 1], points[i + 2] ?? points[i + 1]]; + d += ` C${p1[0] + (p2[0] - p0[0]) / 6},${p1[1] + (p2[1] - p0[1]) / 6} ${p2[0] - (p3[0] - p1[0]) / 6},${p2[1] - (p3[1] - p1[1]) / 6} ${p2[0]},${p2[1]}`; + } + return d; +} +function askName(operation) { + const titles = { save: [tr("Save preset"), tr("Save")], duplicate: [tr("Duplicate preset"), tr("Duplicate")], rename: [tr("Rename preset"), tr("Rename")] }; nameAction = { operation, output: view.output, id: view.preset_id || view.save_target }; - $("name-title").textContent = title; - $("name-submit").textContent = title; - $("name").value = operation === "duplicate" ? tr("Copy of {name}", { name: view.name }) : view.name; + $("name-title").textContent = titles[operation][0]; + $("name-submit").textContent = titles[operation][1]; + $("name").value = operation === "save" ? "" : view.name; $("name-dialog").showModal(); $("name").focus(); $("name").select(); } +const format = (name) => document.querySelector(`input[name="eq-${name}-format"]:checked`).value; +// Each opening starts on Rufin JSON, as GTK builds its dialogs afresh. +function resetFormat(name) { document.querySelector(`input[name="eq-${name}-format"][value="Json"]`).checked = true; } +function showError(id, message) { $(id).textContent = message; $(id).hidden = !message; } +function setImportText(text) { + $("import-text").value = text; + document.querySelector(`input[name="eq-import-format"][value="${text.trimStart().startsWith("{") ? "Json" : "Apo"}"]`).checked = true; + importChanged(); +} +function importChanged() { $("import-accept").disabled = !$("import-text").value.trim(); showError("import-error", ""); } +async function showExport() { + try { const { text } = await request("export", { format: format("export") }); $("export-text").value = text; showError("export-error", ""); $("export-copy").disabled = $("export-save").disabled = false; } + catch (error) { $("export-text").value = ""; showError("export-error", error.message); $("export-copy").disabled = $("export-save").disabled = true; } +} export function init() { const dialog = document.getElementById("equalizer-dialog"); const popup = document.getElementById("playback-settings"), main = document.getElementById("playback-settings-main"), page = document.getElementById("playback-equalizer-page"); - const start = action(async () => { signature = ""; await refreshPresets(); render(await api("/equalizer")); watch(); }); - const stop = () => { clearTimeout(clipTimer); $("clip").classList.remove("clipped"); stream?.close(); stream = null; void flush().then(() => view && request("commit")).catch(report); }; + const start = action(async () => { signature = ""; view = null; await refreshPresets(); render(await api("/equalizer")); watch(); await showOutputs(); }); + const stop = () => { clearTimeout(clipTimer); $("clip").hidden = true; stream?.close(); stream = null; void flush().then(() => view && request("commit")).catch(report); }; // The popover keeps the page it was closed on, and shows the equalizer again when it opens there. enter = () => void start(); exit = stop; @@ -204,37 +306,66 @@ export function init() { $("back").addEventListener("click", () => { stop(); turn(false); place(); }); popup.addEventListener("toggle", event => { if (page.hidden) return; if (event.newState === "closed") stop(); else mount(); }); dialog.addEventListener("close", stop); - // A modal name dialog closes the popover; naming a preset from its page comes back to it. - $("name-dialog").addEventListener("close", () => { if ($("body").parentElement === page && !shown()) place(); }); - $("preset").addEventListener("focus", action(refreshPresets)); $("preset").addEventListener("change", action(() => operation("select", { preset: $("preset").value || null }))); - $("mode").addEventListener("change", () => { signature = ""; render(view); }); + // A modal dialog closes the popover; a preset dialog opened from its page comes back to it. + for (const id of ["name-dialog", "import-dialog", "export-dialog"]) $(id).addEventListener("close", () => { if ($("body").parentElement === page && !shown()) place(); }); + $("preset").addEventListener("change", action(() => operation("select", { preset: $("preset").value || null }))); + $("mode").addEventListener("change", () => { signature = ""; render(view); void loadResponse().catch(report); }); $("layout").addEventListener("change", action(async () => { await flush(); queue("Layout", { value: $("layout").value }); await commit(); })); + $("band-picker").addEventListener("change", () => selectBand(Number($("band-picker").value))); + bindNumber($("band-gain"), "BandGain", value => ({ index: selected, value }), value => { view.profile.bands[selected].gain_db = value; for (const input of document.querySelectorAll(`[data-eq-band="${selected}"][data-field="gain"]`)) input.value = value; }); for (const [id, type] of [["enabled", "Enabled"], ["auto", "AutomaticPreamp"], ["crossfeed", "Crossfeed"], ["mono", "Mono"]]) $(id).addEventListener("change", action(async () => { queue(type, { value: $(id).checked }); await commit(); })); for (const [id, type] of tones) { - $(id).addEventListener("input", () => { queue(type, { value: Number($(id).value) }); if (id === "preamp") { $("preamp-number").value = $(id).value; checked("auto", false); } showResets(); }); $(id).addEventListener("change", action(commit)); - $(`${id}-reset`).addEventListener("click", action(async () => { queue(type, { value: 0 }); await commit(); })); + const fields = id === "preamp" ? ["preamp", "parametric-preamp", "preamp-scale"] : [id, `${id}-scale`]; + const reflect = value => { for (const field of fields) $(field).value = value; if (id === "preamp") checked("auto", false); showResets(); }; + bindSlider($(`${id}-scale`), type, value => ({ value }), reflect); + for (const field of fields.filter(field => !field.endsWith("scale"))) bindNumber($(field), type, value => ({ value }), reflect); + if (id !== "preamp") $(`${id}-reset`).addEventListener("click", action(async () => { reflect(0); queue(type, { value: 0 }); await commit(); })); } - bindNumber($("preamp-number"), "Preamp", value => ({ value }), value => { $("preamp").value = value; checked("auto", false); showResets(); }); $("reset").addEventListener("click", action(async () => { if (!confirm(`${tr("Reset to defaults?")}\n${tr("The settings in this section go back to their defaults.")}`)) return; queue("Flatten", null); await commit(); })); + document.getElementById("playback-settings-button").addEventListener("click", action(showOutputs)); + for (const select of document.querySelectorAll("select.audio-output")) select.addEventListener("change", () => { select.title = select.selectedOptions[0]?.textContent ?? ""; }); $("assigned").addEventListener("change", action(() => operation("assign", { assigned: $("assigned").checked }))); $("cast-format").addEventListener("change", action(async () => { queue("CastFormat", { value: $("cast-format").value }); await commit(); })); - $("response").addEventListener("change", action(async () => { await loadResponse(); draw(); })); $("spectrum").addEventListener("change", watch); + $("response").addEventListener("change", action(async () => { await loadResponse(); draw(); })); + $("spectrum").addEventListener("change", () => { $("spectrum-unit").hidden = !$("spectrum").checked; watch(); }); $("add").addEventListener("click", action(async () => { await flush(); queue("AddBand", null); await commit(); })); $("apply").addEventListener("click", action(() => operation("apply"))); - $("save").addEventListener("click", action(async () => { await flush(); if (view.save_target) await operation("save", { name: null }); else askName("save", tr("Save")); })); - $("duplicate").addEventListener("click", action(async () => { await flush(); askName("duplicate", tr("Duplicate")); })); - $("rename").addEventListener("click", action(async () => { await flush(); askName("rename", tr("Rename")); })); + $("save").addEventListener("click", action(async () => { await flush(); if (view.save_target) await operation("save", { name: null }); else askName("save"); })); + $("duplicate").addEventListener("click", action(async () => { await flush(); askName("duplicate"); })); + $("rename").addEventListener("click", action(async () => { await flush(); askName("rename"); })); $("name-form").addEventListener("submit", event => { event.preventDefault(); const { operation: command, ...target } = nameAction; - void operation(command, { ...target, name: $("name").value }).then(() => $("name-dialog").close()).catch(report); + void operation(command, { ...target, name: $("name").value.trim() }).then(() => $("name-dialog").close()).catch(report); + }); + $("delete").addEventListener("click", action(async () => { + if (!confirm(`${tr("Delete preset")}\n${view.name}`)) return; + await operation("delete", { id: view.preset_id || view.save_target }); + })); + $("import").addEventListener("click", action(async () => { await flush(); resetFormat("import"); $("import-text").value = ""; importChanged(); $("import-dialog").showModal(); $("import-text").focus(); })); + $("import-text").addEventListener("input", importChanged); + $("import-open").addEventListener("click", () => $("file").click()); + $("file").addEventListener("change", action(async () => { const file = $("file").files[0]; if (file) setImportText(await file.text()); $("file").value = ""; })); + $("import-paste").addEventListener("click", async () => { try { setImportText(await navigator.clipboard.readText()); } catch { $("import-text").focus(); } }); + $("import-accept").addEventListener("click", async () => { + $("import-accept").disabled = true; + try { await operation("import", { text: $("import-text").value, format: format("import") }); $("import-dialog").close(); } + catch (error) { $("import-accept").disabled = false; showError("import-error", error.message); } + }); + $("export").addEventListener("click", action(async () => { await flush(); resetFormat("export"); await showExport(); $("export-dialog").showModal(); })); + for (const input of document.querySelectorAll('input[name="eq-export-format"]')) input.addEventListener("change", () => void showExport()); + $("export-copy").addEventListener("click", async () => { + const icon = $("export-copy").querySelector(".icon"); + try { await navigator.clipboard.writeText($("export-text").value); } catch { $("export-text").select(); return; } + setIcon(icon, "rufin-object-select-symbolic"); setTimeout(() => setIcon(icon, "rufin-edit-copy-symbolic"), 1500); + }); + $("export-save").addEventListener("click", () => { + const url = URL.createObjectURL(new Blob([$("export-text").value], { type: "text/plain" })); + const a = element("a"); a.href = url; a.download = format("export") === "Json" ? "equalizer.rufin-eq.json" : "equalizer.txt"; a.click(); + setTimeout(() => URL.revokeObjectURL(url), 0); $("export-dialog").close(); }); - $("delete").addEventListener("click", action(() => operation("delete", { id: view.preset_id || view.save_target }))); - $("import").addEventListener("click", () => $("file").click()); - $("file").addEventListener("change", action(async () => { const file = $("file").files[0]; if (file) await operation("import", { text: await file.text(), format: file.name.toLowerCase().endsWith(".json") ? "Json" : "Apo" }); $("file").value = ""; })); - $("export").addEventListener("click", action(async () => { const format = $("format").value, result = await operation("export", { format }); const url = URL.createObjectURL(new Blob([result.text], { type: "text/plain" })); const a = element("a"); a.href = url; a.download = `equalizer.${format === "Json" ? "json" : "txt"}`; a.click(); setTimeout(() => URL.revokeObjectURL(url), 0); })); new ResizeObserver(draw).observe($("graph")); } diff --git a/web/styles/equalizer.css b/web/styles/equalizer.css index 5ce3886c4..2fa09a6f5 100644 --- a/web/styles/equalizer.css +++ b/web/styles/equalizer.css @@ -1,26 +1,110 @@ -#equalizer-dialog { width: min(920px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; } -.eq-header,.eq-toolbar,.eq-preamp { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; } -.eq-header h2 { margin: 0; flex: 1; }.eq-toolbar label,.eq-header label,.eq-preamp label { display: flex; gap: 8px; align-items: center; } -.eq-toolbar select { max-width: 220px; }.eq-menu { position: relative; }.eq-menu>div { position: absolute; z-index: 3; display: grid; gap: 4px; padding: 8px; background: var(--card-bg, #303030); border-radius: 12px; box-shadow: 0 4px 18px #0005; } -.eq-scroller { overflow-x: auto; margin-block: 12px; }.eq-scroller #eq-graph { position: relative; height: 265px; --eq-band-min: 62; }#eq-plot { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; } -#eq-bands { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; margin-left: 48px; height: 265px; }.eq-band { display: grid; grid-template-rows: 32px 184px auto; justify-items: center; align-items: start; row-gap: 8px; min-width: 62px; }.eq-band input[type=number] { width: 58px; height: 32px; box-sizing: border-box; padding: 4px 2px; text-align: center; }.eq-band input[type=range] { writing-mode: vertical-lr; direction: rtl; height: 184px; width: 24px; padding: 0; background: transparent; }.eq-band button { background: transparent; border: 0; font-size: 12px; padding: 4px; } -.eq-grid { stroke: currentColor; opacity: .15; stroke-width: 1; }.eq-axis { fill: currentColor; opacity: .65; font-size: 11px; }.eq-curve,.eq-response,.eq-spectrum { fill: none; stroke: var(--accent, #3584e4); stroke-width: 2; }.eq-response { stroke-dasharray: 5 4; opacity: .8; }.eq-spectrum { opacity: .3; stroke-width: 1; } -.eq-filter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-block: 10px; }.eq-filter input[type=number] { width: 92px; }.eq-filter input[type=checkbox] { width: 18px; }.eq-preamp { margin-top: 16px; }.eq-preamp input[type=range] { flex: 1; min-width: 160px; }.eq-preamp input[type=number] { width: 80px; }.eq-extra { display: grid; gap: 12px; margin-block: 16px; }.eq-extra label { display: flex; gap: 12px; align-items: center; }.eq-extra input[type=range] { flex: 1; }#eq-clip { opacity: .4; }#eq-clip.clipped { color: #ed333b; opacity: 1; }#eq-status { font-size: .9em; color: var(--muted, #999); } - -#eq-name-dialog { width: min(380px, calc(100vw - 32px)); } #eq-name-form { display: grid; gap: 16px; } #eq-name-form .eq-toolbar { justify-content: end; margin-bottom: 0; } -/* Graphic and parametric: two icon choices in one box, a line between them. */ +/* The equalizer, as GTK's: a switch row, presets with their actions, the band editor, levels and + audio effects, each a boxed group. */ +#equalizer-dialog { width: min(920px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 18px; } +.eq-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; } +.eq-header h2 { margin: 0; flex: 1; font-size: 17px; } +#eq-body .pref-group-header { margin: 18px 0 6px; } +.eq-actions { display: flex; gap: 2px; } +.eq-actions .icon-button { width: 32px; height: 32px; } +#eq-body label.pref-label { margin: 0; color: var(--text); font-size: 14px; } +#eq-body .pref-row > output { color: var(--muted); font-variant-numeric: tabular-nums; } +.eq-output { flex-wrap: wrap; } +.eq-output > .checkbox { margin: 0; color: var(--text); font-size: 14px; } +/* The output picker fills the line between Use for this output and the mode, as GTK's dropdown. */ +#eq-body #eq-output { flex: 1; min-width: 0; width: auto; max-width: none; text-align: start; background: color-mix(in srgb, currentColor 10%, transparent); border-color: transparent; text-overflow: ellipsis; } +#eq-output-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .eq-mode { margin: 0; flex: none; } -.eq-mode label { position: relative; padding: 6px 10px; } -.eq-mode label + label::before { content: ""; position: absolute; left: -2px; top: 7px; bottom: 7px; width: 1px; background: color-mix(in srgb, var(--text) 30%, transparent); } -/* The same body on the playback settings popover's page: narrow bands, Back in place of Close. */ -#playback-settings:has(#playback-equalizer-page:not([hidden])) { width: min(440px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto; padding: 12px; box-sizing: border-box; } +.eq-mode label { padding: 6px 10px; } +.eq-mode .icon { width: 16px; height: 16px; } +#eq-unavailable { margin: 0 0 12px; } +#eq-body .checkbox { margin: 0; color: var(--text); font-size: 13px; } +#eq-body input[type="checkbox"]:not([role="switch"]) { width: 16px; height: 16px; margin: 0; accent-color: var(--blue); } + +#eq-editor { padding: 10px 12px 12px; } +.eq-options { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; } +.eq-options > span { color: var(--muted); font-size: 12px; } +.eq-scroller { overflow: auto hidden; } +.eq-band-row { display: flex; gap: 8px; } +#eq-graph { position: relative; flex: 1; height: 264px; } +#eq-plot { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; } +#eq-bands { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); height: 100%; } +/* A band: its gain, its slider over the plot, its frequency. */ +.eq-band { display: grid; grid-template-rows: 26px auto 1fr; justify-items: center; align-items: start; row-gap: 6px; min-width: 0; height: 264px; font-size: 11px; color: var(--muted); } +.eq-band > input[type="number"] { grid-row: 1; } +.eq-band > input[type="range"] { grid-row: 2; } +.eq-band > span { grid-row: 3; align-self: end; padding-bottom: 2px; } +#eq-bands.dense input[type="range"] { width: 10px; } +#eq-bands.dense input[type="range"]::-webkit-slider-thumb { width: 10px; height: 10px; margin-left: -4px; } +#eq-bands.dense input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; } +#eq-preamp-column { flex: none; width: 44px; } +.eq-band input[type="number"] { width: 100%; max-width: 48px; height: 26px; padding: 0 2px; font-size: 11px; text-align: center; appearance: textfield; border-color: transparent; background: transparent; } +.eq-band input[type="number"]:hover, .eq-band input[type="number"]:focus { border-color: var(--line); background: var(--surface); } +.eq-band input[type="number"]::-webkit-inner-spin-button { appearance: none; } +/* GTK's scale: a thin track under a round knob, no fill, so the plot's curve reads through. */ +.eq-band input[type="range"] { appearance: none; writing-mode: vertical-lr; direction: rtl; width: 20px; height: 100%; margin: 0; padding: 0; background: transparent; } +.eq-band input[type="range"]::-webkit-slider-runnable-track { width: 2px; background: transparent; } +.eq-band input[type="range"]::-moz-range-track { width: 2px; background: transparent; } +.eq-band input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-left: -7px; border-radius: 50%; background: var(--sidebar, var(--bg)); border: 2px solid var(--blue); box-sizing: border-box; } +.eq-band input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--sidebar, var(--bg)); border: 2px solid var(--blue); box-sizing: border-box; } +.eq-band input[type="range"]:focus-visible { outline: none; } +.eq-band input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 1px; } +.eq-band input[type="range"] { height: 212px; } +#eq-preamp-column input[type="range"] { background: linear-gradient(color-mix(in srgb, var(--text) 25%, transparent), color-mix(in srgb, var(--text) 25%, transparent)) center / 2px calc(100% - 16px) no-repeat; } +#eq-preamp-column > span { color: var(--text); } +.eq-grid { stroke: currentColor; opacity: .12; stroke-width: 1; } +.eq-track { stroke: currentColor; opacity: .25; stroke-width: 2; } +.eq-axis { fill: currentColor; opacity: .65; font-size: 11px; } +.eq-curve, .eq-response, .eq-spectrum { fill: none; stroke: var(--blue); stroke-width: 2; } +.eq-curve { opacity: .7; } +.eq-response { stroke-dasharray: 5 4; opacity: .8; } +.eq-spectrum { opacity: .3; stroke-width: 1; } +.eq-point { fill: var(--sidebar, var(--bg)); stroke: var(--blue); stroke-width: 2; } +.eq-point.off { stroke: currentColor; opacity: .4; } + +.eq-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; } +.eq-controls > span { display: inline-flex; align-items: center; gap: 6px; } +.eq-spacer { flex: 1; } +/* Dialogs stretch their fields; these keep their own width, as in the popover. */ +#eq-body :is(.eq-controls, .eq-filter) select { width: auto; } +#eq-band-value input { width: 72px; } +.eq-field { display: inline-flex; align-items: center; gap: 6px; } +.eq-field label { margin: 0; color: var(--text); font-size: 13px; } +.eq-field input[type="number"] { width: 72px; } +#eq-parametric-preamp-field input { width: 72px; } + +#eq-filters { display: grid; gap: 6px; margin-top: 10px; } +.eq-filter { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; } +.eq-filter .checkbox { min-width: 36px; } +.eq-filter input[type="number"] { width: 78px; } +.eq-filter .icon { opacity: .7; } + +/* Bass, treble and balance: a slider, then its value field with Reset. */ +#eq-effects summary { list-style: none; cursor: pointer; font-weight: normal; } +#eq-effects summary::-webkit-details-marker { display: none; } +#eq-effects summary .icon { width: 16px; height: 16px; transition: transform 150ms; } +#eq-effects[open] summary .icon { transform: rotate(180deg); } +#eq-effects .pref-row > label.pref-label { margin: 0; flex: none; min-width: 64px; } +#eq-effects .pref-row > input[type="range"] { flex: 1; min-width: 80px; } +#eq-effects .eq-field input { width: 64px; } +#eq-effects .icon-button { width: 28px; height: 28px; padding: 5px; } +#eq-cast { margin-bottom: 12px; } +#eq-clip { color: #ed333b; font-size: 12px; font-weight: 600; } +#eq-error { margin: 0 0 12px; } + +#eq-name-dialog { width: min(440px, calc(100vw - 32px)); padding: 18px; } +#eq-name-form .dialog-actions { margin-top: 14px; } +.eq-transfer { width: min(520px, calc(100vw - 32px)); padding: 18px; } +.eq-transfer .eq-controls { margin: 0 0 10px; } +.eq-transfer .segmented { margin: 0; } +.eq-transfer textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 12px; resize: vertical; } +.eq-transfer .dialog-actions { margin-top: 14px; } +.eq-transfer .error { margin: 8px 0 0; } + +/* The same body on the playback settings popover's page: Back in place of Close. */ +#playback-settings:has(#playback-equalizer-page:not([hidden])) { width: min(440px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow: auto; padding: 10px; box-sizing: border-box; } #playback-settings-main > .menu-item { display: flex; align-items: center; justify-content: space-between; } #playback-equalizer-page { position: relative; } #eq-back { position: absolute; left: 0; top: 0; } -#playback-equalizer-page .eq-header { padding-left: 40px; min-height: 32px; } +#playback-equalizer-page .eq-header { justify-content: center; min-height: 34px; } #playback-equalizer-page .eq-header [data-close] { display: none; } -#playback-equalizer-page .eq-header h2 { font-size: 1.1em; } -#playback-equalizer-page #eq-graph { --eq-band-min: 34; } -#playback-equalizer-page .eq-band { min-width: 0; } -#playback-equalizer-page .eq-band input[type=number] { width: calc(100% - 2px); padding: 4px 0; font-size: 11px; appearance: textfield; } -#playback-equalizer-page .eq-toolbar select { max-width: 150px; } +#playback-equalizer-page .eq-header h2 { flex: none; font-size: 15px; } diff --git a/web/styles/menus.css b/web/styles/menus.css index df854baca..203253ad3 100644 --- a/web/styles/menus.css +++ b/web/styles/menus.css @@ -120,6 +120,12 @@ html:not(.enhanced) #track-menu { border-radius: 7px; cursor: pointer; } +/* A choice in a popover row, as GTK's Audio output dropdown. */ +.menu-switch > select { + width: 180px; + height: 30px; + text-overflow: ellipsis; +} .menu-switch:hover { background: var(--hover); } diff --git a/web/templates/equalizer.html b/web/templates/equalizer.html index 109320742..5ef67f5c3 100644 --- a/web/templates/equalizer.html +++ b/web/templates/equalizer.html @@ -1,25 +1,72 @@ {% import "macros.html" as m %}
-

{{ localization::tr("Equalizer") }}

-
{{ localization::tr("More") }}
- -
-
{{ localization::tr("Clipping") }}
-
-
-
dB
-
{{ localization::tr("Tone and channels") }}
- - - - -
-
+

{{ localization::tr("Equalizer") }}

+
+

{{ localization::tr("Presets") }}

+ + + + + + +
+
+
+
+
+
+
+ +
+
{{ localization::tr("Gain · dB") }}
+
+
{{ localization::tr("Preamp") }}
+
+
+
+
+ + + + + + +
+
+
+ +
{{ localization::tr("Output gain") }}
+
{{ localization::tr("Sample peak") }}
+
+
{{ localization::tr("Audio effects") }}{% call m::icon("rufin-pan-down-symbolic") %}{% endcall %} +
+
+ +
+ +
+ +
-

{{ localization::tr("Preset name") }}

- -
+

+ +
+ +

{{ localization::tr("Import preset") }}

+
+
+ + +
+
+ +

{{ localization::tr("Export preset") }}

+
+ + +
+
diff --git a/web/templates/index.html b/web/templates/index.html index a4c29b5b9..d0372bb82 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -579,6 +579,7 @@

{% call m::icon("rufin-music-queue-symbolic") %}{% endcall %}{{ localization
+
{% call m::transition_mode("transition-mode") %}{% endcall %}