pub struct TextGrid {
pub xmin: f64,
pub xmax: f64,
pub tiers: Vec<Tier>,
/* private fields */
}
Expand description
Main structure representing a Praat TextGrid with tiers and history.
Fields§
§xmin: f64
Start time of the entire TextGrid.
xmax: f64
End time of the entire TextGrid.
tiers: Vec<Tier>
List of tiers in the TextGrid.
Implementations§
Source§impl TextGrid
impl TextGrid
Sourcepub fn undo(&mut self) -> Result<(), TextGridError>
pub fn undo(&mut self) -> Result<(), TextGridError>
Undoes the last change made to the TextGrid.
§Returns
Returns Ok(())
on success or a TextGridError
if there are no changes to undo or if the undo fails.
Sourcepub fn redo(&mut self) -> Result<(), TextGridError>
pub fn redo(&mut self) -> Result<(), TextGridError>
Redoes the last undone change.
§Returns
Returns Ok(())
on success or a TextGridError
if there are no changes to redo or if the redo fails.
Sourcepub fn remove_tier(&mut self, index: usize) -> Result<(), TextGridError>
pub fn remove_tier(&mut self, index: usize) -> Result<(), TextGridError>
Sourcepub fn get_tier_mut(&mut self, name: &str) -> Option<&mut Tier>
pub fn get_tier_mut(&mut self, name: &str) -> Option<&mut Tier>
Sourcepub fn rename_tier(
&mut self,
old_name: &str,
new_name: String,
) -> Result<(), TextGridError>
pub fn rename_tier( &mut self, old_name: &str, new_name: String, ) -> Result<(), TextGridError>
Sourcepub fn merge_tiers_with_strategy<F>(
&mut self,
name1: &str,
name2: &str,
new_name: String,
merge_strategy: F,
) -> Result<(), TextGridError>
pub fn merge_tiers_with_strategy<F>( &mut self, name1: &str, name2: &str, new_name: String, merge_strategy: F, ) -> Result<(), TextGridError>
Merges two tiers using a custom strategy with undo support.
§Arguments
name1
- Name of the first tier.name2
- Name of the second tier.new_name
- Name for the resulting merged tier.merge_strategy
- Function to determine how overlapping intervals are merged.
§Returns
Returns Ok(())
on success or a TextGridError
if the tiers are not found or not IntervalTiers.
Sourcepub fn merge_tiers(
&mut self,
name1: &str,
name2: &str,
new_name: String,
) -> Result<(), TextGridError>
pub fn merge_tiers( &mut self, name1: &str, name2: &str, new_name: String, ) -> Result<(), TextGridError>
Merges two tiers with a default strategy (merges if text matches or one is empty).
§Arguments
name1
- Name of the first tier.name2
- Name of the second tier.new_name
- Name for the resulting merged tier.
§Returns
Returns Ok(())
on success or a TextGridError
if the tiers are not found or not IntervalTiers.
Sourcepub fn adjust_bounds(
&mut self,
new_xmin: f64,
new_xmax: f64,
) -> Result<(), TextGridError>
pub fn adjust_bounds( &mut self, new_xmin: f64, new_xmax: f64, ) -> Result<(), TextGridError>
Sourcepub fn insert_silence(
&mut self,
tier_name: &str,
start: f64,
end: f64,
) -> Result<(), TextGridError>
pub fn insert_silence( &mut self, tier_name: &str, start: f64, end: f64, ) -> Result<(), TextGridError>
Sourcepub fn tier_add_interval(
&mut self,
tier_name: &str,
interval: Interval,
) -> Result<(), TextGridError>
pub fn tier_add_interval( &mut self, tier_name: &str, interval: Interval, ) -> Result<(), TextGridError>
Sourcepub fn tier_remove_interval(
&mut self,
tier_name: &str,
index: usize,
) -> Result<(), TextGridError>
pub fn tier_remove_interval( &mut self, tier_name: &str, index: usize, ) -> Result<(), TextGridError>
Sourcepub fn tier_add_point(
&mut self,
tier_name: &str,
point: Point,
) -> Result<(), TextGridError>
pub fn tier_add_point( &mut self, tier_name: &str, point: Point, ) -> Result<(), TextGridError>
Sourcepub fn tier_remove_point(
&mut self,
tier_name: &str,
index: usize,
) -> Result<(), TextGridError>
pub fn tier_remove_point( &mut self, tier_name: &str, index: usize, ) -> Result<(), TextGridError>
Sourcepub fn tier_split_interval(
&mut self,
tier_name: &str,
index: usize,
time: f64,
) -> Result<(), TextGridError>
pub fn tier_split_interval( &mut self, tier_name: &str, index: usize, time: f64, ) -> Result<(), TextGridError>
Sourcepub fn tier_merge_intervals(
&mut self,
tier_name: &str,
) -> Result<(), TextGridError>
pub fn tier_merge_intervals( &mut self, tier_name: &str, ) -> Result<(), TextGridError>
Source§impl TextGrid
impl TextGrid
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, TextGridError>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, TextGridError>
Loads a TextGrid from a file (text or binary format).
§Arguments
path
- Path to the.TextGrid
file, implementingAsRef<Path>
.
§Returns
Returns a Result
containing the loaded TextGrid
or a TextGridError
.
§Errors
TextGridError::Format
if the file extension is unsupported or missing, or if the file is malformed.TextGridError::IO
if the file cannot be opened or read.
§Examples
let tg = TextGrid::from_file("example.TextGrid").unwrap();
assert_eq!(tg.tiers.len(), 1); // Assuming one tier in the file
Sourcepub fn to_file<P: AsRef<Path>>(
&self,
path: P,
short_format: bool,
) -> Result<(), TextGridError>
pub fn to_file<P: AsRef<Path>>( &self, path: P, short_format: bool, ) -> Result<(), TextGridError>
Writes a TextGrid to a file in text format.
§Arguments
path
- Path to the output file, implementingAsRef<Path>
.short_format
- Iftrue
, uses the short text format; otherwise, uses the long format.
§Returns
Returns a Result
indicating success (Ok(())
) or a TextGridError
.
§Errors
TextGridError::Format
if the TextGrid data is invalid (e.g., overlapping intervals).TextGridError::IO
if the file cannot be created or written to.
§Examples
let tg = TextGrid::new(0.0, 5.0).unwrap(); // Assume tiers are added
tg.to_file("test.TextGrid", false).unwrap();
Sourcepub fn to_binary_file<P: AsRef<Path>>(
&self,
path: P,
) -> Result<(), TextGridError>
pub fn to_binary_file<P: AsRef<Path>>( &self, path: P, ) -> Result<(), TextGridError>
Writes a TextGrid to a file in binary format.
§Arguments
path
- Path to the output file, implementingAsRef<Path>
.
§Returns
Returns a Result
indicating success (Ok(())
) or a TextGridError
.
§Errors
TextGridError::Format
if the TextGrid data is invalid (e.g., overlapping intervals).TextGridError::IO
if the file cannot be created or written to.
§Examples
let tg = TextGrid::new(0.0, 5.0).unwrap(); // Assume tiers are added
tg.to_binary_file("test.textgridbin").unwrap();