From 644732b04d873a96dfe9e778febdd5fd5f56ebc2 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Mon, 9 Sep 2024 19:10:03 -0400 Subject: Add default soundfont --- src/lib.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 2906d61..a15f3b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,22 +5,32 @@ use bevy::{audio::AddAudioSource, prelude::*}; use rustysynth::SoundFont; use std::{ - io::Read, + io::{Cursor, Read}, sync::{Arc, OnceLock}, }; mod assets; pub use assets::*; +#[cfg(feature = "hl4mgm")] +pub (crate) static HL4MGM: &[u8] = include_bytes!("./embedded_assets/hl4mgm.sf2"); + pub(crate) static SOUNDFONT: OnceLock> = OnceLock::new(); /// This plugin configures the soundfont used for playback and registers MIDI assets. -#[derive(Default, Debug)] +#[derive(Debug)] pub struct RustySynthPlugin { - /// Reader for soundfont data. A default is not provided since soundfonts can be quite large. + /// Reader for soundfont data. pub soundfont: R, } +#[cfg(feature = "hl4mgm")] +impl Default for RustySynthPlugin> { + fn default() -> Self { + Self { soundfont: Cursor::new(HL4MGM) } + } +} + impl Plugin for RustySynthPlugin { fn build(&self, app: &mut App) { let _ = SOUNDFONT.set(Arc::new( -- cgit v1.2.3