88
88
89
89
precompile (precompile_schedule, (AudioSchedule, DEFAULT_SONG, Buffer{Float32}))
90
90
91
+ function add_one_note! (audio_schedule, song, volume, frequency)
92
+ push! (audio_schedule,
93
+ Map (
94
+ Scale (volume),
95
+ Map (song. wave, Cycles (frequency))
96
+ ),
97
+ 0.0 s,
98
+ song. make_envelope (0.5 s),
99
+ )
100
+ end
101
+
91
102
function play_sounds! (song, presses, releases, buffer, audio_schedule)
92
- wave = song. wave
93
- make_envelope = song. make_envelope
94
-
95
103
for (chord_index, note_index) in presses
96
104
buffer_at = 0
97
105
if note_index < 0
@@ -119,15 +127,12 @@ function play_sounds!(song, presses, releases, buffer, audio_schedule)
119
127
frequency = frequency * Rational (chord. interval)
120
128
end
121
129
note = song. chords[chord_index]. notes[note_index]
122
- push! (audio_schedule,
123
- Map (
124
- Scale (volume * note. volume),
125
- Map (wave, Cycles (frequency * Rational (note. interval)))
126
- ),
127
- 0.0 s,
128
- make_envelope (0.5 s),
129
- )
130
-
130
+ add_one_note! (
131
+ audio_schedule,
132
+ song,
133
+ volume * note. volume,
134
+ frequency * Rational (note. interval)
135
+ )
131
136
precompile_schedule (audio_schedule, song, buffer)
132
137
Base. GC. enable (false )
133
138
for series in audio_schedule
@@ -169,7 +174,11 @@ For more information, see the `README`.
169
174
```julia
170
175
julia> using Justly
171
176
172
- julia> edit_song(joinpath(pkgdir(Justly), "examples", "wondrous_love.justly"); test = true)
177
+ julia> edit_song(joinpath(pkgdir(Justly), "examples", "simple.justly"); test = true)
178
+
179
+ julia> edit_song(joinpath(pkgdir(Justly), "not_a_folder", "simple.justly"); test = true)
180
+ ERROR: ArgumentError: Folder doesn't exist!
181
+ [...]
173
182
```
174
183
"""
175
184
function edit_song (
@@ -181,6 +190,10 @@ function edit_song(
181
190
read_justly (song_file; keyword_arguments... )
182
191
else
183
192
@info " Creating file $song_file "
193
+ dir_name = dirname (song_file)
194
+ if ! (isempty (dir_name)) && ! (isdir (dir_name))
195
+ throw (ArgumentError (" Folder doesn't exist!" ))
196
+ end
184
197
Song (Chord[]; keyword_arguments... )
185
198
end
186
199
@@ -215,6 +228,21 @@ function edit_song(
215
228
216
229
audio_schedule = AudioSchedule ()
217
230
231
+ # precompile song
232
+ push! (audio_schedule, song)
233
+ precompile_schedule (audio_schedule, song, buffer)
234
+ empty! (audio_schedule)
235
+
236
+ # precompile note
237
+ add_one_note! (
238
+ audio_schedule,
239
+ song,
240
+ song. volume_observable[],
241
+ (song. frequency_observable[])Hz
242
+ )
243
+ precompile_schedule (audio_schedule, song, buffer)
244
+ empty! (audio_schedule)
245
+
218
246
press_task = @spawn play_sounds! ($ song, $ presses, $ releases, $ buffer, $ audio_schedule)
219
247
220
248
loadqml (
0 commit comments