Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def track(c, mml)
return Fiber.new {
ch = c
dat = mml
curev = -1
loop do
if curev == -1 || curev[1] == 0 then
curev = dat.getnext()
if curev == -1 then
Fiber.yield(-1)
end
if curev[0] != -1 then
tone($t, ch, curev[0])
end
elsif curev[0] != -1 && curev[1] == curev[2] then
$t.write(0x50,0x08+ch,0x00)
curev[1] -= 1
else
curev[1] -= 1
end
Fiber.yield(1)
end
}
end
# main
$t = BsdIic.new(0)
$t.write(0x50,0x07,0xf8)
tr0 = track(0, MML.new(ch0))
tr1 = track(1, MML.new(ch1))
tr2 = track(2, MML.new(ch2))
while 1
if tr0.resume == -1 then
break
end
if tr1.resume == -1 then
break
end
if tr2.resume == -1 then
break
end
tick = (60*1000*1000/(MML::gettempo*120)).to_i
Sleep::usleep(tick)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.