aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml4
-rw-r--r--README.md4
-rw-r--r--src/embedded_assets/hl4mgm.sf2bin0 -> 4191990 bytes
-rw-r--r--src/lib.rs16
4 files changed, 19 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1a83875..3bfc211 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,3 +15,7 @@ rodio = "0.19"
version = "0.14"
default-features = false
features = ["bevy_audio", "bevy_asset"]
+
+[features]
+default = ["hl4mgm"]
+hl4mgm = []
diff --git a/README.md b/README.md
index e4e88b0..3ddd2e6 100644
--- a/README.md
+++ b/README.md
@@ -38,8 +38,8 @@ fn main() {
App::new()
.add_plugins((
DefaultPlugins,
- RustysynthPlugin {
- soundfont: // Bring your own soundfont
+ RustySynthPlugin {
+ soundfont: // Bring your own soundfont or enable the "hl4mgm" feature to use a terrible 4MB default
}
))
.run();
diff --git a/src/embedded_assets/hl4mgm.sf2 b/src/embedded_assets/hl4mgm.sf2
new file mode 100644
index 0000000..2e88994
--- /dev/null
+++ b/src/embedded_assets/hl4mgm.sf2
Binary files differ
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<Arc<SoundFont>> = OnceLock::new();
/// This plugin configures the soundfont used for playback and registers MIDI assets.
-#[derive(Default, Debug)]
+#[derive(Debug)]
pub struct RustySynthPlugin<R: Read + Send + Sync + Clone + 'static> {
- /// 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<Cursor<&[u8]>> {
+ fn default() -> Self {
+ Self { soundfont: Cursor::new(HL4MGM) }
+ }
+}
+
impl<R: Read + Send + Sync + Clone + 'static> Plugin for RustySynthPlugin<R> {
fn build(&self, app: &mut App) {
let _ = SOUNDFONT.set(Arc::new(