diff --git a/src/reskit/soundtrack/formats/dmf.rs b/src/reskit/soundtrack/formats/dmf.rs index a38f736..a791a50 100644 --- a/src/reskit/soundtrack/formats/dmf.rs +++ b/src/reskit/soundtrack/formats/dmf.rs @@ -3,7 +3,7 @@ use flate2::read::ZlibDecoder; use linked_hash_set::LinkedHashSet; use samplerate::convert; use uuid::Uuid; -use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, Ring, print_warning}, soundtrack::{types::{SampleFormat, PsgEnvelope, Note, Sample, PsgSettings, PatternRow, Effect, DcsgChannelMode, NoiseType, Channel}, engines::echo::{EchoFormat, EchoEvent, ESF_FM_1, ESF_FM_2, ESF_FM_3, ESF_FM_4, ESF_FM_5, ESF_PSG_1, ESF_FM_6, ESF_PSG_2, ESF_PSG_3, ESF_PSG_4, get_events_for_row}}}; +use crate::reskit::{utility::{get_string, get_u8, skip, get_u32, get_i8, get_i32, get_u16, get_i16, Ring, print_warning, print_info}, soundtrack::{types::{SampleFormat, PsgEnvelope, Note, Sample, PsgSettings, PatternRow, Effect, DcsgChannelMode, NoiseType, Channel}, engines::echo::{EchoFormat, EchoEvent, ESF_FM_1, ESF_FM_2, ESF_FM_3, ESF_FM_4, ESF_FM_5, ESF_PSG_1, ESF_FM_6, ESF_PSG_2, ESF_PSG_3, ESF_PSG_4, get_events_for_row}}}; const DMF_MAGIC_NUMBER: &'static str = ".DelekDefleMask."; const DMF_SUPPORTED_VERSION: u8 = 27; @@ -97,7 +97,7 @@ impl DmfModule { return Err( format!( "invalid file: missing DMF header" ) )? } - println!( ".DelekDefleMask. DMF file" ); + print_info( ".DelekDefleMask. DMF file" ); let version = get_u8( bytes.by_ref() )?; if version != DMF_SUPPORTED_VERSION { @@ -106,16 +106,16 @@ impl DmfModule { let platform = get_u8( bytes.by_ref() )?; match platform { - DMF_MD => println!( "Mode:\tSega Megadrive" ), + DMF_MD => print_info( "Mode:\tSega Megadrive" ), DMF_MD_ENHANCED_CH3 => return Err( "Extended Ch. 3 mode not yet supported (coming soon!) - if your sequence does not use Extended Ch. 3 mode, try re-exporting as standard mode." )?, _ => return Err( "invalid file: invalid console format" )? }; let song_name_len = get_u8( bytes.by_ref() )?; - println!( "Song name:\t{}", get_string( bytes.by_ref(), song_name_len.into() )? ); + print_info( &format!( "Song name:\t{}", get_string( bytes.by_ref(), song_name_len.into() )? ) ); let song_author_len = get_u8( bytes.by_ref() )?; - println!( "Song author:\t{}", get_string( bytes.by_ref(), song_author_len.into() )? ); + print_info( &format!( "Song author:\t{}", get_string( bytes.by_ref(), song_author_len.into() )? ) ); // Burn 2 bytes, don't care about the highlight patterns skip( bytes.by_ref(), 2 ); @@ -127,9 +127,9 @@ impl DmfModule { let speed_a = get_u8( bytes.by_ref() )?; let speed_b = get_u8( bytes.by_ref() )?; - println!( "Time base:\t{}", time_base ); - println!( "Ticks/Even:\t{}", speed_a ); - println!( "Ticks/Odd:\t{}", speed_b ); + print_info( &format!( "Time base:\t{}", time_base ) ); + print_info( &format!( "Ticks/Even:\t{}", speed_a ) ); + print_info( &format!( "Ticks/Odd:\t{}", speed_b ) ); let frame_mode = match get_u8( bytes.by_ref() )? { 0 => FrameMode::Pal, @@ -148,22 +148,22 @@ impl DmfModule { frame_mode }; - println!( "Frame mode:\t{:?}", frame_mode ); + print_info( &format!( "Frame mode:\t{:?}", frame_mode ) ); let rows_per_pattern = get_u32( bytes.by_ref() )?; - println!( "Rows/pattern:\t{}", rows_per_pattern ); + print_info( &format!( "Rows/pattern:\t{}", rows_per_pattern ) ); let patterns_count = get_u8( bytes.by_ref() )?; - println!( "Patterns:\t{}", patterns_count ); + print_info( &format!( "Patterns:\t{}\n", patterns_count ) ); - println!( "\nPattern Matrix:" ); + print_info( "Pattern Matrix:" ); let system_total_channels = if platform == DMF_MD { - println!( "FM1 FM2 FM3 FM4 FM5 FM6 SN1 SN2 SN3 SN4" ); + print_info( "FM1 FM2 FM3 FM4 FM5 FM6 SN1 SN2 SN3 SN4" ); 10 } else { - println!( "FM1 FM2 OP1 OP2 OP3 OP4 FM4 FM5 FM6 SN1 SN2 SN3 SN4" ); + print_info( "FM1 FM2 OP1 OP2 OP3 OP4 FM4 FM5 FM6 SN1 SN2 SN3 SN4" ); 13 }; @@ -177,29 +177,30 @@ impl DmfModule { } for pattern in &pattern_matrix { + let mut total_string: String = String::new(); for channel in pattern { - print!( "{:#04X?} ", channel ); + total_string += &format!( "{:#04X?} ", channel ); } - print!( "\n" ); + print_info( &total_string ); } - print!( "\n" ); + print_info( "\n" ); let mut instruments: Vec = Vec::new(); let instrument_count = get_u8( bytes.by_ref() )?; - println!( "Instruments:\t{}", instrument_count ); + print_info( &format!( "Instruments:\t{}", instrument_count ) ); for i in 0..instrument_count { let name_len = get_u8( bytes.by_ref() )?; let name = get_string( bytes.by_ref(), name_len.into() )?; - println!( "Instrument {}:\t{}", i, name ); + print_info( &format!( "Instrument {}:\t{}", i, name ) ); let mode = get_u8( bytes.by_ref() )?; let instrument_type = match mode { 0 => { - println!( "Psg Instrument" ); + print_info( "Psg Instrument" ); // Volume envelope let volume = { @@ -221,8 +222,8 @@ impl DmfModule { None }; - println!( "Volume Envelope Size:\t{}", envelope.len() ); - println!( "Loop at:\t{:?}", loop_at ); + print_info( &format!( "Volume Envelope Size:\t{}", envelope.len() ) ); + print_info( &format!( "Loop at:\t{:?}", loop_at ) ); PsgEnvelope { envelope, @@ -255,9 +256,9 @@ impl DmfModule { ( "arpeggio_macro_fixed", get_u8( bytes.by_ref() )? == 1 ) ]); - println!( "Arpeggio Envelope Size:\t{}", envelope.len() ); - println!( "Arpeggio Macro Fixed:\t{}", settings[ "arpeggio_macro_fixed" ] ); - println!( "Loop at:\t{:?}", loop_at ); + print_info( &format!( "Arpeggio Envelope Size:\t{}", envelope.len() ) ); + print_info( &format!( "Arpeggio Macro Fixed:\t{}", settings[ "arpeggio_macro_fixed" ] ) ); + print_info( &format!( "Loop at:\t{:?}", loop_at ) ); PsgEnvelope { envelope, @@ -286,8 +287,8 @@ impl DmfModule { None }; - println!( "Noise Envelope Size:\t{}", envelope.len() ); - println!( "Loop at:\t{:?}", loop_at ); + print_info( &format!( "Noise Envelope Size:\t{}", envelope.len() ) ); + print_info( &format!( "Loop at:\t{:?}", loop_at ) ); PsgEnvelope { envelope, @@ -316,8 +317,8 @@ impl DmfModule { None }; - println!( "WavTbl Envelope Size:\t{}\n", envelope.len() ); - println!( "Loop at:\t{:?}", loop_at ); + print_info( &format!( "WavTbl Envelope Size:\t{}\n", envelope.len() ) ); + print_info( &format!( "Loop at:\t{:?}", loop_at ) ); PsgEnvelope { envelope, @@ -329,17 +330,17 @@ impl DmfModule { InstrumentType::Psg( PsgSettings { volume, arpeggio, noise, wavetable } ) }, 1 => { - println!( "Fm Instrument" ); + print_info( "Fm Instrument" ); let alg = get_u8( bytes.by_ref() )?; let fb = get_u8( bytes.by_ref() )?; let fms = get_u8( bytes.by_ref() )?; let ams = get_u8( bytes.by_ref() )?; - println!( "Alg:\t{}", alg ); - println!( "Fb:\t{}", fb ); - println!( "FMS:\t{}", fms ); - println!( "AMS:\t{}", ams ); + print_info( &format!( "Alg:\t{}", alg ) ); + print_info( &format!( "Fb:\t{}", fb ) ); + print_info( &format!( "FMS:\t{}", fms ) ); + print_info( &format!( "AMS:\t{}", ams ) ); let mut operators: [FmOperator; 4] = [ FmOperator::default(), @@ -363,18 +364,18 @@ impl DmfModule { operators[ 0 ].d2r = get_u8( bytes.by_ref() )?; operators[ 0 ].ssg_mode = get_u8( bytes.by_ref() )?; - println!( "Op 1 AM:\t{}", operators[ 0 ].am ); - println!( "Op 1 AR:\t{}", operators[ 0 ].ar ); - println!( "Op 1 DR:\t{}", operators[ 0 ].dr ); - println!( "Op 1 MULT:\t{}", operators[ 0 ].mult ); - println!( "Op 1 RR:\t{}", operators[ 0 ].rr ); - println!( "Op 1 SL:\t{}", operators[ 0 ].sl ); - println!( "Op 1 TL:\t{}", operators[ 0 ].tl ); - println!( "Op 1 DT2:\t{}", operators[ 0 ].dt2 ); - println!( "Op 1 RS:\t{}", operators[ 0 ].rs ); - println!( "Op 1 DT:\t{}", operators[ 0 ].dt ); - println!( "Op 1 D2R:\t{}", operators[ 0 ].d2r ); - println!( "Op 1 SSG_MODE:\t{}\n", operators[ 0 ].ssg_mode ); + print_info( &format!( "Op 1 AM:\t{}", operators[ 0 ].am ) ); + print_info( &format!( "Op 1 AR:\t{}", operators[ 0 ].ar ) ); + print_info( &format!( "Op 1 DR:\t{}", operators[ 0 ].dr ) ); + print_info( &format!( "Op 1 MULT:\t{}", operators[ 0 ].mult ) ); + print_info( &format!( "Op 1 RR:\t{}", operators[ 0 ].rr ) ); + print_info( &format!( "Op 1 SL:\t{}", operators[ 0 ].sl ) ); + print_info( &format!( "Op 1 TL:\t{}", operators[ 0 ].tl ) ); + print_info( &format!( "Op 1 DT2:\t{}", operators[ 0 ].dt2 ) ); + print_info( &format!( "Op 1 RS:\t{}", operators[ 0 ].rs ) ); + print_info( &format!( "Op 1 DT:\t{}", operators[ 0 ].dt ) ); + print_info( &format!( "Op 1 D2R:\t{}", operators[ 0 ].d2r ) ); + print_info( &format!( "Op 1 SSG_MODE:\t{}\n", operators[ 0 ].ssg_mode ) ); } // Operator 3 @@ -392,18 +393,18 @@ impl DmfModule { operators[ 1 ].d2r = get_u8( bytes.by_ref() )?; operators[ 1 ].ssg_mode = get_u8( bytes.by_ref() )?; - println!( "Op 3 AM:\t{}", operators[ 1 ].am ); - println!( "Op 3 AR:\t{}", operators[ 1 ].ar ); - println!( "Op 3 DR:\t{}", operators[ 1 ].dr ); - println!( "Op 3 MULT:\t{}", operators[ 1 ].mult ); - println!( "Op 3 RR:\t{}", operators[ 1 ].rr ); - println!( "Op 3 SL:\t{}", operators[ 1 ].sl ); - println!( "Op 3 TL:\t{}", operators[ 1 ].tl ); - println!( "Op 3 DT2:\t{}", operators[ 1 ].dt2 ); - println!( "Op 3 RS:\t{}", operators[ 1 ].rs ); - println!( "Op 3 DT:\t{}", operators[ 1 ].dt ); - println!( "Op 3 D2R:\t{}", operators[ 1 ].d2r ); - println!( "Op 3 SSG_MODE:\t{}\n", operators[ 1 ].ssg_mode ); + print_info( &format!( "Op 3 AM:\t{}", operators[ 1 ].am ) ); + print_info( &format!( "Op 3 AR:\t{}", operators[ 1 ].ar ) ); + print_info( &format!( "Op 3 DR:\t{}", operators[ 1 ].dr ) ); + print_info( &format!( "Op 3 MULT:\t{}", operators[ 1 ].mult ) ); + print_info( &format!( "Op 3 RR:\t{}", operators[ 1 ].rr ) ); + print_info( &format!( "Op 3 SL:\t{}", operators[ 1 ].sl ) ); + print_info( &format!( "Op 3 TL:\t{}", operators[ 1 ].tl ) ); + print_info( &format!( "Op 3 DT2:\t{}", operators[ 1 ].dt2 ) ); + print_info( &format!( "Op 3 RS:\t{}", operators[ 1 ].rs ) ); + print_info( &format!( "Op 3 DT:\t{}", operators[ 1 ].dt ) ); + print_info( &format!( "Op 3 D2R:\t{}", operators[ 1 ].d2r ) ); + print_info( &format!( "Op 3 SSG_MODE:\t{}\n", operators[ 1 ].ssg_mode ) ); } // Operator 2 @@ -421,18 +422,18 @@ impl DmfModule { operators[ 2 ].d2r = get_u8( bytes.by_ref() )?; operators[ 2 ].ssg_mode = get_u8( bytes.by_ref() )?; - println!( "Op 2 AM:\t{}", operators[ 2 ].am ); - println!( "Op 2 AR:\t{}", operators[ 2 ].ar ); - println!( "Op 2 DR:\t{}", operators[ 2 ].dr ); - println!( "Op 2 MULT:\t{}", operators[ 2 ].mult ); - println!( "Op 2 RR:\t{}", operators[ 2 ].rr ); - println!( "Op 2 SL:\t{}", operators[ 2 ].sl ); - println!( "Op 2 TL:\t{}", operators[ 2 ].tl ); - println!( "Op 2 DT2:\t{}", operators[ 2 ].dt2 ); - println!( "Op 2 RS:\t{}", operators[ 2 ].rs ); - println!( "Op 2 DT:\t{}", operators[ 2 ].dt ); - println!( "Op 2 D2R:\t{}", operators[ 2 ].d2r ); - println!( "Op 2 SSG_MODE:\t{}\n", operators[ 2 ].ssg_mode ); + print_info( &format!( "Op 2 AM:\t{}", operators[ 2 ].am ) ); + print_info( &format!( "Op 2 AR:\t{}", operators[ 2 ].ar ) ); + print_info( &format!( "Op 2 DR:\t{}", operators[ 2 ].dr ) ); + print_info( &format!( "Op 2 MULT:\t{}", operators[ 2 ].mult ) ); + print_info( &format!( "Op 2 RR:\t{}", operators[ 2 ].rr ) ); + print_info( &format!( "Op 2 SL:\t{}", operators[ 2 ].sl ) ); + print_info( &format!( "Op 2 TL:\t{}", operators[ 2 ].tl ) ); + print_info( &format!( "Op 2 DT2:\t{}", operators[ 2 ].dt2 ) ); + print_info( &format!( "Op 2 RS:\t{}", operators[ 2 ].rs ) ); + print_info( &format!( "Op 2 DT:\t{}", operators[ 2 ].dt ) ); + print_info( &format!( "Op 2 D2R:\t{}", operators[ 2 ].d2r ) ); + print_info( &format!( "Op 2 SSG_MODE:\t{}\n", operators[ 2 ].ssg_mode ) ); } // Operator 4 @@ -450,18 +451,18 @@ impl DmfModule { operators[ 3 ].d2r = get_u8( bytes.by_ref() )?; operators[ 3 ].ssg_mode = get_u8( bytes.by_ref() )?; - println!( "Op 4 AM:\t{}", operators[ 3 ].am ); - println!( "Op 4 AR:\t{}", operators[ 3 ].ar ); - println!( "Op 4 DR:\t{}", operators[ 3 ].dr ); - println!( "Op 4 MULT:\t{}", operators[ 3 ].mult ); - println!( "Op 4 RR:\t{}", operators[ 3 ].rr ); - println!( "Op 4 SL:\t{}", operators[ 3 ].sl ); - println!( "Op 4 TL:\t{}", operators[ 3 ].tl ); - println!( "Op 4 DT2:\t{}", operators[ 3 ].dt2 ); - println!( "Op 4 RS:\t{}", operators[ 3 ].rs ); - println!( "Op 4 DT:\t{}", operators[ 3 ].dt ); - println!( "Op 4 D2R:\t{}", operators[ 3 ].d2r ); - println!( "Op 4 SSG_MODE:\t{}\n", operators[ 3 ].ssg_mode ); + print_info( &format!( "Op 4 AM:\t{}", operators[ 3 ].am ) ); + print_info( &format!( "Op 4 AR:\t{}", operators[ 3 ].ar ) ); + print_info( &format!( "Op 4 DR:\t{}", operators[ 3 ].dr ) ); + print_info( &format!( "Op 4 MULT:\t{}", operators[ 3 ].mult ) ); + print_info( &format!( "Op 4 RR:\t{}", operators[ 3 ].rr ) ); + print_info( &format!( "Op 4 SL:\t{}", operators[ 3 ].sl ) ); + print_info( &format!( "Op 4 TL:\t{}", operators[ 3 ].tl ) ); + print_info( &format!( "Op 4 DT2:\t{}", operators[ 3 ].dt2 ) ); + print_info( &format!( "Op 4 RS:\t{}", operators[ 3 ].rs ) ); + print_info( &format!( "Op 4 DT:\t{}", operators[ 3 ].dt ) ); + print_info( &format!( "Op 4 D2R:\t{}", operators[ 3 ].d2r ) ); + print_info( &format!( "Op 4 SSG_MODE:\t{}\n", operators[ 3 ].ssg_mode ) ); } InstrumentType::Fm( FmSettings { alg, fb, fms, ams, operators } ) @@ -490,7 +491,7 @@ impl DmfModule { for channel in 0..system_total_channels { let mut channel_rows: Vec = Vec::new(); let num_effects = get_u8( bytes.by_ref() )?; - println!( "Patterns for Ch. {}", channel ); + print_info( &format!( "Patterns for Ch. {}", channel ) ); for _ in 0..patterns_count { for row_id in 0..rows_per_pattern { @@ -606,7 +607,7 @@ impl DmfModule { }; let pattern_row = PatternRow { note, volume, effects, instrument_index }; - println!( "{}:\t{:?}", row_id, pattern_row ); + print_info( &format!( "{}:\t{:?}", row_id, pattern_row ) ); channel_rows.push( pattern_row ); } @@ -615,7 +616,7 @@ impl DmfModule { channel_patterns.push( channel_rows ); } - println!( "PCM Samples:" ); + print_info( "PCM Samples:" ); let mut samples: Vec = Vec::new(); let num_samples = get_u8( bytes.by_ref() )?; for i in 0..num_samples { @@ -646,7 +647,7 @@ impl DmfModule { let mut sample = Sample { name, rate, pitch, amp, bitrate, data: Vec::new() }; - println!( "{}:\t{:?}", i, sample ); + print_info( &format!( "{}:\t{:?}", i, sample ) ); for _ in 0..sample_size { sample.data.push( get_i16( bytes.by_ref() )? ); diff --git a/src/reskit/utility.rs b/src/reskit/utility.rs index 3d0ce96..6cfe0b5 100644 --- a/src/reskit/utility.rs +++ b/src/reskit/utility.rs @@ -49,6 +49,10 @@ pub fn print_warning( message: &str ) { yellow!( "warning: " ); println!( "{}", message ); } +pub fn print_info( message: &str ) { + cyan!( "info: " ); println!( "{}", message ); +} + pub fn get_string( bytes: &mut Iter<'_, u8>, take: usize ) -> Result> { let took = bytes.take( take ); let took: Vec = took.cloned().collect();