fireair

fiscit networks mp3 player

Sep 29th, 2020 (edited)
906
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local panel = component.proxy("E843058744625592E02188867504BC4E") -- Get panel component
  2. local speaker = component.proxy("0055A0414AD11202172C73AF14C57DF8") -- get speaker component
  3. local playbutton = panel:getModule(4, 4) -- get play button on panel
  4. local skipbutton = panel:getModule(7, 4) -- get skip button on panel
  5. local volumedial = panel:getModule(5, 4) -- get volume dial on panel
  6. local loopbutton = panel:getModule(8, 5) -- get loop button on panel
  7.  
  8. local playing = false -- whether a song is playing
  9. local songarray = {"cpmoonshine", "cprussian", "cpcrocdandies"} -- song files go in here
  10. local currentsong = 1 -- the arrays/tables in lua start at 1
  11. local numofsongs = #songarray -- the number of songs in the array/table
  12. local currentvolume = 100
  13. local loop = 0
  14. speaker:setVolume(currentvolume) -- setting volume manually
  15. playbutton:setColor(0,1,0,4) -- play button color
  16. skipbutton:setColor(1,1,1,4) -- skip button color
  17. loopbutton:setColor(0,0,0,4) -- loop default button color
  18.  
  19. event.listen(playbutton) -- listen for events from the play button so we know if it got pressed
  20. event.listen(speaker) -- listen for events from the speaker so we know when the sound begins or ends
  21. event.listen(skipbutton) -- listen for events from the skip button so we know if it got pressed
  22. event.listen(loopbutton) -- listen for events from the skip button so we know if it got pressed
  23. event.listen(volumedial) -- listen for events from the volume dial so we know if it got cranked
  24. local function eventHandler(evnt, compo, typ, snd) -- push the event handler into its own function, so its easier to keep organized
  25.   if evnt == "Trigger" and compo == playbutton and not playing then -- if the event is a "Trigger" and it came from the play button and a sound is not currently playing then
  26.     speaker:playSound(songarray[currentsong]) -- play the selected song
  27.   elseif evnt == "SpeakerSound" and compo == speaker then -- if the event is a "SpeakerSound" and it came from the speaker
  28.     if typ == 1 then -- if it stopped because Manually or End of File respectively then
  29.       playing = false -- set playing to false so we can play something again
  30.     elseif typ == 2 then
  31.       if loop == 1 then
  32.         if currentsong == numofsongs then -- if the current song is the last in the array/table
  33.          currentsong = 1
  34.          speaker:playSound(songarray[currentsong]) -- play the selected song
  35.          playing = true -- set playing to true
  36.         else
  37.          currentsong = currentsong + 1
  38.          speaker:playSound(songarray[currentsong]) -- play the selected song
  39.          playing = true -- set playing to true
  40.        end
  41.      elseif loop == 2 then
  42.        speaker:playSound(songarray[currentsong])
  43.        playing = true -- set playing to true
  44.      end
  45.     elseif typ == 0 then -- if it began to play something
  46.       playing = true -- set playing to true
  47.     end
  48.    elseif evnt == "Trigger" and compo == skipbutton then -- if the event is "Trigger" and it came from the skip button
  49.      if currentsong == numofsongs then -- if the current song is the last in the array/table
  50.        currentsong = 1
  51.        speaker:playSound(songarray[currentsong]) -- play the selected song
  52.      else
  53.        currentsong = currentsong + 1
  54.        speaker:playSound(songarray[currentsong]) -- play the selected song
  55.      end
  56.    elseif evnt == "PotRotate" and compo == volumedial then -- if the event is "potrotate" and it came from the volume dial
  57.     if typ == false then -- if it was turned clockwise
  58.           currentvolume = currentvolume + 10 -- increase volume by ten
  59.       speaker:setVolume(currentvolume) -- set volume
  60.     elseif typ == true then
  61.         currentvolume = currentvolume - 10 -- decrease volume by ten
  62.     speaker:setVolume(currentvolume) -- set volume
  63.      end
  64.   elseif evnt == "Trigger" and compo == loopbutton then -- if the event is "Trigger" and it came from the loop button
  65.     if loop == 0 then
  66.       loop = 1
  67.       loopbutton:setColor(0.25,0.25,0.25,4) -- loop button color
  68.     elseif loop == 1 then
  69.       loop = 2
  70.       loopbutton:setColor(1,1,1,4) -- loop button color
  71.     elseif loop == 2 then
  72.       loop = 0
  73.       loopbutton:setColor(0,0,0,4) -- loop button color
  74.     end
  75.   end
  76. end
  77.  
  78. while true do -- a infinite loop
  79.   local evnt, compo, typ, snd = event.pull(0) -- get any events that come in, evnt is signal, compo is the component that sent the signal.
  80.     --everything after is optional parameters a component can send along with the signal
  81.   if evnt ~= nil then -- if there was an evnt this cycle
  82.     eventHandler(evnt, compo, typ, snd) -- send it to the event handler
  83.   end
  84. end
RAW Paste Data