Struct TextGrid

Source
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

Source

pub fn new(xmin: f64, xmax: f64) -> Result<Self, TextGridError>

Creates a new empty TextGrid with given bounds.

§Arguments
  • xmin - Start time of the TextGrid.
  • xmax - End time of the TextGrid.
§Returns

Returns a Result containing the new TextGrid or a TextGridError.

§Errors

Returns TextGridError::Format if xmin is not less than xmax.

Source

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.

Source

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.

Source

pub fn add_tier(&mut self, tier: Tier) -> Result<(), TextGridError>

Adds a tier to the TextGrid with undo support.

§Arguments
  • tier - The tier to add.
§Returns

Returns Ok(()) on success or a TextGridError if the tier bounds are invalid.

Source

pub fn remove_tier(&mut self, index: usize) -> Result<(), TextGridError>

Removes a tier from the TextGrid by index with undo support.

§Arguments
  • index - Index of the tier to remove.
§Returns

Returns Ok(()) on success or a TextGridError if the index is out of bounds.

Source

pub fn get_tier_mut(&mut self, name: &str) -> Option<&mut Tier>

Gets a mutable reference to a tier by name.

§Arguments
  • name - Name of the tier to find.
§Returns

Returns an Option containing a mutable reference to the tier if found, or None if not.

Source

pub fn get_tier(&self, name: &str) -> Option<&Tier>

Gets an immutable reference to a tier by name.

§Arguments
  • name - Name of the tier to find.
§Returns

Returns an Option containing a reference to the tier if found, or None if not.

Source

pub fn rename_tier( &mut self, old_name: &str, new_name: String, ) -> Result<(), TextGridError>

Renames a tier with undo support.

§Arguments
  • old_name - Current name of the tier.
  • new_name - New name for the tier.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found.

Source

pub fn merge_tiers_with_strategy<F>( &mut self, name1: &str, name2: &str, new_name: String, merge_strategy: F, ) -> Result<(), TextGridError>
where F: Fn(&Interval, &Interval) -> Option<Interval>,

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.

Source

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.

Source

pub fn adjust_bounds( &mut self, new_xmin: f64, new_xmax: f64, ) -> Result<(), TextGridError>

Adjusts the bounds of the TextGrid and all tiers.

§Arguments
  • new_xmin - New start time.
  • new_xmax - New end time.
§Returns

Returns Ok(()) on success or a TextGridError if the new bounds are invalid or don’t encompass all data.

Source

pub fn insert_silence( &mut self, tier_name: &str, start: f64, end: f64, ) -> Result<(), TextGridError>

Inserts a silent interval into an IntervalTier.

§Arguments
  • tier_name - Name of the tier to modify.
  • start - Start time of the silence.
  • end - End time of the silence.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found, not an IntervalTier, or bounds are invalid.

Source

pub fn query_intervals_by_time(&self, time: f64) -> Vec<(&Tier, Vec<&Interval>)>

Queries all tiers for intervals containing the specified time.

§Arguments
  • time - Time to search for.
§Returns

Returns a vector of tuples containing tiers and their matching intervals.

Source

pub fn query_points_by_time(&self, time: f64) -> Vec<(&Tier, Vec<&Point>)>

Queries all tiers for points at the specified time.

§Arguments
  • time - Time to search for.
§Returns

Returns a vector of tuples containing tiers and their matching points.

Source

pub fn query_intervals_by_text( &self, text: &str, ) -> Vec<(&Tier, Vec<&Interval>)>

Queries all tiers for intervals containing the specified text substring.

§Arguments
  • text - Substring to search for in interval texts.
§Returns

Returns a vector of tuples containing tiers and their matching intervals.

Source

pub fn tier_add_interval( &mut self, tier_name: &str, interval: Interval, ) -> Result<(), TextGridError>

Adds an interval to a tier with undo support.

§Arguments
  • tier_name - Name of the tier.
  • interval - Interval to add.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found or operation fails.

Source

pub fn tier_remove_interval( &mut self, tier_name: &str, index: usize, ) -> Result<(), TextGridError>

Removes an interval from a tier with undo support.

§Arguments
  • tier_name - Name of the tier.
  • index - Index of the interval to remove.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found or operation fails.

Source

pub fn tier_add_point( &mut self, tier_name: &str, point: Point, ) -> Result<(), TextGridError>

Adds a point to a tier with undo support.

§Arguments
  • tier_name - Name of the tier.
  • point - Point to add.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found or operation fails.

Source

pub fn tier_remove_point( &mut self, tier_name: &str, index: usize, ) -> Result<(), TextGridError>

Removes a point from a tier with undo support.

§Arguments
  • tier_name - Name of the tier.
  • index - Index of the point to remove.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found or operation fails.

Source

pub fn tier_split_interval( &mut self, tier_name: &str, index: usize, time: f64, ) -> Result<(), TextGridError>

Splits an interval in a tier with undo support.

§Arguments
  • tier_name - Name of the tier.
  • index - Index of the interval to split.
  • time - Time at which to split the interval.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found or operation fails.

Source

pub fn tier_merge_intervals( &mut self, tier_name: &str, ) -> Result<(), TextGridError>

Merges intervals in a tier with undo support.

§Arguments
  • tier_name - Name of the tier.
§Returns

Returns Ok(()) on success or a TextGridError if the tier is not found or operation fails.

Source§

impl TextGrid

Source

pub fn with_tiers(self, tiers: Vec<Tier>) -> Self

Adds tiers to an existing TextGrid and returns the modified instance.

§Arguments
  • tiers - Vector of tiers to add.
§Returns

Returns the TextGrid with the added tiers.

Source§

impl TextGrid

Source

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, implementing AsRef<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
Source

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, implementing AsRef<Path>.
  • short_format - If true, 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();
Source

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, implementing AsRef<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();

Trait Implementations§

Source§

impl Debug for TextGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.