Created
February 17, 2020 14:28
-
-
Save yamori813/7f09ac11d18a052939d7ba9632e1db57 to your computer and use it in GitHub Desktop.
This file contains 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
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