mirror of
https://github.com/Xetibo/ReSet.git
synced 2025-04-12 08:28:32 +02:00
wip: generic audio implementation
This commit is contained in:
parent
f2e833eae5
commit
472584649b
|
@ -7,8 +7,9 @@ repository = "https://github.com/Xetibo/ReSet"
|
|||
license = "GPL-3.0-or-later"
|
||||
|
||||
[dependencies]
|
||||
#reset_daemon = "1.1.0"
|
||||
re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" }
|
||||
# reset_daemon = "1.1.0"
|
||||
re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib" , branch = "audioobject"}
|
||||
# re_set-lib = "3.1.6"
|
||||
reset_daemon = { git = "https://github.com/Xetibo/ReSet-Daemon", branch = "dashie" }
|
||||
adw = { version = "0.6.0", package = "libadwaita", features = ["v1_4"] }
|
||||
dbus = "0.9.7"
|
||||
|
|
129
src/components/audio/generic_audio_functions.rs
Normal file
129
src/components/audio/generic_audio_functions.rs
Normal file
|
@ -0,0 +1,129 @@
|
|||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use adw::traits::ComboRowExt;
|
||||
use dbus::{
|
||||
arg::{Arg, Get, ReadAll},
|
||||
blocking::Connection,
|
||||
Error,
|
||||
};
|
||||
use gtk::{
|
||||
gio,
|
||||
prelude::{BoxExt, ButtonExt, CheckButtonExt, ListBoxRowExt, RangeExt},
|
||||
};
|
||||
use re_set_lib::audio::audio_structures::AudioObject;
|
||||
|
||||
use crate::components::{
|
||||
base::error_impl::{show_error, ReSetErrorImpl},
|
||||
utils::{AUDIO, BASE, DBUS_PATH},
|
||||
};
|
||||
|
||||
use super::generic_entry::{Audio, AudioBox, AudioBoxImpl, AudioImpl};
|
||||
|
||||
pub fn set_volume<T: ReSetErrorImpl + 'static>(
|
||||
value: f64,
|
||||
index: u32,
|
||||
channels: u16,
|
||||
reset_box: Arc<T>,
|
||||
function: (&'static str, &'static str),
|
||||
) -> bool {
|
||||
gio::spawn_blocking(move || {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(), Error> =
|
||||
proxy.method_call(AUDIO, function.0, (index, channels, value as u32));
|
||||
if res.is_err() {
|
||||
// TODO: also log this with LOG/ERROR
|
||||
show_error::<T>(reset_box.clone(), function.1);
|
||||
}
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn toggle_audio_object_mute<T: ReSetErrorImpl + 'static>(
|
||||
index: u32,
|
||||
muted: bool,
|
||||
input_box: Arc<T>,
|
||||
function: (&'static str, &'static str),
|
||||
) -> bool {
|
||||
gio::spawn_blocking(move || {
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(), Error> = proxy.method_call(AUDIO, function.0, (index, muted));
|
||||
if res.is_err() {
|
||||
// TODO: also log this with LOG/ERROR
|
||||
show_error::<T>(input_box.clone(), function.1);
|
||||
}
|
||||
});
|
||||
true
|
||||
}
|
||||
|
||||
pub fn set_default_audio_object<T, R>(
|
||||
name: Arc<String>,
|
||||
input_box: Arc<T>,
|
||||
function: (&'static str, &'static str),
|
||||
) -> Option<R>
|
||||
where
|
||||
T: ReSetErrorImpl + 'static,
|
||||
R: Arg + for<'z> Get<'z>,
|
||||
{
|
||||
let conn = Connection::new_session().unwrap();
|
||||
let proxy = conn.with_proxy(BASE, DBUS_PATH, Duration::from_millis(1000));
|
||||
let res: Result<(R,), Error> = proxy.method_call(AUDIO, function.0, (name.as_str(),));
|
||||
if res.is_err() {
|
||||
show_error::<T>(input_box.clone(), function.1);
|
||||
return None;
|
||||
}
|
||||
Some(res.unwrap().0)
|
||||
}
|
||||
|
||||
pub fn refresh_default_audio_object<
|
||||
A: AudioBox<BoxImpl> + Send + Sync + 'static,
|
||||
OBJ: AudioObject + Send + Sync + 'static,
|
||||
Entry: Audio<OBJ, EntryImpl>,
|
||||
EntryImpl: AudioImpl<OBJ>,
|
||||
BoxImpl: AudioBoxImpl<OBJ, Entry, EntryImpl>,
|
||||
>(
|
||||
new_audio_object: OBJ,
|
||||
reset_box: Arc<A>,
|
||||
entry: bool,
|
||||
) {
|
||||
let volume = *new_audio_object.volume().first().unwrap_or(&0_u32);
|
||||
let fraction = (volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
glib::spawn_future(async move {
|
||||
glib::idle_add_once(move || {
|
||||
let imp = reset_box.box_imp();
|
||||
if !entry {
|
||||
let list = imp.audio_object_list();
|
||||
let list = list.read().unwrap();
|
||||
let entry = list.get(&new_audio_object.index());
|
||||
if entry.is_none() {
|
||||
return;
|
||||
}
|
||||
let entry_imp = entry.unwrap().1.entry_imp();
|
||||
entry_imp.selected_audio_object().set_active(true);
|
||||
} else {
|
||||
let index = imp.model_index();
|
||||
let index = index.read().unwrap();
|
||||
let model_list = imp.model_list();
|
||||
let model_list = model_list.read().unwrap();
|
||||
for entry in 0..*index {
|
||||
if model_list.string(entry) == Some(new_audio_object.alias().clone().into()) {
|
||||
imp.audio_object_dropdown().set_selected(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
imp.volume_percentage().set_text(&percentage);
|
||||
imp.volume_slider().set_value(volume as f64);
|
||||
if new_audio_object.muted() {
|
||||
imp.audio_object_mute()
|
||||
.set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.audio_object_mute()
|
||||
.set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
imp.default_audio_object().replace(new_audio_object);
|
||||
});
|
||||
});
|
||||
}
|
197
src/components/audio/generic_entry.rs
Normal file
197
src/components/audio/generic_entry.rs
Normal file
|
@ -0,0 +1,197 @@
|
|||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::RwLock;
|
||||
use std::time::Duration;
|
||||
use std::{cell::RefCell, sync::Arc, time::SystemTime};
|
||||
|
||||
use adw::prelude::{ButtonExt, CheckButtonExt, PreferencesRowExt, RangeExt};
|
||||
use adw::{ActionRow, ComboRow, PreferencesGroup};
|
||||
use dbus::arg::{Arg, Get, ReadAll};
|
||||
use glib::clone::{Downgrade, Upgrade};
|
||||
use glib::{clone, Propagation};
|
||||
use glib::{
|
||||
object::{IsA, IsClass, ObjectSubclassIs, ParentClassIs},
|
||||
subclass::types::{InstanceStruct, InstanceStructExt, ObjectSubclass, ObjectSubclassType},
|
||||
Object,
|
||||
};
|
||||
use gtk::{gio, Button, CheckButton, Label, Scale, StringList, TemplateChild};
|
||||
use re_set_lib::audio::audio_structures::{AudioObject, Source, Volume};
|
||||
|
||||
use crate::components::base::error::ReSetError;
|
||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
use crate::components::utils::set_action_row_ellipsis;
|
||||
|
||||
use super::generic_audio_functions::{
|
||||
refresh_default_audio_object, set_default_audio_object, set_volume, toggle_audio_object_mute,
|
||||
};
|
||||
|
||||
pub trait Audio<T: AudioObject, IMP: AudioImpl<T>>: IsClass + IsA<glib::Object> {
|
||||
fn entry_imp(&self) -> &IMP;
|
||||
}
|
||||
|
||||
pub trait AudioBox<AudioBoxImpl> {
|
||||
fn box_imp(&self) -> &AudioBoxImpl;
|
||||
}
|
||||
|
||||
pub type AudioEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>, String)>>>;
|
||||
pub type AudioStreamEntryMap<T> = Arc<RwLock<HashMap<u32, (Arc<ListEntry>, Arc<T>)>>>;
|
||||
pub type AudioMap = Arc<RwLock<HashMap<String, (u32, String)>>>;
|
||||
|
||||
pub trait AudioBoxImpl<OBJ, ENTRY, STREAMENTRY> {
|
||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow>;
|
||||
fn cards_row(&self) -> &TemplateChild<ActionRow>;
|
||||
fn audio_object_dropdown(&self) -> &TemplateChild<ComboRow>;
|
||||
fn audio_object_mute(&self) -> &TemplateChild<Button>;
|
||||
fn volume_slider(&self) -> &TemplateChild<Scale>;
|
||||
fn volume_percentage(&self) -> &TemplateChild<Label>;
|
||||
fn audio_objects(&self) -> &TemplateChild<gtk::Box>;
|
||||
fn audio_object_stream_button(&self) -> &TemplateChild<ActionRow>;
|
||||
fn audio_object_streams(&self) -> &TemplateChild<gtk::Box>;
|
||||
fn cards_button(&self) -> &TemplateChild<ActionRow>;
|
||||
fn cards(&self) -> &TemplateChild<PreferencesGroup>;
|
||||
fn error(&self) -> &TemplateChild<ReSetError>;
|
||||
fn default_check_button(&self) -> Arc<CheckButton>;
|
||||
fn default_audio_object(&self) -> Arc<RefCell<OBJ>>;
|
||||
fn audio_object_list(&self) -> &AudioEntryMap<ENTRY>;
|
||||
// fn audio_object_stream_list(&self) -> AudioStreamEntryMap<STREAMENTRY>;
|
||||
fn model_list(&self) -> Arc<RwLock<StringList>>;
|
||||
fn model_index(&self) -> Arc<RwLock<u32>>;
|
||||
fn source_map(&self) -> &AudioMap;
|
||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
|
||||
}
|
||||
|
||||
pub trait AudioImpl<T: AudioObject> {
|
||||
fn name(&self) -> &TemplateChild<ActionRow>;
|
||||
fn selected_audio_object(&self) -> &TemplateChild<CheckButton>;
|
||||
fn mute(&self) -> &TemplateChild<Button>;
|
||||
fn volume_slider(&self) -> &TemplateChild<Scale>;
|
||||
fn volume_percentage(&self) -> &TemplateChild<Label>;
|
||||
fn audio_object(&self) -> Arc<RefCell<T>>;
|
||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>>;
|
||||
fn set_volume_fn(&self) -> (&'static str, &'static str);
|
||||
fn set_audio_object_fn(&self) -> (&'static str, &'static str);
|
||||
fn set_mute_fn(&self) -> (&'static str, &'static str);
|
||||
}
|
||||
|
||||
// pub trait AudioObject {
|
||||
// fn alias(&self) -> String;
|
||||
// fn name(&self) -> String;
|
||||
// fn volume(&self) -> Vec<u32>;
|
||||
// fn index(&self) -> u32;
|
||||
// fn channels(&self) -> u16;
|
||||
// fn muted(&self) -> bool;
|
||||
// fn toggle_muted(&mut self);
|
||||
// fn active() -> i32;
|
||||
// }
|
||||
|
||||
pub fn new_entry<
|
||||
AObject: AudioObject + Arg + for<'z> Get<'z> + Send + Sync + 'static,
|
||||
ABox: AudioBox<BoxImpl> + ReSetErrorImpl + 'static,
|
||||
Entry: Audio<AObject, EntryImpl>,
|
||||
EntryImpl: AudioImpl<AObject>,
|
||||
BoxImpl: AudioBoxImpl<AObject, Entry, EntryImpl>,
|
||||
>(
|
||||
is_default: bool,
|
||||
check_group: Arc<CheckButton>,
|
||||
audio_object: AObject,
|
||||
reset_box: Arc<ABox>,
|
||||
) -> Arc<Entry> {
|
||||
let obj: Arc<Entry> = Arc::new(Object::builder().build());
|
||||
// TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||
{
|
||||
let imp = obj.entry_imp();
|
||||
let slider_obj_ref = obj.clone();
|
||||
let mute_obj_ref = obj.clone();
|
||||
imp.name().set_title(audio_object.alias().clone().as_str());
|
||||
let name = Arc::new(audio_object.name().clone());
|
||||
let volume = audio_object.volume();
|
||||
let volume = volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
let output_box_slider = reset_box.clone();
|
||||
let output_box_ref = reset_box.clone();
|
||||
imp.volume_percentage().set_text(&percentage);
|
||||
imp.volume_slider().set_value(*volume as f64);
|
||||
imp.audio_object().replace(audio_object);
|
||||
imp.volume_slider()
|
||||
.connect_change_value(move |_, _, value| {
|
||||
let imp = slider_obj_ref.entry_imp();
|
||||
let fraction = (value / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.volume_percentage().set_text(&percentage);
|
||||
let sink = imp.audio_object();
|
||||
let sink = sink.borrow();
|
||||
let index = sink.index();
|
||||
let channels = sink.channels();
|
||||
{
|
||||
let time = imp.volume_time_stamp();
|
||||
let mut time = time.borrow_mut();
|
||||
if time.is_some()
|
||||
&& time.unwrap().elapsed().unwrap() < Duration::from_millis(50)
|
||||
{
|
||||
return Propagation::Proceed;
|
||||
}
|
||||
*time = Some(SystemTime::now());
|
||||
}
|
||||
set_volume(
|
||||
value,
|
||||
index,
|
||||
channels,
|
||||
output_box_slider.clone(),
|
||||
imp.set_volume_fn(),
|
||||
);
|
||||
Propagation::Proceed
|
||||
});
|
||||
imp.selected_audio_object().set_group(Some(&*check_group));
|
||||
if is_default {
|
||||
imp.selected_audio_object().set_active(true);
|
||||
} else {
|
||||
imp.selected_audio_object().set_active(false);
|
||||
}
|
||||
|
||||
let audio_object_fn = imp.set_audio_object_fn();
|
||||
imp.selected_audio_object().connect_toggled(move |button| {
|
||||
let output_box_ref = reset_box.clone();
|
||||
if button.is_active() {
|
||||
let name = name.clone();
|
||||
gio::spawn_blocking(move || {
|
||||
// TODO: make this generic as well
|
||||
let result = set_default_audio_object::<ABox, AObject>(
|
||||
name,
|
||||
output_box_ref.clone(),
|
||||
audio_object_fn,
|
||||
);
|
||||
if result.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
refresh_default_audio_object::<ABox, AObject, Entry, EntryImpl, BoxImpl>(
|
||||
result.unwrap(),
|
||||
output_box_ref,
|
||||
true,
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
imp.mute().connect_clicked(move |_| {
|
||||
let imp = mute_obj_ref.entry_imp();
|
||||
let audio_object = imp.audio_object().clone();
|
||||
let mut audio_object = audio_object.borrow_mut();
|
||||
audio_object.toggle_muted();
|
||||
if audio_object.muted() {
|
||||
imp.mute().set_icon_name("audio-volume-muted-symbolic");
|
||||
} else {
|
||||
imp.mute().set_icon_name("audio-volume-high-symbolic");
|
||||
}
|
||||
toggle_audio_object_mute::<ABox>(
|
||||
audio_object.index(),
|
||||
audio_object.muted(),
|
||||
output_box_ref.clone(),
|
||||
imp.set_mute_fn(),
|
||||
);
|
||||
});
|
||||
set_action_row_ellipsis(imp.name().get());
|
||||
}
|
||||
obj
|
||||
}
|
|
@ -14,6 +14,7 @@ use glib::Variant;
|
|||
use gtk::gio;
|
||||
use gtk::prelude::ActionableExt;
|
||||
|
||||
use crate::components::audio::generic_entry::AudioBox;
|
||||
use crate::components::audio::input::source_box_impl;
|
||||
use crate::components::base::error::{self};
|
||||
use crate::components::base::error_impl::ReSetErrorImpl;
|
||||
|
@ -45,6 +46,12 @@ impl ReSetErrorImpl for SourceBox {
|
|||
}
|
||||
}
|
||||
|
||||
impl AudioBox<super::source_box_impl::SourceBox> for SourceBox {
|
||||
fn box_imp(&self) -> &super::source_box_impl::SourceBox {
|
||||
self.imp()
|
||||
}
|
||||
}
|
||||
|
||||
impl SourceBox {
|
||||
pub fn new() -> Self {
|
||||
let obj: Self = Object::builder().build();
|
||||
|
|
|
@ -37,12 +37,12 @@ pub fn source_added_handler(source_box: Arc<SourceBox>, ir: SourceAdded) -> bool
|
|||
if source_box_imp.reset_default_source.borrow().name == ir.source.name {
|
||||
is_default = true;
|
||||
}
|
||||
let source_entry = Arc::new(SourceEntry::new(
|
||||
let source_entry = SourceEntry::new(
|
||||
is_default,
|
||||
source_box_imp.reset_default_check_button.clone(),
|
||||
ir.source,
|
||||
source_box.clone(),
|
||||
));
|
||||
);
|
||||
let source_clone = source_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*source_entry));
|
||||
entry.set_activatable(false);
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
|||
use std::sync::{Arc, RwLock};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::components::audio::generic_entry::AudioBoxImpl;
|
||||
use crate::components::audio::input::source_box;
|
||||
use crate::components::base::error::ReSetError;
|
||||
use crate::components::base::list_entry::ListEntry;
|
||||
|
@ -35,7 +36,6 @@ pub struct SourceBox {
|
|||
pub reset_volume_slider: TemplateChild<Scale>,
|
||||
#[template_child]
|
||||
pub reset_volume_percentage: TemplateChild<Label>,
|
||||
|
||||
#[template_child]
|
||||
pub reset_sources: TemplateChild<gtk::Box>,
|
||||
#[template_child]
|
||||
|
@ -93,3 +93,89 @@ impl WidgetImpl for SourceBox {}
|
|||
impl WindowImpl for SourceBox {}
|
||||
|
||||
impl ApplicationWindowImpl for SourceBox {}
|
||||
|
||||
impl AudioBoxImpl<Source, SourceEntry, super::source_entry_impl::SourceEntry> for SourceBox {
|
||||
fn audio_object_row(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_source_row
|
||||
}
|
||||
|
||||
fn cards_row(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_cards_row
|
||||
}
|
||||
|
||||
fn audio_object_dropdown(&self) -> &TemplateChild<ComboRow> {
|
||||
&self.reset_source_dropdown
|
||||
}
|
||||
|
||||
fn audio_object_mute(&self) -> &TemplateChild<Button> {
|
||||
&self.reset_source_mute
|
||||
}
|
||||
|
||||
fn volume_slider(&self) -> &TemplateChild<Scale> {
|
||||
&self.reset_volume_slider
|
||||
}
|
||||
|
||||
fn volume_percentage(&self) -> &TemplateChild<Label> {
|
||||
&self.reset_volume_percentage
|
||||
}
|
||||
|
||||
fn audio_objects(&self) -> &TemplateChild<gtk::Box> {
|
||||
&self.reset_sources
|
||||
}
|
||||
|
||||
fn audio_object_stream_button(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_output_stream_button
|
||||
}
|
||||
|
||||
fn audio_object_streams(&self) -> &TemplateChild<gtk::Box> {
|
||||
&self.reset_output_streams
|
||||
}
|
||||
|
||||
fn cards_button(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_input_cards_back_button
|
||||
}
|
||||
|
||||
fn cards(&self) -> &TemplateChild<PreferencesGroup> {
|
||||
&self.reset_cards
|
||||
}
|
||||
|
||||
fn error(&self) -> &TemplateChild<ReSetError> {
|
||||
&self.error
|
||||
}
|
||||
|
||||
fn default_check_button(&self) -> Arc<CheckButton> {
|
||||
self.reset_default_check_button.clone()
|
||||
}
|
||||
|
||||
fn default_audio_object(&self) -> Arc<RefCell<Source>> {
|
||||
self.reset_default_source.clone()
|
||||
}
|
||||
|
||||
fn audio_object_list(
|
||||
&self,
|
||||
) -> &crate::components::audio::generic_entry::AudioEntryMap<SourceEntry> {
|
||||
&self.reset_source_list
|
||||
}
|
||||
|
||||
// fn audio_object_stream_list(
|
||||
// &self,
|
||||
// ) -> &crate::components::audio::generic_entry::AudioStreamEntryMap<SourceEntry> {
|
||||
// &
|
||||
// }
|
||||
|
||||
fn model_list(&self) -> Arc<RwLock<StringList>> {
|
||||
self.reset_model_list.clone()
|
||||
}
|
||||
|
||||
fn model_index(&self) -> Arc<RwLock<u32>> {
|
||||
self.reset_model_index.clone()
|
||||
}
|
||||
|
||||
fn source_map(&self) -> &crate::components::audio::generic_entry::AudioMap {
|
||||
&self.reset_source_map
|
||||
}
|
||||
|
||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
|
||||
&self.volume_time_stamp
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ pub fn populate_source_information(source_box: Arc<SourceBox>, sources: Vec<Sour
|
|||
if source_box_imp.reset_default_source.borrow().name == source.name {
|
||||
is_default = true;
|
||||
}
|
||||
let source_entry = Arc::new(SourceEntry::new(
|
||||
let source_entry = SourceEntry::new(
|
||||
is_default,
|
||||
source_box_imp.reset_default_check_button.clone(),
|
||||
source,
|
||||
source_box.clone(),
|
||||
));
|
||||
);
|
||||
let source_clone = source_entry.clone();
|
||||
let entry = Arc::new(ListEntry::new(&*source_entry));
|
||||
entry.set_activatable(false);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use crate::components::audio::generic_entry::{new_entry, Audio, AudioImpl};
|
||||
use crate::components::base::error_impl::show_error;
|
||||
use crate::components::utils::set_action_row_ellipsis;
|
||||
use adw::glib::Object;
|
||||
|
@ -27,85 +28,105 @@ glib::wrapper! {
|
|||
unsafe impl Send for SourceEntry {}
|
||||
unsafe impl Sync for SourceEntry {}
|
||||
|
||||
impl Audio<Source, super::source_entry_impl::SourceEntry> for SourceEntry {
|
||||
fn entry_imp(&self) -> &super::source_entry_impl::SourceEntry {
|
||||
self.imp()
|
||||
}
|
||||
}
|
||||
|
||||
impl SourceEntry {
|
||||
pub fn new(
|
||||
is_default: bool,
|
||||
check_group: Arc<CheckButton>,
|
||||
source: Source,
|
||||
input_box: Arc<SourceBox>,
|
||||
) -> Self {
|
||||
let obj: Self = Object::builder().build();
|
||||
// TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||
{
|
||||
let imp = obj.imp();
|
||||
imp.reset_source_name
|
||||
.set_title(source.alias.clone().as_str());
|
||||
let name = Arc::new(source.name.clone());
|
||||
let volume = source.volume.first().unwrap_or(&0_u32);
|
||||
let fraction = (*volume as f64 / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
let input_box_slider = input_box.clone();
|
||||
let input_box_ref = input_box.clone();
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
imp.reset_volume_slider.set_value(*volume as f64);
|
||||
imp.source.replace(source);
|
||||
imp.reset_volume_slider.connect_change_value(
|
||||
clone!(@weak imp => @default-return Propagation::Stop, move |_, _, value| {
|
||||
let fraction = (value / 655.36).round();
|
||||
let percentage = (fraction).to_string() + "%";
|
||||
imp.reset_volume_percentage.set_text(&percentage);
|
||||
let source = imp.source.borrow();
|
||||
let index = source.index;
|
||||
let channels = source.channels;
|
||||
{
|
||||
let mut time = imp.volume_time_stamp.borrow_mut();
|
||||
if time.is_some()
|
||||
&& time.unwrap().elapsed().unwrap() < Duration::from_millis(50)
|
||||
{
|
||||
return Propagation::Proceed;
|
||||
}
|
||||
*time = Some(SystemTime::now());
|
||||
}
|
||||
set_source_volume(value, index, channels, input_box_slider.clone());
|
||||
Propagation::Proceed
|
||||
}),
|
||||
);
|
||||
imp.reset_selected_source.set_group(Some(&*check_group));
|
||||
if is_default {
|
||||
imp.reset_selected_source.set_active(true);
|
||||
} else {
|
||||
imp.reset_selected_source.set_active(false);
|
||||
}
|
||||
imp.reset_selected_source.connect_toggled(move |button| {
|
||||
let input_box = input_box.clone();
|
||||
if button.is_active() {
|
||||
let name = name.clone();
|
||||
gio::spawn_blocking(move || {
|
||||
let result = set_default_source(name, input_box.clone());
|
||||
if result.is_none() {
|
||||
return;
|
||||
}
|
||||
refresh_default_source(result.unwrap(), input_box, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
imp.reset_source_mute
|
||||
.connect_clicked(clone!(@weak imp => move |_| {
|
||||
let mut source = imp.source.borrow_mut();
|
||||
source.muted = !source.muted;
|
||||
if source.muted {
|
||||
imp.reset_source_mute
|
||||
.set_icon_name("microphone-disabled-symbolic");
|
||||
} else {
|
||||
imp.reset_source_mute
|
||||
.set_icon_name("audio-input-microphone-symbolic");
|
||||
}
|
||||
toggle_source_mute(source.index, source.muted, input_box_ref.clone());
|
||||
}));
|
||||
set_action_row_ellipsis(imp.reset_source_name.get());
|
||||
}
|
||||
obj
|
||||
) -> Arc<Self> {
|
||||
new_entry::<
|
||||
Source,
|
||||
SourceBox,
|
||||
SourceEntry,
|
||||
super::source_entry_impl::SourceEntry,
|
||||
super::source_box_impl::SourceBox,
|
||||
>(is_default, check_group, source, input_box)
|
||||
}
|
||||
// pub fn new(
|
||||
// is_default: bool,
|
||||
// check_group: Arc<CheckButton>,
|
||||
// source: Source,
|
||||
// input_box: Arc<SourceBox>,
|
||||
// ) -> Self {
|
||||
// let obj: Self = Object::builder().build();
|
||||
// // TODO use event callback for progress bar -> this is the "im speaking" indicator
|
||||
// {
|
||||
// let imp = obj.imp();
|
||||
// imp.reset_source_name
|
||||
// .set_title(source.alias.clone().as_str());
|
||||
// let name = Arc::new(source.name.clone());
|
||||
// let volume = source.volume.first().unwrap_or(&0_u32);
|
||||
// let fraction = (*volume as f64 / 655.36).round();
|
||||
// let percentage = (fraction).to_string() + "%";
|
||||
// let input_box_slider = input_box.clone();
|
||||
// let input_box_ref = input_box.clone();
|
||||
// imp.reset_volume_percentage.set_text(&percentage);
|
||||
// imp.reset_volume_slider.set_value(*volume as f64);
|
||||
// imp.source.replace(source);
|
||||
// imp.reset_volume_slider.connect_change_value(
|
||||
// clone!(@weak imp => @default-return Propagation::Stop, move |_, _, value| {
|
||||
// let fraction = (value / 655.36).round();
|
||||
// let percentage = (fraction).to_string() + "%";
|
||||
// imp.reset_volume_percentage.set_text(&percentage);
|
||||
// let source = imp.source.borrow();
|
||||
// let index = source.index;
|
||||
// let channels = source.channels;
|
||||
// {
|
||||
// let mut time = imp.volume_time_stamp.borrow_mut();
|
||||
// if time.is_some()
|
||||
// && time.unwrap().elapsed().unwrap() < Duration::from_millis(50)
|
||||
// {
|
||||
// return Propagation::Proceed;
|
||||
// }
|
||||
// *time = Some(SystemTime::now());
|
||||
// }
|
||||
// set_source_volume(value, index, channels, input_box_slider.clone());
|
||||
// Propagation::Proceed
|
||||
// }),
|
||||
// );
|
||||
// imp.reset_selected_source.set_group(Some(&*check_group));
|
||||
// if is_default {
|
||||
// imp.reset_selected_source.set_active(true);
|
||||
// } else {
|
||||
// imp.reset_selected_source.set_active(false);
|
||||
// }
|
||||
// imp.reset_selected_source.connect_toggled(move |button| {
|
||||
// let input_box = input_box.clone();
|
||||
// if button.is_active() {
|
||||
// let name = name.clone();
|
||||
// gio::spawn_blocking(move || {
|
||||
// let result = set_default_source(name, input_box.clone());
|
||||
// if result.is_none() {
|
||||
// return;
|
||||
// }
|
||||
// refresh_default_source(result.unwrap(), input_box, true);
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// imp.reset_source_mute
|
||||
// .connect_clicked(clone!(@weak imp => move |_| {
|
||||
// let mut source = imp.source.borrow_mut();
|
||||
// source.muted = !source.muted;
|
||||
// if source.muted {
|
||||
// imp.reset_source_mute
|
||||
// .set_icon_name("microphone-disabled-symbolic");
|
||||
// } else {
|
||||
// imp.reset_source_mute
|
||||
// .set_icon_name("audio-input-microphone-symbolic");
|
||||
// }
|
||||
// toggle_source_mute(source.index, source.muted, input_box_ref.clone());
|
||||
// }));
|
||||
// set_action_row_ellipsis(imp.reset_source_name.get());
|
||||
// }
|
||||
// obj
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn set_source_volume(value: f64, index: u32, channels: u16, input_box: Arc<SourceBox>) -> bool {
|
||||
|
|
|
@ -8,6 +8,8 @@ use std::time::SystemTime;
|
|||
use gtk::subclass::prelude::*;
|
||||
use gtk::{Button, CheckButton, CompositeTemplate, Label, Scale};
|
||||
|
||||
use crate::components::audio::generic_entry::AudioImpl;
|
||||
|
||||
use super::source_entry;
|
||||
|
||||
#[derive(Default, CompositeTemplate)]
|
||||
|
@ -48,3 +50,45 @@ impl PreferencesGroupImpl for SourceEntry {}
|
|||
impl ObjectImpl for SourceEntry {}
|
||||
|
||||
impl WidgetImpl for SourceEntry {}
|
||||
|
||||
impl AudioImpl<Source> for SourceEntry {
|
||||
fn name(&self) -> &TemplateChild<ActionRow> {
|
||||
&self.reset_source_name
|
||||
}
|
||||
|
||||
fn selected_audio_object(&self) -> &TemplateChild<CheckButton> {
|
||||
&self.reset_selected_source
|
||||
}
|
||||
|
||||
fn mute(&self) -> &TemplateChild<Button> {
|
||||
&self.reset_source_mute
|
||||
}
|
||||
|
||||
fn volume_slider(&self) -> &TemplateChild<Scale> {
|
||||
&self.reset_volume_slider
|
||||
}
|
||||
|
||||
fn volume_percentage(&self) -> &TemplateChild<Label> {
|
||||
&self.reset_volume_percentage
|
||||
}
|
||||
|
||||
fn audio_object(&self) -> Arc<RefCell<Source>> {
|
||||
self.source.clone()
|
||||
}
|
||||
|
||||
fn volume_time_stamp(&self) -> &RefCell<Option<SystemTime>> {
|
||||
&self.volume_time_stamp
|
||||
}
|
||||
|
||||
fn set_volume_fn(&self) -> (&'static str, &'static str) {
|
||||
("SetSourceVolume", "Failed to set set source volume")
|
||||
}
|
||||
|
||||
fn set_audio_object_fn(&self) -> (&'static str, &'static str) {
|
||||
("SetDefaultSource", "Faield to set default source")
|
||||
}
|
||||
|
||||
fn set_mute_fn(&self) -> (&'static str, &'static str) {
|
||||
("SetSourceMute", "Failed to mute source")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
pub mod generic_audio_functions;
|
||||
pub mod generic_entry;
|
||||
pub mod input;
|
||||
pub mod output;
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
use crate::components::plugin::function::{TSideBarInfo};
|
||||
use crate::components::plugin::function::TSideBarInfo;
|
||||
use crate::components::window::sidebar_entry_impl;
|
||||
use crate::components::window::sidebar_entry_impl::SidebarAction;
|
||||
use adw::subclass::prelude::ObjectSubclassIsExt;
|
||||
use glib::Object;
|
||||
use gtk::prelude::*;
|
||||
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct SidebarEntry(ObjectSubclass<sidebar_entry_impl::SidebarEntry>)
|
||||
@extends gtk::ListBoxRow, gtk::Widget,
|
||||
|
|
Loading…
Reference in a new issue