Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

style(timeline): the VU meters are two slim bars on a scale that numbers only what fits

Jareer9ef4badfb2af
diff --git a/src/crates/concat/ui/timeline/vu-meter.slint b/src/crates/concat/ui/timeline/vu-meter.slint
index cbb70e61..e6fc6107 100644
--- a/src/crates/concat/ui/timeline/vu-meter.slint
+++ b/src/crates/concat/ui/timeline/vu-meter.slint
@@ -8,20 +8,22 @@
// meter button shows and hides it.
//
// Each bar is the peak level on a decibel scale - 0 dB at the top, -60 at
-// the foot - with the loudest of the last moment held as a line, a clip
-// light over the bars that stays red once the mix has clipped, until it
-// is clicked, and under them the held peak as a number.
+// the foot - lit green, then yellow past -18, then red past -6, with the
+// loudest of the last moment held as a line. A cap over each bar is the
+// clip light: red once the mix has clipped, until it is clicked. The held
+// peak reads as a number in the band beside the lanes' ruler, over the
+// bars it speaks for, and "L" and "R" sit under their own bars.
//
-// The column reads as one instrument: the scale is a ruler down the left
-// with a tick every three decibels and a number every six to -24 and
-// every twelve below, where the ear stops caring about the odd decibel;
-// the light sits in the band beside the lanes' ruler, over the two bars
-// it speaks for; the legend under the bars names them and the unit.
+// The scale down the left numbers only as many decibels as the column has
+// room for: 0, -6, -12 and then every twelve when it is tall, every twelve
+// when it is middling, 0, -30 and -60 when it is short, so two numbers
+// never touch. Each number is centred on its own tick, and the ticks are
+// the bars' own scale: the bars start half a number below the top, so 0
+// has room to sit level with the bars' head rather than be pushed down.
import { I18n } from "../i18n.slint";
import { Theme } from "../theme/theme.slint";
import { Fmt } from "../util.slint";
-import { LevelMeter } from "../primitives/level-meter.slint";
import { Tip } from "../primitives/tooltip.slint";
/// The levels, published by Rust (concat's meters.rs) thirty times a second
@@ -38,35 +40,133 @@ export global Meters {
callback clip-cleared();
}
+/// One channel's bar. Drawn here rather than with the shared LevelMeter,
+/// whose ramp is tuned for the inspector's short bars: a programme meter's
+/// colours belong at -18 and -6 dB, and on a -60 dB scale that is 70% and
+/// 90% of the way up.
+///
+/// The ramp is painted at full length and revealed by a clipping window, so
+/// a colour always means the same level however far the bar has filled. A
+/// faint copy of it lies under the window, so the unlit track still shows
+/// where yellow and red begin. Nothing animates: the level arrives at the
+/// feed rate, and an animation re-armed on every sample would keep the
+/// window repainting at the monitor's rate instead.
+component VuBar inherits Rectangle {
+ in property <float> value;
+ /// The held peak, 0..1; negative hides it.
+ in property <float> peak: -1;
+
+ property <float> level: Fmt.clamp(root.value, 0, 1);
+ property <float> hold: Fmt.clamp(root.peak, 0, 1);
+
+ background: Theme.well;
+ border-radius: 2px;
+ clip: true;
+
+ // The ramp's zones, unlit: a hint on the light theme's pale well, where
+ // any more reads as a bar already full.
+ Rectangle {
+ background: @linear-gradient(0deg,
+ Theme.meter-low 0%, Theme.meter-low 64%,
+ Theme.meter-mid 72%, Theme.meter-mid 86%,
+ Theme.meter-high 92%, Theme.meter-high 100%);
+ opacity: Theme.dark ? 0.13 : 0.06;
+ }
+
+ // The reveal window, and the ramp in it, offset back so its stops stay
+ // anchored to the track.
+ window := Rectangle {
+ y: root.height * (1 - root.level);
+ height: root.height * root.level;
+ clip: true;
+ Rectangle {
+ y: -window.y;
+ height: root.height;
+ background: @linear-gradient(0deg,
+ Theme.meter-low 0%, Theme.meter-low 64%,
+ Theme.meter-mid 72%, Theme.meter-mid 86%,
+ Theme.meter-high 92%, Theme.meter-high 100%);
+ }
+ }
+
+ // The held peak: a line across the bar, kept whole at either end.
+ if root.peak >= 0: Rectangle {
+ y: Fmt.clamp(Math.round((root.height * (1 - root.hold)) / 1px) - 1,
+ 0, root.height / 1px - 2) * 1px;
+ height: 2px;
+ background: Theme.fg;
+ opacity: 0.9;
+ }
+}
+
export component VuMeter inherits Rectangle {
- /// The lanes' ruler band: the clip light sits in a band this tall, so
+ /// The lanes' ruler band: the held peak reads in a band this tall, so
/// the bars start where the lanes do.
in property <length> ruler-height: 28px;
/// The scale's floor, in dB: the meters' 0 is this, their 1 is 0 dB.
property <float> floor-db: -60;
- /// A tick every three decibels, the whole way down.
- property <[int]> ticks: [0, -3, -6, -9, -12, -15, -18, -21, -24, -27, -30, -33, -36, -39, -42, -45, -48, -51, -54, -57, -60];
- /// The ticks that carry a number: every six to -24, every twelve below.
- property <[int]> labelled: [0, -6, -12, -18, -24, -36, -48, -60];
-
- /// The ruler's width: the numbers, a gap, and the ticks.
- property <length> scale-w: 26px;
- property <length> tick-w: 6px;
- /// One bar's width, and the gap between the two. The light over them
- /// and the readout under them are sized to the pair. Slimmer than the
- /// old pane's: every pixel here is one the lanes do not get.
- property <length> bar-w: 10px;
- property <length> bar-gap: 3px;
+
+ // The instrument, left to right: the numbers, a gap, the ticks, a gap,
+ // and the two bars with a hair between them.
+ property <length> label-w: 18px;
+ property <length> label-gap: 3px;
+ property <length> tick-w: 4px;
+ property <length> minor-w: 2px;
+ property <length> tick-gap: 2px;
+ property <length> bar-w: 7px;
+ property <length> bar-gap: 2px;
property <length> pair-w: 2 * root.bar-w + root.bar-gap;
+ property <length> inst-w: root.label-w + root.label-gap + root.tick-w + root.tick-gap + root.pair-w;
+ /// A number's box: centred on its tick, so the bars stand half of one
+ /// in from either end of the scale.
+ property <length> label-h: 12px;
+ /// The clip lights over the bars, and the air between them and the bars.
+ property <length> cap-h: 3px;
+ property <length> cap-gap: 3px;
+ property <length> caption-h: 12px;
+
+ /// Where the instrument starts: centred in the column right of the
+ /// hairline, on a whole pixel so the ticks stay crisp.
+ property <length> ix: Math.round(Math.max(1px, 1px + (root.width - 1px - root.inst-w) / 2) / 1px) * 1px;
+ property <length> ticks-x: root.ix + root.label-w + root.label-gap;
+ property <length> bars-x: root.ticks-x + root.tick-w + root.tick-gap;
+ property <length> cap-y: root.ruler-height + 7px;
+ property <length> bar-top: root.cap-y + root.cap-h + root.cap-gap;
+ property <length> bar-bottom: root.height - 6px - root.caption-h - 4px;
+ property <length> bar-h: Math.max(0px, root.bar-bottom - root.bar-top);
+
+ /// How many numbers fit: six decibels must leave a number's height and
+ /// a hair of air for every six to be read, twelve for every twelve.
+ property <int> tier: root.bar-h >= 140px ? 0 : root.bar-h >= 70px ? 1 : root.bar-h >= 28px ? 2 : 3;
+ property <[int]> labelled: root.tier == 0 ? [0, -6, -12, -24, -36, -48, -60]
+ : root.tier == 1 ? [0, -12, -24, -36, -48, -60]
+ : root.tier == 2 ? [0, -30, -60]
+ : [0];
+ /// A tick every six decibels while they stand six pixels apart; only
+ /// the numbered ones below that.
+ property <[int]> ticks: root.bar-h >= 60px ? [0, -6, -12, -18, -24, -30, -36, -42, -48, -54, -60] : root.labelled;
+ /// Whether `db` carries a number at this height.
+ pure function numbered(db: int) -> bool {
+ if (root.tier == 0) {
+ return db >= -12 || Math.mod(db, 12) == 0;
+ }
+ if (root.tier == 1) {
+ return Math.mod(db, 12) == 0;
+ }
+ if (root.tier == 2) {
+ return Math.mod(db, 30) == 0;
+ }
+ return db == 0;
+ }
/// The decibels a meter value stands for.
pure function db-of(value: float) -> float {
return root.floor-db + value * (0 - root.floor-db);
}
- /// Where `db` sits down a ruler `height` tall.
- pure function y-of(db: float, height: length) -> length {
- return (1 - (db - root.floor-db) / (0 - root.floor-db)) * height;
+ /// Where `db` sits down the bars, on a whole pixel, from their head.
+ pure function y-of(db: float) -> length {
+ return Math.round((1 - (db - root.floor-db) / (0 - root.floor-db)) * root.bar-h / 1px) * 1px;
}
/// The held peak of the two sides, as a whole number of decibels, or a
/// dash when neither side holds one.
@@ -89,166 +189,131 @@ export component VuMeter inherits Rectangle {
background: Theme.line;
}
- VerticalLayout {
- padding-left: 1px;
+ // The ruler's band, ruled off the way the lanes' ruler is, and the held
+ // peak in it over the bars.
+ Rectangle {
+ x: 1px;
+ y: root.ruler-height - 1px;
+ width: root.width - 1px;
+ height: 1px;
+ background: Theme.line;
+ }
+ Rectangle {
+ x: root.bars-x + root.pair-w / 2 - 16px;
+ y: 0;
+ width: 32px;
+ height: root.ruler-height - 1px;
+ Text {
+ text: root.peak-text();
+ color: Meters.clipped ? Theme.danger : Theme.fg-muted;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs-sm;
+ horizontal-alignment: center;
+ vertical-alignment: center;
+ }
+ peak-touch := TouchArea { }
+ Tip {
+ text: I18n.t("meters.peak");
+ active: peak-touch.has-hover;
+ }
+ }
- // The ruler's band, and the clip light in it: red once the mix has
- // hit full scale, until clicked. The empty box on the left is the
- // scale's width, so the light lines up with the bars and not with
- // the column.
+ // The clip lights: a cap over each bar, red once the mix has hit full
+ // scale, until clicked. The box is taller than the caps so a pointer
+ // need not find three pixels.
+ Rectangle {
+ x: root.bars-x;
+ y: root.cap-y - 4px;
+ width: root.pair-w;
+ height: root.cap-h + 8px;
Rectangle {
- height: root.ruler-height;
- Rectangle {
- y: parent.height - 1px;
- height: 1px;
- background: Theme.line;
- }
- HorizontalLayout {
- alignment: center;
- spacing: root.bar-gap;
- Rectangle { width: root.scale-w; }
- VerticalLayout {
- alignment: center;
- light := Rectangle {
- width: root.pair-w;
- height: 6px;
- border-radius: 3px;
- background: Meters.clipped ? Theme.danger : Theme.field;
- border-width: 1px;
- border-color: Meters.clipped ? Theme.danger : Theme.line;
-
- light-touch := TouchArea {
- mouse-cursor: pointer;
- clicked => { Meters.clip-cleared(); }
- }
- Tip {
- text: Meters.clipped ? I18n.t("meters.clipped") : I18n.t("meters.clipLight");
- active: light-touch.has-hover;
- }
- }
- }
- }
+ x: 0;
+ y: 4px;
+ width: root.bar-w;
+ height: root.cap-h;
+ border-radius: 1px;
+ background: Meters.clipped ? Theme.danger : Theme.well;
}
-
- VerticalLayout {
- padding-top: 8px;
- padding-bottom: 8px;
- spacing: 4px;
-
- // The ruler and the bars. The ruler's foot and head are the
- // bars' own, so a number sits level with the tick it names.
- HorizontalLayout {
- vertical-stretch: 1;
- alignment: center;
- spacing: root.bar-gap;
-
- Rectangle {
- width: root.scale-w;
-
- // A hairline the ticks grow from, on the ruler's inner
- // edge against the bars.
- Rectangle {
- x: parent.width - 1px;
- y: 0;
- width: 1px;
- height: parent.height;
- background: Theme.line;
- }
- for db in root.ticks: Rectangle {
- property <bool> major: Math.mod(db, 6) == 0;
- x: parent.width - self.width;
- y: Fmt.clamp(root.y-of(db, parent.height) / 1px, 0, parent.height / 1px - 1) * 1px;
- width: self.major ? root.tick-w : root.tick-w / 2;
- height: 1px;
- background: self.major ? Theme.fg-dim : Theme.line-strong;
- }
- for db in root.labelled: Text {
- x: parent.width - root.tick-w - 3px - self.width;
- // Centred on its tick, and held inside the ruler at
- // either end so 0 and -60 are whole.
- y: Fmt.clamp(
- (root.y-of(db, parent.height) - self.height / 2) / 1px,
- 0, (parent.height - self.height) / 1px) * 1px;
- text: "\{db}";
- color: db == 0 ? Theme.fg-muted : Theme.fg-dim;
- font-family: Theme.font-technical;
- font-size: Theme.fs-xs;
- }
- }
- LevelMeter {
- vertical: true;
- thickness: root.bar-w;
- value: Meters.left;
- peak: Meters.hold-left;
- }
- LevelMeter {
- vertical: true;
- thickness: root.bar-w;
- value: Meters.right;
- peak: Meters.hold-right;
- }
- }
-
- // The legend: the unit under the ruler, a name under each bar.
- HorizontalLayout {
- alignment: center;
- spacing: root.bar-gap;
- Rectangle {
- width: root.scale-w;
- Text {
- x: parent.width - root.tick-w - 3px - self.width;
- text: "dB";
- color: Theme.fg-dim;
- font-family: Theme.font-technical;
- font-size: Theme.fs-xs;
- }
- }
- Text {
- width: root.bar-w;
- text: "L";
- color: Theme.fg-muted;
- font-size: Theme.fs-xs;
- font-weight: Theme.weight-title;
- horizontal-alignment: center;
- }
- Text {
- width: root.bar-w;
- text: "R";
- color: Theme.fg-muted;
- font-size: Theme.fs-xs;
- font-weight: Theme.weight-title;
- horizontal-alignment: center;
- }
- }
-
- // The held peak as a number, under the pair: the loudest the
- // last moment reached, in whole decibels below full scale.
- HorizontalLayout {
- alignment: center;
- spacing: root.bar-gap;
- Rectangle { width: root.scale-w; }
- Rectangle {
- width: root.pair-w;
- height: 18px;
- border-radius: Theme.r-xs;
- background: Theme.well;
- Text {
- width: parent.width;
- height: parent.height;
- text: root.peak-text();
- color: Meters.clipped ? Theme.danger : Theme.fg;
- font-family: Theme.font-technical;
- font-size: Theme.fs-xs;
- horizontal-alignment: center;
- vertical-alignment: center;
- }
- peak-touch := TouchArea { }
- Tip {
- text: I18n.t("meters.peak");
- active: peak-touch.has-hover;
- }
- }
- }
+ Rectangle {
+ x: root.bar-w + root.bar-gap;
+ y: 4px;
+ width: root.bar-w;
+ height: root.cap-h;
+ border-radius: 1px;
+ background: Meters.clipped ? Theme.danger : Theme.well;
+ }
+ light-touch := TouchArea {
+ mouse-cursor: pointer;
+ clicked => { Meters.clip-cleared(); }
}
+ Tip {
+ text: Meters.clipped ? I18n.t("meters.clipped") : I18n.t("meters.clipLight");
+ active: light-touch.has-hover;
+ }
+ }
+
+ // The scale: ticks against the bars, numbered ones longer and darker,
+ // and each number centred on its tick.
+ for db in root.ticks: Rectangle {
+ property <bool> major: root.numbered(db);
+ x: root.ticks-x + (self.major ? 0 : root.tick-w - root.minor-w);
+ y: root.bar-top + Math.min(root.y-of(db), Math.max(0px, root.bar-h - 1px));
+ width: self.major ? root.tick-w : root.minor-w;
+ height: 1px;
+ background: self.major ? Theme.line-strong : Theme.line;
+ }
+ for db in root.labelled: Text {
+ x: root.ix;
+ y: root.bar-top + root.y-of(db) - root.label-h / 2;
+ width: root.label-w;
+ height: root.label-h;
+ text: "\{db}";
+ color: Theme.fg-dim;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs-xs;
+ horizontal-alignment: right;
+ vertical-alignment: center;
+ }
+
+ // The bars.
+ VuBar {
+ x: root.bars-x;
+ y: root.bar-top;
+ width: root.bar-w;
+ height: root.bar-h;
+ value: Meters.left;
+ peak: Meters.hold-left;
+ }
+ VuBar {
+ x: root.bars-x + root.bar-w + root.bar-gap;
+ y: root.bar-top;
+ width: root.bar-w;
+ height: root.bar-h;
+ value: Meters.right;
+ peak: Meters.hold-right;
+ }
+
+ // Each bar's name, centred under it.
+ Text {
+ x: root.bars-x - 2px;
+ y: root.bar-bottom + 4px;
+ width: root.bar-w + 4px;
+ height: root.caption-h;
+ text: "L";
+ color: Theme.fg-muted;
+ font-size: Theme.fs-xs;
+ horizontal-alignment: center;
+ vertical-alignment: center;
+ }
+ Text {
+ x: root.bars-x + root.bar-w + root.bar-gap - 2px;
+ y: root.bar-bottom + 4px;
+ width: root.bar-w + 4px;
+ height: root.caption-h;
+ text: "R";
+ color: Theme.fg-muted;
+ font-size: Theme.fs-xs;
+ horizontal-alignment: center;
+ vertical-alignment: center;
}
}