-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathplayer.lua
More file actions
901 lines (743 loc) · 22.9 KB
/
Copy pathplayer.lua
File metadata and controls
901 lines (743 loc) · 22.9 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
-- Timber Player
-- 1.0.0 Beta 7 @markeats
-- llllllll.co/t/timber
--
-- Trigger samples with a grid
-- or MIDI keyboard.
--
-- E1 : Page
-- K1+E1 : Sample slot
-- K1 (Hold) : Shift / Fine
--
-- GLOBAL PAGE:
-- K2 : Play / Stop
-- K3 : Load folder
-- K1+K3 : Add folder
-- E2 : BPM
--
-- SAMPLE PAGES:
-- K2 : Focus
-- K3 : Action
-- E2/3 : Params
--
local Timber = include("timber/lib/timber_engine")
local MusicUtil = require "musicutil"
local UI = require "ui"
local Formatters = require "formatters"
local BeatClock = require "beatclock"
engine.name = "Timber"
local options = {}
options.OFF_ON = {"Off", "On"}
options.QUANTIZATION = {"None", "1/32", "1/24", "1/16", "1/12", "1/8", "1/6", "1/4", "1/3", "1/2", "1 bar"}
options.QUANTIZATION_DIVIDERS = {nil, 32, 24, 16, 12, 8, 6, 4, 3, 2, 1}
local SCREEN_FRAMERATE = 15
local screen_dirty = true
local GRID_FRAMERATE = 30
local grid_dirty = true
local grid_w, grid_h = 16, 8
local midi_in_device
local midi_clock_in_device
local grid_device
local NUM_SAMPLES = 256
local beat_clock
local note_queue = {}
local sample_status = {}
local STATUS = {
STOPPED = 0,
STARTING = 1,
PLAYING = 2,
STOPPING = 3
}
for i = 0, NUM_SAMPLES - 1 do sample_status[i] = STATUS.STOPPED end
local pages
local global_view
local sample_setup_view
local waveform_view
local filter_amp_view
local amp_env_view
local mod_env_view
local lfos_view
local mod_matrix_view
local current_sample_id = 0
local shift_mode = false
local file_select_active = false
local function load_folder(file, add)
local sample_id = 0
if add then
for i = NUM_SAMPLES - 1, 0, -1 do
if Timber.samples_meta[i].num_frames > 0 then
sample_id = i + 1
break
end
end
end
Timber.clear_samples(sample_id, NUM_SAMPLES - 1)
local split_at = string.match(file, "^.*()/")
local folder = string.sub(file, 1, split_at)
file = string.sub(file, split_at + 1)
local found = false
for k, v in ipairs(Timber.FileSelect.list) do
if v == file then found = true end
if found then
if sample_id > 255 then
print("Max files loaded")
break
end
-- Check file type
local lower_v = v:lower()
if string.find(lower_v, ".wav") or string.find(lower_v, ".aif") or string.find(lower_v, ".aiff") or string.find(lower_v, ".ogg") then
Timber.load_sample(sample_id, folder .. v)
sample_id = sample_id + 1
else
print("Skipped", v)
end
end
end
end
local function set_sample_id(id)
current_sample_id = id
while current_sample_id >= NUM_SAMPLES do current_sample_id = current_sample_id - NUM_SAMPLES end
while current_sample_id < 0 do current_sample_id = current_sample_id + NUM_SAMPLES end
sample_setup_view:set_sample_id(current_sample_id)
waveform_view:set_sample_id(current_sample_id)
filter_amp_view:set_sample_id(current_sample_id)
amp_env_view:set_sample_id(current_sample_id)
mod_env_view:set_sample_id(current_sample_id)
lfos_view:set_sample_id(current_sample_id)
mod_matrix_view:set_sample_id(current_sample_id)
end
local function id_to_x(id)
return (id - 1) % grid_w + 1
end
local function id_to_y(id)
return math.ceil(id / grid_w)
end
local function note_on(sample_id, vel)
if Timber.samples_meta[sample_id].num_frames > 0 then
-- print("note_on", sample_id)
vel = vel or 1
engine.noteOn(sample_id, MusicUtil.note_num_to_freq(60), vel, sample_id)
sample_status[sample_id] = STATUS.PLAYING
global_view:add_play_visual()
screen_dirty = true
grid_dirty = true
end
end
local function note_off(sample_id)
-- print("note_off", sample_id)
engine.noteOff(sample_id)
screen_dirty = true
grid_dirty = true
end
local function clear_queue()
for k, v in pairs(note_queue) do
if Timber.samples_meta[v.sample_id].playing then
sample_status[v.sample_id] = STATUS.PLAYING
else
sample_status[v.sample_id] = STATUS.STOPPED
end
end
note_queue = {}
end
local function queue_note_event(event_type, sample_id, vel)
local quant = options.QUANTIZATION_DIVIDERS[params:get("quantization_" .. sample_id)]
if params:get("quantization_" .. sample_id) > 1 then
-- Check for already queued
for i = #note_queue, 1, -1 do
if note_queue[i].sample_id == sample_id then
if note_queue[i].event_type ~= event_type then
table.remove(note_queue, i)
if Timber.samples_meta[sample_id].playing then
sample_status[sample_id] = STATUS.PLAYING
else
sample_status[sample_id] = STATUS.STOPPED
end
grid_dirty = true
end
return
end
end
if event_type == "on" or sample_status[sample_id] == STATUS.PLAYING then
if Timber.samples_meta[sample_id].num_frames > 0 then
local note_event = {
event_type = event_type,
sample_id = sample_id,
vel = vel,
quant = quant
}
table.insert(note_queue, note_event)
if event_type == "on" then
sample_status[sample_id] = STATUS.STARTING
else
sample_status[sample_id] = STATUS.STOPPING
end
end
end
else
if event_type == "on" then
note_on(sample_id, vel)
else
note_off(sample_id)
end
end
grid_dirty = true
end
local function note_off_all()
engine.noteOffAll()
clear_queue()
screen_dirty = true
grid_dirty = true
end
local function note_kill_all()
engine.noteKillAll()
clear_queue()
screen_dirty = true
grid_dirty = true
end
local function set_pressure_voice(voice_id, pressure)
engine.pressureVoice(voice_id, pressure)
end
local function set_pressure_sample(sample_id, pressure)
engine.pressureSample(sample_id, pressure)
end
local function set_pressure_all(pressure)
engine.pressureAll(pressure)
end
local function set_pitch_bend_voice(voice_id, bend_st)
engine.pitchBendVoice(voice_id, MusicUtil.interval_to_ratio(bend_st))
end
local function set_pitch_bend_sample(sample_id, bend_st)
engine.pitchBendSample(sample_id, MusicUtil.interval_to_ratio(bend_st))
end
local function set_pitch_bend_all(bend_st)
engine.pitchBendAll(MusicUtil.interval_to_ratio(bend_st))
end
local function key_down(sample_id, vel)
if pages.index == 2 then
sample_setup_view:sample_key(sample_id)
end
if params:get("launch_mode_" .. sample_id) == 1 then
queue_note_event("on", sample_id, vel)
else
if (sample_status[sample_id] ~= STATUS.PLAYING and sample_status[sample_id] ~= STATUS.STARTING) or sample_status[sample_id] == STATUS.STOPPING then
queue_note_event("on", sample_id, vel)
else
queue_note_event("off", sample_id)
end
end
end
local function key_up(sample_id)
if params:get("launch_mode_" .. sample_id) == 1 and params:get("play_mode_" .. sample_id) ~= 4 then
queue_note_event("off", sample_id)
end
end
-- Clock callbacks
local function advance_step()
local tick = (beat_clock.beat * 24) + beat_clock.step -- 0-95
-- Fire quantized note on/offs
for i = #note_queue, 1, -1 do
local note_event = note_queue[i]
if tick % (96 / note_event.quant) == 0 then
if note_event.event_type == "on" then
note_on(note_event.sample_id, note_event.vel)
else
note_off(note_event.sample_id)
end
table.remove(note_queue, i)
end
end
-- Every beat
if beat_clock.step == 0 then
if pages.index == 1 then screen_dirty = true end
end
end
local function stop()
note_kill_all()
end
-- Encoder input
function enc(n, delta)
-- Global
if n == 1 then
if shift_mode then
if pages.index > 1 then
set_sample_id(current_sample_id + delta)
end
else
pages:set_index_delta(delta, false)
end
else
if pages.index == 1 then
global_view:enc(n, delta)
elseif pages.index == 2 then
sample_setup_view:enc(n, delta)
elseif pages.index == 3 then
waveform_view:enc(n, delta)
elseif pages.index == 4 then
filter_amp_view:enc(n, delta)
elseif pages.index == 5 then
amp_env_view:enc(n, delta)
elseif pages.index == 6 then
mod_env_view:enc(n, delta)
elseif pages.index == 7 then
lfos_view:enc(n, delta)
elseif pages.index == 8 then
mod_matrix_view:enc(n, delta)
end
end
screen_dirty = true
end
-- Key input
function key(n, z)
if n == 1 then
-- Shift
if z == 1 then
shift_mode = true
Timber.shift_mode = shift_mode
else
shift_mode = false
Timber.shift_mode = shift_mode
end
else
if pages.index == 1 then
global_view:key(n, z)
elseif pages.index == 2 then
sample_setup_view:key(n, z)
elseif pages.index == 3 then
waveform_view:key(n, z)
elseif pages.index == 4 then
filter_amp_view:key(n, z)
elseif pages.index == 5 then
amp_env_view:key(n, z)
elseif pages.index == 6 then
mod_env_view:key(n, z)
elseif pages.index == 7 then
lfos_view:key(n, z)
elseif pages.index == 8 then
mod_matrix_view:key(n, z)
end
end
screen_dirty = true
end
-- MIDI input
local function midi_event(device_id, data)
local msg = midi.to_msg(data)
local channel_param = params:get("midi_in_channel")
-- MIDI In
if device_id == params:get("midi_in_device") then
if channel_param == 1 or (channel_param > 1 and msg.ch == channel_param - 1) then
-- Note off
if msg.type == "note_off" then
key_up(msg.note)
-- Note on
elseif msg.type == "note_on" then
key_down(msg.note, msg.vel / 127)
if params:get("follow") >= 3 then
set_sample_id(msg.note)
end
-- Key pressure
elseif msg.type == "key_pressure" then
set_pressure_voice(msg.note, msg.val / 127)
-- Channel pressure
elseif msg.type == "channel_pressure" then
set_pressure_all(msg.val / 127)
-- Pitch bend
elseif msg.type == "pitchbend" then
local bend_st = (util.round(msg.val / 2)) / 8192 * 2 -1 -- Convert to -1 to 1
local bend_range = params:get("bend_range")
set_pitch_bend_all(bend_st * bend_range)
end
end
end
-- MIDI Clock In
if device_id == params:get("midi_clock_in_device") then
beat_clock:process_midi(data)
if not beat_clock.playing then
screen_dirty = true
end
end
end
local function reconnect_midi_ins()
midi_in_device.event = nil
midi_clock_in_device.event = nil
midi_in_device = midi.connect(params:get("midi_in_device"))
midi_clock_in_device = midi.connect(params:get("midi_clock_in_device"))
midi_in_device.event = function(data) midi_event(params:get("midi_in_device"), data) end
midi_clock_in_device.event = function(data) midi_event(params:get("midi_clock_in_device"), data) end
end
-- Grid event
local function grid_key(x, y, z)
local sample_id = (y - 1) * grid_w + x - 1
if z == 1 then
key_down(sample_id)
if params:get("follow") == 2 or params:get("follow") == 4 then
set_sample_id(sample_id)
end
else
key_up(sample_id)
end
end
local function update()
global_view:update()
waveform_view:update()
lfos_view:update()
end
function grid_redraw()
if grid_device then
grid_w = grid_device.cols
grid_h = grid_device.rows
if grid_w ~= 8 and grid_w ~= 16 then grid_w = 16 end
if grid_h ~= 8 and grid_h ~= 16 then grid_h = 8 end
end
local leds = {}
local num_leds = grid_w * grid_h
for i = 1, num_leds do
if sample_status[i - 1] == STATUS.STOPPING then
leds[i] = 8
elseif sample_status[i - 1] == STATUS.STARTING or sample_status[i - 1] == STATUS.PLAYING then
leds[i] = 15
elseif Timber.samples_meta[i - 1].num_frames > 0 then
leds[i] = 4
end
end
grid_device:all(0)
for k, v in pairs(leds) do
grid_device:led(id_to_x(k), id_to_y(k), v)
end
grid_device:refresh()
end
local function callback_set_screen_dirty(id)
if id == nil or id == current_sample_id or pages.index == 1 then
screen_dirty = true
end
end
local function callback_set_waveform_dirty(id)
if (id == nil or id == current_sample_id) and pages.index == 3 then
screen_dirty = true
end
end
-- Views
local GlobalView = {}
GlobalView.__index = GlobalView
function GlobalView.new()
local global = {
play_visuals = {}
}
setmetatable(GlobalView, {__index = GlobalView})
setmetatable(global, GlobalView)
return global
end
function GlobalView:add_play_visual()
local visual = {
level = math.random(8, 10),
x = math.random(68, 115),
y = math.random(8, 55),
size = 2,
}
table.insert(self.play_visuals, visual)
end
function GlobalView:enc(n, delta)
if n == 2 and beat_clock.external == false then
params:delta("bpm", delta)
end
callback_set_screen_dirty(nil)
end
function GlobalView:key(n, z)
if z == 1 then
if n == 2 then
if not beat_clock.external then
if beat_clock.playing then
beat_clock:stop()
beat_clock:reset()
else
beat_clock:start()
end
end
elseif n == 3 then
file_select_active = true
local add = shift_mode
shift_mode = false
Timber.shift_mode = shift_mode
Timber.FileSelect.enter(_path.audio, function(file)
file_select_active = false
screen_dirty = true
if file ~= "cancel" then
load_folder(file, add)
end
end)
end
callback_set_screen_dirty(nil)
end
end
function GlobalView:update()
for i = #self.play_visuals, 1, -1 do
self.play_visuals[i].size = self.play_visuals[i].size + 1.5
self.play_visuals[i].level = self.play_visuals[i].level - 1.5
if self.play_visuals[i].level < 1 then
table.remove(self.play_visuals, i)
end
callback_set_screen_dirty(nil)
end
end
function GlobalView:redraw()
-- Beat visual
for i = 1, 4 do
if beat_clock.playing and i == beat_clock.beat + 1 then
screen.level(15)
screen.rect(3 + (i - 1) * 12, 19, 4, 4)
else
screen.level(3)
screen.rect(4 + (i - 1) * 12, 20, 2, 2)
end
screen.fill()
end
-- Grid or text prompt
local num_to_draw = 128
if grid_device.device then
num_to_draw = grid_w * grid_h
end
local draw_grid = false
for i = 1, num_to_draw do
if Timber.samples_meta[i - 1].num_frames > 0 then
draw_grid = true
break
end
end
if draw_grid then
local LEFT = 68
local top = 20
local SIZE = 2
local GUTTER = 1
if grid_device.device and grid_h == 16 then top = top - 12 end
local x, y = LEFT, top
for i = 1, num_to_draw do
if sample_status[i - 1] == STATUS.STOPPING then
screen.level(8)
elseif sample_status[i - 1] == STATUS.STARTING or sample_status[i - 1] == STATUS.PLAYING then
screen.level(15)
elseif Timber.samples_meta[i - 1].num_frames > 0 then
screen.level(3)
else
screen.level(1)
end
screen.rect(x, y, SIZE, SIZE)
screen.fill()
x = x + SIZE + GUTTER
if i % grid_w == 0 then
x = LEFT
y = y + SIZE + GUTTER
end
end
else
screen.level(3)
screen.move(68, 28)
screen.text("K3 to")
screen.move(68, 37)
if shift_mode then
screen.text("add folder")
else
screen.text("load folder")
end
screen.fill()
end
-- Info
screen.move(4, 37)
if beat_clock.external then
screen.level(3)
screen.text("External")
else
screen.level(15)
screen.text(params:get("bpm") .. " BPM")
end
screen.fill()
screen.line_width(0.75)
for k, v in pairs(self.play_visuals) do
screen.level(util.round(v.level))
screen.circle(v.x, v.y, v.size)
screen.stroke()
end
screen.line_width(1)
end
-- Drawing functions
local function draw_background_rects()
-- 4px edge margins. 8px gutter.
screen.level(1)
screen.rect(4, 22, 56, 38)
screen.rect(68, 22, 56, 38)
screen.fill()
end
function redraw()
screen.clear()
if file_select_active or Timber.file_select_active then
Timber.FileSelect.redraw()
return
end
-- draw_background_rects()
pages:redraw()
if pages.index == 1 then
global_view:redraw()
elseif pages.index == 2 then
sample_setup_view:redraw()
elseif pages.index == 3 then
waveform_view:redraw()
elseif pages.index == 4 then
filter_amp_view:redraw()
elseif pages.index == 5 then
amp_env_view:redraw()
elseif pages.index == 6 then
mod_env_view:redraw()
elseif pages.index == 7 then
lfos_view:redraw()
elseif pages.index == 8 then
mod_matrix_view:redraw()
end
screen.update()
end
function init()
midi_in_device = midi.connect(1)
midi_in_device.event = function(data) midi_event(1, data) end
midi_clock_in_device = midi.connect(1)
midi_clock_in_device.event = function(data) midi_event(1, data) end
local grid = util.file_exists(_path.code.."midigrid") and include "midigrid/lib/mg_128" or grid
grid_device = grid.connect(1)
grid_device.key = grid_key
pages = UI.Pages.new(1, 8)
-- Clock
beat_clock = BeatClock.new()
beat_clock.on_step = advance_step
beat_clock.on_stop = stop
beat_clock.on_select_internal = function()
beat_clock:start()
if pages.index == 1 then screen_dirty = true end
end
beat_clock.on_select_external = function()
beat_clock:reset()
if pages.index == 1 then screen_dirty = true end
end
beat_clock.ticks_per_step = 1
beat_clock.steps_per_beat = 96 / 4 -- 96ths
beat_clock:bpm_change(beat_clock.bpm)
Timber.set_bpm(beat_clock.bpm)
-- Timber callbacks
Timber.sample_changed_callback = function(id)
-- Set loop default based on sample length or name
if Timber.samples_meta[id].manual_load and Timber.samples_meta[id].streaming == 0 and Timber.samples_meta[id].num_frames / Timber.samples_meta[id].sample_rate < 1 and string.find(string.lower(params:get("sample_" .. id)), "loop") == nil then
params:set("play_mode_" .. id, 3) -- One shot
end
grid_dirty = true
callback_set_screen_dirty(id)
end
Timber.meta_changed_callback = function(id)
if Timber.samples_meta[id].playing and sample_status[id] ~= STATUS.STOPPING then
sample_status[id] = STATUS.PLAYING
elseif not Timber.samples_meta[id].playing and sample_status[id] ~= STATUS.STARTING then
sample_status[id] = STATUS.STOPPED
end
grid_dirty = true
callback_set_screen_dirty(id)
end
Timber.waveform_changed_callback = callback_set_waveform_dirty
Timber.play_positions_changed_callback = callback_set_waveform_dirty
Timber.views_changed_callback = callback_set_screen_dirty
-- Add params
params:add_separator("In/Out")
params:add{type = "number", id = "grid_device", name = "Grid Device", min = 1, max = 4, default = 1,
action = function(value)
grid_device:all(0)
grid_device:refresh()
grid_device.key = nil
grid_device = grid.connect(value)
grid_device.key = grid_key
end}
params:add{type = "number", id = "midi_in_device", name = "MIDI In Device", min = 1, max = 4, default = 1, action = reconnect_midi_ins}
local channels = {"All"}
for i = 1, 16 do table.insert(channels, i) end
params:add{type = "option", id = "midi_in_channel", name = "MIDI In Channel", options = channels}
params:add{type = "number", id = "midi_clock_in_device", name = "MIDI Clock In Device", min = 1, max = 4, default = 1, action = reconnect_midi_ins}
params:add{type = "option", id = "clock", name = "Clock", options = {"Internal", "External"}, default = beat_clock.external or 2 and 1,
action = function(value)
beat_clock:clock_source_change(value)
end}
params:add{type = "option", id = "clock_out", name = "Clock Out", options = options.OFF_ON, default = beat_clock.send or 2 and 1,
action = function(value)
if value == 1 then beat_clock.send = false
else beat_clock.send = true end
end}
params:add_separator("Player")
params:add{type = "number", id = "bpm", name = "BPM", min = 1, max = 240, default = beat_clock.bpm,
action = function(value)
beat_clock:bpm_change(value)
Timber.set_bpm(beat_clock.bpm)
if pages.index == 1 then screen_dirty = true end
end}
params:add{type = "number", id = "bend_range", name = "Pitch Bend Range", min = 1, max = 48, default = 2}
params:add{type = "option", id = "follow", name = "Follow", options = {"Off", "Grid", "MIDI", "Both"}, default = 4}
params:add{type = "option", id = "display", name = "Display", options = {"IDs", "Notes"}, default = 1, action = function(value)
if value == 1 then Timber.display = "id"
else Timber.display = "note" end
end}
params:add{type = "trigger", id = "launch_mode_all_gate", name = "Launch Mode: All Gate", action = function()
for i = 0, NUM_SAMPLES - 1 do
params:set("launch_mode_" .. i, 1)
end
end}
params:add{type = "trigger", id = "launch_mode_all_toggle", name = "Launch Mode: All Toggle", action = function()
for i = 0, NUM_SAMPLES - 1 do
params:set("launch_mode_" .. i, 2)
end
end}
Timber.add_params()
params:add_separator()
-- Index zero to align with MIDI note numbers
for i = 0, NUM_SAMPLES - 1 do
local extra_params = {
{type = "option", id = "launch_mode_" .. i, name = "Launch Mode", options = {"Gate", "Toggle"}, default = 1, action = function(value)
Timber.setup_params_dirty = true
end},
{type = "option", id = "quantization_" .. i, name = "Quantization", options = options.QUANTIZATION, default = 1, action = function(value)
if value == 1 then
for n = #note_queue, 1, -1 do
if note_queue[n].sample_id == i then
table.remove(note_queue, n)
if Timber.samples_meta[i].playing then
sample_status[i] = STATUS.PLAYING
else
sample_status[i] = STATUS.STOPPED
end
grid_dirty = true
end
end
end
Timber.setup_params_dirty = true
end}
}
Timber.add_sample_params(i, true, extra_params)
end
-- UI
global_view = GlobalView.new()
sample_setup_view = Timber.UI.SampleSetup.new(current_sample_id, nil)
waveform_view = Timber.UI.Waveform.new(current_sample_id)
filter_amp_view = Timber.UI.FilterAmp.new(current_sample_id)
amp_env_view = Timber.UI.AmpEnv.new(current_sample_id)
mod_env_view = Timber.UI.ModEnv.new(current_sample_id)
lfos_view = Timber.UI.Lfos.new(current_sample_id)
mod_matrix_view = Timber.UI.ModMatrix.new(current_sample_id)
screen.aa(1)
local screen_redraw_metro = metro.init()
screen_redraw_metro.event = function()
update()
if screen_dirty then
redraw()
screen_dirty = false
end
end
local grid_redraw_metro = metro.init()
grid_redraw_metro.event = function()
if grid_dirty and grid_device.device then
grid_dirty = false
grid_redraw()
end
end
screen_redraw_metro:start(1 / SCREEN_FRAMERATE)
grid_redraw_metro:start(1 / GRID_FRAMERATE)
beat_clock:start()
end