Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Music Player
- --this program takes data from a selected file and plays the notes through a connected speaker
- --this program is for Minecraft 1.16.5, with the mod CC Tweaked
- local tArg = {...}
- Music_SelectedSong = Music_SelectedSong
- Music_Bit = Music_Bit
- Music_PlayState = Music_PlayState
- Music_SongLength = Music_SongLength
- Music_ReferenceLoc = nil
- Music_SettingsEnd = 5
- local NoteOutput = ["block.note_block.bass","block.note_block.basedrum","block.note_block.bell","block.note_block.chime","block.note_block.guitar","block.note_block.bit","block.note_block.pling","block.note_block.harp","block.note_block.flute"]
- local speaker = peripheral.find("speaker")
- start()
- local function start()
- if fs.exists("/rom/music/"..Music_SelectedSong..".mtf") == true or Music_PlayState == "n" then
- ResetScript()
- if Music_PlayState == "n" then
- Music_SelectedSong = tArg[4]
- Music_PlayState = "ready"
- local file = fs.open("/rom/music/"..Music_SelectedSong..".mtf","r")
- file.close()
- else
- if tArg[1] == "Play" and Music_PlayState == "ready" or Music_PlayState == "paused" then
- Music_PlayState = "playing"
- elseif tArg[1] == "Pause" and Music_PlayState == "playing" then
- Music_PlayState = "paused"
- elseif tArg[1] == "Stop" and Music_PlayState ~= "n" then
- Music_PlayState = "n"
- ResetScript()
- elseif tArg[1] == "Seek" and Music_PlayState ~= "n" then
- Music_Bit = Music_ReferenceEnd+tArg[2]
- if Music_Bit >= Music_SongLength then
- ResetScript()
- else
- end
- end
- SongRead()
- end
- local function ResetScript()
- Music_PlayState = "n"
- Music_Bit = 0
- Music_SongLength = 10
- Music_SelectedSong = nil
- end
- local function SongRead()
- local Song = fs.open("/rom/music/"..Music_SelectedSong..".mtf","r")
- local i = 1
- while true do
- if Song.substring(i,i) == "|" then
- break
- else
- i = i + 1
- end
- end
- Music_SettingsEnd = i
- SettingsRead()
- if Music_Bit == 0 then
- Music_Bit = Music_SettingsEnd + 1
- end
- local i = Music_ReferenceLoc
- local I = 1
- while true do
- if Song.readLine(i) == "end" then
- break
- else
- NoteOutput[I] = Song.readLine(i)
- I = I + 1
- i = i + 1
- end
- end
- while true do
- sleep(1)
- if Music_Bit >= Music_SongLength then
- Song.close()
- ResetScript()
- else
- speaker.playNote( NoteOutput[ Song.substring( Music_Bit, Music_Bit) ], Song.read( Music_Bit),Song.read( Music_Bit))
- Music_Bit = Music Bit + 4
- end
- end
- Song.close()
- end
- local function SettingsRead()
- local I = 1
- for i = 1, Music_SettingsEnd/2 do
- local Item = Song.substring(i,i+2)
- if I == 1 --Song End
- Music_SongLength = Item
- elseif I == 2 --Reference Variables Location
- Music_ReferenceLoc = Item
- elseif I == 1
- elseif I == 1
- end
- I = I + 1
- i = i + 3
- end
- end
- --//Tutorial//
- --to use this script you need to know the variables and terms and what they mean
- --Note: this is what the program runs every time a bit goes by. a Note is made up of 4 characters, the OutputID(01-99), Pitch, and Volume. for the script to work properly, you must also have a reference file so the script can find what Sounds a Output ID stands for.
- --file. the file has to be set up like this "(Song Name).mtf". the mtf at the end stands for Music Text Format labeling the file as an item that only scripts that can read it are ones who read files based on the mtf format, and also the label helps with an organization with so many other scripts out there.
- --a Bit usually lasts for 0.4-0.8 seconds.
Add Comment
Please, Sign In to add comment