mirror of
https://github.com/iluvcapra/bwavfile.git
synced 2025-12-31 08:50:44 +00:00
Cue lists implemented
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2,7 +2,7 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bwavfile"
|
name = "bwavfile"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"encoding",
|
"encoding",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bwavfile"
|
name = "bwavfile"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
authors = ["Jamie Hardt <jamiehardt@me.com>"]
|
authors = ["Jamie Hardt <jamiehardt@me.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
28
src/cue.rs
28
src/cue.rs
@@ -1,9 +1,13 @@
|
|||||||
use super::fourcc::{FourCC,ReadFourCC, LABL_SIG, NOTE_SIG, LTXT_SIG};
|
use super::fourcc::{FourCC,ReadFourCC, LABL_SIG, NOTE_SIG, LTXT_SIG};
|
||||||
use super::list_form::collect_list_form;
|
use super::list_form::collect_list_form;
|
||||||
|
|
||||||
use byteorder::{ReadBytesExt, LittleEndian};
|
use byteorder::{ReadBytesExt, LittleEndian};
|
||||||
|
|
||||||
|
use encoding::{DecoderTrap};
|
||||||
|
use encoding::{Encoding};
|
||||||
|
use encoding::all::ASCII;
|
||||||
|
|
||||||
use std::io::{Cursor, Error, Read};
|
use std::io::{Cursor, Error, Read};
|
||||||
use std::str;
|
|
||||||
|
|
||||||
#[derive(Copy,Clone, Debug)]
|
#[derive(Copy,Clone, Debug)]
|
||||||
struct RawCue {
|
struct RawCue {
|
||||||
@@ -46,13 +50,12 @@ impl RawLabel {
|
|||||||
fn read_from(data : &[u8]) -> Result<Self, Error> {
|
fn read_from(data : &[u8]) -> Result<Self, Error> {
|
||||||
let mut rdr = Cursor::new(data);
|
let mut rdr = Cursor::new(data);
|
||||||
let length = data.len();
|
let length = data.len();
|
||||||
|
|
||||||
Ok( Self {
|
Ok( Self {
|
||||||
cue_point_id : rdr.read_u32::<LittleEndian>()?,
|
cue_point_id : rdr.read_u32::<LittleEndian>()?,
|
||||||
text : {
|
text : {
|
||||||
let mut buf = vec![0u8; (length - 4) as usize ];
|
let mut buf = vec![0u8; (length - 4) as usize ];
|
||||||
rdr.read_exact(&mut buf)?;
|
rdr.read_exact(&mut buf)?;
|
||||||
//if buf.len() % 2 == 1 { rdr.read_u8()?; };
|
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -75,7 +78,6 @@ impl RawNote {
|
|||||||
text : {
|
text : {
|
||||||
let mut buf = vec![0u8; (length - 4) as usize ];
|
let mut buf = vec![0u8; (length - 4) as usize ];
|
||||||
rdr.read_exact(&mut buf)?;
|
rdr.read_exact(&mut buf)?;
|
||||||
//if length % 2 == 1 { rdr.read_u8()?; };
|
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -111,9 +113,7 @@ impl RawLtxt {
|
|||||||
if length - 20 > 0 {
|
if length - 20 > 0 {
|
||||||
let mut buf = vec![0u8; (length - 20) as usize];
|
let mut buf = vec![0u8; (length - 20) as usize];
|
||||||
rdr.read_exact(&mut buf)?;
|
rdr.read_exact(&mut buf)?;
|
||||||
//if length % 2 == 1 { rdr.read_u8()?; };
|
|
||||||
Some( buf )
|
Some( buf )
|
||||||
//Some( String::from_utf8(buf).unwrap_or(String::from("<TEXT ENCODING ERROR>")) )
|
|
||||||
} else {
|
} else {
|
||||||
None
|
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 {
|
impl Cue {
|
||||||
|
|
||||||
pub fn collect_from(cue_chunk : &[u8], adtl_chunk : Option<&[u8]>) -> Result<Vec<Cue>, Error> {
|
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,
|
ident : i.cue_point_id,
|
||||||
frame : i.frame,
|
frame : i.frame,
|
||||||
length: {
|
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: {
|
label: {
|
||||||
raw_adtl.labels_for_cue_point(i.cue_point_id).iter()
|
raw_adtl.labels_for_cue_point(i.cue_point_id).iter()
|
||||||
.filter_map(|x| str::from_utf8(&x.text).ok())
|
.map(|s| convert_to_cue_string(&s.text))
|
||||||
.map(|s| String::from(s))
|
|
||||||
.next()
|
.next()
|
||||||
},
|
},
|
||||||
note : {
|
note : {
|
||||||
raw_adtl.notes_for_cue_point(i.cue_point_id).iter()
|
raw_adtl.notes_for_cue_point(i.cue_point_id).iter()
|
||||||
.filter_map(|x| str::from_utf8(&x.text).ok())
|
//.filter_map(|x| str::from_utf8(&x.text).ok())
|
||||||
.map(|s| String::from(s))
|
.map(|s| convert_to_cue_string(&s.text))
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,13 +185,22 @@ impl<R: Read + Seek> WaveReader<R> {
|
|||||||
/// assert_eq!(cue_points.len(), 3);
|
/// assert_eq!(cue_points.len(), 3);
|
||||||
/// assert_eq!(cue_points[0].ident, 1);
|
/// assert_eq!(cue_points[0].ident, 1);
|
||||||
/// assert_eq!(cue_points[0].frame, 12532);
|
/// 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].ident, 2);
|
||||||
/// assert_eq!(cue_points[1].frame, 20997);
|
/// 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].ident, 3);
|
||||||
/// assert_eq!(cue_points[2].frame, 26711);
|
/// 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> {
|
pub fn cue_points(&mut self) -> Result<Vec<Cue>,ParserError> {
|
||||||
let mut cue_buffer : Vec<u8> = vec![];
|
let mut cue_buffer : Vec<u8> = vec![];
|
||||||
|
|||||||
Reference in New Issue
Block a user