Quality of life improvements
parent
d7735901e2
commit
2233841eca
26
src/main.rs
26
src/main.rs
|
@ -47,6 +47,20 @@ fn run() -> Result<(), Box<dyn Error>> {
|
|||
.about( "Generate an on-console soundtrack from a chiptune tracker module" )
|
||||
.arg_from_usage( "-i, --input=<FILE> 'Specify input module'" )
|
||||
.arg_from_usage( "-o, --output=<FILE> '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<dyn Error>> {
|
|||
.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<dyn Error>> {
|
|||
|
||||
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 )?
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ pub type EchoEvent = Vec<u8>;
|
|||
|
||||
pub trait EchoFormat {
|
||||
|
||||
fn get_instruments( &self, instrument_list_label: &str ) -> Result<HashMap<String, Vec<u8>>, Box<dyn Error>>;
|
||||
fn get_artifacts( &self, soundtrack_label: &str, soundtrack_path: &str, artifact_path: &str, instrument_list_label: &str ) -> Result<HashMap<String, Vec<u8>>, Box<dyn Error>>;
|
||||
|
||||
fn get_esf( &self ) -> Result<Vec<u8>, Box<dyn Error>>;
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -633,7 +633,7 @@ impl DmfModule {
|
|||
|
||||
impl EchoFormat for DmfModule {
|
||||
|
||||
fn get_instruments( &self, instr_list_label: &str ) -> Result<HashMap<String, Vec<u8>>, Box<dyn Error>> {
|
||||
fn get_artifacts( &self, soundtrack_label: &str, soundtrack_path: &str, artifact_path: &str, instr_list_label: &str ) -> Result<HashMap<String, Vec<u8>>, Box<dyn Error>> {
|
||||
let mut files: HashMap<String, Vec<u8>> = HashMap::new();
|
||||
// This next list preserves order of filenames to generate the echo .asm file
|
||||
let mut instrument_filenames: Vec<String> = 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 )
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue