Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lenQuant=0.1
- fileName="nyan.mus"
- os.loadAPI("ocs/apis/sensor")
- proximity = sensor.wrap("right")
- function isPlayerPresent()
- local targets = proximity.getTargets()
- for k,v in pairs(targets) do
- if v ~= nil then
- return true
- else
- return false
- end
- end
- end
- function strsplit(str)
- local arr = {}
- for i in string.gmatch(str, "%S+") do
- table.insert(arr,i)
- end
- return arr
- end
- note = peripheral.wrap("top")
- instrument=0
- R = {
- A=1,Ab=0,Ad=2,
- B=2,Bb=1,Bd=3,
- H=3,Hb=2,Hd=4,
- C=4,Cb=3,Cd=5,
- D=6,Db=5,Dd=7,
- E=8,Eb=7,Ed=9,
- F=9,Fb=9,Fd=10,
- G=11,Gb=10,G1d=12,
- A1=13,A1b=12,A1d=14,
- B1=14,B1b=13,B1d=15,
- H1=15,H1b=14,H1d=16,
- C1=16,C1b=15,C1d=17,
- D1=18,D1b=17,D1d=19,
- E1=20,E1b=19,E1d=21,
- F1=21,F1b=20,F1d=22,
- G1=23,G1b=22,G1d=24,
- }
- melody = {}
- file = io.open(fileName, "r")
- while true do
- tmp = file:read("*l")
- if tmp == nil then
- break
- end
- if not(tmp:sub(1,2)=="--") then
- n_ = strsplit(tmp);
- if n_[2]==nil then
- n_[2]=0.1
- end
- table.insert(melody,n_)
- end
- end
- function main()
- while true do
- for i=1,table.getn(melody),1 do
- n = melody[i]
- if not(n[1]=="p") and not(n[1]=="P") and isPlayerPresent() then
- note.playNote(instrument,R[n[1]])
- end
- sleep(tonumber(n[2])*lenQuant)
- end
- sleep(0.001)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement