single_bank/single_bank.rs
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let contents = std::fs::read("example.mid")?;
3 // Note that if your MIDAS file is compressed, you will need to decompress
4 // its contents (using an external crate) before parsing it.
5 let file_view = midasio::FileView::try_from_bytes(&contents)?;
6
7 // Iterate only through events with an ID of 1
8 for event in file_view.into_iter().filter(|event| event.id() == 1) {
9 // Lets assume that these events have multiple data banks, but they are
10 // guaranteed to have a single bank with the name "TRGB" (which is the
11 // one we are interested in)
12 let [trg_bank] = event
13 .into_iter()
14 .filter(|bank| bank.name() == *b"TRGB")
15 .collect::<Vec<_>>()[..]
16 else {
17 unreachable!();
18 };
19 // You can now access the data in the bank
20 let _trg_data = trg_bank.data();
21 }
22
23 Ok(())
24}