Add live peak meters (pavucontrol-style level bars)
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:
1 parent
92ae5cdbfe
commit
f08f241edb
17 files changed
+503
-18
No files matched your search
+17
@@ -136,6 +136,12 @@ extern "C" fn ffi_dropdown_new(tag : Int32) -> Widget = "mm_gtk_dropdown_new"
|
||||
#borrow(items)
|
||||
extern "C" fn ffi_dropdown_set(dd : Widget, items : Bytes, selected : Int32) = "mm_gtk_dropdown_set"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_levelbar_new() -> Widget = "mm_gtk_levelbar_new"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_levelbar_set(lb : Widget, v : Double) = "mm_gtk_levelbar_set"
|
||||
|
||||
///|
|
||||
#borrow(text)
|
||||
extern "C" fn ffi_set_tooltip(w : Widget, text : Bytes) = "mm_gtk_widget_set_tooltip"
|
||||
@@ -436,6 +442,17 @@ pub fn Widget::set_items(
|
||||
ffi_dropdown_set(self, cstr(clean.join("\n")), selected)
|
||||
}
|
||||
|
||||
///|
|
||||
/// A 0..1 level bar (peak meter).
|
||||
pub fn level_bar() -> Widget {
|
||||
ffi_levelbar_new()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::set_level(self : Widget, v : Double) -> Unit {
|
||||
ffi_levelbar_set(self, v)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::set_tooltip(self : Widget, text : String) -> Unit {
|
||||
ffi_set_tooltip(self, cstr(text))
|
||||
|
||||
+22
-1
@@ -7,6 +7,7 @@
|
||||
* widgets programmatically (mm_gtk_set_*), callbacks are suppressed so model
|
||||
* updates never echo back into PipeWire.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "moonbit.h"
|
||||
@@ -314,6 +315,22 @@ MOONBIT_FFI_EXPORT void mm_gtk_dropdown_set(GtkWidget *dd,
|
||||
g_suppress--;
|
||||
}
|
||||
|
||||
/* Thin 0..1 level bar for peak meters, without GTK's low/high/full colour
|
||||
* offsets (a quiet signal is not a warning). */
|
||||
MOONBIT_FFI_EXPORT GtkWidget *mm_gtk_levelbar_new(void) {
|
||||
GtkWidget *lb = gtk_level_bar_new_for_interval(0.0, 1.0);
|
||||
GtkLevelBar *l = GTK_LEVEL_BAR(lb);
|
||||
gtk_level_bar_remove_offset_value(l, GTK_LEVEL_BAR_OFFSET_LOW);
|
||||
gtk_level_bar_remove_offset_value(l, GTK_LEVEL_BAR_OFFSET_HIGH);
|
||||
gtk_level_bar_remove_offset_value(l, GTK_LEVEL_BAR_OFFSET_FULL);
|
||||
gtk_widget_set_hexpand(lb, TRUE);
|
||||
return lb;
|
||||
}
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_gtk_levelbar_set(GtkWidget *lb, double v) {
|
||||
gtk_level_bar_set_value(GTK_LEVEL_BAR(lb), v);
|
||||
}
|
||||
|
||||
/* ---- generic widget properties ------------------------------------------ */
|
||||
|
||||
MOONBIT_FFI_EXPORT void mm_gtk_widget_set_tooltip(GtkWidget *w,
|
||||
@@ -356,8 +373,10 @@ MOONBIT_FFI_EXPORT void mm_gtk_widget_set_valign_center(GtkWidget *w) {
|
||||
MOONBIT_FFI_EXPORT int32_t mm_gtk_save_png(GtkWidget *w, moonbit_bytes_t path) {
|
||||
int width = gtk_widget_get_width(w), height = gtk_widget_get_height(w);
|
||||
GtkNative *native = gtk_widget_get_native(w);
|
||||
if (width <= 0 || height <= 0 || !native)
|
||||
if (width <= 0 || height <= 0 || !native) {
|
||||
fprintf(stderr, "moonmix: save_png: not realized (%dx%d)\n", width, height);
|
||||
return 0;
|
||||
}
|
||||
GdkPaintable *paintable = gtk_widget_paintable_new(w);
|
||||
GtkSnapshot *snap = gtk_snapshot_new();
|
||||
gdk_paintable_snapshot(paintable, snap, width, height);
|
||||
@@ -368,6 +387,8 @@ MOONBIT_FFI_EXPORT int32_t mm_gtk_save_png(GtkWidget *w, moonbit_bytes_t path) {
|
||||
graphene_rect_t bounds = GRAPHENE_RECT_INIT(0, 0, width, height);
|
||||
GdkTexture *tex = gsk_renderer_render_texture(r, node, &bounds);
|
||||
ok = gdk_texture_save_to_png(tex, s(path));
|
||||
if (!ok)
|
||||
fprintf(stderr, "moonmix: save_png: writing %s failed\n", s(path));
|
||||
g_object_unref(tex);
|
||||
gsk_render_node_unref(node);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ pub fn init_gtk() -> Bool
|
||||
|
||||
pub fn label(String) -> Widget
|
||||
|
||||
pub fn level_bar() -> Widget
|
||||
|
||||
pub fn load_css(String) -> Unit
|
||||
|
||||
pub fn notebook(on_switch? : (Int32) -> Unit) -> Widget
|
||||
@@ -58,6 +60,7 @@ pub fn Widget::set_child(Self, Self) -> Unit
|
||||
pub fn Widget::set_hexpand(Self, Bool) -> Unit
|
||||
pub fn Widget::set_icon(Self, String) -> Unit
|
||||
pub fn Widget::set_items(Self, Array[String], Int32) -> Unit
|
||||
pub fn Widget::set_level(Self, Double) -> Unit
|
||||
pub fn Widget::set_margins(Self, Int32) -> Unit
|
||||
pub fn Widget::set_page(Self, Int32) -> Unit
|
||||
pub fn Widget::set_sensitive(Self, Bool) -> Unit
|
||||
|
||||
Reference in new issue
Block a user