Hello!
Coding noob here, making my first LUA script for Crow.
A “Harp Interface” for Mutable Rings, utilizing a 2hp Switch module and a quad quantizer.
I can’t figure out how to make a working sample & hold function. I basically need “in2” to be sampled and sent out of “out4”, everytime a pulse is sent out of “out3”.
The idea is that when I move a fader (in1) and it crosses one of 4 virtual “strings”, a short trigger is fired to trigger Rings, while the pitch of the “string”, is sent from a quad quantizer via 2hp Switch.
Here is the code:
--- Harp Interface
-- in1: Controller Output
-- in2: 2hp Switch Out (1v/oct)
-- out1: 2hp Switch Selector
-- out2:
-- out3: Trigger Out
-- out4: Sample & Hold Out
--- input modes
function init()
input[1].mode('stream', 0.001) -- Read input1 from controller
input[2].mode('stream', 0.001) -- Read input2 from 2hp Switch
--- virtual string thresholds
string1 = 0.58
string2 = 1.80
string3 = 3.20
string4 = 4.38
position = 1
end
--- Send switch CV from in1 to out1
input[1].stream = function(switch) -- Make switch function
output[1].volts = switch -- Send switch CV to out1
--- Send a pulse to out3 when crossing virtual strings
if switch < string1 and position ~= 1
then
output[3] (pulse(0.01,8))
position = 1
end
if switch > string1 and switch < string2 and position ~= 2
then
output[3] (pulse(0.01,8))
position = 2
end
if switch > string2 and switch < string3 and position ~= 3
then
output[3] (pulse(0.01,8))
position = 3
end
if switch > string3 and switch < string4 and position ~= 4
then
output[3] (pulse(0.01,8))
position = 4
end
if switch > string4 and position ~= 5
then
output[3] (pulse(0.01,8))
position = 5
end
end