robbielyman / seamstress

seamstress is an art engine
GNU General Public License v3.0
123 stars 12 forks source link

Pattern Time, Potential Feedback Issue #111

Closed yams7457 closed 9 months ago

yams7457 commented 9 months ago

Pattern time playback steadily increases in speed, then cuts out entirely. Can test with the attached script by calling "key(3,1)" (to start recording) and then a series of grid presses, and then "key(3,1)" again to stop recording and begin playback.


pattern_time = require 'pattern_time' -- use the pattern_time lib in this script

g = grid.connect()

function init()
  grid_pattern = pattern_time.new() -- establish a pattern recorder
  grid_pattern.process = parse_grid_pattern -- assign the function to be executed when the pattern plays back

  pattern_message = "press K3 to start recording"
  erase_message = "(no pattern recorded)"
  overdub_message = ""

  screen_dirty = true
  screen_timer = clock.run(
    function()
      while true do
        clock.sleep(1/15)
        if screen_dirty then
          redraw()
          screen_dirty = false
        end
      end
    end
  )
end

function record_grid_value(x,y,z)
  grid_pattern:watch(
    {
      ["x"] = x,
      ["y"] = y,
      ["z"] = z
    }
  )
end

function parse_grid_pattern(data)
  print(data.x, data.y, data.z)
  screen_dirty = true
end

function key(n,z)
  if n == 3 and z == 1 then
    if grid_pattern.rec == 1 then -- if we're recording...
      grid_pattern:rec_stop() -- stop recording
      grid_pattern:start() -- start playing
      pattern_message = "playing, press K3 to stop"
      erase_message = "press K2 to erase"
      overdub_message = "hold K1 to overdub"
    elseif grid_pattern.count == 0 then -- otherwise, if there are no events recorded..
      grid_pattern:rec_start() -- start recording
      pattern_message = "recording, press K3 to stop"
      erase_message = "press K2 to erase"
      overdub_message = ""
    elseif grid_pattern.play == 1 then -- if we're playing...
      grid_pattern:stop() -- stop playing
      pattern_message = "stopped, press K3 to play"
      erase_message = "press K2 to erase"
      overdub_message = ""
    else -- if by this point, we're not playing...
      grid_pattern:start() -- start playing
      pattern_message = "playing, press K3 to stop"
      erase_message = "press K2 to erase"
      overdub_message = "hold K1 to overdub"
    end
  elseif n == 2 and z == 1 then
    grid_pattern:rec_stop() -- stops recording
    grid_pattern:stop() -- stops playback
    grid_pattern:clear() -- clears the pattern
    erase_message = "(no pattern recorded)"
    pattern_message = "press K3 to start recording"
    overdub_message = ""
  elseif n == 1 then
    grid_pattern:set_overdub(z) -- toggles overdub
    overdub_message = z == 1 and "overdubbing" or "hold K1 to overdub"
  end
  screen_dirty = true
end

function g.key(x,y,z)
  g:all(0)
  record_grid_value(x,y,z)
  if z == 1 then
    g:led(x,y,12)
  end
  g:refresh()
end

function redraw()
  screen.clear()
  screen.level(15)
  screen.move(0,10)
  -- screen.text("encoder 3 value: "..enc_value)
  screen.move(0,40)
  screen.text(pattern_message)
  screen.move(0,50)
  screen.text(erase_message)
  screen.move(0,60)
  screen.text(overdub_message)
  screen.update()
end
robbielyman commented 9 months ago

thanks for the issue! just for future reference, to make the code pretty, you want to do three backticks, then the language name (so lua) then the code on a new line, and finally three backticks :)

robbielyman commented 9 months ago

i believe this should be fixed in 1.2.6! try it out when you get the chance and let me know :)