Add live peak meters (pavucontrol-style level bars)
CI / check (push) Successful in 10s
CI / native (push) Successful in 1m39s

Each row on Playback, Output Devices and Input Devices gets a level bar
under its slider. A meter is a small capture pw_stream on WirePlumber's
pw_core with the properties pipewire-pulse gives pavucontrol's peak
streams (stream.monitor, target.object, stream.capture.sink for sinks);
its process callback folds samples into a peak that a 40 ms GUI timer
reads, maps with the slider's cubic curve and decays smoothly.

- Only the visible tab is metered; output/stream meters are passive.
- stream.monitor nodes (ours and pavucontrol's) are hidden from the tabs.
- moonmix-probe gains `meter <id>`; the smoke test now plays noise and
  checks the stream and sink meters see it.
- Screenshot mode holds the meters still before capturing, since a
  constantly redrawing window never yields a frame under broadway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-22 16:33:12 -08:00
1 parent 92ae5cdbfe
commit f08f241edb
17 files changed
+503 -18

No files matched your search

+50 -1
View File
@@ -103,6 +103,18 @@ extern "C" fn ffi_set_default(kind : Int32, id : Int32) -> Int32 = "mm_wp_set_de
///|
extern "C" fn ffi_move_stream(stream : Int32, device : Int32) -> Int32 = "mm_wp_move_stream"
///|
extern "C" fn ffi_meter_start(id : Int32, kind : Int32) -> Int32 = "mm_wp_meter_start"
///|
extern "C" fn ffi_meter_stop(id : Int32) = "mm_wp_meter_stop"
///|
extern "C" fn ffi_meter_stop_all() = "mm_wp_meter_stop_all"
///|
extern "C" fn ffi_meter_take(id : Int32) -> Double = "mm_wp_meter_take"
///|
/// NUL-terminated UTF-8 for C.
fn cstr(s : String) -> Bytes {
@@ -158,7 +170,9 @@ pub fn node_prop(id : Int32, key : String) -> String {
///|
/// Current state of a node as a model node, or None if it is gone.
pub fn read_node(id : Int32) -> @model.Node? {
if ffi_node_exists(id) == 0 {
// Peak-meter streams (ours, pavucontrol's via pipewire-pulse) are not
// something to show or control.
if ffi_node_exists(id) == 0 || node_prop(id, "stream.monitor") == "true" {
return None
}
let nch = ffi_query_volume(id)
@@ -264,3 +278,38 @@ pub fn set_default_source(id : Int32) -> Bool {
pub fn move_stream(stream_id : Int32, device_id : Int32) -> Bool {
ffi_move_stream(stream_id, device_id) != 0
}
///|
/// Start a live peak meter on a sink, source or playback stream (other
/// kinds have nothing to meter). True if one is running for `id`.
pub fn meter_start(id : Int32, kind : @model.NodeKind) -> Bool {
let k = match kind {
Sink => 0
Source => 1
PlaybackStream => 2
RecordStream | Other => return false
}
ffi_meter_start(id, k) != 0
}
///|
pub fn meter_stop(id : Int32) -> Unit {
ffi_meter_stop(id)
}
///|
pub fn meter_stop_all() -> Unit {
ffi_meter_stop_all()
}
///|
/// Linear peak (0..1, may exceed 1 when clipping) since the last call, or
/// None if `id` has no meter.
pub fn meter_take(id : Int32) -> Double? {
let p = ffi_meter_take(id)
if p < 0.0 {
None
} else {
Some(p)
}
}