diff --git a/src/main.rs b/src/main.rs index 613b517..4ca8922 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ extern crate colour; mod reskit; use std::error::Error; +use std::fs::File; +use std::io::Write; use clap::{App, Arg, SubCommand}; use reskit::soundtrack::dmf::DmfModule; use reskit::utility; @@ -79,6 +81,13 @@ fn run() -> Result<(), Box> { let result = DmfModule::from_file( &input_filename )?; + let eef_files = result.get_eefs()?; + for ( filename, data ) in eef_files { + println!( "Creating EEF instrument file {}", filename ); + let mut file = File::create( filename )?; + file.write_all( &data )? + } + // TODO !! Ok( () ) diff --git a/src/reskit/soundtrack/dmf.rs b/src/reskit/soundtrack/dmf.rs index 821a447..0cc8c04 100644 --- a/src/reskit/soundtrack/dmf.rs +++ b/src/reskit/soundtrack/dmf.rs @@ -1,6 +1,6 @@ use std::{error::Error, fs::File, io::Read, convert::TryInto, collections::HashMap, cmp::{min, max}}; use flate2::read::ZlibDecoder; -use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, Ring, arrays_equal}, soundtrack::types::{SampleRate, SampleFormat, PsgEnvelope}}; +use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, Ring}, soundtrack::types::{SampleRate, SampleFormat, PsgEnvelope}}; use super::types::{Sample, Note, PsgSettings}; @@ -676,8 +676,8 @@ impl DmfModule { initial_arpeggio_repeat.push( arpeggio_repeat_pattern.next().expect( "fatal: internal error (arpeggio_repeat_pattern)" ) ); } - volume_repeat.append( &mut initial_volume_repeat ); - arpeggio_repeat.append( &mut initial_arpeggio_repeat ); + volume_repeat.extend( &initial_volume_repeat ); + arpeggio_repeat.extend( &initial_arpeggio_repeat ); loop { // Guard against OOM @@ -693,7 +693,7 @@ impl DmfModule { } // End loop once the pattern begins repeating - if arrays_equal( &initial_volume_repeat, &volume_repeat_period ) && arrays_equal( &initial_arpeggio_repeat, &arpeggio_repeat_period ) { + if initial_volume_repeat == volume_repeat_period && initial_arpeggio_repeat == arpeggio_repeat_period { break; } else { // If it doesn't repeat, append and generate another period @@ -718,7 +718,7 @@ impl DmfModule { // Echo end loop command envelope.push( 0xFF ); - eefs.insert( instrument.name.clone(), envelope ); + eefs.insert( format!( "{}.eef", instrument.name ), envelope ); } } @@ -733,7 +733,7 @@ impl DmfModule { } fn get_eef_volume( dmf_volume: u8 ) -> Result> { - Ok( max( dmf_volume, 0x0F ) ) + Ok( min( dmf_volume, 0x0F ) ) } fn get_eef_shift( dmf_shift: i8 ) -> Result> { diff --git a/src/reskit/utility.rs b/src/reskit/utility.rs index 6f385fe..8e108be 100644 --- a/src/reskit/utility.rs +++ b/src/reskit/utility.rs @@ -37,22 +37,6 @@ impl< Type: Copy > Iterator for Ring< Type > { } -pub fn arrays_equal< Type: PartialEq >( array1: &Vec, array2: &Vec ) -> bool { - if array1.len() != array2.len() { - return false - } - - for i1 in 0..array1.len() { - for i2 in 0..array2.len() { - if array1[ i1 ] != array2[ i2 ] { - return false - } - } - } - - true -} - pub fn print_error( error_msg: &str ) { red!( "fatal: " ); println!( "{}", error_msg ); }