single_track/
single_track.rs

1use midia::{
2    pitch::Pitch,
3    track::MidiTrack,
4    typ::{InstrumentType, Tonality, TrackType},
5    MidiWriter,
6};
7
8fn main() {
9    let mut writer = MidiWriter::new(TrackType::Single, 1, 120);
10    let mut track = MidiTrack::new();
11    track
12        .set_bpm(120)
13        .set_tonality(Tonality::G)
14        .change_instrument(InstrumentType::AcousticGrandPiano)
15        .note(0.5, Pitch::A4, 90)
16        .note(0.5, Pitch::B4, 90)
17        .note(2., Pitch::C5, 90)
18        .note(0.5, Pitch::B4, 90)
19        .note(1., Pitch::C5, 90)
20        .note(1., Pitch::E5, 90)
21        .note(3., Pitch::B4, 90)
22        .note(1., Pitch::E4, 90)
23        .note(1.5, Pitch::A4, 90)
24        .note(0.5, Pitch::G4, 90)
25        .note(1., Pitch::A4, 90)
26        .note(1., Pitch::C5, 90)
27        .note(3., Pitch::G4, 90)
28        .note(1., Pitch::E4, 90)
29        .note(1.5, Pitch::F4, 90)
30        .note(0.5, Pitch::E4, 90)
31        .note(1., Pitch::F4, 90)
32        .note(1., Pitch::C5, 90)
33        .note(2., Pitch::E4, 90)
34        .note(0.5, Pitch::E4, 0)
35        .note(0.5, Pitch::C5, 90)
36        .note(0.5, Pitch::C5, 90)
37        .note(0.5, Pitch::C5, 90)
38        .note(1.5, Pitch::B4, 90)
39        .note(0.5, Pitch::Fs4, 90)
40        .note(1., Pitch::F4, 90)
41        .note(1., Pitch::B4, 90)
42        .note(3., Pitch::B4, 90)
43        .note(0.5, Pitch::A4, 90)
44        .note(0.5, Pitch::B4, 90)
45        .note(1.5, Pitch::C5, 90)
46        .note(0.5, Pitch::B4, 90)
47        .note(1., Pitch::C5, 90)
48        .note(1., Pitch::E5, 90)
49        .note(3., Pitch::B4, 90)
50        .note(1., Pitch::E4, 90)
51        .note(1.5, Pitch::A4, 90)
52        .note(0.5, Pitch::G4, 90)
53        .note(1., Pitch::A4, 90)
54        .note(1., Pitch::C5, 90)
55        .note(3., Pitch::G4, 90)
56        .note(1., Pitch::E4, 90)
57        .note(1., Pitch::F4, 90)
58        .note(0.5, Pitch::C5, 90)
59        .note(1.5, Pitch::B4, 90)
60        .note(1., Pitch::C5, 90)
61        .note(1., Pitch::D5, 90)
62        .note(0.5, Pitch::E5, 90)
63        .note(2.5, Pitch::C5, 90)
64        .note(0.5, Pitch::C5, 90)
65        .note(0.5, Pitch::B4, 90)
66        .note(1., Pitch::A4, 90)
67        .note(1., Pitch::B4, 90)
68        .note(1., Pitch::Gs4, 90)
69        .note(3., Pitch::A4, 90)
70        .note(0.5, Pitch::C5, 90)
71        .note(0.5, Pitch::D5, 90)
72        .note(1.5, Pitch::E5, 90)
73        .note(0.5, Pitch::D5, 90)
74        .note(1., Pitch::E5, 90)
75        .note(1., Pitch::G5, 90)
76        .note(3., Pitch::D5, 90)
77        .note(1., Pitch::G5, 90)
78        .note(1.5, Pitch::C5, 90)
79        .note(0.5, Pitch::B4, 90)
80        .note(1., Pitch::C5, 90)
81        .note(1., Pitch::E5, 90)
82        .note(4., Pitch::E5, 90)
83        .note(0.5, Pitch::A4, 90)
84        .note(0.5, Pitch::B4, 90)
85        .note(1., Pitch::C5, 90)
86        .note(0.5, Pitch::B4, 90)
87        .note(0.5, Pitch::C5, 90)
88        .note(1., Pitch::D5, 90)
89        .note(1., Pitch::C5, 90)
90        .note(1., Pitch::G4, 90)
91        .note(2., Pitch::G4, 90)
92        .note(1., Pitch::F5, 90)
93        .note(1., Pitch::E5, 90)
94        .note(1., Pitch::D5, 90)
95        .note(1., Pitch::C5, 90)
96        .repeat(5);
97    writer.add_track(track);
98    writer.write("./examples/single_track.mid");
99}