Skip to main content

ChannelStatistics

Struct ChannelStatistics 

Source
pub struct ChannelStatistics<D: MIDINum> { /* private fields */ }
Expand description

A struct to hold the statistics of a sequence.

Implementations§

Source§

impl<T: MIDINum> ChannelStatistics<T>

Source

pub fn note_on_count(&self) -> u64

The number of note on events

Source

pub fn note_count(&self) -> u64

Alias for note_on_count

Examples found in repository?
examples/parse_benchmark.rs (line 43)
31fn main() {
32    let filename = "D:/Midis/toilet story 3 2020 ver 3840 black with tempo.mid";
33    let repeats = 4;
34
35    println!("Opening midi...");
36    let file = MIDIFile::open(filename, None).unwrap();
37
38    println!("Tracks: {}", file.track_count());
39
40    // Make windows cache stuff
41    let stats = file.iter_all_tracks().channel_statistics().unwrap();
42
43    println!("Note count: {}", stats.note_count());
44
45    do_run("Parse tracks in parallel", repeats, || {
46        let stats = file.iter_all_tracks().channel_statistics().unwrap();
47        stats.note_count()
48    });
49
50    do_run("Iter event batches merged", repeats, || {
51        let ppq = file.ppq();
52        let merged = file
53            .iter_all_track_events_merged_batches()
54            .cast_event_delta::<f64>()
55            .cancel_tempo_events(250000)
56            .scale_event_time(1.0 / ppq as f64)
57            .unwrap_items();
58
59        let mut note_count = 0;
60        for batch in merged {
61            for e in batch.into_iter() {
62                if let Event::NoteOn(_) = e.as_event() {
63                    note_count += 1
64                }
65            }
66        }
67
68        note_count
69    });
70
71    // do_run("Merge all tracks together while parsing", repeats, || {
72    //     let merged = pipe!(file.iter_all_tracks()|>to_vec()|>merge_events_array());
73    //     for _ in merged {}
74    // });
75    // do_run("Clone all events", repeats, || {
76    //     let iters = pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned())));
77    //     for track in iters {
78    //         for _ in track {}
79    //     }
80    // });
81    // do_run(
82    //     "Clone all events, then wrap and unwrap them in Result",
83    //     repeats,
84    //     || {
85    //         let iters = pipe!(loaded_tracks
86    //             .iter()
87    //             .map(|t| pipe!(t.iter().cloned()|>wrap_ok()|>unwrap_items())));
88    //         for track in iters {
89    //             for _ in track {}
90    //         }
91    //     },
92    // );
93    // do_run("Merge all tracks together while cloning", repeats, || {
94    //     let iters =
95    //         pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned()|>wrap_ok()))|>to_vec());
96    //     let merged = pipe!(iters|>merge_events_array());
97    //     for _ in merged {}
98    // });
99    // do_run("Write each track while cloning", repeats, || {
100    //     let output = Cursor::new(Vec::<u8>::new());
101    //     let writer = MIDIWriter::new_from_stream(Box::new(output), file.ppq()).unwrap();
102
103    //     let iters = pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned())));
104    //     for track in iters {
105    //         let mut track_writer = writer.open_next_track();
106    //         for e in track {
107    //             track_writer.write_event(e).unwrap();
108    //         }
109    //     }
110    // });
111    // do_run("Merge each track while cloning then write", repeats, || {
112    //     let output = Cursor::new(Vec::<u8>::new());
113    //     let writer = MIDIWriter::new_from_stream(Box::new(output), file.ppq()).unwrap();
114
115    //     let iters =
116    //         pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned()|>wrap_ok()))|>to_vec());
117    //     let merged = pipe!(iters|>merge_events_array()|>unwrap_items());
118    //     let mut track_writer = writer.open_next_track();
119    //     for e in merged {
120    //         track_writer.write_event(e).unwrap();
121    //     }
122    // });
123}
Source

pub fn note_off_count(&self) -> u64

The number of note off events

Source

pub fn other_event_count(&self) -> u64

The number of events that are not note on and note off.

Alias for (total_event_count() - note_on_count() - note_off_count())

Source

pub fn total_event_count(&self) -> u64

The total number of events

Source

pub fn total_length_ticks(&self) -> T

The sum of all delta times in each event

Source

pub fn calculate_total_duration(&self, ppq: u16) -> Duration

Calculate the length in seconds based on the tick length and the tempo events, as well as the ppq

Examples found in repository?
examples/statistics.rs (line 28)
13fn main() {
14    println!("Opening midi...");
15    let file = MIDIFile::open_in_ram("D:/Midis/tau2.5.9.mid", None).unwrap();
16    println!("Parsing midi...");
17
18    let now = Instant::now();
19    let stats1 = file
20        .iter_all_tracks()
21        .merge_all()
22        .channel_statistics()
23        .unwrap();
24
25    println!("Calculated merged stats in {:?}", now.elapsed());
26    println!(
27        "MIDI length: {}",
28        duration_to_minutes_seconds(stats1.calculate_total_duration(file.ppq()))
29    );
30    println!("Other stats: {stats1:#?}\n\n");
31
32    let now = Instant::now();
33    let stats2 = file.iter_all_tracks().channel_statistics().unwrap();
34    println!("Calculated multithreaded stats in {:?}", now.elapsed());
35    println!(
36        "MIDI length: {}",
37        duration_to_minutes_seconds(stats2.calculate_total_duration(file.ppq()))
38    );
39    println!("Other stats: {stats2:#?}");
40}

Trait Implementations§

Source§

impl<D: Clone + MIDINum> Clone for ChannelStatistics<D>

Source§

fn clone(&self) -> ChannelStatistics<D>

Returns a duplicate 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<T: MIDINum> Debug for ChannelStatistics<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D> Freeze for ChannelStatistics<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for ChannelStatistics<D>
where D: RefUnwindSafe,

§

impl<D> Send for ChannelStatistics<D>

§

impl<D> Sync for ChannelStatistics<D>

§

impl<D> Unpin for ChannelStatistics<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for ChannelStatistics<D>
where D: UnsafeUnpin,

§

impl<D> UnwindSafe for ChannelStatistics<D>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.