Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Jun 12, 2022
1 parent 07dbafc commit 3293b8f
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/Justly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ end

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

function add_one_note!(audio_schedule, song, volume, frequency)
push!(audio_schedule,
Map(
Scale(volume),
Map(song.wave, Cycles(frequency))
),
0.0s,
song.make_envelope(0.5s),
)
end

function play_sounds!(song, presses, releases, buffer, audio_schedule)
wave = song.wave
make_envelope = song.make_envelope

for (chord_index, note_index) in presses
buffer_at = 0
if note_index < 0
Expand Down Expand Up @@ -119,15 +127,12 @@ function play_sounds!(song, presses, releases, buffer, audio_schedule)
frequency = frequency * Rational(chord.interval)
end
note = song.chords[chord_index].notes[note_index]
push!(audio_schedule,
Map(
Scale(volume * note.volume),
Map(wave, Cycles(frequency * Rational(note.interval)))
),
0.0s,
make_envelope(0.5s),
)

add_one_note!(
audio_schedule,
song,
volume * note.volume,
frequency * Rational(note.interval)
)
precompile_schedule(audio_schedule, song, buffer)
Base.GC.enable(false)
for series in audio_schedule
Expand Down Expand Up @@ -169,7 +174,11 @@ For more information, see the `README`.
```julia
julia> using Justly
julia> edit_song(joinpath(pkgdir(Justly), "examples", "wondrous_love.justly"); test = true)
julia> edit_song(joinpath(pkgdir(Justly), "examples", "simple.justly"); test = true)
julia> edit_song(joinpath(pkgdir(Justly), "not_a_folder", "simple.justly"); test = true)
ERROR: ArgumentError: Folder doesn't exist!
[...]
```
"""
function edit_song(
Expand All @@ -181,6 +190,10 @@ function edit_song(
read_justly(song_file; keyword_arguments...)
else
@info "Creating file $song_file"
dir_name = dirname(song_file)
if !(isempty(dir_name)) && !(isdir(dir_name))
throw(ArgumentError("Folder doesn't exist!"))
end
Song(Chord[]; keyword_arguments...)
end

Expand Down Expand Up @@ -215,6 +228,21 @@ function edit_song(

audio_schedule = AudioSchedule()

# precompile song
push!(audio_schedule, song)
precompile_schedule(audio_schedule, song, buffer)
empty!(audio_schedule)

# precompile note
add_one_note!(
audio_schedule,
song,
song.volume_observable[],
(song.frequency_observable[])Hz
)
precompile_schedule(audio_schedule, song, buffer)
empty!(audio_schedule)

press_task = @spawn play_sounds!($song, $presses, $releases, $buffer, $audio_schedule)

loadqml(
Expand Down

2 comments on commit 3293b8f

@bramtayl
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/62266

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 3293b8f497c5d7a43d93d4231379f22cd3263f26
git push origin v0.2.0

Please sign in to comment.