Jump to content




Repeat music


5 replies to this topic

#1 Backplague

  • New Members
  • 38 posts
  • LocationEarth

Posted 01 June 2012 - 02:45 PM

Hi!

This is a simple program i made to infinitely repeat music from a disk drive. It can detect when the disc is removed so to stop music, just take the disc out. I have not tested this on every single music disc, so the time until the song starts over may vary. Will adjust if needed.

Install:
1. Go to "%appdata%/.minecraft/mods/ComputerCraft/lua/programs"
2. Create a new file called "repeat" without any extensions
3. Open that file in Notepad or some other text editor
4. Copy-Paste the code to that file
5. Save and quit

Usage:
Just type in "repeat <side of disk drive>" to the computer console.


lengths = {["C418 - 13"]=180, ["C418 - cat"]=186, ["C418 - blocks"]=347, ["C418 - chirp"]=186, ["C418 - far"]=172, ["C418 - mall"]=197, ["C418 - mellohi"]=98, ["C418 - stal"]=151, ["C418 - strad"]=191, ["C418 - ward"]=250, ["C418 - 11"]=70}
args = { ... }
if #args == 0 then
print("Usage: repeat <side>")
return
end
command = args[1]
if disk.isPresent(command) then
if disk.hasAudio(command) then
  while disk.isPresent(command) do
   print("Playing ".. disk.getLabel(command))
   disk.playAudio(command)
  
   timesSlept = 0
   length = lengths[disk.getLabel(command)]
   while timesSlept <= length do
    if disk.isPresent(command) == false then
  print("Disk removed")
  return
end
    sleep(1)
timesSlept = timesSlept + 1
   end
  end
else
  print("Disk in ".. command .. " drive is not an audio disk")
end
else
print("No disk in ".. command .. " drive")
end

Please give feedback and suggestions if you want to.

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 01 June 2012 - 05:31 PM

It would be better to use a timer and the "disk_eject" event instead of the sleep and disk.isPresent:
print("Playing ", disk.getLabel(command))
local lenght = lenghts[disk.getLabel(command)]
local timer = os.startTimer(lenght)
while true do
  local evt, arg = os.pullEvent()
  if evt == "disk_ejected" then
    if arg == command then
	  break
    end
  elseif evt == "timer" then
    if arg == timer then
	  disk.playAudio(command)
	  timer = os.startTimer(lenght)
    end
  end
end
It would wait for the disk to be ejected/removed or until time ends instead of checking every second.

#3 Backplague

  • New Members
  • 38 posts
  • LocationEarth

Posted 01 June 2012 - 06:14 PM

View PostMysticT, on 01 June 2012 - 05:31 PM, said:

It would be better to use a timer and the "disk_eject" event instead of the sleep and disk.isPresent:
print("Playing ", disk.getLabel(command))
local lenght = lenghts[disk.getLabel(command)]
local timer = os.startTimer(lenght)
while true do
  local evt, arg = os.pullEvent()
  if evt == "disk_ejected" then
	if arg == command then
	  break
	end
  elseif evt == "timer" then
	if arg == timer then
	  disk.playAudio(command)
	  timer = os.startTimer(lenght)
	end
  end
end
It would wait for the disk to be ejected/removed or until time ends instead of checking every second.
Cool, i didnt know about that. :)/>

#4 _Spy_Crab_

  • New Members
  • 1 posts

Posted 01 September 2013 - 10:29 AM

I absolutely love this program, but I have one question. I have the Portal music, from the Portal Gun Mod, and I was wondering how you timed the music discs. Was it in seconds or ticks?

#5 Mitchfizz05

  • Members
  • 125 posts
  • LocationAdelaide, Australia

Posted 06 September 2013 - 06:58 AM

Great job, it must have been a nightmare to get all that timing right.

View Post_Spy_Crab_, on 01 September 2013 - 10:29 AM, said:

I absolutely love this program, but I have one question. I have the Portal music, from the Portal Gun Mod, and I was wondering how you timed the music discs. Was it in seconds or ticks?
Looking at the code, it would be seconds.

#6 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 07 September 2013 - 07:00 PM

How did you time the disks? Did you some sort of CC program, or just did you just use a stopwatch?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users