add "apply" method variant that handles device locking itself

rename the old "apply" to "apply_to_device". meh. naming is hard.
i expect that most of the time i'd want to use the "apply" method i'm
adding here that handles device locking internally, so that is why i've
chosen to let it be called "apply" and to rename the other one.
This commit is contained in:
Gered 2022-07-10 14:21:52 -04:00
parent 253e70463e
commit 44984c716c
2 changed files with 7 additions and 2 deletions

View file

@ -152,7 +152,7 @@ fn main() -> Result<()> {
} }
} }
system.audio_queue.apply(&mut audio_device)?; system.audio_queue.apply_to_device(&mut audio_device)?;
if system.keyboard.is_key_pressed(Scancode::KpMinus) { if system.keyboard.is_key_pressed(Scancode::KpMinus) {
volume -= 0.1; volume -= 0.1;

View file

@ -161,7 +161,7 @@ impl AudioQueue {
Ok(()) Ok(())
} }
pub fn apply(&mut self, device: &mut AudioDevice) -> Result<(), AudioDeviceError> { pub fn apply_to_device(&mut self, device: &mut AudioDevice) -> Result<(), AudioDeviceError> {
loop { loop {
if let Some(command) = self.commands.pop_front() { if let Some(command) = self.commands.pop_front() {
use AudioCommand::*; use AudioCommand::*;
@ -196,4 +196,9 @@ impl AudioQueue {
} }
} }
} }
pub fn apply(&mut self, audio: &mut Audio) -> Result<(), AudioDeviceError> {
let mut device = audio.lock();
self.apply_to_device(&mut device)
}
} }