diff --git a/tracker/agb-midi-core/src/lib.rs b/tracker/agb-midi-core/src/lib.rs index f39e2f83..ebb4d8ef 100644 --- a/tracker/agb-midi-core/src/lib.rs +++ b/tracker/agb-midi-core/src/lib.rs @@ -1,8 +1,10 @@ -use std::{error::Error, path::Path}; +use std::{error::Error, fs::File, io::BufReader, path::Path}; +use agb_tracker_interop::Track; use proc_macro2::TokenStream; use proc_macro_error::abort; use quote::quote; +use rustysynth::SoundFont; use syn::{ parse::{Parse, ParseStream}, LitStr, Token, @@ -57,14 +59,31 @@ pub fn agb_midi_core(args: TokenStream) -> TokenStream { } } -pub struct MidiInfo {} +pub struct MidiInfo { + sound_font: SoundFont, +} impl MidiInfo { pub fn load_from_file(sf2_file: &Path, midi_file: &Path) -> Result> { - Ok(Self {}) + let mut sound_font_file = BufReader::new(File::open(sf2_file)?); + let sound_font = SoundFont::new(&mut sound_font_file)?; + + Ok(Self { sound_font }) } } pub fn parse_midi(midi_info: &MidiInfo) -> TokenStream { - quote! {} + let track = Track { + samples: &[], + envelopes: &[], + pattern_data: &[], + patterns: &[], + patterns_to_play: &[], + num_channels: 0, + frames_per_tick: 2.into(), + ticks_per_step: 2, + repeat: 0, + }; + + quote!(#track) } diff --git a/tracker/agb-midi/src/lib.rs b/tracker/agb-midi/src/lib.rs index 37429939..7918f3ca 100644 --- a/tracker/agb-midi/src/lib.rs +++ b/tracker/agb-midi/src/lib.rs @@ -3,6 +3,6 @@ use proc_macro_error::proc_macro_error; #[proc_macro_error] #[proc_macro] -pub fn include_xm(args: TokenStream) -> TokenStream { +pub fn include_midi(args: TokenStream) -> TokenStream { agb_midi_core::agb_midi_core(args.into()).into() } diff --git a/tracker/agb-tracker/src/lib.rs b/tracker/agb-tracker/src/lib.rs index 47ca4b69..406d9c48 100644 --- a/tracker/agb-tracker/src/lib.rs +++ b/tracker/agb-tracker/src/lib.rs @@ -77,6 +77,10 @@ use agb::{ #[cfg(feature = "xm")] pub use agb_xm::include_xm; +/// Import a midi file. Only available if you have the `midi` feature enabled (enabled by default). +#[cfg(feature = "midi")] +pub use agb_midi::include_midi; + #[doc(hidden)] pub mod __private { pub use agb::fixnum::Num;