Skip to content

Commit

Permalink
feat: Add generic audio object (#2)
Browse files Browse the repository at this point in the history
* wip: AudioObject

* fix: clone on vec

* chore: Bump version

* wip: AudioObject for Sink

* wip: Add TAudioStreamObject

* wip: Add setmute to stream

* wip: Add generic audio events

* wip: Add Send + Sync to traits

* feat: Add requires_backend check to capabilities

* fix: Use proper types for capabilities

* fix: differentiate between backend and frontend
  • Loading branch information
DashieTM authored Apr 11, 2024
1 parent 493b7dd commit ea5c675
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 12 deletions.
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

0 comments on commit ea5c675

Please sign in to comment.