PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Helpers.lua

https://code.google.com/p/airmann-faderport-driver/
Lua | 41 lines | 25 code | 9 blank | 7 comment | 3 complexity | ae15d214902a6bf6f4108d4319efaeeb MD5 | raw file
 1--[[-------------------------------------------------------
 2  
 3  FaderPort helper functions
 4  
 5  Taken from GlobalMidiActions.lua, Author: taktik 
 6  
 7---------------------------------------------------------]]
 8
 9function song()
10  return renoise.song()
11end
12
13function clamp_value(value, min_value, max_value)
14  return math.min(max_value, math.max(value, min_value))
15end
16
17function wrap_value(value, min_value, max_value)
18  local range = max_value - min_value + 1
19  assert(range > 0, "invalid range")
20
21  while value < min_value do
22    value = value + range
23  end
24
25  while value > max_value do
26    value = value - range
27  end
28
29  return value
30end
31
32function quantize_value(value, quantum)
33  if value >= 0 then
34     value = value + quantum / 2
35  else
36     value = value - quantum / 2
37  end
38
39  return math.floor(value / quantum) * quantum
40end
41