Skip to content

Commit 5077198

Browse files
committed
Python: use getter/setter for AudioParam value
1 parent c930e96 commit 5077198

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

python/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import web_audio_api
2+
from time import sleep
3+
4+
ctx = web_audio_api.AudioContext()
5+
osc = web_audio_api.OscillatorNode(ctx)
6+
osc.connect(ctx.destination())
7+
osc.start()
8+
9+
print("freq =", osc.frequency().value);
10+
sleep(4)
11+
12+
osc.frequency().value = 300
13+
print("freq =", osc.frequency().value);
14+
15+
sleep(4)

python/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ struct AudioParam(web_audio_api_rs::AudioParam);
4242

4343
#[pymethods]
4444
impl AudioParam {
45-
fn value(&self) -> f32 {
46-
self.0.value()
45+
#[getter]
46+
fn value(&self) -> PyResult<f32> {
47+
Ok(self.0.value())
4748
}
4849

49-
fn set_value(&self, value: f32) -> Self {
50-
Self(self.0.set_value(value).clone())
50+
#[setter]
51+
fn set_value(&self, value: f32) -> PyResult<()> {
52+
self.0.set_value(value);
53+
Ok(())
5154
}
5255
}
5356

0 commit comments

Comments
 (0)