From 2233841eca0615b7a70846efaabc0bb9b6f20a13 Mon Sep 17 00:00:00 2001 From: ashley Date: Sat, 26 Aug 2023 17:27:53 -0400 Subject: [PATCH] Quality of life improvements --- src/main.rs | 26 +++++++++++++++++++++----- src/reskit/soundtrack/engines/echo.rs | 8 +++++--- src/reskit/soundtrack/formats/dmf.rs | 9 ++++++--- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index b6aca27..f9a7b2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,20 @@ fn run() -> Result<(), Box> { .about( "Generate an on-console soundtrack from a chiptune tracker module" ) .arg_from_usage( "-i, --input= 'Specify input module'" ) .arg_from_usage( "-o, --output= 'Specify output filename (may output multiple files depending on format)'") + .arg( + Arg::with_name( "ARTIFACT_OUTPUT_DIRECTORY" ) + .long( "artifact-output-directory" ) + .help( "Specify directory to output secondary artifacts (e.g. instruments)" ) + .default_value( "./" ) + .takes_value( true ) + ) + .arg( + Arg::with_name( "SOUNDTRACK_LABEL" ) + .long( "soundtrack-label" ) + .help( "In sound drivers supporting generated boilerplate, specify label to use for soundtrack" ) + .default_value( "MuzPlaceholder1" ) + .takes_value( true ) + ) .arg( Arg::with_name( "TRACKER_FORMAT" ) .long( "tracker-format" ) @@ -64,14 +78,14 @@ fn run() -> Result<(), Box> { .arg( Arg::with_name( "EXPORT_INSTRUMENT_LIST_LABEL" ) .long( "instrument-list-label" ) - .help( "In sound drivers supporting generated-code instrument lists, specify label to use for instrument list" ) + .help( "In sound drivers supporting generated boilerplate, specify label to use for instrument list" ) .default_value( "MuzInstrumentList" ) .takes_value( true ) ) .arg( Arg::with_name( "EXPORT_INSTRUMENT_LIST_FORMAT" ) .long( "instrument-list-format" ) - .help( "In sound drivers supporting generated-code instrument lists, specify output format for instrument list" ) + .help( "In sound drivers supporting generated boilerplate, specify output format for instrument list" ) .default_value( "asmx" ) .takes_value( true ) ) @@ -96,9 +110,11 @@ fn run() -> Result<(), Box> { let result = DmfModule::from_file( &input_filename )?; - for ( filename, data ) in result.get_instruments( matches.value_of( "EXPORT_INSTRUMENT_LIST_LABEL" ).ok_or( "internal error" )? )? { - println!( "Creating instrument file {}", filename ); - let mut file = File::create( filename )?; + let artifact_path = matches.value_of( "ARTIFACT_OUTPUT_DIRECTORY" ).unwrap_or( "./" ); + let soundtrack_label = matches.value_of( "SOUNDTRACK_LABEL" ).unwrap_or( "MuzPlaceholder1" ); + for ( filename, data ) in result.get_artifacts( soundtrack_label, output_filename, artifact_path, matches.value_of( "EXPORT_INSTRUMENT_LIST_LABEL" ).ok_or( "internal error" )? )? { + println!( "Creating artifact file {}{}", artifact_path, filename ); + let mut file = File::create( format!( "{}{}", artifact_path, filename ) )?; file.write_all( &data )? } diff --git a/src/reskit/soundtrack/engines/echo.rs b/src/reskit/soundtrack/engines/echo.rs index 1dcb758..7278556 100644 --- a/src/reskit/soundtrack/engines/echo.rs +++ b/src/reskit/soundtrack/engines/echo.rs @@ -55,7 +55,7 @@ pub type EchoEvent = Vec; pub trait EchoFormat { - fn get_instruments( &self, instrument_list_label: &str ) -> Result>, Box>; + fn get_artifacts( &self, soundtrack_label: &str, soundtrack_path: &str, artifact_path: &str, instrument_list_label: &str ) -> Result>, Box>; fn get_esf( &self ) -> Result, Box>; @@ -452,8 +452,10 @@ fn get_note_cut( channel: &mut Channel, note_cut_effect: &Effect, tick: u8 ) -> }; if tick >= after_ticks { - channel.active_note = None; - return Ok( vec![ ESF_NOTE_OFF | channel.id ] ); + if channel.active_note.is_some() { + channel.active_note = None; + return Ok( vec![ ESF_NOTE_OFF | channel.id ] ); + } } // Nothing to generate this tick diff --git a/src/reskit/soundtrack/formats/dmf.rs b/src/reskit/soundtrack/formats/dmf.rs index b3612c1..1554626 100644 --- a/src/reskit/soundtrack/formats/dmf.rs +++ b/src/reskit/soundtrack/formats/dmf.rs @@ -633,7 +633,7 @@ impl DmfModule { impl EchoFormat for DmfModule { - fn get_instruments( &self, instr_list_label: &str ) -> Result>, Box> { + fn get_artifacts( &self, soundtrack_label: &str, soundtrack_path: &str, artifact_path: &str, instr_list_label: &str ) -> Result>, Box> { let mut files: HashMap> = HashMap::new(); // This next list preserves order of filenames to generate the echo .asm file let mut instrument_filenames: Vec = Vec::new(); @@ -880,6 +880,9 @@ impl EchoFormat for DmfModule { // Write Echo ASM file that includes all the instruments let mut echo_asm: String = format!( "; Echo instrument definitions file\n; Generated by reskit v{}\n\n", env!( "CARGO_PKG_VERSION" ) ); + echo_asm += &format!( "{}:\n", soundtrack_label ); + echo_asm += &format!( "\tincbin '{}'\n\n", soundtrack_path ); + echo_asm += &format!( "{}:\n", instr_list_label ); for filename in &instrument_filenames { echo_asm += &format!( "\tEcho_ListEntry Instr_{}\n", filename.replace( ".", "_" ).to_case( Case::Pascal ) ); @@ -889,10 +892,10 @@ impl EchoFormat for DmfModule { for filename in &instrument_filenames { echo_asm += &format!( "Instr_{}:\n", filename.replace( ".", "_" ).to_case( Case::Pascal ) ); - echo_asm += &format!( "\tincbin '{}'\n\n", filename ); + echo_asm += &format!( "\tincbin '{}{}'\n\n", artifact_path, filename ); } - files.insert( format!( "{}_instruments.asm", self.path ), echo_asm.into_bytes() ); + files.insert( format!( "music.asm" ), echo_asm.into_bytes() ); Ok( files ) }