-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstudy1.lua
93 lines (76 loc) · 2.02 KB
/
study1.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
-- nest_ study 1
-- nested affordances
--
-- 1-5
-- 1: strum 1
-- 2: strum 2
-- 3: strum 3
-- 4: strum 4
include 'lib/nest/core'
include 'lib/nest/norns'
include 'lib/nest/grid'
engine.name = "PolyPerc"
scale = { 0, 2, 4, 7, 9 } -- scale degrees in semitones
root = 440 * 2^(5/12) -- the d above middle a
function play(deg, oct)
local octave = oct - 3
local note = scale[deg]
local hz = root * 2^octave * 2^(note/12)
engine.hz(hz)
end
strum = nest_ {
_grid.number {
x = { 1, 5 },
y = 1,
value = math.random(5),
action = function(self, value)
play(value, self.y)
end
},
_grid.number {
x = { 1, 5 },
y = 2,
value = math.random(5),
action = function(self, value)
play(value, self.y)
local above = self.parent[self.key - 1]
clock.run(function()
clock.sleep(0.2)
above.value = (above.value == 1) and 5 or (above.value - 1)
above:update()
end)
end
},
_grid.number {
x = { 1, 5 },
y = 3,
value = math.random(5),
action = function(self, value)
play(value, self.y)
local above = self.parent[self.key - 1]
clock.run(function()
clock.sleep(0.15)
above.value = math.random(5)
above:update()
end)
end
},
_grid.number {
x = { 1, 5 },
y = 4,
value = math.random(5),
action = function(self, value)
play(value, self.y)
local above = self.parent[self.key - 1]
clock.run(function()
clock.sleep(0.1)
above.value = above.value % 5 + 1,
above:update()
end)
end
}
}
strum:connect { g = grid.connect() }
function init()
strum:init()
end