Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --mtf reader v4
- --this is a new version of my file reader for my file type MTF(Music Text Format)
- --this program is made for Minecraft 1.16.5, CC Tweaked
- local tArg = {..}
- local Instrument = {"block.note_block.bass", "block.note_block.snare", "block.note_block.basedrum", "block.note_block.bell", "block.note_block.flute", "block.note_block.chime", "block.note_block.guitar", "block.note_block.xyloph", "block.note_block.bit", "block.note_block.pling", "block.note_block.harp"}
- local Pitch = {2,4,6,8,10,2,2,2,2,2,2}
- --Note layout (2 digits for Instrument, if it is less then ten then add a zero to the beginning)(Pitch 1-5(the actual pitch will be twice what you put))
- --there cant be spaces between parts of a note and cant be spaces between notes.
- local Repeat = false
- local Volume = 5
- local SelectedFile = tArg[1]
- local Position = 1
- local TrackState = "Playing"
- local function SongMenu()
- term.clear()
- term.setCursorPos(1,1)
- print("Music Player--V4--------")
- print("Buttons = p = play/pause, e = exit, w/s = +/- Volume, r = repeat on/off")
- print(TrackState.." "..SelectedFile)
- print("Volume = "..Volume)
- print("Repeat? = "..Repeat)
- Player()
- local e, p = os.pullEvent("key")
- if key == keys.e then
- TrackState = "Stopped"
- elseif key == keys.p then
- if TrackState == "Stopped" then
- TrackState = "Playing"
- elseif TrackState == "Playing" then
- TrackState = "Stopped"
- end
- Player()
- elseif key == keys.w then
- Volume = Volume + 1
- elseif key == keys.s then
- Volume = Volume - 1
- elseif key == keys.r then
- if Repeat == true then
- Repeat = false
- elseif Repeat == false then
- Repeat = true
- end
- end
- if key ~= keys.e then
- SongMenu()
- end
- end
- local function Player()
- local speaker = peripheral.find("speaker")
- local file = fs.open(SelectedFile,"r")
- local Note = string.substring(file.readAll(),file.read(Position),file.read(Position+1))
- local NotePitch = string.substring(file.readAll(),file.read(Position+2),file.read(Position+2))
- while TrackState == "Playing" and Position < #file.readAll() do
- Note = string.substring(file.readAll(),file.read(Position),file.read(Position+1))
- NotePitch = string.substring(file.readAll(),file.read(Position+2),file.read(Position+2))
- speaker.playNote(Instrument[Note], Volume, Pitch[NotePitch])
- Position = Position + 3
- sleep(2)
- end
- file.close()
- if Repeat == true and TrackState == "Playing" then
- Position = 1
- Player()
- else
- shell.run(settings.get("MenuScriptName"))
- end
- end
- Player()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement