Advertisement
Frekvens1

[OC] [Music] [In-Progress] OpenRadio

Feb 22nd, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. -- This script is [Work in progress], and will not function as title says just about yet --
  2.  
  3. -- Script created by Frekvens1, however, most songs within the script are not --
  4. -- OpenRadio version: Alpha 1.0.0 --
  5.  
  6. -- Check out my Github! 'https://github.com/Frekvens1/OpenComputers'
  7.  
  8. -- OpenComputers Mod for Minecraft, usi+ng Lua 5.2 --
  9. -- pastebin get qq9CcAg2 openRadio.lua --
  10.  
  11.  
  12. --[START] local variables used to perform tasks within the OpenComputers mod --
  13.  
  14. local component = require("component")
  15. local term = require("term")
  16. local fs = require("filesystem")
  17. local shell = require("shell")
  18. local inb = component.iron_noteblock.playNote
  19.  
  20. --[END] local variables used to perform tasks within the OpenComputers mod --
  21.  
  22.  
  23. --[START] Music player, using iron note block --
  24.  
  25. function playSong(song)
  26.  
  27. local noteCount = 0
  28. local maxLayers = song.layers
  29. maxLayers = maxLayers + 1
  30.  
  31. local name = song.name
  32.  
  33. if not (name == "nil") then
  34. term.clear()
  35. print("Playing: "..name)
  36. end
  37.  
  38. while noteCount < song.n_total do
  39.  
  40. os.sleep(song.speed)
  41.  
  42. local layerCount = 0
  43.  
  44. while layerCount < maxLayers do
  45.      local variable = song["note_"..noteCount.."_"..layerCount]
  46.      --print("String name: ".."note_"..noteCount.."_"..layerCount)
  47.      
  48.      if (variable == "nil") then
  49.      elseif (variable == nil) then
  50.      else
  51.      
  52.          local inst
  53.          local note
  54.          
  55.          for count, i in ipairs(variable) do
  56.              if count == 1 then
  57.                 inst = i
  58.              elseif count == 2 then
  59.                  note = i
  60.              end
  61.          end
  62.          
  63.          if (note == "nil") then
  64.          elseif (inst == "nil") then
  65.          else
  66.          
  67.          local fixInst
  68.          
  69.          if (inst==0) then
  70.             fixInst = 0
  71.          elseif (inst==1) then
  72.             fixInst = 4
  73.          elseif (inst==2) then
  74.             fixInst = 1
  75.          elseif (inst==3) then
  76.             fixInst = 2
  77.          elseif (inst==4) then
  78.             fixInst = 3
  79.          end
  80.          
  81.          inb(tonumber(fixInst), tonumber(note))
  82.          end
  83.      end
  84.      
  85.      layerCount = layerCount + 1
  86.      
  87. end
  88.  
  89. noteCount = noteCount + 1
  90.  
  91. end
  92.  
  93. end
  94. --[END] Music player, using iron note block --
  95.  
  96. --playSong(he_s_a_pirate)
  97.  
  98. local myRadioSongs = {}
  99.  
  100. local files, reason = fs.list("songs")
  101. if files then
  102.     local i = 1
  103.     for mySong in files do
  104.  
  105.         if not (mySong == "nil") then
  106.  
  107.             if (string.find(mySong, "_openradio.lua")) then
  108.                 myRadioSongs[tonumber(i)] = mySong
  109.                 i = i + 1
  110.             end
  111.  
  112.         end
  113.  
  114.     end
  115.  
  116. end
  117.  
  118. local args, options = shell.parse(...)
  119.  
  120. if (args[1] == nil) then
  121. for i, mySong in ipairs(myRadioSongs) do
  122. print(i..": "..mySong)
  123. end
  124. print("")
  125. print("Arguments:")
  126. print("openRadio {song as index}, openRadio list, openRadio random, openRadio loop")
  127. elseif args[1] == "list" then
  128. print("Will now play songs in order")
  129. elseif args[1] == "random" then
  130. print("Will now play something random")
  131. elseif args[1] == "loop" then
  132. print("Will now loop the songs")
  133. else
  134. local path = "songs/"..myRadioSongs[tonumber(args[1])]
  135. local path_lenght = string.len(path)
  136. local fixedPath = path:sub(1,path_lenght - 4)
  137.  
  138. print(fixedPath)
  139.  
  140. playSong(require(fixedPath))
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement