aboutsummaryrefslogtreecommitdiff
path: root/src/itfile.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/itfile.rs')
-rw-r--r--src/itfile.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/itfile.rs b/src/itfile.rs
index e744ce3..6d85a87 100644
--- a/src/itfile.rs
+++ b/src/itfile.rs
@@ -3,6 +3,7 @@ use std::io::prelude::*;
use std::io::SeekFrom;
use std::fs::File;
use std::mem::{size_of, zeroed};
+use std::collections::HashSet;
use crate::portmod::{Effect, Slide};
@@ -112,7 +113,8 @@ pub struct Inst
pub header: InstHeader,
pub env_vol: Envelope,
pub env_pan: Envelope,
- pub env_pit: Envelope
+ pub env_pit: Envelope,
+ key_samples: [u8; 120]
}
impl Inst
@@ -125,12 +127,20 @@ impl Inst
let env_pan: Envelope = read_struct(f)?;
f.seek(SeekFrom::Start(1))?;
let env_pit: Envelope = read_struct(f)?;
- Ok(Inst{header, env_vol, env_pan, env_pit})
+ let mut ks = [0u8; 120];
+ for i in 0..120
+ {
+ if header.sample_table[i * 2] < 120
+ { ks[header.sample_table[i * 2] as usize] = header.sample_table[i * 2 + 1]; }
+ }
+ Ok(Inst{header, env_vol, env_pan, env_pit, key_samples: ks})
}
pub fn inst_name(self: &Self) -> String
{ String::from_utf8_lossy(terminate_cstr(&self.header.inst_name)).into_owned() }
pub fn filename(self: &Self) -> String
{ String::from_utf8_lossy(terminate_cstr(&self.header.dos_filename)).into_owned() }
+ pub fn samp_for_key(self: &Self, key: u8) -> u8
+ { self.key_samples[key as usize] }
}
#[repr(C, packed)]
@@ -178,6 +188,7 @@ impl Samp
pub fn is_compressed(self: &Self) -> bool { self.header.flag & 0x8 != 0 }
pub fn num_channels(self: &Self) -> u8 { if self.header.flag & 0x4 != 0 { 2 } else { 1 }}
pub fn bits_per_sample(self: &Self) -> u8 { if self.header.flag & 0x2 != 0 { 16 } else { 8 }}
+ pub fn default_vol(self: &Self) -> u8 { self.header.default_volume }
}
#[derive(Copy, Clone, Default)]
@@ -357,6 +368,7 @@ impl ITFile
} else { None }
}
}
+ pub fn inst_mode(self: &Self) -> bool { self.header.ninst > 0 }
}
#[derive(Debug)]
@@ -549,7 +561,13 @@ pub fn load(filename: &str) -> Result<ITFile, self::Error>
{
return Err(self::Error::InvalidHeader);
}
- println!("{}", inst.inst_name());
+ let mut sampsused = HashSet::<u8>::new();
+ for i in 0u8..120
+ {
+ if inst.samp_for_key(i) > 0
+ { sampsused.insert(inst.samp_for_key(i)); }
+ }
+ println!("{} [{}] samples {:?}", inst.inst_name(), inst.filename(), sampsused);
insts.push(inst);
}
@@ -577,7 +595,7 @@ pub fn load(filename: &str) -> Result<ITFile, self::Error>
}
let dataend_off = f.stream_position()?;
last_samp_off = std::cmp::max(last_samp_off, dataend_off);
- println!("{}", samp.sample_name());
+ println!("{} [{}]", samp.sample_name(), samp.filename());
samps.push(samp);
}
let mut patterns: Vec<Patt> = Vec::new();