From 5b9332556dd0dfda93d82da5002fb5ef770da43b Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 24 Sep 2024 20:53:13 +0100 Subject: [PATCH] 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:?}"), + } }