Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Nov 8, 2023
2 parents dc4a07b + 4fb41dc commit 0e12812
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 1,808 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ReSet-Lib = "0.1.0"
ReSet-Lib = "0.1.8"
dbus = "0.9.7"
dbus-crossroads = "0.5.2"
dbus-tokio = "0.7.6"
Expand Down
332 changes: 5 additions & 327 deletions src/audio/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@ use std::{cell::RefCell, ops::Deref, rc::Rc};

use std::sync::mpsc::{Receiver, Sender};

use dbus::{
arg::{self, Append, Arg, ArgType, Get},
Signature,
};
use pulse::context::introspect::{SinkInputInfo, SourceOutputInfo};
use pulse::volume::{ChannelVolumes, Volume};
use pulse::{
self,
callbacks::ListResult,
context::{
introspect::{SinkInfo, SourceInfo},
Context, FlagSet,
},
context::{Context, FlagSet},
mainloop::threaded::Mainloop,
proplist::Proplist,
};
use ReSet_Lib::audio::audio::{InputStream, OutputStream, Sink, Source};

use crate::reset_dbus::{AudioRequest, AudioResponse};

Expand All @@ -31,323 +24,6 @@ pub struct PulseServer {
#[derive(Debug)]
pub struct PulseError(&'static str);

pub struct Source {
index: u32,
name: String,
alias: String,
channels: u16,
volume: Vec<u32>,
muted: bool,
}

impl Append for Source {
fn append_by_ref(&self, iter: &mut arg::IterAppend) {
iter.append_struct(|i| {
i.append(&self.index);
i.append(&self.name);
i.append(&self.alias);
i.append(&self.channels);
i.append(&self.volume);
i.append(&self.muted);
});
}
}

impl<'a> Get<'a> for Source {
fn get(i: &mut arg::Iter<'a>) -> Option<Self> {
let (index, name, alias, channels, volume, muted) =
<(u32, String, String, u16, Vec<u32>, bool)>::get(i)?;
Some(Self {
index,
name,
alias,
channels,
volume,
muted,
})
}
}

impl Arg for Source {
const ARG_TYPE: arg::ArgType = ArgType::Struct;
fn signature() -> Signature<'static> {
unsafe { Signature::from_slice_unchecked("(ussqaub)\0") }
}
}

impl From<&SourceInfo<'_>> for Source {
fn from(value: &SourceInfo<'_>) -> Self {
let name_opt = &value.name;
let alias_opt = &value.description;
let name: String;
let alias: String;
if name_opt.is_none() {
name = String::from("");
} else {
name = String::from(name_opt.clone().unwrap());
}
if alias_opt.is_none() {
alias = String::from("");
} else {
alias = String::from(alias_opt.clone().unwrap());
}
let index = value.index;
let channels = value.channel_map.len() as u16;
let mut volume = vec![0; channels as usize];
for i in 0..channels as usize {
unsafe { *volume.get_unchecked_mut(i) = value.volume.get()[i].0 };
}
let muted = value.mute;
Self {
index,
name,
alias,
channels,
volume,
muted,
}
}
}

#[derive(Debug)]
pub struct Sink {
index: u32,
name: String,
alias: String,
channels: u16,
volume: Vec<u32>,
muted: bool,
}

impl Append for Sink {
fn append_by_ref(&self, iter: &mut arg::IterAppend) {
iter.append_struct(|i| {
i.append(&self.index);
i.append(&self.name);
i.append(&self.alias);
i.append(&self.channels);
i.append(&self.volume);
i.append(&self.muted);
});
}
}

impl<'a> Get<'a> for Sink {
fn get(i: &mut arg::Iter<'a>) -> Option<Self> {
let (index, name, alias, channels, volume, muted) =
<(u32, String, String, u16, Vec<u32>, bool)>::get(i)?;
Some(Self {
index,
name,
alias,
channels,
volume,
muted,
})
}
}

impl Arg for Sink {
const ARG_TYPE: arg::ArgType = ArgType::Struct;
fn signature() -> Signature<'static> {
unsafe { Signature::from_slice_unchecked("(ussqaub)\0") }
}
}

impl From<&SinkInfo<'_>> for Sink {
fn from(value: &SinkInfo<'_>) -> Self {
let name_opt = &value.name;
let alias_opt = &value.description;
let name: String;
let alias: String;
if name_opt.is_none() {
name = String::from("");
} else {
name = String::from(name_opt.clone().unwrap());
}
if alias_opt.is_none() {
alias = String::from("");
} else {
alias = String::from(alias_opt.clone().unwrap());
}
let index = value.index;
let channels = value.channel_map.len() as u16;
let mut volume = vec![0; channels as usize];
for i in 0..channels as usize {
unsafe { *volume.get_unchecked_mut(i) = value.volume.get()[i].0 };
}
let muted = value.mute;
Self {
index,
name,
alias,
channels,
volume,
muted,
}
}
}

