Cue lists implemented

This commit is contained in:
Jamie Hardt
2020-12-10 18:09:28 -08:00
parent 8519854596
commit 4890483dcd
4 changed files with 29 additions and 14 deletions

2
Cargo.lock generated
View File

@@ -2,7 +2,7 @@
# It is not intended for manual editing.
[[package]]
name = "bwavfile"
version = "0.1.6"
version = "0.1.7"
dependencies = [
"byteorder",
"encoding",

View File

@@ -1,6 +1,6 @@
[package]
name = "bwavfile"
version = "0.1.6"
version = "0.1.7"
authors = ["Jamie Hardt <jamiehardt@me.com>"]
edition = "2018"
license = "MIT"

View File

@@ -1,9 +1,13 @@
use super::fourcc::{FourCC,ReadFourCC, LABL_SIG, NOTE_SIG, LTXT_SIG};
use super::list_form::collect_list_form;
use byteorder::{ReadBytesExt, LittleEndian};
use encoding::{DecoderTrap};
use encoding::{Encoding};
use encoding::all::ASCII;
use std::io::{Cursor, Error, Read};
use std::str;
#[derive(Copy,Clone, Debug)]
struct RawCue {
@@ -52,7 +56,6 @@ impl RawLabel {
text : {
let mut buf = vec![0u8; (length - 4) as usize ];
rdr.read_exact(&mut buf)?;
//if buf.len() % 2 == 1 { rdr.read_u8()?; };
buf
}
})
@@ -75,7 +78,6 @@ impl RawNote {
text : {
let mut buf = vec![0u8; (length - 4) as usize ];
rdr.read_exact(&mut buf)?;
//if length % 2 == 1 { rdr.read_u8()?; };
buf
}
})
@@ -111,9 +113,7 @@ impl RawLtxt {
if length - 20 > 0 {
let mut buf = vec![0u8; (length - 20) as usize];
rdr.read_exact(&mut buf)?;
//if length % 2 == 1 { rdr.read_u8()?; };
Some( buf )
//Some( String::from_utf8(buf).unwrap_or(String::from("<TEXT ENCODING ERROR>")) )
} else {
None
}
@@ -210,6 +210,11 @@ pub struct Cue {
}
fn convert_to_cue_string(buffer : &[u8]) -> String {
let trimmed : Vec<u8> = buffer.iter().take_while(|c| **c != 0 as u8).cloned().collect();
ASCII.decode(&trimmed, DecoderTrap::Ignore).expect("Error decoding text")
}
impl Cue {
pub fn collect_from(cue_chunk : &[u8], adtl_chunk : Option<&[u8]>) -> Result<Vec<Cue>, Error> {
@@ -230,18 +235,19 @@ impl Cue {
ident : i.cue_point_id,
frame : i.frame,
length: {
raw_adtl.ltxt_for_cue_point(i.cue_point_id).first().map(|x| x.frame_length)
raw_adtl.ltxt_for_cue_point(i.cue_point_id).first()
.filter(|x| x.purpose == FourCC::make(b"rgn "))
.map(|x| x.frame_length)
},
label: {
raw_adtl.labels_for_cue_point(i.cue_point_id).iter()
.filter_map(|x| str::from_utf8(&x.text).ok())
.map(|s| String::from(s))
.map(|s| convert_to_cue_string(&s.text))
.next()
},
note : {
raw_adtl.notes_for_cue_point(i.cue_point_id).iter()
.filter_map(|x| str::from_utf8(&x.text).ok())
.map(|s| String::from(s))
//.filter_map(|x| str::from_utf8(&x.text).ok())
.map(|s| convert_to_cue_string(&s.text))
.next()
}
}

View File

@@ -185,13 +185,22 @@ impl<R: Read + Seek> WaveReader<R> {
/// assert_eq!(cue_points.len(), 3);
/// assert_eq!(cue_points[0].ident, 1);
/// assert_eq!(cue_points[0].frame, 12532);
/// //assert_eq!(cue_points[0].label, Some(String::from("Marker 1")));
/// assert_eq!(cue_points[0].length, None);
/// assert_eq!(cue_points[0].label, Some(String::from("Marker 1")));
/// assert_eq!(cue_points[0].note, Some(String::from("Marker 1 Comment")));
///
/// assert_eq!(cue_points[1].ident, 2);
/// assert_eq!(cue_points[1].frame, 20997);
/// assert_eq!(cue_points[1].length, None);
/// assert_eq!(cue_points[1].label, Some(String::from("Marker 2")));
/// assert_eq!(cue_points[1].note, Some(String::from("Marker 2 Comment")));
///
/// assert_eq!(cue_points[2].ident, 3);
/// assert_eq!(cue_points[2].frame, 26711);
/// assert_eq!(cue_points[2].length, Some(6465));
/// assert_eq!(cue_points[2].label, Some(String::from("Timed Region")));
/// assert_eq!(cue_points[2].note, Some(String::from("Region Comment")));
///
/// ```
pub fn cue_points(&mut self) -> Result<Vec<Cue>,ParserError> {
let mut cue_buffer : Vec<u8> = vec![];