Skip to content

Commit 3293b8f

Browse files
committed
update
1 parent 07dbafc commit 3293b8f

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/Justly.jl

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ end
8888

8989
precompile(precompile_schedule, (AudioSchedule, DEFAULT_SONG, Buffer{Float32}))
9090

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.0s,
98+
song.make_envelope(0.5s),
99+
)
100+
end
101+
91102
function play_sounds!(song, presses, releases, buffer, audio_schedule)
92-
wave = song.wave
93-
make_envelope = song.make_envelope
94-
95103
for (chord_index, note_index) in presses
96104
buffer_at = 0
97105
if note_index < 0
@@ -119,15 +127,12 @@ function play_sounds!(song, presses, releases, buffer, audio_schedule)
119127
frequency = frequency * Rational(chord.interval)
120128
end
121129
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.0s,
128-
make_envelope(0.5s),
129-
)
130-
130+
add_one_note!(
131+
audio_schedule,
132+
song,
133+
volume * note.volume,
134+
frequency * Rational(note.interval)
135+
)
131136
precompile_schedule(audio_schedule, song, buffer)
132137
Base.GC.enable(false)
133138
for series in audio_schedule
@@ -169,7 +174,11 @@ For more information, see the `README`.
169174
```julia
170175
julia> using Justly
171176
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+
[...]
173182
```
174183
"""
175184
function edit_song(
@@ -181,6 +190,10 @@ function edit_song(
181190
read_justly(song_file; keyword_arguments...)
182191
else
183192
@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
184197
Song(Chord[]; keyword_arguments...)
185198
end
186199

@@ -215,6 +228,21 @@ function edit_song(
215228

216229
audio_schedule = AudioSchedule()
217230

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+
218246
press_task = @spawn play_sounds!($song, $presses, $releases, $buffer, $audio_schedule)
219247

220248
loadqml(

0 commit comments

Comments
 (0)