Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Make sure to edit the Data Config!
- --
- local dataconfig = {
- supportedversion = "znepb sound format 1",
- lTrack = "",
- rTrack = "",
- }
- local args = {...}
- local function logStr(str,lType)
- if lType == "warn" then
- term.setTextColor(colors.orange)
- print("[WARN] "..str)
- elseif lType == "info" then
- term.setTextColor(colors.white)
- print("[INFO] "..str)
- end
- end
- local function check()
- end
- logStr("Make sure to change the lTrack and rTrack in the dataconfig in this file before you use it, or you may encounter errors.",'warn')
- local function loadFile()
- if not string.find(args[1],".zsf") then
- logStr(".zsf extension not found in "..args[1]..", trying to add","warn")
- args[1] = args[1]..".zsf"
- else
- logStr("found good extension","info")
- end
- if not fs.exists(args[1]) then
- logStr("bad argument #1, arg1 should be file but could not find "..args[1],"warn")
- error("bad argument #1 (could not find file; see log for more details)")
- else
- logStr("found valid file","info")
- logStr("attempting to load","info")
- local soundfile = fs.open(args[1],"r")
- local soundT = textutils.unserialize(soundfile.readAll())
- if not soundT.version then
- logStr("invalid version, found version to be "..tostring(soundT.version),"warn")
- error("corrupted sound file")
- elseif soundT.version ~= dataconfig.supportedversion then
- logStr("version may not be supported","warn")
- end
- local leftTrack = peripheral.wrap(dataconfig.lTrack)
- local rightTrack = peripheral.wrap(dataconfig.lTrack)
- for i, _ in pairs(soundT.sounds) do
- logStr("playing note "..i,"info")
- leftTrack.playNote(soundT.sounds[i].left.note,0.5,soundT.sounds[i].left.pitch)
- rightTrack.playNote(soundT.sounds[i].right.note,0.5,soundT.sounds[i].right.pitch)
- sleep(soundT.sounds[i].waitTime)
- end
- end
- end
- loadFile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement