From 05b5b3e882279e87913f5685a0eb562ea57e805e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:26:50 +0000 Subject: [PATCH 1/7] Update Rust crate xmrs to v0.7.2 --- tracker/agb-xm-core/Cargo.toml | 2 +- tracker/agb-xm/Cargo.toml | 2 +- tracker/desktop-player/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tracker/agb-xm-core/Cargo.toml b/tracker/agb-xm-core/Cargo.toml index 44246efe..8fc99f26 100644 --- a/tracker/agb-xm-core/Cargo.toml +++ b/tracker/agb-xm-core/Cargo.toml @@ -16,4 +16,4 @@ syn = "2" agb_tracker_interop = { version = "0.21.0", path = "../agb-tracker-interop", default-features = false } agb_fixnum = { version = "0.21.0", path = "../../agb-fixnum" } -xmrs = { version = "0.6.1", features = ["std"] } +xmrs = { version = "0.7.0", features = ["std"] } diff --git a/tracker/agb-xm/Cargo.toml b/tracker/agb-xm/Cargo.toml index de4b9909..d259c519 100644 --- a/tracker/agb-xm/Cargo.toml +++ b/tracker/agb-xm/Cargo.toml @@ -19,4 +19,4 @@ proc-macro2 = "1" quote = "1" syn = "2" -xmrs = "0.6" +xmrs = "0.7" diff --git a/tracker/desktop-player/Cargo.toml b/tracker/desktop-player/Cargo.toml index 650a3989..92681918 100644 --- a/tracker/desktop-player/Cargo.toml +++ b/tracker/desktop-player/Cargo.toml @@ -12,6 +12,6 @@ agb_xm_core = { version = "0.21.0", path = "../agb-xm-core" } agb_tracker = { version = "0.21.0", path = "../agb-tracker", default-features = false } agb_fixnum = { version = "0.21.0", path = "../../agb-fixnum" } -xmrs = "0.6" +xmrs = "0.7" cpal = "0.15" From 5b9332556dd0dfda93d82da5002fb5ef770da43b Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 20:53:13 +0100 Subject: [PATCH 2/7] Add s3m and mod support to the desktop player --- tracker/desktop-player/Cargo.toml | 1 + tracker/desktop-player/src/main.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tracker/desktop-player/Cargo.toml b/tracker/desktop-player/Cargo.toml index 92681918..e9ac39a3 100644 --- a/tracker/desktop-player/Cargo.toml +++ b/tracker/desktop-player/Cargo.toml @@ -12,6 +12,7 @@ agb_xm_core = { version = "0.21.0", path = "../agb-xm-core" } agb_tracker = { version = "0.21.0", path = "../agb-tracker", default-features = false } agb_fixnum = { version = "0.21.0", path = "../../agb-fixnum" } +anyhow = "1" xmrs = "0.7" cpal = "0.15" diff --git a/tracker/desktop-player/src/main.rs b/tracker/desktop-player/src/main.rs index 5f8e6092..24867363 100644 --- a/tracker/desktop-player/src/main.rs +++ b/tracker/desktop-player/src/main.rs @@ -1,15 +1,18 @@ -use std::{env, error::Error, fs, path::Path, sync::mpsc}; +use std::{env, fs, path::Path, sync::mpsc}; use cpal::{ traits::{DeviceTrait, HostTrait, StreamTrait}, SampleFormat, SampleRate, }; use mixer::Mixer; -use xmrs::{module::Module, xm::xmmodule::XmModule}; +use xmrs::{ + amiga::amiga_module::AmigaModule, module::Module, s3m::s3m_module::S3mModule, + xm::xmmodule::XmModule, +}; mod mixer; -fn main() -> Result<(), Box> { +fn main() -> anyhow::Result<()> { let args: Vec = env::args().collect(); let file_path = &args[1]; @@ -60,7 +63,13 @@ fn main() -> Result<(), Box> { } } -fn load_module_from_file(xm_path: &Path) -> Result> { +fn load_module_from_file(xm_path: &Path) -> anyhow::Result { let file_content = fs::read(xm_path)?; - Ok(XmModule::load(&file_content)?.to_module()) + + match xm_path.extension().and_then(|ex| ex.to_str()) { + Some("xm") => Ok(XmModule::load(&file_content)?.to_module()), + Some("s3m") => Ok(S3mModule::load(&file_content)?.to_module()), + Some("mod") => Ok(AmigaModule::load(&file_content)?.to_module()), + ex => anyhow::bail!("Invalid file extension {ex:?}"), + } } From 2d69b2a7a46a938c67e4aa84affda146331d4ecc Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 20:56:55 +0100 Subject: [PATCH 3/7] Make agb_xm_core generic on parsing --- tracker/agb-xm/src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tracker/agb-xm/src/lib.rs b/tracker/agb-xm/src/lib.rs index 749d3c7e..97a43d4d 100644 --- a/tracker/agb-xm/src/lib.rs +++ b/tracker/agb-xm/src/lib.rs @@ -10,10 +10,13 @@ use xmrs::{module::Module, xm::xmmodule::XmModule}; #[proc_macro_error] #[proc_macro] pub fn include_xm(args: TokenStream) -> TokenStream { - agb_xm_core(args) + agb_xm_core(args, parse_xm) } -fn agb_xm_core(args: TokenStream) -> TokenStream { +fn agb_xm_core( + args: TokenStream, + load_module: impl Fn(&[u8]) -> Result>, +) -> TokenStream { let input = match syn::parse::(args) { Ok(input) => input, Err(err) => return err.to_compile_error().into(), @@ -26,7 +29,12 @@ fn agb_xm_core(args: TokenStream) -> TokenStream { let include_path = path.to_string_lossy(); - let module = match load_module_from_file(&path) { + let file_content = match fs::read(&path) { + Ok(content) => content, + Err(e) => abort!(input, e), + }; + + let module = match load_module(&file_content) { Ok(track) => track, Err(e) => abort!(input, e), }; @@ -43,7 +51,6 @@ fn agb_xm_core(args: TokenStream) -> TokenStream { .into() } -fn load_module_from_file(xm_path: &Path) -> Result> { - let file_content = fs::read(xm_path)?; - Ok(XmModule::load(&file_content)?.to_module()) +fn parse_xm(file_content: &[u8]) -> Result> { + Ok(XmModule::load(file_content)?.to_module()) } From a7e7455c577ecf0e7a6f6b824b91de5dc65beb21 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 20:59:01 +0100 Subject: [PATCH 4/7] Add macros for include_s3m and include_mod --- tracker/agb-xm/src/lib.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tracker/agb-xm/src/lib.rs b/tracker/agb-xm/src/lib.rs index 97a43d4d..22b2aef0 100644 --- a/tracker/agb-xm/src/lib.rs +++ b/tracker/agb-xm/src/lib.rs @@ -5,12 +5,27 @@ use proc_macro::TokenStream; use proc_macro_error::{abort, proc_macro_error}; use quote::quote; use syn::LitStr; -use xmrs::{module::Module, xm::xmmodule::XmModule}; +use xmrs::{ + amiga::amiga_module::AmigaModule, module::Module, s3m::s3m_module::S3mModule, + xm::xmmodule::XmModule, +}; #[proc_macro_error] #[proc_macro] pub fn include_xm(args: TokenStream) -> TokenStream { - agb_xm_core(args, parse_xm) + agb_xm_core(args, |content| Ok(XmModule::load(content)?.to_module())) +} + +#[proc_macro_error] +#[proc_macro] +pub fn include_s3m(args: TokenStream) -> TokenStream { + agb_xm_core(args, |content| Ok(S3mModule::load(content)?.to_module())) +} + +#[proc_macro_error] +#[proc_macro] +pub fn include_mod(args: TokenStream) -> TokenStream { + agb_xm_core(args, |content| Ok(AmigaModule::load(content)?.to_module())) } fn agb_xm_core( @@ -50,7 +65,3 @@ fn agb_xm_core( } .into() } - -fn parse_xm(file_content: &[u8]) -> Result> { - Ok(XmModule::load(file_content)?.to_module()) -} From 40fd424205b23aa7e5958dcc1f833244364c805a Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 21:01:10 +0100 Subject: [PATCH 5/7] Export the include_s3m and include_mod macros --- tracker/agb-tracker/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tracker/agb-tracker/src/lib.rs b/tracker/agb-tracker/src/lib.rs index 8a5b5ed7..c957f21d 100644 --- a/tracker/agb-tracker/src/lib.rs +++ b/tracker/agb-tracker/src/lib.rs @@ -79,6 +79,14 @@ use agb_fixnum::Num; #[cfg(feature = "xm")] pub use agb_xm::include_xm; +/// Import an S3M file. Only available if you have the `xm` feature enabled (enabled by default). +#[cfg(feature = "xm")] +pub use agb_xm::include_s3m; + +/// Import a MOD file. Only available if you have the `xm` feature enabled (enabled by default). +#[cfg(feature = "xm")] +pub use agb_xm::include_mod; + /// Import a midi file. Only available if you have the `midi` feature enabled (enabled by default). /// This is currently experimental, and many types of MIDI file or MIDI features are not supported. /// From 89eb11d5efdedc087605e0e7d7550f299825bb74 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 21:03:09 +0100 Subject: [PATCH 6/7] Add changelog entry for s3m and mod format --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 392cccdc..4be13fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added support for s3m and mod format files to `agb-tracker`. + ## [0.21.0] - 2024/09/24 ### Added From 282e0702169bfe4d89afeaf68fa48347ec6bc92d Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 21:04:51 +0100 Subject: [PATCH 7/7] Use version 0.7.2 --- tracker/agb-xm-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracker/agb-xm-core/Cargo.toml b/tracker/agb-xm-core/Cargo.toml index 8fc99f26..f04236ea 100644 --- a/tracker/agb-xm-core/Cargo.toml +++ b/tracker/agb-xm-core/Cargo.toml @@ -16,4 +16,4 @@ syn = "2" agb_tracker_interop = { version = "0.21.0", path = "../agb-tracker-interop", default-features = false } agb_fixnum = { version = "0.21.0", path = "../../agb-fixnum" } -xmrs = { version = "0.7.0", features = ["std"] } +xmrs = { version = "0.7.2", features = ["std"] }