Guest User

Untitled

a guest
Apr 19th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. local par_table = {}
  2. local par_string_table = {}
  3. local t_final = {}
  4. local old_str = 'x'
  5.  
  6. local function dump_pars(par)
  7. local adjusted_string
  8. par.value = 0
  9. for x=0, 1, 0.1 do --0.1 for testing purposes, full range will take too long
  10. par.value = x
  11. if old_str ~= par.value_string then
  12. old_str = par.value_string
  13. --remove non-digits
  14. adjusted_string = string.gsub(par.value_string, '%a' , '')
  15. adjusted_string = string.gsub(adjusted_string, '%p', '')
  16. --insert
  17. table.insert(par_table, par.value)
  18. table.insert(par_string_table, tonumber(adjusted_string))
  19. end
  20. end
  21.  
  22. --add 00
  23. local par_string_table_00 = {}
  24. for i=1, #par_string_table do
  25. table.insert(par_string_table_00, par_string_table[i]*100)
  26. end
  27. par_string_table = par_string_table_00
  28.  
  29. --interpolate
  30. local function interpol(y,y1,y2,y3,x)
  31. local x2 = x*x
  32. local a = y3 - y2 - y + y1
  33. local a1 = y - y1 - a
  34. local a2 = y2 - y
  35. return(a*x*x2+a1*x2+a2*x+y3)
  36. end
  37.  
  38. --for readability
  39. local tt = table.rcopy(par_string_table)
  40. local ts = table.rcopy(par_table)
  41.  
  42. for i=1, #tt do
  43. --return if reached the end of the table
  44. if not tt[i+3] then break end
  45.  
  46. --load up the values for interpolation
  47. local ts0, ts1, ts2, ts3 = ts[i], ts[i+1], ts[i+2], ts[i+3]
  48. local tt0, tt1, tt2, tt3 = tt[i], tt[i+1], tt[i+2], tt[i+3]
  49.  
  50. for x=1, 99 do
  51. --interpolate values at t0+x (starting value handled with +x)
  52. local interp_key = interpol(ts0, ts1, ts2, ts3, ts0+x)
  53. local interp_val = interpol(tt0, tt1, tt2, tt3, tt0+x)
  54. --insert result of interpolation in between the current values with additional '00' in the original tables, at position i+1 (insert data right before next iteration's data)
  55. table.insert(par_string_table, i+1, interp_key)
  56. table.insert(par_table, i+1, interp_val)
  57. end
  58. end
  59. for i=1, #par_table do
  60. table.insert(t_final, par_string_table[i], par_table[i])
  61. print(t_final[par_string_table[i]], par_string_table[i], par_table[i])
  62. end
  63.  
  64. end
  65.  
  66. local sel_par = renoise.song().selected_device:parameter(2)
  67.  
  68. dump_pars(sel_par)
  69. --for x=1, #par_table do
  70. -- par_table[x] = '<Point>'..x..','..par_table[x]..'</Point>'
  71. -- end
  72. -- for x=1, #par_table do
  73. -- print(par_table[x])
  74. -- end
Advertisement
Add Comment
Please, Sign In to add comment