|
@@ -156,7 +156,7 @@ where
|
|
|
|
|
|
fn de_snds<'de, D>(deserializer: D) -> Result<HashMap<(usize, usize), Sound>, D::Error>
|
|
|
where
|
|
|
- D: serde::de::Deserializer<'de>,
|
|
|
+D: serde::de::Deserializer<'de>,
|
|
|
{
|
|
|
// TODO err checking
|
|
|
let s: HashMap<String, Sound> = serde::de::Deserialize::deserialize(deserializer)?;
|
|
@@ -165,7 +165,9 @@ where
|
|
|
Ok(x)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
|
+/// A pattern. This holds a matrix of sounds - defined by a length and several tracks.
|
|
|
pub struct Pattern {
|
|
|
pub name: String,
|
|
|
pub repeat: i32,
|
|
@@ -176,6 +178,7 @@ pub struct Pattern {
|
|
|
pub sounds: HashMap<(usize, usize), Sound>,
|
|
|
}
|
|
|
|
|
|
+/// Some basic defaults for a pattern.
|
|
|
impl Default for Pattern {
|
|
|
fn default() -> Pattern {
|
|
|
Pattern {
|
|
@@ -205,6 +208,7 @@ impl Pattern {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Deserialize a pattern from a file.
|
|
|
pub fn load(file: &Path) -> Result<Pattern, String> {
|
|
|
match File::open(file) {
|
|
|
Ok(f) => {
|
|
@@ -215,6 +219,9 @@ impl Pattern {
|
|
|
Err(e) => Err(e.to_string())
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// Replace all souds in a row by a new sound.
|
|
|
+ /// This only replaces the source, leaving other settings intact.
|
|
|
pub fn replace_sounds(&mut self, new_sound: &Sound, row: usize) {
|
|
|
for x in 0..self.xsize {
|
|
|
if let Some(snd) = self.sounds.get_mut(&(x, row)) {
|
|
@@ -225,6 +232,7 @@ impl Pattern {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Guess the name from the most commpn sound in a pattern.
|
|
|
pub fn name_from_row(&self, row: usize) -> String {
|
|
|
let mut names: HashMap<String, usize> = HashMap::new();
|
|
|
|
|
@@ -252,6 +260,7 @@ impl Pattern {
|
|
|
s
|
|
|
}
|
|
|
|
|
|
+ /// Clear all sound in a pattern row
|
|
|
pub fn clear_sounds(&mut self, row: usize) {
|
|
|
for x in 0..self.xsize {
|
|
|
if let Some(_) = self.sounds.get(&(x, row)) {
|
|
@@ -260,27 +269,24 @@ impl Pattern {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// Clear all sounds in a pattern.
|
|
|
pub fn clear_all_sounds(&mut self) {
|
|
|
self.sounds.clear();
|
|
|
}
|
|
|
|
|
|
+ /// Reload all sounds in a pattern
|
|
|
pub fn reload_sounds(&mut self) -> Pattern {
|
|
|
- // let mut newp = self.clone();
|
|
|
for x in 0..self.xsize {
|
|
|
for y in 0..self.ysize {
|
|
|
if let Some(snd) = self.sounds.get_mut(&(x,y)) {
|
|
|
- println!("RELOAD {:?}", &snd.name);
|
|
|
-
|
|
|
- // snd.data = snd.updated_drom_source().unwrap().data;
|
|
|
+ // println!("RELOAD {:?}", &snd.name);
|
|
|
match snd.updated_drom_source() {
|
|
|
Ok(newdata) => snd.data = newdata.data,
|
|
|
- Err(e) => println!("ERROR LOADING {:?}", e)
|
|
|
+ Err(e) => println!("ERROR LOADING SND {:?} {:?}", e, snd.location)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // newp.clone()
|
|
|
self.clone()
|
|
|
}
|
|
|
|