Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. -- constants
  2. patterns = {34952,34954,34962,34964,34978}
  3. num_patterns = #patterns
  4.  
  5. factors = {1,2,4,8,16,3,6,9,12,5,10,15,7,14,11,13}
  6. num_factors = #factors
  7.  
  8. -- state
  9. reset = false
  10. step = 0 -- current step [0-15]
  11. pattern = 0 -- current pattern value
  12. fs = {} -- current factor values
  13.  
  14. function clock_in(v)
  15. if reset and ((step % 4) == 0) then
  16. -- print("did reset on: ".. step)
  17. step = 0
  18. reset = false
  19. end
  20. local s = 15 - step
  21.  
  22. local o1 = (pattern >> s) & 0x1
  23. if o1 == 1 then output[1]() end
  24.  
  25. local o2 = ((pattern * fs[1]) >> s) & 0x1
  26. if o2 == 1 then output[2]() end
  27.  
  28. local o3 = (((pattern & 0x0f0f) * fs[2]) >> s) & 0x1
  29. if o3 == 1 then output[3]() end
  30.  
  31. local o4 = (((pattern & 0xf003) * fs[3]) >> s) & 0x1
  32. if o4 == 1 then output[4]() end
  33.  
  34. -- advance step
  35. step = (step + 1) % 16
  36. end
  37.  
  38. function reset(v)
  39. reset = true
  40. -- print("reset")
  41. end
  42.  
  43. function prime(n)
  44. pattern = patterns[(n % num_patterns) + 1]
  45. print("pattern: " .. pattern)
  46. end
  47.  
  48. function factor(f, n)
  49. fs[f] = factors[(n % num_factors) + 1]
  50. end
  51.  
  52. function txi_event(e, data)
  53. print("e: " .. e .. " d: " .. data)
  54. end
  55.  
  56. function txi_poll(count)
  57. ii.txi.get('param', 3)
  58. end
  59.  
  60. function init()
  61. -- inputs
  62. input[1]{mode = 'change', direction = 'rising'}
  63. input[1].change = clock_in
  64. input[2]{mode = 'change', direction = 'rising'}
  65. input[2].change = reset
  66.  
  67. -- outputs
  68. for i = 1,4 do
  69. output[i].slew = 0
  70. output[i].volts = 0
  71. output[i].action = pulse(0.02, 6, true)
  72. end
  73.  
  74. -- misc
  75. ii.pullup(false)
  76. ii.txi.event = txi_event
  77. --poller = metro.init{ event = txi_poll, time = 0.5 }
  78. --poller:start()
  79.  
  80. -- TODO: txi for factor selection and factor cv
  81.  
  82. prime(0)
  83. factor(1, 3)
  84. factor(2, 0)
  85. factor(3, 0)
  86.  
  87. reset(true)
  88. end
  89.  
  90. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement