Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Configuration
- local speakerSide = "top"
- local playSpeed = 0.2
- local playVolume = 20
- --Argument Definition
- local filePath, playNotes = ...
- --Note Dictionary
- local note = {
- ["a"] = 220,
- ["b"] = 248.942,
- ["c"] = 261.626,
- ["d"] = 293.665,
- ["e"] = 329.628,
- ["f"] = 349.228,
- ["g"] = 391.995
- }
- --Usage Label
- local function usage()
- print("This program is designed to play music in notation 'aabbcc'.")
- print("Usage: chime [File Path] [true to show notes, or false to not]")
- end
- --File Loader and Parser
- local function fileParse()
- return fs.open(filePath,"r").readLine()
- end
- --Player
- local function play()
- peripheral.wrap(speakerSide).setAttenuation(playVolume)
- if playNotes == "false" then
- if c ~= " " then
- peripheral.wrap(speakerSide).start(1,note[c])
- sleep(playSpeed)
- peripheral.wrap(speakerSide).stop(1)
- else
- sleep(playSpeed)
- end
- elseif playNotes == "true" then
- for c in fileParse():gmatch"." do
- if c ~= " " then
- peripheral.wrap(speakerSide).start(1,note[c])
- sleep(playSpeed)
- peripheral.wrap(speakerSide).stop(1)
- print(c)
- else
- sleep(playSpeed)
- end
- end
- else
- usage()
- end
- end
- --Main
- local function main()
- term.clear()
- term.setCursorPos(1,1)
- play()
- print("Song Finished")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment