Add Rust implementation of volume

This commit is contained in:
Dylan Jaide White 2022-03-12 20:42:20 +00:00
parent 8d95b3b5de
commit 2537d27886
2 changed files with 65 additions and 1 deletions

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -61,6 +61,70 @@ impl TTS {
}
fn register(builder: &ClassBuilder<Self>) {
builder
.add_property("volume")
.with_getter(|this: &TTS, _| match this.0.get_volume() {
Ok(volume) => volume,
_ => 0.,
})
.with_setter(|this: &mut TTS, _, v: f32| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
let mut v = v;
if v < this.0.min_volume() {
v = this.0.min_volume();
} else if v > this.0.max_volume() {
v = this.0.max_volume();
}
this.0.set_volume(v).expect("Failed to set volume");
}
})
.done();
builder
.add_property("min_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
this.0.min_volume()
} else {
0.
}
})
.done();
builder
.add_property("max_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
this.0.max_volume()
} else {
0.
}
})
.done();
builder
.add_property("normal_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
this.0.normal_volume()
} else {
0.
}
})
.done();
builder
.add_property("rate")
.with_getter(|this: &TTS, _| match this.0.get_rate() {