Created
March 10, 2019 09:53
-
-
Save ranch-verdin/7c641533185167eee0d14ca264c3692a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- patterning | |
-- norns study 2 | |
engine.name = "./sgynth.so" | |
function init() | |
--engine.release(3) | |
notes = {} | |
selected = {} | |
--build a scale, clear selected notes | |
for m = 1,5 do | |
notes[m] = {} | |
selected[m] = {} | |
for n = 1,5 do | |
notes[m][n] = 55 * 2^((m*12+n*2)/12) | |
selected[m][n] = 0 | |
end | |
end | |
light = 0 | |
number = 3 | |
--metro[1]:start() | |
--metro[2]:start() | |
--metro[3]:start() | |
--metro[5]:start() | |
--metro[6]:start() | |
drumvol = 0.5 | |
engine.sgynth_bd_vol(drumvol*4.0) | |
engine.sgynth_sd_vol(drumvol *0.5) | |
engine.sgynth_hatz_vol(drumvol * 4.0) | |
engine.sgynth_cp_vol(drumvol * 4) | |
engine.sgynth_wub_params_vol(1.0) | |
engine.sgynth_organ_vol(2) | |
key(2,1) | |
organs = {{engine.sgynth_organ_voice1_freq, engine.sgynth_organ_voice1_gate}, | |
{engine.sgynth_organ_voice2_freq, engine.sgynth_organ_voice2_gate}, | |
{engine.sgynth_organ_voice3_freq, engine.sgynth_organ_voice3_gate}, | |
{engine.sgynth_organ_voice4_freq, engine.sgynth_organ_voice4_gate}} | |
strings = {{engine.sgynth_string_string1_freq, engine.sgynth_string_string1_gate}, | |
{engine.sgynth_string_string2_freq, engine.sgynth_string_string2_gate}, | |
{engine.sgynth_string_string3_freq, engine.sgynth_string_string3_gate}, | |
{engine.sgynth_string_string4_freq, engine.sgynth_string_string4_gate}} | |
drumz = {engine.sgynth_cp_cp, engine.sgynth_sd_sd, engine.sgynth_bd_bd, engine.sgynth_bd_bl, engine.sgynth_hatz_hh, engine.sgynth_hatz_oh} | |
unshush() | |
end | |
function redraw() | |
screen.clear() | |
for m = 1,5 do | |
for n = 1,5 do | |
screen.rect(0.5+m*9, 0.5+n*9, 6, 6) | |
l = 2 | |
if selected[m][n] == 1 then | |
l = l + 3 + light | |
end | |
screen.level(l) | |
screen.stroke() | |
end | |
end | |
screen.move(10, 60) | |
screen.text(number) | |
screen.update() | |
end | |
function key(n, z) | |
if n == 2 and z== 1 then | |
-- clear selected | |
for x = 1,5 do | |
for y = 1,5 do | |
selected[x][y] = 0 | |
end | |
end | |
-- choose new random notes | |
for i = 1,number do | |
selected[math.random(5)][math.random(5)] = 1 | |
end | |
elseif n == 3 then | |
-- find notes to play | |
if z == 1 then | |
for x = 1,5 do | |
for y = 1,5 do | |
if selected[x][y] == 1 then | |
sgynth_poly_string(notes[x][y]) | |
end | |
end | |
end | |
light = 7 | |
else | |
light = 0 | |
end | |
end | |
redraw() | |
end | |
stringidx = 1 | |
strings = {} | |
function sgynth_poly_string (freq) | |
strings[stringidx][1](freq) | |
strings[stringidx][2](1) | |
stringidx = stringidx + 1 | |
if(stringidx > 4) then | |
stringidx = 1 | |
end | |
end | |
-- set up a metro | |
c = metro[1] | |
-- count forever | |
c.count = -1 | |
-- count interval to 1 second | |
c.time = 0.010 | |
-- callback function on each count | |
c.event = function(stage) | |
--norns.log.post("tick "..t) | |
key(2,1) | |
key(3,1) | |
end | |
function wub(freq,duration) | |
engine.sgynth_wub_freq(freq); | |
engine.sgynth_wub_gate(1) | |
metro[4].count = 1 | |
metro[4].time = duration | |
metro[4].event = function (stage) | |
engine.sgynth_wub_gate(0) | |
end | |
metro[4]:start() | |
end | |
metro[2].count = -1 | |
metro[2].time = 0.015 | |
metro[2].event = function(stage) | |
enc(1,1) | |
metro[2].time = floatrandom(0.01, 0.06) | |
end | |
metro[3].count = -1 | |
metro[3].time = 0.0033 | |
metro[3].event = function(stage) | |
stringidx = stringidx - 1 | |
if(stringidx < 1) then | |
stringidx = 4 | |
end | |
end | |
metro[5].count = -1 | |
metro[5].time = 0.02 | |
metro[5].event = function(stage) | |
wubit() | |
end | |
organs = {} | |
metro[6].count = -1 | |
metro[6].time = 0.016 | |
metro[6].event = function(stage) | |
if(math.random(2) > 1) then | |
organs[math.random(4)][1](floatrandom(50,600)) | |
organs[math.random(4)][2](1) | |
else | |
organs[math.random(4)][2](0) | |
end | |
end | |
function floatrandom(min,max) | |
return math.random() * (max - min) + min | |
end | |
string_strength = 1.0 | |
function clamp(var,minval,maxval) | |
return math.min(maxval, math.max(var, minval)) | |
end | |
drumidx = 1 | |
drumz = {} | |
function enc(n, d) | |
if n == 1 then | |
drumidx = 1 + drumidx | |
if (drumidx > 6) then drumidx = 1 end | |
drumz[drumidx](1) | |
end | |
if n == 2 then | |
string_strength = clamp(string_strength + d * 0.02, 0, 1) | |
engine.sgynth_string_params_expos(string_strength) | |
engine.sgynth_string_params_strength(string_strength * 3) | |
end | |
if n == 3 then | |
-- clamp number of notes from 1 to 4 | |
number = math.min(4, (math.max(number + d, 1))) | |
end | |
redraw() | |
end | |
function wubit() | |
wub(floatrandom(30,300),floatrandom(0.01, 0.199)) | |
end | |
function shush() | |
for idx = 1,6,1 do | |
metro[idx]:stop() | |
end | |
end | |
function unshush() | |
for idx = 1,6,1 do | |
metro[idx]:start() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment