View difference between Paste ID: CB212P9V and L9NG43B4
SHOW: | | - or go back to the newest paste.
1
s = peripheral.wrap("top")
2
volume = 2.0
3
songName = "test.lua"
4
5
function playNote(instrument, note)
6
    s.playNote(instrument, volume, tonumber(note))
7
end
8
9
function wait(time)
10
	time = tonumber(time)*2
11
    sleep(tonumber(time)*0.05)
12
end
13
14
function parse(str)
15
    if(string.find(str, "delay:")) then
16
        wait(string.sub(str,7))
17
    else
18
        instru_pre = string.match(str, ".*:")
19
        print(instru_pre)
20
        instru = string.sub(instru_pre, 1, string.len(instru_pre)-1)
21
        note_pre = string.match(str, ":.*")
22
        note = string.sub(note_pre, 2)
23
        playNote(instru,note)
24
    end
25
end
26
27
function main()
28
    song = fs.open(songName, "r")
29
    x = song.readLine()
30
    while x ~= nil do
31
        parse(x)
32
        x = song.readLine()
33
    end
34
end
35
36
main()