mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Generate lookup and add waveform to interop
This commit is contained in:
parent
9c2d02f161
commit
0daeba1876
|
@ -77,6 +77,15 @@ pub enum PatternEffect {
|
||||||
PitchBend(Num<u32, 8>),
|
PitchBend(Num<u32, 8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||||
|
pub enum Waveform {
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
Sine,
|
||||||
|
Saw,
|
||||||
|
Square,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "quote")]
|
#[cfg(feature = "quote")]
|
||||||
impl quote::ToTokens for Track {
|
impl quote::ToTokens for Track {
|
||||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||||
|
@ -333,3 +342,21 @@ impl quote::ToTokens for PatternEffect {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "quote")]
|
||||||
|
impl quote::ToTokens for Waveform {
|
||||||
|
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||||
|
use quote::{quote, TokenStreamExt};
|
||||||
|
|
||||||
|
let name = match self {
|
||||||
|
Waveform::None => quote!(None),
|
||||||
|
Waveform::Sine => quote!(Sine),
|
||||||
|
Waveform::Saw => quote!(Saw),
|
||||||
|
Waveform::Square => quote!(Square),
|
||||||
|
};
|
||||||
|
|
||||||
|
tokens.append_all(quote! {
|
||||||
|
agb_tracker::__private::agb_tracker_interop::Waveform::#name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@ agb = { version = "0.20.5", path = "../../agb", optional = true }
|
||||||
agb_fixnum = { version = "0.20.5", path = "../../agb-fixnum" }
|
agb_fixnum = { version = "0.20.5", path = "../../agb-fixnum" }
|
||||||
agb_tracker_interop = { version = "0.20.5", path = "../agb-tracker-interop", default-features = false }
|
agb_tracker_interop = { version = "0.20.5", path = "../agb-tracker-interop", default-features = false }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
agb_fixnum = { version = "0.20.5", path = "../../agb-fixnum" }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
debug = true
|
debug = true
|
||||||
|
|
48
tracker/agb-tracker/build.rs
Normal file
48
tracker/agb-tracker/build.rs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
use agb_fixnum::Num;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let sine = (0..64).map(|i| (Num::<i32, 8>::new(i) / 64).sin());
|
||||||
|
|
||||||
|
let square = (0..64).map(|i| {
|
||||||
|
if i < 32 {
|
||||||
|
Num::<i32, 8>::new(-1)
|
||||||
|
} else {
|
||||||
|
Num::<i32, 8>::new(1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let saw = (0..64).map(|i| (Num::<i32, 8>::new(i) - 32) / 32);
|
||||||
|
|
||||||
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
let dest_path = Path::new(&out_dir).join("lookups.rs");
|
||||||
|
|
||||||
|
fs::write(
|
||||||
|
&dest_path,
|
||||||
|
format!(
|
||||||
|
"
|
||||||
|
pub(crate) static SINE_LOOKUP: [agb_fixnum::Num<i32, 8>; 64] = [{sine_lookup}];
|
||||||
|
pub(crate) static SQUARE_LOOKUP: [agb_fixnum::Num<i32, 8>; 64] = [{square_lookup}];
|
||||||
|
pub(crate) static SAW_LOOKUP: [agb_fixnum::Num<i32, 8>; 64] = [{saw_lookup}];
|
||||||
|
",
|
||||||
|
sine_lookup = gen_lookup(sine),
|
||||||
|
square_lookup = gen_lookup(square),
|
||||||
|
saw_lookup = gen_lookup(saw),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
println!("cargo::rerun-if-changed=build.rs");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_lookup(input: impl IntoIterator<Item = Num<i32, 8>>) -> String {
|
||||||
|
let output: Vec<_> = input
|
||||||
|
.into_iter()
|
||||||
|
.map(|v| format!("agb_fixnum::Num::from_raw({})", v.to_raw()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
output.join(", ")
|
||||||
|
}
|
|
@ -65,6 +65,7 @@
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
mod lookups;
|
||||||
mod mixer;
|
mod mixer;
|
||||||
|
|
||||||
use agb_tracker_interop::{PatternEffect, Sample};
|
use agb_tracker_interop::{PatternEffect, Sample};
|
||||||
|
|
3
tracker/agb-tracker/src/lookups.rs
Normal file
3
tracker/agb-tracker/src/lookups.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub(crate) mod lookups {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/lookups.rs"));
|
||||||
|
}
|
Loading…
Reference in a new issue