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 48)
35fn main() {
36    let filename = "D:/Midis/toilet story 3 2020 ver 3840 black with tempo.mid";
37    let repeats = 4;
38
39    println!("Opening midi...");
40    let file = MIDIFile::open(filename, None).unwrap();
41
42    println!("Tracks: {}", file.track_count());
43
44    // Make windows cache stuff
45    let tracks = file.iter_all_tracks().collect();
46    let stats = get_channels_array_statistics(tracks).unwrap();
47
48    println!("Note count: {}", stats.note_count());
49
50    do_run("Parse tracks in parallel", repeats, || {
51        let tracks = file.iter_all_tracks().collect();
52        let stats = get_channels_array_statistics(tracks).unwrap();
53        stats.note_count()
54    });
55
56    do_run("Iter event batches merged", repeats, || {
57        let ppq = file.ppq();
58        let merged = pipe!(
59            file.iter_all_track_events_merged_batches()
60            |>TimeCaster::<f64>::cast_event_delta()
61            |>cancel_tempo_events(250000)
62            |>scale_event_time(1.0 / ppq as f64)
63            |>unwrap_items()
64        );
65
66        let mut note_count = 0;
67        for batch in merged {
68            for e in batch.into_iter() {
69                if let Event::NoteOn(_) = e.as_event() {
70                    note_count += 1
71                }
72            }
73        }
74
75        note_count
76    });
77
78    // do_run("Merge all tracks together while parsing", repeats, || {
79    //     let merged = pipe!(file.iter_all_tracks()|>to_vec()|>merge_events_array());
80    //     for _ in merged {}
81    // });
82    // do_run("Clone all events", repeats, || {
83    //     let iters = pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned())));
84    //     for track in iters {
85    //         for _ in track {}
86    //     }
87    // });
88    // do_run(
89    //     "Clone all events, then wrap and unwrap them in Result",
90    //     repeats,
91    //     || {
92    //         let iters = pipe!(loaded_tracks
93    //             .iter()
94    //             .map(|t| pipe!(t.iter().cloned()|>wrap_ok()|>unwrap_items())));
95    //         for track in iters {
96    //             for _ in track {}
97    //         }
98    //     },
99    // );
100    // do_run("Merge all tracks together while cloning", repeats, || {
101    //     let iters =
102    //         pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned()|>wrap_ok()))|>to_vec());
103    //     let merged = pipe!(iters|>merge_events_array());
104    //     for _ in merged {}
105    // });
106    // do_run("Write each track while cloning", repeats, || {
107    //     let output = Cursor::new(Vec::<u8>::new());
108    //     let writer = MIDIWriter::new_from_stram(Box::new(output), file.ppq()).unwrap();
109
110    //     let iters = pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned())));
111    //     for track in iters {
112    //         let mut track_writer = writer.open_next_track();
113    //         for e in track {
114    //             track_writer.write_event(e).unwrap();
115    //         }
116    //     }
117    // });
118    // do_run("Merge each track while cloning then write", repeats, || {
119    //     let output = Cursor::new(Vec::<u8>::new());
120    //     let writer = MIDIWriter::new_from_stram(Box::new(output), file.ppq()).unwrap();
121
122    //     let iters =
123    //         pipe!(loaded_tracks.iter().map(|t| pipe!(t.iter().cloned()|>wrap_ok()))|>to_vec());
124    //     let merged = pipe!(iters|>merge_events_array()|>unwrap_items());
125    //     let mut track_writer = writer.open_next_track();
126    //     for e in merged {
127    //         track_writer.write_event(e).unwrap();
128    //     }
129    // });
130}
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 36)
20fn main() {
21    println!("Opening midi...");
22    let file = MIDIFile::open_in_ram("D:/Midis/tau2.5.9.mid", None).unwrap();
23    println!("Parsing midi...");
24
25    let now = Instant::now();
26    let stats1 = pipe!(
27        file.iter_all_tracks()
28        |>to_vec()
29        |>merge_events_array()
30        |>get_channel_statistics().unwrap()
31    );
32
33    println!("Calculated merged stats in {:?}", now.elapsed());
34    println!(
35        "MIDI length: {}",
36        duration_to_minutes_seconds(stats1.calculate_total_duration(file.ppq()))
37    );
38    println!("Other stats: {stats1:#?}\n\n");
39
40    let now = Instant::now();
41    let stats2 = pipe!(
42        file.iter_all_tracks()|>to_vec()|>get_channels_array_statistics().unwrap()
43    );
44    println!("Calculated multithreaded stats in {:?}", now.elapsed());
45    println!(
46        "MIDI length: {}",
47        duration_to_minutes_seconds(stats2.calculate_total_duration(file.ppq()))
48    );
49    println!("Other stats: {stats2:#?}");
50}

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> 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> 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.