Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add generic audio object #2

Merged
merged 11 commits into from
Apr 11, 2024
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "re_set-lib"
version = "3.1.7"
version = "3.1.11"
edition = "2021"
description = "Data structure library for ReSet"
repository = "https://github.com/Xetibo/ReSet-Lib"
Expand Down
167 changes: 167 additions & 0 deletions src/audio/audio_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ pub struct Volume {
value: u32,
}

pub trait TAudioObject: Arg + for<'z> Get<'z> + Send + Sync + 'static {
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(&self) -> i32;
}

pub trait TAudioStreamObject: Arg + for<'z> Get<'z> + Send + Sync + 'static {
fn index(&self) -> u32;
fn name(&self) -> String;
fn application_name(&self) -> String;
fn audio_object_index(&self) -> u32;
fn channels(&self) -> u16;
fn volume(&self) -> Vec<u32>;
fn muted(&self) -> bool;
fn toggle_muted(&mut self);
fn corked(&self) -> bool;
}

impl Volume {
pub fn from_i32(value: i32) -> Option<Self> {
match value {
Expand Down Expand Up @@ -170,6 +193,40 @@ impl From<&SourceInfo<'_>> for Source {
}
}

impl TAudioObject for Source {
fn alias(&self) -> String {
self.alias.clone()
}

fn name(&self) -> String {
self.name.clone()
}

fn volume(&self) -> Vec<u32> {
self.volume.clone()
}

fn index(&self) -> u32 {
self.index
}

fn channels(&self) -> u16 {
self.channels
}

fn muted(&self) -> bool {
self.muted
}

fn toggle_muted(&mut self) {
self.muted = !self.muted;
}

fn active(&self) -> i32 {
self.active
}
}

#[derive(Debug, Clone, Default)]
pub struct Sink {
pub index: u32,
Expand Down Expand Up @@ -250,6 +307,40 @@ impl From<&SinkInfo<'_>> for Sink {
}
}

impl TAudioObject for Sink {
fn alias(&self) -> String {
self.alias.clone()
}

fn name(&self) -> String {
self.name.clone()
}

fn volume(&self) -> Vec<u32> {
self.volume.clone()
}

fn index(&self) -> u32 {
self.index
}

fn channels(&self) -> u16 {
self.channels
}

fn muted(&self) -> bool {
self.muted
}

fn toggle_muted(&mut self) {
self.muted = !self.muted;
}

fn active(&self) -> i32 {
self.active
}
}

#[derive(Debug, Clone, Default)]
pub struct InputStream {
pub index: u32,
Expand Down Expand Up @@ -330,6 +421,44 @@ impl From<&SinkInputInfo<'_>> for InputStream {
}
}

impl TAudioStreamObject for InputStream {
fn index(&self) -> u32 {
self.index
}

fn name(&self) -> String {
self.name.clone()
}

fn application_name(&self) -> String {
self.application_name.clone()
}

fn audio_object_index(&self) -> u32 {
self.index
}

fn channels(&self) -> u16 {
self.channels
}

fn volume(&self) -> Vec<u32> {
self.volume.clone()
}

fn muted(&self) -> bool {
self.muted
}

fn toggle_muted(&mut self) {
self.muted = !self.muted;
}

fn corked(&self) -> bool {
self.corked
}
}

#[derive(Debug, Clone, Default)]
pub struct OutputStream {
pub index: u32,
Expand Down Expand Up @@ -410,6 +539,44 @@ impl From<&SourceOutputInfo<'_>> for OutputStream {
}
}

impl TAudioStreamObject for OutputStream {
fn index(&self) -> u32 {
self.index
}

fn name(&self) -> String {
self.name.clone()
}

fn application_name(&self) -> String {
self.application_name.clone()
}

fn audio_object_index(&self) -> u32 {
self.index
}

fn channels(&self) -> u16 {
self.channels
}

fn volume(&self) -> Vec<u32> {
self.volume.clone()
}

fn muted(&self) -> bool {
self.muted
}

fn toggle_muted(&mut self) {
self.muted = !self.muted;
}

fn corked(&self) -> bool {
self.corked
}
}

#[derive(Debug, Clone, Default)]
pub struct Card {
pub index: u32,
Expand Down
Loading
Loading