Hi!
Good you found your first solutions yourself!
Yes, lua has no bitops (which include gate/binary operations), only values (floating point) or bools (which can do logics as well, and maybe even be converted, but…hehe). As I said, the renoise tool interface has bitops, but formula device not, well, one can code simple gates oneself with float or bools.
I’ve coded some building blocks for you in the float way, as I think it fits the input/output format best. You can just put them into the user field to use the functions in there or in the formula field.
Click to view contents
–[[ uncomment if using in lua environment for tests, and not in formula device
local floor = math.floor
local ceil = math.ceil
local abs = math.abs
–]]
– discretize value x range 0.0…1.0 - make it either 0.0 or 1.0 if it is above thres
function gdisc(x, thres)
thres = thres or 0.5
return floor(x+1.0-thres)
end
–these functions only work with either 0.0 or 1.0 as input(s), use disc() first
– x AND y
function gand(x,y)
return x*y
end
– x OR y
function gor(x,y)
return ceil((x+y)*0.5)
end
– NOT x
function gnot(x)
return 1.0 - x
end
– x XOR y
function gxor(x,y)
– return (x+y) - floor((x+y)*0.5)*2.0 – LOL I shouldn’t do this at night
return abs(x-y)
end
all the functions should be self explaining, and with exception of the first they need each input value be exactly either 1.0 or 0.0 to work correctly. this is why the first function “gdisc()” is there, you can make a value between 0.0 and 1.0 be exactly either of them, depending on it being above or below the second parameter, if you give only one parameter this threshold is considered to be 0.5. It is useful for doing these logics with input from stuff like the signal follower. sorry for the “g” in front of these functions, but “and”, “not” and “or” are reserved names I think.
The results will be either 0.0 or 1.0, too (if not abused…), so you can happily multiply other values with them to make them jump between whatever they are and zero.
For example you could do a “formula” with this like “gnot( gxor( gdisc(A), gdisc( B) ) )” which will be “NOT ( A XOR B )”, and you can leave out the “gdisc” commands if you use LFOs in point mode with only exactly 0.0 or 1.0 value points.
Have fun, I only tested this vaguely…
EDIT: I replaced the messy XOR function with something more straightforward