music_note/staff/
mod.rs

1use crate::{note::Flat, Interval, Natural, Note, Pitch};
2
3mod key;
4pub use key::Key;
5
6pub struct Staff<T> {
7    key: Key,
8    notes: T,
9}
10
11impl<T> Staff<T> {
12    pub fn new(key: Key, notes: T) -> Self {
13        Self { key, notes }
14    }
15}
16
17impl<T> Iterator for Staff<T>
18where
19    T: Iterator<Item = Note<Flat>>,
20{
21    type Item = Pitch;
22
23    fn next(&mut self) -> Option<Self::Item> {
24        self.notes.next().map(move |note| {
25            let pitch = Pitch::from(note);
26            if note.natural() >= Natural::from(self.key.flats()) {
27                pitch + Interval::MINOR_SECOND
28            } else {
29                pitch
30            }
31        })
32    }
33}