MidiWriter

Struct MidiWriter 

Source
pub struct MidiWriter { /* private fields */ }

Implementations§

Source§

impl MidiWriter

Source

pub fn new(typ: TrackType, track_number: u16, bpm: u16) -> Self

Examples found in repository?
examples/single_track.rs (line 9)
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}
Source

pub fn add_track(&mut self, track: MidiTrack) -> &mut Self

Examples found in repository?
examples/single_track.rs (line 97)
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}
Source

pub fn write(&self, path: &str)

Examples found in repository?
examples/single_track.rs (line 98)
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}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.