From 44984c716ce2407fa8c8842270181a6d199974da Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 10 Jul 2022 14:21:52 -0400 Subject: [PATCH] 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. --- examples/audio_playback/src/main.rs | 2 +- libretrogd/src/audio/queue.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/audio_playback/src/main.rs b/examples/audio_playback/src/main.rs index 5c871dd..812ae57 100644 --- a/examples/audio_playback/src/main.rs +++ b/examples/audio_playback/src/main.rs @@ -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) { volume -= 0.1; diff --git a/libretrogd/src/audio/queue.rs b/libretrogd/src/audio/queue.rs index a9cbdc5..5560383 100644 --- a/libretrogd/src/audio/queue.rs +++ b/libretrogd/src/audio/queue.rs @@ -161,7 +161,7 @@ impl AudioQueue { Ok(()) } - pub fn apply(&mut self, device: &mut AudioDevice) -> Result<(), AudioDeviceError> { + pub fn apply_to_device(&mut self, device: &mut AudioDevice) -> Result<(), AudioDeviceError> { loop { if let Some(command) = self.commands.pop_front() { 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) + } } \ No newline at end of file