Skip to content

Commit

Permalink
Add over-amplification support.
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed Jun 9, 2024
1 parent 470a3bf commit 88e29bb
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
5 changes: 5 additions & 0 deletions data/com.saivert.pwvucontrol.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
<summary>Default window maximized behaviour</summary>
<description></description>
</key>
<key name="enable-overamplification" type="b">
<default>false</default>
<summary>Enable over-amplification</summary>
<description></description>
</key>
</schema>
</schemalist>
4 changes: 4 additions & 0 deletions data/resources/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@
</template>
<menu id="primary_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Enable over-amplification</attribute>
<attribute name="action">win.enable-overamplification</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
Expand Down
31 changes: 29 additions & 2 deletions src/backend/pwnodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use wp::{
registry::{Constraint, ConstraintType, Interest}
};
use std::cell::{Cell, RefCell};
use glib::{self, clone, subclass::{prelude::*, Signal}, ObjectExt, ParamSpec, Properties, Value, CastNone};
use glib::{self, clone, subclass::{prelude::*, Signal}, ObjectExt, ParamSpec, Properties, Value, CastNone, Cast};
use once_cell::sync::{Lazy, OnceCell};
use gtk::{gio, prelude::ListModelExt};
use super::{PwDeviceObject, PwRouteObject, PwChannelObject, PwvucontrolManager};
use wp::registry::ObjectManager;

use crate::macros::*;

mod mixerapi;
Expand Down Expand Up @@ -83,6 +85,8 @@ pub mod imp {
pub(super) wpnode: OnceCell<wp::pw::Node>,

pub(super) block: Cell<bool>,

pub(super) om: RefCell<ObjectManager>,
}

impl Default for PwNodeObject {
Expand All @@ -104,6 +108,7 @@ pub mod imp {
channellock: Default::default(),
wpnode: OnceCell::default(),
block: Default::default(),
om: Default::default(),
hidden: Default::default(),
}
}
Expand Down Expand Up @@ -205,6 +210,27 @@ pub mod imp {
obj.update_volume_using_mixerapi();
obj.update_icon_name();

let om = self.om.borrow();

om.add_interest([Constraint::compare(ConstraintType::PwProperty, "link.output.node", node.bound_id(), true)]
.iter().collect::<Interest<wp::pw::Link>>());

if let Ok(Some(device_id)) = node.device_id() {
om.add_interest([Constraint::compare(ConstraintType::PwGlobalProperty, "device.id", device_id, true)]
.iter()
.collect::<Interest<wp::pw::Device>>());
}


om.connect_object_added(clone!(@weak self as widget => move |_om, obj| {
if let Some(link) = obj.downcast_ref::<wp::pw::Link>() {
let linked_node_id: u32 = link.pw_property("link.input.node").expect("link.input.node property");
let linked_node = PwvucontrolManager::default().get_node_by_id(linked_node_id);
pwvucontrol_info!("Node {} linked to node id {linked_node_id} ({:?})", widget.obj().name(), linked_node.map(|x|x.name()));
}
}));

PwvucontrolManager::default().wp_core().install_object_manager(&om);
}
}

Expand Down Expand Up @@ -241,7 +267,7 @@ impl PwNodeObject {
let props = wp_node.global_properties().expect("Node has no properties");

let name_gstr = match self.nodetype() {
NodeType::Sink => {
NodeType::Sink | NodeType::Source => {
props
.get("node.description")
.or_else(|| props.get("node.nick"))
Expand Down Expand Up @@ -486,6 +512,7 @@ impl PwNodeObject {
}

pub(crate) fn get_device(&self) -> Option<PwDeviceObject> {

if let Ok(Some(device_id)) = self.wpnode().device_id() {
let manager = PwvucontrolManager::default();
return manager.get_device_by_id(device_id);
Expand Down
26 changes: 25 additions & 1 deletion src/ui/volumebox.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::{backend::PwChannelObject, backend::PwNodeObject, backend::PwvucontrolManager, ui::LevelbarProvider, ui::PwChannelBox};
use crate::{backend::{PwChannelObject, PwNodeObject, PwvucontrolManager}, ui::{LevelbarProvider, PwChannelBox, PwvucontrolWindow}};

use glib::{clone, closure_local, ControlFlow, SignalHandlerId};
use gtk::{prelude::*, subclass::prelude::*};
Expand Down Expand Up @@ -136,6 +136,30 @@ mod imp {
.transform_from(cubic_to_linear)
.build();

fn update_overamplification(volume_scale: &gtk::Scale) {
let window: PwvucontrolWindow = PwvucontrolWindow::default();
let enable_overamplification = window.imp().settings.boolean("enable-overamplification");

volume_scale.clear_marks();
volume_scale.add_mark(0.0, gtk::PositionType::Bottom, Some("Silence"));
volume_scale.add_mark(1.0, gtk::PositionType::Bottom, Some("100%"));


if enable_overamplification {
volume_scale.add_mark(1.525, gtk::PositionType::Bottom, Some("150%"));
volume_scale.set_range(0.0, 1.525);
} else {
volume_scale.set_range(0.0, 1.0);
}
}

update_overamplification(&self.volume_scale);

let window = PwvucontrolWindow::default();
window.imp().settings.connect_changed(Some("enable-overamplification"), clone!(@weak self as widget => move |_,_| {
update_overamplification(&widget.volume_scale);
}));

let manager = PwvucontrolManager::default();

let defaultnodesapi = manager.default_nodes_api();
Expand Down
3 changes: 3 additions & 0 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ mod imp {
}
});

let overamplification_action = self.settings.create_action("enable-overamplification");
self.obj().add_action(&overamplification_action);

self.obj().load_window_state();
}
}
Expand Down

0 comments on commit 88e29bb

Please sign in to comment.