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>
impl<T: MIDINum> 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 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}
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 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>
impl<D: Clone + MIDINum> Clone for ChannelStatistics<D>
Source§fn clone(&self) -> ChannelStatistics<D>
fn clone(&self) -> ChannelStatistics<D>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto 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>where
D: 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