|
@@ -166,6 +166,8 @@ pub struct Pattern {
|
|
pub ysize: usize,
|
|
pub ysize: usize,
|
|
#[serde(serialize_with="ser_snds", deserialize_with="de_snds")]
|
|
#[serde(serialize_with="ser_snds", deserialize_with="de_snds")]
|
|
pub sounds: HashMap<(usize, usize), Sound>,
|
|
pub sounds: HashMap<(usize, usize), Sound>,
|
|
|
|
+ #[serde(skip)]
|
|
|
|
+ pub progress: Option<(usize, usize)>
|
|
}
|
|
}
|
|
|
|
|
|
/// Some basic defaults for a pattern.
|
|
/// Some basic defaults for a pattern.
|
|
@@ -177,25 +179,48 @@ impl Default for Pattern {
|
|
bpm: 120,
|
|
bpm: 120,
|
|
xsize: 8,
|
|
xsize: 8,
|
|
ysize: 1,
|
|
ysize: 1,
|
|
- sounds: HashMap::new()
|
|
|
|
|
|
+ sounds: HashMap::new(),
|
|
|
|
+ progress: None
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
impl Pattern {
|
|
impl Pattern {
|
|
- pub fn play(&self, device: &rodio::Device) {
|
|
|
|
|
|
+ pub fn play(&self, device: &Arc<rodio::Device>) {
|
|
|
|
+
|
|
|
|
+ let pat_clone = self.clone();
|
|
|
|
+
|
|
|
|
+ let device = device.clone();
|
|
let delay = ((60.0 / self.bpm as f32)*1000.0) as u64;
|
|
let delay = ((60.0 / self.bpm as f32)*1000.0) as u64;
|
|
- // loop for repeats
|
|
|
|
- for _ in 0..self.repeat + 1 {
|
|
|
|
- for x in 0..self.xsize {
|
|
|
|
- for y in 0..self.ysize {
|
|
|
|
- if let Some(s) = self.sounds.get(&(x, y)) {
|
|
|
|
- s.play(device);
|
|
|
|
|
|
+
|
|
|
|
+ thread::spawn(move || {
|
|
|
|
+
|
|
|
|
+ // loop for repeats
|
|
|
|
+ for _ in 0..pat_clone.repeat + 1 {
|
|
|
|
+ for x in 0..pat_clone.xsize {
|
|
|
|
+ for y in 0..pat_clone.ysize {
|
|
|
|
+ if let Some(s) = pat_clone.sounds.get(&(x, y)) {
|
|
|
|
+ s.play(&device);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ thread::sleep(Duration::from_millis(delay));
|
|
}
|
|
}
|
|
- thread::sleep(Duration::from_millis(delay));
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // for _ in 0..self.repeat + 1 {
|
|
|
|
+ // for x in 0..self.xsize {
|
|
|
|
+ // for y in 0..self.ysize {
|
|
|
|
+ // if let Some(s) = self.sounds.get(&(x, y)) {
|
|
|
|
+ // s.play(device);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // thread::sleep(Duration::from_millis(delay));
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// Deserialize a pattern from a file.
|
|
/// Deserialize a pattern from a file.
|
|
@@ -212,7 +237,7 @@ impl Pattern {
|
|
|
|
|
|
/// Replace all souds in a row by a new sound.
|
|
/// Replace all souds in a row by a new sound.
|
|
/// This only replaces the source, leaving other settings intact.
|
|
/// This only replaces the source, leaving other settings intact.
|
|
- pub fn replace_sounds(&mut self, new_sound: &Sound, row: usize) {
|
|
|
|
|
|
+ pub fn replace_sound_sources(&mut self, new_sound: &Sound, row: usize) {
|
|
for x in 0..self.xsize {
|
|
for x in 0..self.xsize {
|
|
if let Some(snd) = self.sounds.get_mut(&(x, row)) {
|
|
if let Some(snd) = self.sounds.get_mut(&(x, row)) {
|
|
snd.location = new_sound.location.clone();
|
|
snd.location = new_sound.location.clone();
|
|
@@ -222,6 +247,19 @@ impl Pattern {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// 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)) {
|
|
|
|
+ *snd = new_sound.clone();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/// Guess the name from the most commpn sound in a pattern.
|
|
/// Guess the name from the most commpn sound in a pattern.
|
|
pub fn name_from_row(&self, row: usize) -> String {
|
|
pub fn name_from_row(&self, row: usize) -> String {
|
|
let mut names: HashMap<String, usize> = HashMap::new();
|
|
let mut names: HashMap<String, usize> = HashMap::new();
|