Add s3m and mod support to the desktop player

This commit is contained in:
Gwilym Inzani 2024-09-24 20:53:13 +01:00
parent 05b5b3e882
commit 5b9332556d
2 changed files with 15 additions and 5 deletions

View file

@ -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"

View file

@ -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<dyn Error>> {
fn main() -> anyhow::Result<()> {
let args: Vec<String> = env::args().collect();
let file_path = &args[1];
@ -60,7 +63,13 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
fn load_module_from_file(xm_path: &Path) -> Result<Module, Box<dyn Error>> {
fn load_module_from_file(xm_path: &Path) -> anyhow::Result<Module> {
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:?}"),
}
}