It actually builds now

This commit is contained in:
Gwilym Inzani 2023-11-01 11:42:42 +00:00
parent 5768b56028
commit 32aaaef4cd
3 changed files with 28 additions and 5 deletions

View file

@ -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_macro2::TokenStream;
use proc_macro_error::abort; use proc_macro_error::abort;
use quote::quote; use quote::quote;
use rustysynth::SoundFont;
use syn::{ use syn::{
parse::{Parse, ParseStream}, parse::{Parse, ParseStream},
LitStr, Token, 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 { impl MidiInfo {
pub fn load_from_file(sf2_file: &Path, midi_file: &Path) -> Result<Self, Box<dyn Error>> { pub fn load_from_file(sf2_file: &Path, midi_file: &Path) -> Result<Self, Box<dyn Error>> {
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 { 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)
} }

View file

@ -3,6 +3,6 @@ use proc_macro_error::proc_macro_error;
#[proc_macro_error] #[proc_macro_error]
#[proc_macro] #[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() agb_midi_core::agb_midi_core(args.into()).into()
} }

View file

@ -77,6 +77,10 @@ use agb::{
#[cfg(feature = "xm")] #[cfg(feature = "xm")]
pub use agb_xm::include_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)] #[doc(hidden)]
pub mod __private { pub mod __private {
pub use agb::fixnum::Num; pub use agb::fixnum::Num;