-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzorns.lua
More file actions
157 lines (133 loc) · 3.6 KB
/
Copy pathzorns.lua
File metadata and controls
157 lines (133 loc) · 3.6 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
engine.name = 'PolyPerc'
er = require "lib.er"
local UI = require "ui"
musicutil = require "musicutil"
tabutil = require "tabutil"
include("lib/id_list")
include("lib/global_variables")
include("lib/grid_ui")
include("lib/redraw_subroutines")
include("lib/helpers")
include("lib/connections")
include("lib/zorns_module")
include("lib/module_catalogue")
DIAL = include("lib/dial")
category_list = UI.ScrollingList.new (38, 8, 2, category_names)
module_list = UI.ScrollingList.new (70, 8, 2, module_names[category_list.index])
module_param = 1
dirty_screen = true
selection = nil
CTRL_RATE = 1/128
MODULES = ID_LIST.new()
CONNECTIONS = ID_LIST.new()
select_module = function (x,y)
for _,m in pairs(MODULES.list) do
if m:in_area(x,y) then
local info = m:get_cell_info(x,y)
tabutil.print(info)
return SEL.new(x,y,m.id,info.port_id,info.type)
end
end
return nil
end
ctrl_loop = function ()
main_clock:update()
for _,m in pairs(MODULES.list) do
m:ctrl_rate()
--m:propagate_signals()
end
for _,m in pairs(MODULES.list) do
m:propagate_signals()
end
end
function redraw()
if not dirty_screen then return end
dirty_screen = false
screen.clear()
if SEL.is_module(selection) then
redraw_module_settings(selection)
redraw_module_port(selection)
dirty_screen = true
elseif SEL.is_connection(selection) then
redraw_connection(selection)
elseif SEL.is_empty(selection) then
category_list:redraw ()
module_list:redraw ()
elseif not selection then
redraw_no_selection()
end
screen.update()
end
function init ()
-- LOAD PATCH
stored_patch = tabutil.load(_path.data.."/zorns/patch.txt")
if stored_patch then
for i,m in pairs(stored_patch.modules) do
local mo = restore_module(m)
MODULES:insert(mo)
end
for i,con in pairs(stored_patch.connections) do
CONNECTIONS:insert(con)
end
end
metro.init(ctrl_loop,CTRL_RATE):start()
metro.init(draw_loop, 1/15):start()
clock.run(
function()
while true do
clock.sleep(1/15)
redraw()
end
end
)
end
function key (n,z)
dirty_screen = true
if n==1 and z==1 then
if SEL.is_connection(selection) then
CON.remove(selection.con_id)
selection = nil
elseif SEL.is_module(selection) then
-- DELETE ALL CONNECTIONS
local sel_id = selection.module_id
for id,con in pairs(CONNECTIONS.list) do
if con.source.module_id==sel_id or con.target.module_id==sel_id then
CON.remove(selection.con_id)
end
end
-- DELETE MODULE
MODULES:pop_id(selection.module_id)
selection = nil
end
elseif n==2 and z==1 then
-- save MODULES
tabutil.save({modules=MODULES.list,connections=CONNECTIONS.list}, _path.data.."/zorns/patch.txt")
elseif n==3 and z==1 then
-- clear MODULES
MODULES = ID_LIST.new()
CONNECTIONS = ID_LIST.new()
end
end
function enc (n,d)
dirty_screen = true
if SEL.is_module(selection) then
local m = MODULES.list[selection.module_id]
if n==1 then
local port = SEL.get_port(selection)
PORT.change_value(port,d)
elseif n==2 then
module_param = util.clamp(module_param+d,1,#m.params)
else
m:change_param(module_param,d)
end
elseif SEL.is_connection(selection) then
CON.change_strength(selection.con_id,d)
elseif SEL.is_empty(selection) then
if n==2 then
category_list:set_index_delta(d,false)
module_list = UI.ScrollingList.new (70, 8, 1, module_names[category_list.index])
elseif n==3 then
module_list:set_index_delta(d,false)
end
end
end