1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| pub struct GuitarNotePitch { base: AbsulateNotePitch, position: u8, }
impl GuitarNotePitch { pub fn new(base: AbsulateNotePitch, position: u8) -> Self { GuitarNotePitch { base, position } }
fn to_absulate(&self) -> AbsulateNotePitch { let note_type = (self.base.note_type as u8 + self.position) % 12; let octave = self.base.octave as u8 + (self.base.note_type as u8 + self.position) / 12; AbsulateNotePitch::new(note_type.into(), octave.into()) } }
pub struct GuitarNote { pitch: GuitarNotePitch, duration: NoteDuration, }
impl GuitarNote { pub fn to_absulate(&self) -> Note { Note { pitch: self.pitch.to_absulate(), duration: self.duration, } } }
pub struct Guitar { base: HashMap<GuitarString, AbsulateNotePitch>, capo_position: u8, }
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] pub enum GuitarString { S1, S2, S3, S4, S5, S6, }
impl Default for Guitar { fn default() -> Self { use NoteName::*; use Octave::*; Self { base: HashMap::from_iter(vec![ (GuitarString::S1, AbsulateNotePitch::new(E, O4)), (GuitarString::S2, AbsulateNotePitch::new(B, O3)), (GuitarString::S3, AbsulateNotePitch::new(G, O3)), (GuitarString::S4, AbsulateNotePitch::new(D, O3)), (GuitarString::S5, AbsulateNotePitch::new(A, O2)), (GuitarString::S6, AbsulateNotePitch::new(E, O2)), ]), capo_position: 0, } } }
impl Guitar { pub fn set_capo_position(&mut self, position: u8) { self.capo_position = position; }
pub fn get_capo_position(&self) -> u8 { self.capo_position }
pub fn to_absulate_note(&self, s: GuitarString, position: u8, duration: NoteDuration) -> Note { let mut note = GuitarNote { pitch: GuitarNotePitch::new(self.base[&s], position), duration, } .to_absulate(); note.pitch.add(self.capo_position as i32); note } }
|