From 1e80d0684ddbcd3d995a05e572fafb181263758c Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Mon, 9 Sep 2024 18:44:52 -0400 Subject: Initial Commit --- src/lib.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..2906d61 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,31 @@ +#![warn(missing_docs)] + +//! A plugin which adds MIDI file and soundfont audio support to the [bevy](https://crates.io/crates/bevy) engine via [rustysynth](https://crates.io/crates/rustysynth). + +use bevy::{audio::AddAudioSource, prelude::*}; +use rustysynth::SoundFont; +use std::{ + io::Read, + sync::{Arc, OnceLock}, +}; + +mod assets; +pub use assets::*; + +pub(crate) static SOUNDFONT: OnceLock> = OnceLock::new(); + +/// This plugin configures the soundfont used for playback and registers MIDI assets. +#[derive(Default, Debug)] +pub struct RustySynthPlugin { + /// Reader for soundfont data. A default is not provided since soundfonts can be quite large. + pub soundfont: R, +} + +impl Plugin for RustySynthPlugin { + fn build(&self, app: &mut App) { + let _ = SOUNDFONT.set(Arc::new( + SoundFont::new(&mut self.soundfont.clone()).unwrap(), + )); + app.add_audio_source::().init_asset::().init_asset_loader::(); + } +} -- cgit v1.2.3