|
@@ -23,12 +23,16 @@ pub struct Sound {
|
|
|
pub location: PathBuf,
|
|
|
#[serde(skip)]
|
|
|
data: Arc<Vec<u8>>,
|
|
|
+ #[serde(skip)]
|
|
|
+ data_rev: Arc<Vec<u8>>,
|
|
|
pub volume: f32,
|
|
|
pub roll: i32,
|
|
|
pub rollrate: i32,
|
|
|
pub trim: f32,
|
|
|
pub active: bool,
|
|
|
- pub speed: f32
|
|
|
+ pub speed: f32,
|
|
|
+ #[serde(default)]
|
|
|
+ pub reverse: bool
|
|
|
}
|
|
|
|
|
|
|
|
@@ -44,8 +48,11 @@ impl Sound {
|
|
|
let mut buf = Vec::new();
|
|
|
let mut file = File::open(filename)?;
|
|
|
file.read_to_end(&mut buf)?;
|
|
|
+ let mut rev_buf = buf.clone();
|
|
|
+ rev_buf.reverse();
|
|
|
Ok(Sound{
|
|
|
data: Arc::new(buf),
|
|
|
+ data_rev: Arc::new(rev_buf),
|
|
|
name: path.file_name().unwrap_or_default().to_string_lossy().to_string(),
|
|
|
location: path,
|
|
|
volume: 1.0,
|
|
@@ -60,7 +67,7 @@ impl Sound {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- pub fn reload_data(&self) -> Result<Sound, std::io::Error>{
|
|
|
+ pub fn updated_drom_source(&self) -> Result<Sound, std::io::Error>{
|
|
|
Sound::new(&self.location.to_string_lossy())
|
|
|
}
|
|
|
|
|
@@ -72,17 +79,38 @@ impl Sound {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- pub fn decoder(self: &Self) -> Decoder<Cursor<Sound>> {
|
|
|
- Decoder::new(self.cursor()).unwrap()
|
|
|
+ pub fn cursor_rev(self: &Self) -> Cursor<Sound> {
|
|
|
+ Cursor::new(
|
|
|
+ Sound {
|
|
|
+ data: self.data_rev.clone(),
|
|
|
+ ..Default::default()
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
+ // pub fn decoder(self: &Self) -> Decoder<Cursor<Sound>> {
|
|
|
+ // Decoder::new(self.cursor()).unwrap()
|
|
|
+ // }
|
|
|
+
|
|
|
pub fn play(&self, device: &rodio::Device) {
|
|
|
- // let s = self.decoder().convert_samples()
|
|
|
- rodio::play_raw(&device, self.decoder()
|
|
|
- .speed(self.speed)
|
|
|
- .amplify(self.volume)
|
|
|
- .convert_samples());
|
|
|
- // self.active = true;
|
|
|
+
|
|
|
+ let decoder = match self.reverse {
|
|
|
+ false => Decoder::new(self.cursor()),
|
|
|
+ true => Decoder::new(self.cursor_rev()),
|
|
|
+ };
|
|
|
+
|
|
|
+ match decoder {
|
|
|
+ Ok(ok_decoder) => {
|
|
|
+ rodio::play_raw(&device, ok_decoder
|
|
|
+ .speed(self.speed)
|
|
|
+ .amplify(self.volume)
|
|
|
+ .convert_samples());
|
|
|
+
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ dbg!(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -242,7 +270,7 @@ impl Pattern {
|
|
|
for y in 0..self.ysize {
|
|
|
if let Some(snd) = self.sounds.get_mut(&(x,y)) {
|
|
|
println!("RELOAD {:?}", &snd.name);
|
|
|
- snd.data = snd.reload_data().unwrap().data;
|
|
|
+ snd.data = snd.updated_drom_source().unwrap().data;
|
|
|
// let s = snd.reload_data().unwrap();
|
|
|
// snd.data = s.data.clone();
|
|
|
}
|