Skip to content

Commit 9cc4c5f

Browse files
committed
channel volume setter
1 parent 1720714 commit 9cc4c5f

File tree

7 files changed

+197
-2
lines changed

7 files changed

+197
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rpaudio"
3-
version = "0.0.17"
3+
version = "0.0.18"
44
edition = "2021"
55

66
[dependencies]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "rpaudio"
7-
version = "0.0.17"
7+
version = "0.0.18"
88
authors = [
99
{ name="Ryan Skiles", email="r.p.skiles@gmail.com" },
1010
{ name="Beaux44"}

python/effects.pyi

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file is automatically generated by pyo3_stub_gen
2+
# ruff: noqa: E501, F401
3+
4+
import typing
5+
from enum import Enum, auto
6+
7+
class ChangeSpeed:
8+
duration: typing.Optional[float]
9+
start_val: typing.Optional[float]
10+
end_val: typing.Optional[float]
11+
apply_after: typing.Optional[float]
12+
def __new__(cls,duration = ...,start_val = ...,end_val = ...,apply_after = ...): ...
13+
14+
class FadeIn:
15+
duration: typing.Optional[float]
16+
start_val: typing.Optional[float]
17+
end_val: typing.Optional[float]
18+
apply_after: typing.Optional[float]
19+
def __new__(cls,duration = ...,start_val = ...,end_val = ...,apply_after = ...): ...
20+
21+
class FadeOut:
22+
duration: typing.Optional[float]
23+
start_val: typing.Optional[float]
24+
end_val: typing.Optional[float]
25+
apply_after: typing.Optional[float]
26+
def __new__(cls,duration = ...,start_val = ...,end_val = ...,apply_after = ...): ...
27+
28+
class ActionType(Enum):
29+
FadeIn = auto()
30+
FadeOut = auto()
31+
ChangeSpeed = auto()
32+

python/metadata.pyi

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is automatically generated by pyo3_stub_gen
2+
# ruff: noqa: E501, F401
3+
4+
import rpaudio
5+
import typing
6+
7+
class MetaData:
8+
title: typing.Optional[str]
9+
artist: typing.Optional[str]
10+
date: typing.Optional[str]
11+
year: typing.Optional[str]
12+
album_title: typing.Optional[str]
13+
album_artist: typing.Optional[str]
14+
track_number: typing.Optional[str]
15+
total_tracks: typing.Optional[str]
16+
disc_number: typing.Optional[str]
17+
total_discs: typing.Optional[str]
18+
genre: typing.Optional[str]
19+
composer: typing.Optional[str]
20+
comment: typing.Optional[str]
21+
sample_rate: typing.Optional[int]
22+
channels: typing.Optional[str]
23+
duration: typing.Optional[float]
24+
def __new__(cls,audio_sink:AudioSink): ...
25+
def as_dict(self) -> dict:
26+
...
27+
28+

python/rpaudio.pyi

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# This file is automatically generated by pyo3_stub_gen
2+
# ruff: noqa: E501, F401
3+
4+
import typing
5+
6+
class AudioChannel:
7+
auto_consume: bool
8+
current_audio: typing.Optional[AudioSink]
9+
queue_contents: list[AudioSink]
10+
is_playing: bool
11+
effects: list
12+
def __new__(cls,): ...
13+
def push(self, sink:AudioSink) -> None:
14+
...
15+
16+
def set_auto_consume(self, value:bool) -> None:
17+
...
18+
19+
def drop_current_audio(self) -> None:
20+
...
21+
22+
def set_effects_chain(self, effect_list:list) -> None:
23+
...
24+
25+
def current_audio_data(self) -> typing.Any:
26+
...
27+
28+
29+
class AudioSink:
30+
metadata: typing.Any
31+
metadata_dict: typing.Any
32+
is_playing: bool
33+
callback: typing.Optional[typing.Any]
34+
def __new__(cls,callback = ...): ...
35+
def load_audio(self, file_path:str) -> AudioSink:
36+
...
37+
38+
def play(self) -> None:
39+
...
40+
41+
def pause(self) -> None:
42+
...
43+
44+
def stop(self) -> None:
45+
...
46+
47+
def get_volume(self) -> float:
48+
...
49+
50+
def set_volume(self, volume:float) -> None:
51+
...
52+
53+
def get_pos(self) -> float:
54+
...
55+
56+
def set_duration(self, duration:float) -> None:
57+
...
58+
59+
def get_remaining_time(self) -> float:
60+
...
61+
62+
def get_speed(self) -> float:
63+
...
64+
65+
def set_speed(self, speed:float) -> None:
66+
...
67+
68+
def try_seek(self, position:float) -> None:
69+
...
70+
71+
def cancel_callback(self) -> None:
72+
...
73+
74+
def empty(self) -> bool:
75+
...
76+
77+
def apply_effects(self, effect_list:list) -> None:
78+
...
79+
80+
def playback_data(self) -> typing.Any:
81+
...
82+
83+
84+
class ChannelManager:
85+
def new(self) -> ChannelManager:
86+
...
87+
88+
def add_channel(self, name:str, channel:AudioChannel) -> None:
89+
...
90+
91+
def drop_channel(self, name:str) -> None:
92+
...
93+
94+
def channel(self, name:str) -> typing.Optional[AudioChannel]:
95+
...
96+
97+
def start_all(self) -> None:
98+
...
99+
100+
def stop_all(self) -> None:
101+
...
102+
103+

src/audioqueue.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct AudioChannel {
1414
pub auto_consume: Arc<Mutex<bool>>,
1515
currently_playing: Arc<Mutex<Option<AudioSink>>>,
1616
effects_chain: Arc<Mutex<Vec<ActionType>>>,
17+
channel_volume: Arc<Mutex<f32>>,
1718
}
1819

1920
impl fmt::Debug for AudioSink {
@@ -33,9 +34,17 @@ impl AudioChannel {
3334

3435
pub fn consume(&mut self) {
3536
if let Some(mut sink) = self.pop() {
37+
let volume = self.channel_volume.lock().unwrap();
38+
let _ = sink.set_volume(*volume);
3639
let _ = sink.play();
3740
}
3841
}
42+
43+
pub fn set_volume(&mut self, volume: f32) {
44+
if let Ok(mut volume_guard) = self.channel_volume.lock() {
45+
*volume_guard = volume;
46+
}
47+
}
3948
}
4049

4150
#[pymethods]
@@ -47,6 +56,7 @@ impl AudioChannel {
4756
auto_consume: Arc::new(Mutex::new(false)),
4857
currently_playing: Arc::new(Mutex::new(None)),
4958
effects_chain: Arc::new(Mutex::new(Vec::new())),
59+
channel_volume: Arc::new(Mutex::new(1.0)),
5060
};
5161

5262
let channel_arc = Arc::new(Mutex::new(channel));
@@ -72,6 +82,8 @@ impl AudioChannel {
7282
{
7383
if playing_guard.is_none() && !queue_guard.is_empty() {
7484
let mut next_sink = queue_guard.remove(0);
85+
let volume = channel.channel_volume.lock().unwrap();
86+
let _ = next_sink.set_volume(*volume);
7587

7688
drop(queue_guard);
7789

@@ -137,6 +149,18 @@ impl AudioChannel {
137149
}
138150
}
139151

152+
#[setter]
153+
pub fn channel_volume(&mut self, volume: f32) {
154+
if let Ok(mut volume_guard) = self.channel_volume.lock() {
155+
*volume_guard = volume;
156+
if let Ok(mut currently_playing) = self.currently_playing.lock() {
157+
if let Some(ref mut sink) = *currently_playing {
158+
let _ = sink.set_volume(volume);
159+
}
160+
}
161+
}
162+
}
163+
140164
#[getter]
141165
pub fn auto_consume(&self) -> bool {
142166
if let Ok(auto_consume_guard) = self.auto_consume.lock() {

src/bin/stub_gen.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use pyo3_stub_gen::Result;
2+
3+
fn main() -> Result<()> {
4+
// `stub_info` is a function defined by `define_stub_info_gatherer!` macro.
5+
let stub = rpaudio::stub_info()?;
6+
stub.generate()?;
7+
Ok(())
8+
}

0 commit comments

Comments
 (0)