@@ -11,6 +11,7 @@ If the `channel` of the note is `0` (default), it is not shown.
11
11
You can also create a `Note` with the following keyword constructor:
12
12
```julia
13
13
Note(pitch, position; velocity = 100, duration = 960, channel = 0)
14
+ Note(pitch_name::String; position = 0, velocity = 100, duration = 960, channel = 0)
14
15
```
15
16
16
17
## Fields:
@@ -41,6 +42,8 @@ mutable struct Note <: AbstractNote
41
42
end
42
43
Note (pitch, position; velocity = 100 , duration = 960 , channel = 0 ) =
43
44
Note (pitch, velocity, position, duration, channel)
45
+ Note (pitch_name:: String ; position = 0 , velocity = 100 , duration = 960 , channel = 0 ) =
46
+ Note (name_to_pitch (pitch_name), velocity, position, duration, channel)
44
47
45
48
@inline Note (n:: Note ) = n
46
49
@@ -69,9 +72,16 @@ N(n.pitch, n.velocity, n.position, n.duration, n.channel)
69
72
70
73
"""
71
74
Notes(note_vector, tpq = 960) -> Notes
75
+ Notes(notes_string::String, tpq::Int = 960) -> Notes
72
76
A data structure describing a collection of music notes, bundled with the ticks
73
77
per quarter note (so that the notes can be attributed rhythmic value).
74
78
79
+ Notes can be initialized by string, the name of notes are separated by spaces.
80
+
81
+ ```julia
82
+ Notes("C2 F3 D#6")
83
+ ```
84
+
75
85
`Notes` can be iterated and accessed as the given `note_vector`.
76
86
This eliminates the need for custom iteration or search functions.
77
87
For example, to get the note of maximum pitch you can do:
@@ -94,6 +104,7 @@ function Notes(notes::Vector{N}, tpq::Int = 960) where {N <: AbstractNote}
94
104
end
95
105
96
106
Notes (; tpq = 960 ) = Notes {Note} (Vector{Note}[], tpq)
107
+ Notes (notes_string:: String , tpq:: Int = 960 ) = Notes ([Note (String (s)) for s in split (notes_string," " )], tpq)
97
108
98
109
# Iterator Interface for notes:
99
110
Base. iterate (n:: Notes , i = 1 ) = iterate (n. notes, i)
0 commit comments