pub struct InputStream {
index: u32,
name: String,
application_name: String,
sink_index: u32,
channels: u16,
volume: Vec<u32>,
muted: bool,
}

impl Append for InputStream {
fn append_by_ref(&self, iter: &mut arg::IterAppend) {
iter.append_struct(|i| {
i.append(&self.index);
i.append(&self.name);
i.append(&self.application_name);
i.append(&self.sink_index);
i.append(&self.channels);
i.append(&self.volume);
i.append(&self.muted);
});
}
}

impl<'a> Get<'a> for InputStream {
fn get(i: &mut arg::Iter<'a>) -> Option<Self> {
let (index, name, application_name, sink_index, channels, volume, muted) =
<(u32, String, String, u32, u16, Vec<u32>, bool)>::get(i)?;
Some(Self {
index,
name,
application_name,
sink_index,
channels,
volume,
muted,
})
}
}

impl Arg for InputStream {
const ARG_TYPE: arg::ArgType = ArgType::Struct;
fn signature() -> Signature<'static> {
unsafe { Signature::from_slice_unchecked("(ussuqaub)\0") }
}
}

impl From<&SinkInputInfo<'_>> for InputStream {
fn from(value: &SinkInputInfo<'_>) -> Self {
let name_opt = &value.name;
let name: String;
if name_opt.is_none() {
name = String::from("");
} else {
name = String::from(name_opt.clone().unwrap());
}
let application_name = value
.proplist
.get_str("application.name")
.unwrap_or_default();
let sink_index = value.sink;
let index = value.index;
let channels = value.channel_map.len() as u16;
let mut volume = vec![0; channels as usize];
for i in 0..channels as usize {
unsafe { *volume.get_unchecked_mut(i) = value.volume.get()[i].0 };
}
let muted = value.mute;
Self {
index,
name,
application_name,
sink_index,
channels,
volume,
muted,
}
}
}

pub struct OutputStream {
index: u32,
name: String,
application_name: String,
source_index: u32,
channels: u16,
volume: Vec<u32>,
muted: bool,
}

impl Append for OutputStream {
fn append_by_ref(&self, iter: &mut arg::IterAppend) {
iter.append_struct(|i| {
i.append(&self.index);
i.append(&self.name);
i.append(&self.application_name);
i.append(&self.source_index);
i.append(&self.channels);
i.append(&self.volume);
i.append(&self.muted);
});
}
}

impl<'a> Get<'a> for OutputStream {
fn get(i: &mut arg::Iter<'a>) -> Option<Self> {
let (index, name, application_name, source_index, channels, volume, muted) =
<(u32, String, String, u32, u16, Vec<u32>, bool)>::get(i)?;
Some(Self {
index,
name,
application_name,
source_index,
channels,
volume,
muted,
})
}
}

impl Arg for OutputStream {
const ARG_TYPE: arg::ArgType = ArgType::Struct;
fn signature() -> Signature<'static> {
unsafe { Signature::from_slice_unchecked("(ussuqaub)\0") }
}
}

impl From<&SourceOutputInfo<'_>> for OutputStream {
fn from(value: &SourceOutputInfo<'_>) -> Self {
let name_opt = &value.name;
let name: String;
if name_opt.is_none() {
name = String::from("");
} else {
name = String::from(name_opt.clone().unwrap());
}
let application_name = value
.proplist
.get_str("application.name")
.unwrap_or_default();
let sink_index = value.source;
let index = value.index;
let channels = value.channel_map.len() as u16;
let mut volume = vec![0; channels as usize];
for i in 0..channels as usize {
unsafe { *volume.get_unchecked_mut(i) = value.volume.get()[i].0 };
}
let muted = value.mute;
Self {
index,
name,
application_name,
source_index: sink_index,
channels,
volume,
muted,
}
}
}

impl PulseServer {
pub fn create(
sender: Sender<AudioResponse>,
Expand Down Expand Up @@ -438,7 +114,9 @@ impl PulseServer {
AudioRequest::ListSources => self.get_sources(),
AudioRequest::ListInputStreams => self.get_input_streams(),
AudioRequest::ListOutputStreams => self.get_output_streams(),
AudioRequest::SetInputStreamMute(input_stream) => self.set_input_stream_mute(input_stream),
AudioRequest::SetInputStreamMute(input_stream) => {
self.set_input_stream_mute(input_stream)
}
AudioRequest::SetInputStreamVolume(input_stream) => {
self.set_volume_of_input_stream(input_stream)
}
Expand Down
Loading

0 comments on commit 0e12812

Please sign in to comment.