abc_parser/datatypes/
builder.rs1use crate::datatypes::*;
2
3pub struct NoteBuilder {
4 note: MusicSymbol,
5}
6
7impl NoteBuilder {
8 pub fn build(self) -> MusicSymbol {
9 self.note
10 }
11
12 pub fn new(note: Note) -> NoteBuilder {
13 NoteBuilder {
14 note: MusicSymbol::Note {
15 accidental: None,
16 note,
17 octave: 1,
18 length: None,
19 tie: None,
20 },
21 }
22 }
23
24 pub fn accidental(mut self, accidental: Accidental) -> Self {
25 match self.note {
26 MusicSymbol::Note {
27 accidental: _,
28 note,
29 octave,
30 length,
31 tie,
32 } => {
33 self.note = MusicSymbol::Note {
34 accidental: Some(accidental),
35 note,
36 octave,
37 length,
38 tie,
39 }
40 }
41 _ => unreachable!(),
42 }
43
44 self
45 }
46
47 pub fn octave(mut self, octave: i8) -> Self {
48 match self.note {
49 MusicSymbol::Note {
50 accidental,
51 note,
52 octave: _,
53 length,
54 tie,
55 } => {
56 self.note = MusicSymbol::Note {
57 accidental,
58 note,
59 octave,
60 length,
61 tie,
62 }
63 }
64 _ => unreachable!(),
65 }
66
67 self
68 }
69
70 pub fn length(mut self, length: f32) -> Self {
71 match self.note {
72 MusicSymbol::Note {
73 accidental,
74 note,
75 octave,
76 length: _,
77 tie,
78 } => {
79 self.note = MusicSymbol::Note {
80 accidental,
81 note,
82 octave,
83 length: Some(Length::new(length)),
84 tie,
85 }
86 }
87 _ => unreachable!(),
88 }
89
90 self
91 }
92
93 pub fn tie(mut self, tie: Tie) -> Self {
94 match self.note {
95 MusicSymbol::Note {
96 accidental,
97 note,
98 octave,
99 length,
100 tie: _,
101 } => {
102 self.note = MusicSymbol::Note {
103 accidental,
104 note,
105 octave,
106 length,
107 tie: Some(tie),
108 }
109 }
110 _ => unreachable!(),
111 }
112
113 self
114 }
115}