Created
June 8, 2019 10:27
-
-
Save Yamakaky/57fdb86e6032655ae8c99a1c8aa036ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sb_available = ref [0, 1, 2, 3] | |
def sb_name(idx) | |
"soundboard#{idx}" | |
end | |
def mk_sb_track(idx) | |
def on_e(_, _) | |
log.debug(label = "soundboard", "Reusing id #{idx}") | |
sb_available := list.add(idx, !sb_available) | |
end | |
name = sb_name(idx) | |
r = request.queue(id=name) | |
r = audio_to_stereo(id = "#{name}.stereo", r) | |
on_end(id="#{name}.on_end", on_e, r, delay=0.) | |
end | |
soundboard_tracks = list.map(mk_sb_track, !sb_available) | |
soundboard = add( | |
id = "soundboard", | |
normalize = false, | |
soundboard_tracks | |
) | |
def sb_push(uri) | |
# TODO: replaygain | |
idx = list.hd(!sb_available, default = -1) | |
if idx != -1 then | |
log.debug(label = "soundboard", "Id #{idx} plays \"#{uri}\"") | |
ignore(server.execute("#{sb_name(idx)}.push #{uri}")) | |
sb_available := list.remove(idx, !sb_available) | |
else | |
log.warning(label = "soundboard", "No available sounboard slots") | |
end | |
() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment