Struct Track

Source
pub struct Track { /* private fields */ }
Expand description

2.3 - Track Chunks The track chunks (type MTrk) are where actual song data is stored. Each track chunk is simply a stream of MIDI events (and non-MIDI events), preceded by delta-time values. The format for Track Chunks (described below) is exactly the same for all three formats (0, 1, and 2: see “Header Chunk” above) of MIDI Files.

Here is the syntax of an MTrk chunk (the + means “one or more”: at least one MTrk event must be present):

<Track Chunk> = <chunk type><length><MTrk event>+

Implementations§

Source§

impl Track

Source

pub fn is_empty(&self) -> bool

Returns true if the track has no events.

Source

pub fn events_len(&self) -> usize

The number of events in the track.

Source

pub fn events(&self) -> impl Iterator<Item = &TrackEvent>

Iterator over the events in the track.

Source

pub fn push_event(&mut self, delta_time: u32, event: Event) -> Result<()>

Add an event to the end.

Source

pub fn insert_event( &mut self, index: u32, delta_time: u32, event: Event, ) -> Result<()>

Add event at index and shift everything after it.

Source

pub fn replace_event( &mut self, index: u32, delta_time: u32, event: Event, ) -> Result<()>

Replace the event at index.

Source

pub fn set_name<S: Into<String>>(&mut self, name: S) -> Result<()>

Add, or replace, the track name at the beginning of a track.

Source

pub fn set_instrument_name<S: Into<String>>(&mut self, name: S) -> Result<()>

Add, or replace, the instrument name at the beginning of a track.

Source

pub fn set_general_midi( &mut self, channel: Channel, value: GeneralMidi, ) -> Result<()>

Add, or replace, the general midi program at the beginning of a track.

Source

pub fn push_time_signature( &mut self, delta_time: u32, numerator: u8, denominator: DurationName, click: Clocks, ) -> Result<()>

Add a time signature.

Source

pub fn push_tempo( &mut self, delta_time: u32, quarters_per_minute: QuartersPerMinute, ) -> Result<()>

Add a tempo message.

Source

pub fn push_note_on( &mut self, delta_time: u32, channel: Channel, note_number: NoteNumber, velocity: Velocity, ) -> Result<()>

Add a note on message.

Source

pub fn push_note_off( &mut self, delta_time: u32, channel: Channel, note_number: NoteNumber, velocity: Velocity, ) -> Result<()>

Add a note off message.

Source

pub fn push_lyric<S: Into<String>>( &mut self, delta_time: u32, lyric: S, ) -> Result<()>

Add a lyric.

Source

pub fn push_pitch_bend( &mut self, delta_time: u32, channel: Channel, pitch_bend: PitchBendValue, ) -> Result<()>

Add a pitch bend value.

Trait Implementations§

Source§

impl Clone for Track

Source§

fn clone(&self) -> Track

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Track

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Track

Source§

fn default() -> Track

Returns the “default value” for a type. Read more
Source§

impl Hash for Track

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Track

Source§

fn cmp(&self, other: &Track) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Track

Source§

fn eq(&self, other: &Track) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Track

Source§

fn partial_cmp(&self, other: &Track) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Track

Source§

impl StructuralPartialEq for Track

Auto Trait Implementations§

§

impl Freeze for Track

§

impl RefUnwindSafe for Track

§

impl Send for Track

§

impl Sync for Track

§

impl Unpin for Track

§

impl UnwindSafe for Track

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.