use bevy::prelude::*;
use firewheel::{FirewheelConfig, backend::AudioBackend, clock::ClockSeconds};
#[cfg(target_arch = "wasm32")]
mod web;
#[cfg(target_arch = "wasm32")]
use web::InnerContext;
#[cfg(not(target_arch = "wasm32"))]
mod os;
#[cfg(not(target_arch = "wasm32"))]
use os::InnerContext;
mod seedling_context;
pub use seedling_context::{SeedlingContext, SeedlingContextError, SeedlingContextWrapper};
#[derive(Debug, Resource)]
pub struct AudioContext(InnerContext);
impl AudioContext {
pub fn new<B>(settings: FirewheelConfig, stream_settings: B::Config) -> Self
where
B: AudioBackend + 'static,
B::Config: Send + 'static,
B::StreamError: Send + Sync + 'static,
{
AudioContext(InnerContext::new::<B>(settings, stream_settings))
}
pub fn now(&mut self) -> ClockSeconds {
self.with(|c| c.clock_now())
}
pub fn with<F, O>(&mut self, f: F) -> O
where
F: FnOnce(&mut SeedlingContext) -> O + Send,
O: Send + 'static,
{
self.0.with(f)
}
}