Fix some bugs, tested EEF save
parent
ebd33b96db
commit
2e0a07c189
|
@ -5,6 +5,8 @@ extern crate colour;
|
||||||
|
|
||||||
mod reskit;
|
mod reskit;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use reskit::soundtrack::dmf::DmfModule;
|
use reskit::soundtrack::dmf::DmfModule;
|
||||||
use reskit::utility;
|
use reskit::utility;
|
||||||
|
@ -79,6 +81,13 @@ fn run() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
let result = DmfModule::from_file( &input_filename )?;
|
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 !!
|
// TODO !!
|
||||||
|
|
||||||
Ok( () )
|
Ok( () )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{error::Error, fs::File, io::Read, convert::TryInto, collections::HashMap, cmp::{min, max}};
|
use std::{error::Error, fs::File, io::Read, convert::TryInto, collections::HashMap, cmp::{min, max}};
|
||||||
use flate2::read::ZlibDecoder;
|
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};
|
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)" ) );
|
initial_arpeggio_repeat.push( arpeggio_repeat_pattern.next().expect( "fatal: internal error (arpeggio_repeat_pattern)" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
volume_repeat.append( &mut initial_volume_repeat );
|
volume_repeat.extend( &initial_volume_repeat );
|
||||||
arpeggio_repeat.append( &mut initial_arpeggio_repeat );
|
arpeggio_repeat.extend( &initial_arpeggio_repeat );
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Guard against OOM
|
// Guard against OOM
|
||||||
|
@ -693,7 +693,7 @@ impl DmfModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// End loop once the pattern begins repeating
|
// 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;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// If it doesn't repeat, append and generate another period
|
// If it doesn't repeat, append and generate another period
|
||||||
|
@ -718,7 +718,7 @@ impl DmfModule {
|
||||||
// Echo end loop command
|
// Echo end loop command
|
||||||
envelope.push( 0xFF );
|
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<u8, Box<dyn Error>> {
|
fn get_eef_volume( dmf_volume: u8 ) -> Result<u8, Box<dyn Error>> {
|
||||||
Ok( max( dmf_volume, 0x0F ) )
|
Ok( min( dmf_volume, 0x0F ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_eef_shift( dmf_shift: i8 ) -> Result<u8, Box<dyn Error>> {
|
fn get_eef_shift( dmf_shift: i8 ) -> Result<u8, Box<dyn Error>> {
|
||||||
|
|
|
@ -37,22 +37,6 @@ impl< Type: Copy > Iterator for Ring< Type > {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn arrays_equal< Type: PartialEq >( array1: &Vec<Type>, array2: &Vec<Type> ) -> 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 ) {
|
pub fn print_error( error_msg: &str ) {
|
||||||
red!( "fatal: " ); println!( "{}", error_msg );
|
red!( "fatal: " ); println!( "{}", error_msg );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue