pub struct ChannelGroupStatistics<T: MIDINum> { /* private fields */ }Expand description
A struct to hold the statistics of a group of sequences.
Implementations§
Source§impl<T: MIDINum> ChannelGroupStatistics<T>
impl<T: MIDINum> ChannelGroupStatistics<T>
Sourcepub fn channels(&self) -> &[ChannelStatistics<T>]
pub fn channels(&self) -> &[ChannelStatistics<T>]
The list of statistics for individual channels
Methods from Deref<Target = ChannelStatistics<T>>§
Sourcepub fn note_on_count(&self) -> u64
pub fn note_on_count(&self) -> u64
The number of note on events
Sourcepub fn note_count(&self) -> u64
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}Sourcepub fn note_off_count(&self) -> u64
pub fn note_off_count(&self) -> u64
The number of note off events
Sourcepub fn other_event_count(&self) -> u64
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())
Sourcepub fn total_event_count(&self) -> u64
pub fn total_event_count(&self) -> u64
The total number of events
Sourcepub fn total_length_ticks(&self) -> T
pub fn total_length_ticks(&self) -> T
The sum of all delta times in each event
Sourcepub fn calculate_total_duration(&self, ppq: u16) -> Duration
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<T: MIDINum> Debug for ChannelGroupStatistics<T>
impl<T: MIDINum> Debug for ChannelGroupStatistics<T>
Auto Trait Implementations§
impl<T> Freeze for ChannelGroupStatistics<T>where
T: Freeze,
impl<T> RefUnwindSafe for ChannelGroupStatistics<T>where
T: RefUnwindSafe,
impl<T> Send for ChannelGroupStatistics<T>
impl<T> Sync for ChannelGroupStatistics<T>
impl<T> Unpin for ChannelGroupStatistics<T>where
T: Unpin,
impl<T> UnsafeUnpin for ChannelGroupStatistics<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ChannelGroupStatistics<T>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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