Repository navigation
Expand file tree
/
Copy pathmosaic.lua
More file actions
260 lines (206 loc) · 5.89 KB
/
Copy pathmosaic.lua
File metadata and controls
260 lines (206 loc) · 5.89 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
-- mosaic v1.3.0
-- grid-first rhythm and
-- harmony sequencer.
--
-- llllllll.co/t/mosaic/69304
-- manual: t.ly/h-Wsw
-- Copyright Andrew Hillel 2024. See the included GNU licence for more information.
testing = false
pages = include("mosaic/lib/pages/pages")
program = include("mosaic/lib/models/program")
fn = include("mosaic/lib/helpers/functions")
scheduler = include("mosaic/lib/scheduler")
m_grid = include("mosaic/lib/m_grid")
ui = include("mosaic/lib/ui")
sinfonion = include("mosaic/lib/sinfonion_harmonic_sync")
m_midi = include("mosaic/lib/m_midi")
memory = include("mosaic/lib/memory")
recorder = include("mosaic/lib/recorder")
-- Debug
-- profiler = include("mosaic/lib/helpers/profiler")
-- p = newProfiler()
local fileselect = require("fileselect")
local textentry = require("textentry")
local as_metro = metro.init(do_autosave, 1, 1)
local autosave_timer = metro.init(prime_autosave, 60, 1)
local param_manager = include("mosaic/lib/devices/param_manager")
local application_parameters = include("mosaic/lib/application_parameters")
local project_validation = include("mosaic/lib/project_validation")
local ui_splash_screen_active = false
local project = include("mosaic/lib/project_lifecycle").new(
as_metro, autosave_timer, param_manager, project_validation,
function(active) ui_splash_screen_active = active end
)
local redraw_clock = nil
local grid_redraw_clock = nil
local scheduler_clock = nil
local screen_keep_alive = nil
nb = require("mosaic/lib/nb/lib/nb")
m_clock = include("mosaic/lib/clock/m_clock")
local redraw_guard = include("mosaic/lib/clock/redraw_guard")
pattern = include("mosaic/lib/pattern")
m_midi = include("mosaic/lib/m_midi")
step = include("lib/step")
device_map = include("mosaic/lib/devices/device_map")
norns_param_state_handler = include("mosaic/lib/devices/norns_param_state_handler")
g = grid.connect()
local function post_splash_init()
end
function redraw()
screen.clear()
if fn.dirty_screen() == true then
if ui_splash_screen_active then
screen.level(15)
screen.move(60, 38)
screen.font_face(math.random(3, 8))
screen.font_size(12)
screen.text("m°")
screen.font_face(1)
screen.update()
else
screen.level(5)
screen.font_size(8)
ui.redraw()
screen.update()
end
fn.dirty_screen(false)
end
end
local function blink()
program.toggle_blink_state()
fn.dirty_grid(true)
clock.run(function() clock.sleep(0.4); blink() end)
end
function init()
ui_splash_screen_active = true
math.randomseed(os.time())
program.init()
m_midi.init()
grid_connected = g.device~= nil and true or false
nb:init()
if note_players then
nb:add_param("voice_id", "NB PARAMS") -- adds a voice selector param to your script.
nb:add_player_params() -- Adds the parameters for the selected voices to your script.
end
device_map.init()
sinfonion.set_root_note(0)
sinfonion.set_degree_nr(0)
sinfonion.set_mode_nr(0)
sinfonion.set_transposition(0)
sinfonion.set_clock(0)
sinfonion.set_beat(0)
sinfonion.set_step(0)
sinfonion.set_reset(0)
sinfonion.set_chaotic_detune(0)
sinfonion.set_harmonic_shift(0)
crow.ii.pullup(true)
scheduler_clock = clock.run(
function()
while true do
clock.sleep(1/300)
scheduler.update()
end
end
)
-- A screen redraw is native-heavy and cannot be interrupted, so it must not
-- start just before a step's notes. Leave that slot to the next cycle.
local screen_guard = redraw_guard.new(m_clock.seconds_to_next_step, util.time)
local grid_guard = redraw_guard.new(m_clock.seconds_to_next_step, util.time)
redraw_clock = clock.run(
function()
while true do
clock.sleep(1/30)
if fn.dirty_screen() then screen_guard.run(redraw) end
end
end
)
grid_redraw_clock = clock.run(
function()
while true do
clock.sleep(1/20)
if fn.dirty_grid() then grid_guard.run(m_grid.grid_redraw) end
end
end
)
screen_keep_alive = clock.run(
function()
while true do
clock.sleep(1)
fn.dirty_screen(true)
end
end
)
blink()
application_parameters.register({
save = function() textentry.enter(project.save, "new") end,
load = function() fileselect.enter(norns.state.data, project.load) end,
new = project.new
})
param_manager.init()
clock.tempo_change_handler = function(x)
song_edit_page_ui.refresh_tempo()
end
project.load(norns.state.data .. "autosave.ptn", true)
if program == nil then
project.new()
end
device_map.validate_devices()
params:bang()
m_midi.set_up_midi_mapping_params()
ui.init()
m_grid.init()
m_clock.init()
ui_splash_screen_active = false
fn.dirty_grid(true)
fn.dirty_screen(true)
end
function enc(n, d)
ui.enc(n, d)
end
function key(n, z)
ui.key(n, z)
end
function autosave_reset()
project.reset_autosave()
end
function clock.transport:start()
m_clock:start(params:get("clock_source") == 2)
end
function clock.transport:stop()
m_clock:stop()
end
-- -- Debug
-- local outfile
-- local p
-- function start_profiler()
-- -- Determine the script's directory
-- local script_path = debug.getinfo(1, "S").source:match("^@(.*/)")
-- if not script_path then
-- script_path = "./"
-- end
-- -- Attempt to open the output file
-- outfile, err = io.open(script_path .. "profile.txt", "w+")
-- if not outfile then
-- error("Failed to open output file for profiling: " .. err)
-- end
-- -- Start the profiler
-- p = newProfiler()
-- p:start()
-- end
-- function stop_profiler()
-- if not p then
-- print("Profiler has not been started.")
-- return
-- end
-- p:stop()
-- if not outfile then
-- print("Output file is not available.")
-- return
-- end
-- p:report(outfile)
-- outfile:close()
-- end
-- Restore script-owned vport hooks before norns loads another script.
function cleanup()
m_midi.cleanup()
end