Advertisement
Marlingaming

MTF Music Player V4

Sep 15th, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. --mtf reader v4
  2. --this is a new version of my file reader for my file type MTF(Music Text Format)
  3. --this program is made for Minecraft 1.16.5, CC Tweaked
  4.  
  5. local tArg = {..}
  6. 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"}
  7. local Pitch = {2,4,6,8,10,2,2,2,2,2,2}
  8. --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))
  9. --there cant be spaces between parts of a note and cant be spaces between notes.
  10. local Repeat = false
  11. local Volume = 5
  12. local SelectedFile = tArg[1]
  13.  
  14. local Position = 1
  15. local TrackState = "Playing"
  16.  
  17. local function SongMenu()
  18. term.clear()
  19. term.setCursorPos(1,1)
  20. print("Music Player--V4--------")
  21. print("Buttons = p = play/pause, e = exit, w/s = +/- Volume, r = repeat on/off")
  22. print(TrackState.." "..SelectedFile)
  23. print("Volume = "..Volume)
  24. print("Repeat? = "..Repeat)
  25. Player()
  26. local e, p = os.pullEvent("key")
  27. if key == keys.e then
  28. TrackState = "Stopped"
  29. elseif key == keys.p then
  30. if TrackState == "Stopped" then
  31. TrackState = "Playing"
  32. elseif TrackState == "Playing" then
  33. TrackState = "Stopped"
  34. end
  35. Player()
  36. elseif key == keys.w then
  37. Volume = Volume + 1
  38. elseif key == keys.s then
  39. Volume = Volume - 1
  40. elseif key == keys.r then
  41. if Repeat == true then
  42. Repeat = false
  43. elseif Repeat == false then
  44. Repeat = true
  45. end
  46. end
  47. if key ~= keys.e then
  48. SongMenu()
  49. end
  50. end
  51.  
  52. local function Player()
  53. local speaker = peripheral.find("speaker")
  54. local file = fs.open(SelectedFile,"r")
  55. local Note = string.substring(file.readAll(),file.read(Position),file.read(Position+1))
  56. local NotePitch = string.substring(file.readAll(),file.read(Position+2),file.read(Position+2))
  57. while TrackState == "Playing" and Position < #file.readAll() do
  58. Note = string.substring(file.readAll(),file.read(Position),file.read(Position+1))
  59. NotePitch = string.substring(file.readAll(),file.read(Position+2),file.read(Position+2))
  60. speaker.playNote(Instrument[Note], Volume, Pitch[NotePitch])
  61. Position = Position + 3
  62. sleep(2)
  63. end
  64. file.close()
  65. if Repeat == true and TrackState == "Playing" then
  66. Position = 1
  67. Player()
  68. else
  69. shell.run(settings.get("MenuScriptName"))
  70. end
  71. end
  72.  
  73. Player()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement