This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Blaurgh's profile picture

Music Machine

Started by Blaurgh, 03 November 2012 - 05:40 AM
Blaurgh #1
Posted 03 November 2012 - 06:40 AM
I have been working on a music machine using noteblocks and bundled cables. However, as it seems, i am unable to send redstone signals that are within 0.2 seconds of each other without randomly missing a few of them. The program is built up by functions like this one.


local function F(time)
rs.setBundledOutput("back",colors.orange)
sleep(time-0.1)
rs.setBundledOutput("back",0)
sleep(0.1)
end

There are 25 of these functions. One for each noteblock. However, if i lower the sleep time between changing bundled outputs, it starts to loose notes. Aparently the redstone signals does not update very often, and i have to wait for each signal to update in order to start a new one.

Does anyone know a way to get past this problem? Its really hard to make good music if the minimum tone length is 0.2 seconds…
KaoS #2
Posted 03 November 2012 - 06:46 AM
the problem is that you are trying to change redstone faster than MC ticks, there is a way around it with a more complicated code. you can only change input for 0.2 secs but it will no longer lose pulses
Blaurgh #3
Posted 03 November 2012 - 06:53 AM
I am not sure what you mean by that. I am aware that i can have .1 second tones if i skip turning off the bundled output between tones, however, that would make it impossible to make two identical tones in a row, which is kind of an anoying limitation if you want to make music of it. So what is this other way around then? And why the hell is minecraft's framerate so freaking low?
KaoS #4
Posted 03 November 2012 - 07:05 AM
here is a basic template


local side='back'
local tCols={}
local function add(colour,time)
  tCols[#tCols+1]={colour,time}
end
local do=coroutine.wrap(function()
  while true do
   local total=0
   for k,v in pairs(tCols) do
    v[2]=v[2]-0.1
    if v[2]==0 then
	 tCols[k]=nil
    else
	 total=colors.combine(total,v[1])
    end
   end
   rs.setBundledInput(side,total)
   sleep(0.1)
  end
end)
local evts={}
while true do
  --your adding function in a wrapped coroutine
  do(unpack(evts))
  evts={os.pullEvent()}
end
civilwargeeky #5
Posted 03 November 2012 - 09:18 AM
Wait, just curious, but isn't a tick in minecraft 0.05 seconds? I'm pretty sure its 20 ticks per second. It should update every 20th of a second
KaoS #6
Posted 03 November 2012 - 10:12 AM
ok to be honest I am not sure. I would use the above method though
Doyle3694 #7
Posted 03 November 2012 - 01:16 PM
A minecraft tick is 0,05 secs. However, a redstone tick is 0,1 secs