-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcheat_codes_2.lua
executable file
·7273 lines (6771 loc) · 261 KB
/
cheat_codes_2.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
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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- cheat codes 2
-- a sample playground
-- rev: 240301 - LTS13.2
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- need help?
-- please visit:
-- l.llllllll.co/cheat-codes-2
-- -------------------------------
if tonumber(norns.version.update) < 221214 then
norns.script.clear()
norns.script.load('code/cheat_codes_2/lib/fail_state-update.lua')
end
if not util.file_exists(_path.code..'cheat_codes_2/lib/nb/lib/') then
norns.script.clear()
norns.script.load('code/cheat_codes_2/lib/fail_state-nb.lua')
end
if util.file_exists(_path.code.."passthrough") then
local passthru = include 'passthrough/lib/passthrough'
passthru.init()
end
function developer_mode()
params:set("rec_loop_1",2)
params:set("one_shot_clock_div",4)
params:set("one_shot_threshold",70)
end
if util.file_exists(_path.code.."namesizer") then
Namesizer = include 'namesizer/lib/namesizer'
end
function grid.add(dev)
grid_dirty = true
end
midigrid_present = util.file_exists(_path.code.."midigrid") and grid.vports[1].name == 'none'
grid_device = midigrid_present and include "midigrid/lib/mg_128" or grid
function push_to_cc2(encoder, d)
-- translate the bank of 8 encoders to whatever params you want!
local param_map =
{
[1] = "macro 1"
, [2] = nil
, [3] = nil
, [4] = nil
, [5] = nil
, [6] = nil
, [7] = nil
, [8] = nil
}
if param_map[encoder] ~= nil then
params:delta(param_map[encoder], d == 1 and 1 or -1)
end
end
-- if util.file_exists(_path.code.."mx.samples") then
-- mxsamples = include 'mx.samples/lib/mx.samples'
-- engine.name = "MxSamples"
-- mxcc = mxsamples:new()
-- print("available instruments: ")
-- tab.print(mxcc:list_instruments())
-- end
engine.name = 'PolyPerc'
function metronome_audio()
while true do
clock.sync(1)
if params:string("metronome_audio_state") == "on" and transport.is_running then
if util.round(clock.get_beats()%4) == 0 then
engine.hz(params:get("metronome_one_beat_pitch"))
else
engine.hz(params:get("metronome_alt_beat_pitch"))
end
end
end
end
local pattern_time = include 'lib/cc_pattern_time'
MU = require "musicutil"
UI = require "ui"
lattice = require "lattice"
fileselect = require 'fileselect'
textentry = require 'textentry'
main_menu = include 'lib/main_menu'
encoder_actions = include 'lib/encoder_actions'
arc_actions = include 'lib/arc_actions'
rightangleslice = include 'lib/zilchmos'
start_up = include 'lib/start_up'
grid_actions = include 'lib/grid_actions'
easingFunctions = include 'lib/easing'
arps = include 'lib/arp_actions'
rnd = include 'lib/rnd_actions'
del = include 'lib/delay'
rytm = include 'lib/euclid'
mc = include 'lib/midicheat'
-- sharer = include 'lib/sharer'
macros = include 'lib/macros'
transport = include 'lib/transport'
speed_dial = include 'lib/speed_dial'
_lfos = include 'lib/lfos'
_lfos.max_per_group = 9
math.randomseed(os.time())
splash_done = true
actively_loading_collection = false
cc_json = include 'lib/cc_json'
nb = include 'lib/nb/lib/nb'
macro = {}
for i = 1,8 do
macro[i] = macros.new_macro()
end
-- thank you zack (@infinitedigits) for pioneering aubiogo on norns!!!
cursors = {{},{},{}}
detecting_onsets_popup = {}
detected_onsets_popup = {}
osc_fun={
progressbar=function(args)
-- print(args[1],tonumber(args[2]))
detecting_onsets_popup = {state = true, percent = args[2], id = tonumber(string.match(args[1],"%d+"))}
end,
aubiodone=function(args)
local id=tonumber(args[1])
stuff=args[2]
local data=cc_json.parse(stuff)
if data==nil then
print("error getting onset data!")
do return end
end
if data.error~=nil then
print("error getting onset data: "..data.error)
do return end
end
if data.result==nil then
print("no onset results!")
do return end
end
cursors[id] = data.result
if not util.file_exists(_path.data..'/cheat_codes_2/cursors/') then
util.make_dir(_path.data..'/cheat_codes_2/cursors/')
end
tab.save(data.result,_path.data..'/cheat_codes_2/cursors/'..params:string('clip '..id..' sample')..'.cursors')
params:hide('detect_onsets_'..id)
params:show('clear_onsets_'..id)
detecting_onsets_popup = {state = false, percent = nil, id = nil}
detected_onsets_popup = {state = true, id = id}
for b = 1,3 do
for i = 1,16 do
if bank[b][i].mode == 2 and bank[b][i].clip == id then
rightangleslice.start_end_default(bank[b][i])
end
end
end
clock.run(clear_detected_onsets_popup)
_menu.rebuild_params()
-- print(id)
end,
}
function clear_detected_onsets_popup()
clock.sleep(clip[detected_onsets_popup.id].sample_rate < 48000 and 2 or 1)
detected_onsets_popup = {state = false, id = nil}
end
function detect_onsets(id,file)
if util.file_exists(_path.data..'/cheat_codes_2/cursors/'..params:string('clip '..id..' sample')..'.cursors') then
cursors[id] = tab.load(_path.data..'/cheat_codes_2/cursors/'..params:string('clip '..id..' sample')..'.cursors')
params:hide('detect_onsets_'..id)
params:show('clear_onsets_'..id)
detecting_onsets_popup = {state = false, percent = nil, id = nil}
detected_onsets_popup = {state = true, id = id}
for b = 1,3 do
for i = 1,16 do
if bank[b][i].mode == 2 and bank[b][i].clip == id then
rightangleslice.start_end_default(bank[b][i])
end
end
end
clock.run(clear_detected_onsets_popup)
_menu.rebuild_params()
else
os.execute(_path.code.."zxcvbn/lib/aubiogo/aubiogo --id "..id.." --filename '"..file.."' --num 16 &")
end
end
SOS = {}
function SOS.sync_to_recordhead(source,target)
-- expects source: x, target: bank[x][y]
if target.mode == 1 and target.clip == source then
softcut.loop_start(target.bank_id+1,rec[source].start_point)
softcut.loop_end(target.bank_id+1,rec[source].end_point)
-- softcut.voice_sync(target.bank_id,0,0.1)
softcut.position(target.bank_id+1,poll_position_new[1]+0.01)
softcut.loop(target.bank_id+1,1)
target.start_point = rec[source].start_point
target.end_point = rec[source].end_point
target.loop = true
end
end
function SOS.voice_overwrite(target)
-- this should just 1:1 replace the corresponding Live clip
softcut.pre_level(target.bank_id+1,1)
softcut.rec_level(target.bank_id+1,1)
softcut.level_input_cut(1,target.bank_id+1,1)
softcut.level_input_cut(2,target.bank_id+1,1)
softcut.rec(target.bank_id+1,1)
end
function SOS.voice_sync(source,target)
-- expects source: bank[x][y], target: bank[z][a]
softcut.loop_start(target.bank_id+1,source.start_point)
softcut.loop_end(target.bank_id+1,source.end_point)
softcut.position(target.bank_id+1,poll_position_new[source.bank_id+1])
target.start_point = source.start_point
target.end_point = source.end_point
end
function make_a_gif(filename,time)
local steps = time*24
local gif_step = 1
local dirnames = {"/home/we/dust/tmp", "/home/we/dust/tmp/frames"}
for i = 1,2 do
if os.rename(dirnames[i], dirnames[i]) == nil then
os.execute("mkdir " .. dirnames[i])
end
end
while gif_step <= steps do
_norns.screen_export_png("/home/we/dust/tmp/frames/"..string.format("%04d",gif_step)..".gif")
gif_step = gif_step + 1
clock.sleep(1/24)
end
print("creating gif...")
os.execute("convert -delay "..(100/24).." -dispose previous -loop 0 /home/we/dust/tmp/frames/*.gif "..'home/we/dust/gifs/'..filename..'.gif')
-- print("converting gif...")
-- os.execute("convert home/we/dust/image.gif -gamma 1.25 -filter point -resize 400% -gravity center -background black -extent 120% home/we/dust/image.gif")
os.execute("rm -r /home/we/dust/tmp/frames/")
print("done!")
end
function record_screen(state)
if state == 1 then
gif_step = 1
recording_screen = true
else
recording_screen = false
end
end
function screenshot()
if recording_screen then
-- os.execute("mkdir /home/we/dust/tmp")
-- os.execute("mkdir /home/we/dust/tmp/frames")
-- local which_screen = string.match(string.match(string.match(norns.state.script,"/home/we/dust/code/(.*)"),"/(.*)"),"(.+).lua")
-- _norns.screen_export_png("/home/we/dust/"..which_screen.."-"..os.time()..".png")
_norns.screen_export_png("/home/we/dust/"..gif_step..".png")
gif_step = gif_step + 1
end
end
-- waveform stuff
local interval = 0
waveform_samples = {}
scale = 25
function on_render(ch, start, i, s)
-- cursor = util.clamp(cursor, 1, #s)
waveform_samples = s
interval = i
-- if menu ~= 1 then screen_dirty = true end
if ch == 2 then
if start < 33 then
clip[1].waveform_samples = s
elseif start < 65 then
clip[2].waveform_samples = s
else
clip[3].waveform_samples = s
end
elseif ch == 1 then
if start < 9 then
rec[1].waveform_samples = s
elseif start < 17 then
rec[2].waveform_samples = s
else
rec[3].waveform_samples = s
end
end
end
function update_waveform(buffer,winstart,winend,samples)
softcut.render_buffer(buffer, winstart, winend - winstart, 128)
end
--/ waveform stuff
function r()
norns.script.load(norns.state.script)
end
tau = math.pi * 2
arc_param = {}
arc_switcher = {}
for i = 1,3 do
arc_param[i] = 1
--arc_switcher[i] = 0
arc_switcher[i] = {}
end
arc_control = {}
for i = 1,3 do
arc_control[i] = i
end
arc_meta_focus = 1
arc_offset = 0 --IMPORTANT TO REVISIT
clip = {}
for i = 1,3 do
clip[i] = {}
clip[i].length = 90
clip[i].sample_length = 8
clip[i].start_point = nil
clip[i].end_point = nil
clip[i].mode = 1
clip[i].waveform_samples = {}
clip[i].waveform_rendered = false
end
pre_cc2_sample = { false, false, false }
clip[1].min = 1
clip[1].max = 1 + clip[1].sample_length
clip[2].min = 33
clip[2].max = clip[2].min + clip[2].sample_length
clip[3].min = 65
clip[3].max = clip[3].min + clip[3].sample_length
live = {}
for i = 1,3 do
live[i] = {}
live[i].waveform_samples = {}
end
live[1].min = 1
live[1].max = 9
live[2].min = 9
live[2].max = 17
live[3].min = 17
live[3].max = 25
help_menu = "welcome"
function f1()
softcut.post_filter_lp(2,0)
softcut.post_filter_hp(2,1)
softcut.post_filter_fc(2,10)
params:set("filter 1 cutoff",10)
end
function f2()
softcut.post_filter_hp(2,0)
softcut.post_filter_lp(2,1)
softcut.post_filter_fc(2,12000)
params:set("filter 1 cutoff",12000)
end
pattern_saver = { {},{},{} }
for i = 1,3 do
pattern_saver[i].active = false
pattern_saver[i].source = i
pattern_saver[i].save_slot = nil
pattern_saver[i].load_slot = 0
pattern_saver[i].saved = {}
pattern_saver[i].clock = nil
for j = 1,8 do
pattern_saver[i].saved[j] = 0
end
end
env_counter = {}
for i = 1,3 do
env_counter[i] = metro.init()
env_counter[i].time = 0.01
env_counter[i].butt = 1
env_counter[i].l_del_butt = 0
env_counter[i].r_del_butt = 0
env_counter[i].stage = nil
-- env_counter[i].mode = 1 -- this needs to be per pad!!
env_counter[i].event = function() envelope(i) end
end
slew_counter = {}
for i = 1,3 do
slew_counter[i] = metro.init()
slew_counter[i].time = 0.01
slew_counter[i].count = 100
slew_counter[i].current = 0.00
slew_counter[i].event = function() easing_slew(i) end
slew_counter[i].ease = easingFunctions.inSine
slew_counter[i].beginVal = 0
slew_counter[i].endVal = 1
slew_counter[i].change = slew_counter[i].endVal - slew_counter[i].beginVal
slew_counter[i].beginQ = 0
slew_counter[i].endQ = 0
slew_counter[i].changeQ = slew_counter[i].endQ - slew_counter[i].beginQ
slew_counter[i].duration = (slew_counter[i].count/100)-0.01
slew_counter[i].slewedVal = 0
slew_counter[i].prev_tilt = 0
slew_counter[i].next_tilt = 0
slew_counter[i].prev_q = 0
slew_counter[i].next_q = 0
end
quantize = 1
quantize_events = {}
for i = 1,3 do
quantize_events[i] = {}
end
grid_pat_quantize = 1
grid_pat_quantize_events = {}
for i = 1,3 do
grid_pat_quantize_events[i] = {}
end
function cheat_clock_synced(i)
if quantize_events[i].bank ~= nil then
cheat(quantize_events[i].bank,quantize_events[i].pad)
quantize_events[i] = {}
end
end
function how_many_bars(bank)
local total_pattern_time = 0
for i = 1,#grid_pat[bank].event do
total_pattern_time = total_pattern_time + grid_pat[bank].time[i]
end
local time_per_bar = clock.get_beat_sec()*4
local this_many_bars = math.floor((total_pattern_time/time_per_bar)+0.5)
-- need at least ONE bar, so...
if this_many_bars == 0 then this_many_bars = 1 end
return this_many_bars
end
function better_grid_pat_q_clock(i)
if grid_pat[i].rec == 1 then
grid_pat[i]:rec_stop()
midi_clock_linearize(i)
grid_pat[i].loop = 1
if grid_pat[i].count > 0 then
grid_pat[i].tightened_start = 1
if grid_pat[i].auto_snap == 1 then
print("auto-snap")
snap_to_bars(i,how_many_bars(i))
end
end
elseif grid_pat[i].count == 0 then
grid_pat[i]:rec_start()
elseif grid_pat[i].play == 1 then
grid_pat[i]:stop()
elseif grid_pat[i].tightened_start == 1 then
grid_pat[i].tightened_start = 0
grid_pat[i].step = grid_pat[i].start_point
quantized_grid_pat[i].current_step = grid_pat[i].start_point
quantized_grid_pat[i].sub_step = 1
else
grid_pat[i].tightened_start = 1
end
end
function snap_to_bars(bank,bar_count)
if grid_pat[bank].rec == 0 and grid_pat[bank].count > 0 then
local total_time = 0
for i = 1,#grid_pat[bank].event do
total_time = total_time + grid_pat[bank].time[i]
end
print("before total: "..total_time)
if old_pat_time == nil then
old_pat_time = table.clone(grid_pat[bank].time)
end
local bar_time = ((clock.get_beat_sec()*4)*bar_count)/total_time
for k = 1,grid_pat[bank].count do
grid_pat[bank].time[k] = grid_pat[bank].time[k] * bar_time
end
total_time = 0
for i = 1,#grid_pat[bank].event do
total_time = total_time + grid_pat[bank].time[i]
end
print("after total: "..total_time)
snap_to_bars_midi(bank,bar_count)
end
end
local snakes =
{ [1] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
, [2] = { 1,2,3,4,8,7,6,5,9,10,11,12,16,15,14,13 }
, [3] = { 1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16 }
, [4] = { 1,5,9,13,14,10,6,2,3,7,11,15,16,12,8,4 }
, [5] = { 1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 }
, [6] = { 13,14,15,16,12,8,4,3,2,1,5,9,10,11,7,6 }
, [7] = { 1,2,5,9,6,3,4,7,10,13,14,11,8,12,15,16 }
, [8] = { 1,6,11,16,15,10,5,2,7,12,8,3,9,14,13,4 }
}
function random_grid_pat(which,mode)
print(mode)
local pattern = grid_pat[which]
-- if pattern.playmode == 1 then
-- pattern.playmode = 2
-- pattern.rec_clock_time = 8
-- end
if mode == 1 then
for i = #pattern.time,2,-1 do
local j = math.random(i)
pattern.time[i], pattern.time[j] = pattern.time[j], pattern.time[i]
end
elseif mode == 2 then
stop_pattern(pattern)
for i = #pattern.event,2,-1 do
local j = math.random(i)
local original, shuffled = pattern.event[i], pattern.event[j]
if original ~= "pause" and shuffled ~= "pause" then
original.id, shuffled.id = shuffled.id, original.id
original.rate, shuffled.rate = shuffled.rate, original.rate
original.loop, shuffled.loop = shuffled.loop, original.loop
original.mode, shuffled.mode = shuffled.mode, original.mode
original.pause, shuffled.pause = shuffled.pause, original.pause
original.start_point, shuffled.start_point = shuffled.start_point, original.start_point
original.clip, shuffled.clip = shuffled.clip, original.clip
original.end_point = original.end_point
original.rate_adjusted, shuffled.rate_adjusted = shuffled.rate_adjusted, original.rate_adjusted
original.y, shuffled.y = shuffled.y, original.y
original.x, shuffled.x = shuffled.x, original.x
original.action, shuffled.action = shuffled.action, original.action
original.i, shuffled.i = shuffled.i, original.i
original.previous_rate, shuffled.previous_rate = shuffled.previous_rate, original.previous_rate
original.row, shuffled.row = shuffled.row, original.row
original.con, shuffled.con = shuffled.con, original.con
original.bank, shuffled.bank = shuffled.bank, original.bank
else
original, shuffled = shuffled, original
end
end
elseif mode == 3 then
local auto_pat = params:get("random_patterning_"..which)
if auto_pat ~= 1 then
-- params:set("pattern_"..which.."_quantization", 2)
local vals_to_dur = {4,8,16,32,64,math.random(4,32)}
local note_val = params:get("rand_pattern_"..which.."_note_length")
pattern.rec_clock_time = vals_to_dur[note_val]
end
if pattern.playmode == 3 or pattern.playmode == 4 then
pattern.playmode = 2
end
local potential_total = pattern.rec_clock_time*4
-- local count = auto_pat == 1 and math.random(2,24) or 16
local count = auto_pat == 1 and (pattern.rec_clock_time * 4) or 16
if pattern.count > 0 or pattern.rec == 1 then
pattern:rec_stop()
stop_pattern(pattern)
pattern.tightened_start = 0
pattern:clear()
pattern_saver[which].load_slot = 0
end
for i = 1,count do
pattern.event[i] = {}
local constructed = pattern.event[i]
constructed.id = auto_pat == 1 and math.random(1,16) or snakes[auto_pat-1][i]
local assigning_pad = bank[which][constructed.id]
local new_rates =
{ [1] = math.pow(2,math.random(-3,-1))*((math.random(1,2)*2)-3)
, [2] = math.pow(2,math.random(-1,1))*((math.random(1,2)*2)-3)
, [3] = math.pow(2,math.random(1,2))*((math.random(1,2)*2)-3)
, [4] = math.pow(2,math.random(-2,2))*((math.random(1,2)*2)-3)
, [5] = assigning_pad.rate
}
constructed.rate = new_rates[pattern.random_pitch_range]
local pre_rate = assigning_pad.rate
assigning_pad.rate = constructed.rate
local new_levels =
{ [0.125] = 1.75
, [0.25] = 1.5
, [0.5] = 1.25
, [1.0] = 1.0
, [2.0] = 0.75
, [4.0] = 0.5
}
if pre_rate == assigning_pad.rate then
assigning_pad.level = assigning_pad.level
else
assigning_pad.level = assigning_pad.level == 0 and 0 or new_levels[math.abs(constructed.rate)]
end
constructed.loop = assigning_pad.loop
constructed.mode = assigning_pad.mode
constructed.pause = assigning_pad.pause
constructed.start_point = (math.random(10,75)/10)+(8*(assigning_pad.clip-1))
constructed.clip = assigning_pad.clip
constructed.end_point = constructed.start_point + (math.random(1,15)/10)
constructed.rate_adjusted = false
assigning_pad.fifth = false
constructed.x = (5*(which-1)+1)+(math.ceil(constructed.id/4)-1)
if (constructed.id % 4) ~= 0 then
constructed.y = 9-(constructed.id % 4)
else
constructed.y = 5
end
constructed.action = "pads"
constructed.i = which
local tempo = clock.get_beat_sec()
local divisors = { 4,2,1,0.5,0.25,math.pow(2,math.random(-2,2)) }
local note_length = (tempo / divisors[params:get("rand_pattern_"..which.."_note_length")])
pattern.time[i] = note_length
pattern.time_beats[i] = pattern.time[i] / tempo
pattern:calculate_quantum(i)
end
pattern.count = count
pattern.start_point = 1
pattern.end_point = count
end
midi_clock_linearize(which)
if pattern.quantize == 0 then
if pattern.auto_snap == 1 then
print("auto-snap")
snap_to_bars(which,how_many_bars(which))
end
start_pattern(pattern)
pattern.loop = 1
else
pattern.loop = 1
if pattern.count > 0 then
pattern.tightened_start = 1
if pattern.auto_snap == 1 then
print("auto-snap")
snap_to_bars(which,how_many_bars(which))
end
end
end
end
function print_my_g_p_q(bank)
for i = #quantized_grid_pat[bank].event,1,-1 do
print(i)
tab.print(quantized_grid_pat[bank].event[i])
end
end
function snap_to_bars_midi(bank,bar_count)
local entry_count = 0
local target_entry_count = bar_count*16
for i = 1,#quantized_grid_pat[bank].event do
entry_count = entry_count + #quantized_grid_pat[bank].event[i]
end
print("before trimming midi event count: "..entry_count)
if entry_count < target_entry_count then
for i = 1,target_entry_count-entry_count do
table.insert(quantized_grid_pat[bank].event[#quantized_grid_pat[bank].event],"nothing")
end
elseif entry_count > target_entry_count then
--print("subtracting...")
local last_event = #quantized_grid_pat[bank].event
local last_group = #quantized_grid_pat[bank].event
--print("last event: "..last_event)
local distance_count = entry_count - target_entry_count
print("removing "..distance_count.." event")
local current_count = 0
while current_count < distance_count do
if last_group > 0 then
if #quantized_grid_pat[bank].event[last_group] > 1 and quantized_grid_pat[bank].event[last_group][#quantized_grid_pat[bank].event[last_group]] == "nothing" then
local check_table = #quantized_grid_pat[bank].event
--print("removing: "..quantized_grid_pat[bank].event[last_group][#quantized_grid_pat[bank].event[last_group]].." from group "..last_group..", entry "..#quantized_grid_pat[bank].event[last_group])
table.remove(quantized_grid_pat[bank].event[last_group])
current_count = current_count + 1
if current_count == distance_count then print("done now!") break end
--print("current count :" .. current_count)
elseif #quantized_grid_pat[bank].event[last_group] == 1 and quantized_grid_pat[bank].event[last_group][#quantized_grid_pat[bank].event[last_group]] == "something" then
--print("skipping: "..quantized_grid_pat[bank].event[last_group][#quantized_grid_pat[bank].event[last_group]].." from group "..last_group..", entry "..#quantized_grid_pat[bank].event[last_group])
last_group = last_group - 1
elseif #quantized_grid_pat[bank].event[last_group] == 1 and quantized_grid_pat[bank].event[last_group][#quantized_grid_pat[bank].event[last_group]] == "nothing" then
--print("there's only nothing in group "..last_group..", but removing it")
table.remove(quantized_grid_pat[bank].event[last_group])
--print_my_g_p_q(1)
current_count = current_count + 1
if current_count == distance_count then print("done now!") break end
--print("current count :" .. current_count)
last_group = last_group - 1
elseif quantized_grid_pat[bank].event[last_group][#quantized_grid_pat[bank].event[last_group]] == nil then
--print("A NIL IN"..last_group)
table.remove(quantized_grid_pat[bank].event,last_group)
last_group = last_group - 1
--break
end
elseif last_group == 0 then
--print("still got some left!!!: "..current_count.." / "..distance_count)
table.remove(quantized_grid_pat[bank].event)
current_count = current_count + 1
end
end
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point
quantized_grid_pat[bank].sub_step = 1
end
local entry_count = 0
for i = 1,#quantized_grid_pat[bank].event do
entry_count = entry_count + #quantized_grid_pat[bank].event[i]
end
print("after trimming midi event count: "..entry_count)
if entry_count ~= target_entry_count then
--doubletap? is this ok??
snap_to_bars_midi(bank,bar_count)
end
end
function copy_entire_pattern(bank)
original_pattern = {}
original_pattern[bank] = {}
original_pattern[bank].time = table.clone(grid_pat[bank].time)
original_pattern[bank].event = {}
for i = 1,#grid_pat[bank].event do
original_pattern[bank].event[i] = {}
-- new stuff!
if grid_pat[bank].event[i] ~= "pause" then
for k,v in pairs(grid_pat[bank].event[i]) do
original_pattern[bank].event[i][k] = v
end
else
original_pattern[bank].event[i] = "pause"
end
end
original_pattern[bank].quantum = {}
for k,v in pairs(grid_pat[bank].quantum) do
original_pattern[bank].quantum[k] = v
end
original_pattern[bank].time_beats = {}
for k,v in pairs(grid_pat[bank].time_beats) do
original_pattern[bank].time_beats[k] = v
end
-- /new stuff!
original_pattern[bank].metro = {}
original_pattern[bank].metro.props = {}
original_pattern[bank].metro.props.time = grid_pat[bank].metro.props.time
original_pattern[bank].prev_time = grid_pat[bank].prev_time
original_pattern[bank].count = grid_pat[bank].count
original_pattern[bank].start_point = grid_pat[bank].start_point
original_pattern[bank].end_point = grid_pat[bank].end_point
original_pattern[bank].mode = grid_pat[bank].mode
-- new stuff
original_pattern[bank].rec_clock_time = grid_pat[bank].rec_clock_time
--/ new stuff
if grid_pat[bank].playmode ~= nil then
if grid_pat[bank].playmode ~= 1 then
original_pattern[bank].playmode = 2
else
original_pattern[bank].playmode = 1
end
else
original_pattern[bank].playmode = 1
end
end
function copy_metatable(obj)
if type(obj) ~= 'table' then return obj end
local res = setmetatable({}, getmetatable(obj))
for k, v in pairs(obj) do res[copy_metatable(k)] = copy_metatable(v) end
return res
end
function commit_midi_to_disk(target)
end
function update_pattern_bpm(bank)
grid_pat[bank].time_factor = 1*(synced_to_bpm/bpm)
end
function table.clone(org)
return {table.unpack(org)}
end
function midi_clock_linearize(bank)
quantized_grid_pat[bank].event = {}
for i = 1,grid_pat[bank].count do
quantized_grid_pat[bank].clicks[i] = math.floor((grid_pat[bank].time[i] / (clock.get_beat_sec()/4))+0.5)
quantized_grid_pat[bank].event[i] = {} -- critical
if grid_pat[bank].time[i] == 0 or quantized_grid_pat[bank].clicks[i] == 0 then
quantized_grid_pat[bank].event[i][1] = "nothing"
else
for j = 1,quantized_grid_pat[bank].clicks[i] do
if j == 1 then
quantized_grid_pat[bank].event[i][1] = "something"
else
quantized_grid_pat[bank].event[i][j] = "nothing"
end
end
end
end
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point
quantized_grid_pat[bank].sub_step = 1
end
function midi_clock_linearize_overdub(bank)
local curr = quantized_grid_pat[bank].current_step + 1
local sub = quantized_grid_pat[bank].sub_step
local removed = #quantized_grid_pat[bank].event[quantized_grid_pat[bank].current_step] - quantized_grid_pat[bank].sub_step
for i = quantized_grid_pat[bank].sub_step,#quantized_grid_pat[bank].event[quantized_grid_pat[bank].current_step] do
table.remove(quantized_grid_pat[bank].event[curr-1],sub)
end
table.insert(quantized_grid_pat[bank].event,curr,{"something"})
if removed ~= 0 then
for i = 1,removed do
table.insert(quantized_grid_pat[bank].event[curr],"nothing")
end
end
if quantized_grid_pat[bank].current_step < grid_pat[bank].end_point then
quantized_grid_pat[bank].current_step = quantized_grid_pat[bank].current_step + 1
else
quantized_grid_pat[bank].current_step = 1
end
quantized_grid_pat[bank].sub_step = 1
end
key1_hold = false
key1_hold_and_modify = false
function count_key2()
clock.sleep(0.25)
key2_hold = true
screen_dirty = true
end
key2_hold = false
key2_hold_and_modify = false
grid_alt = false
grid_loop_mod = 0
local function crow_flush()
norns.crow.init() -- clears & inits both crow & norns-support-of-crow
end
local function crow_init()
for i = 1,4 do
crow.output[i].action = "{to(5,0),to(0,0.05)}"
print("output["..i.."] initialized")
end
crow.input[2].mode("change",2,0.1,"rising")
crow.input[2].change = buff_freeze
end
-- crow hotplug support
norns.crow.add = function()
norns.crow.init()
crow_init()
if params:get("jf_toggle") == 2 then
crow.ii.jf.mode(1)
end
end
local function process_stream_1(v)
params:set("macro 1",util.round(util.linlin(0,params:get("crow input 1 max voltage"),0,127,v)))
end
local function process_stream_2(v)
params:set("macro 2",util.round(util.linlin(0,params:get("crow input 2 max voltage"),0,127,v)))
end
function set_crow_input(id,type)
if type == 3 then
crow.input[id].mode("stream",0.05)
if id == 1 then
crow.input[1].stream = process_stream_1
elseif id == 2 then
crow.input[2].stream = process_stream_2
end
elseif type == 2 then
crow.input[id].mode("change",2,0.1,"rising")
crow.input[id].change = buff_freeze
elseif type == 4 then
crow.input[id].mode("change",2,0.1,"rising")
crow.input[id].change = transport.crow_toggle
elseif type == 5 then
crow.input[id].mode("change",2,0.1,"both")
crow.input[id].change = transport.crow_toggle
elseif type == 6 then
crow.input[id].mode("change",2,0.1,"rising")
crow.input[id].change = transport.crow_toggle_now
elseif type == 1 then
crow.input[id].mode('none')
end
end
local lit = {}
zilch_leds =
{ [1] = {{0},{0},{0}}
, [2] = {{0,0},{0,0},{0,0}}
, [3] = {{0,0,0},{0,0,0},{0,0,0}}
, [4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0}}
}
function init()
type_of_pattern_loaded = {"grid","grid","grid"}
loading_arp_from_grid = {nil,nil,nil}
loading_euclid_from_grid = {nil,nil,nil}
loading_free_from_grid = {nil,nil,nil}
engine.release(0.1)
amp_in = {}
local amp_src = {"amp_in_l","amp_in_r"}
for i = 1,2 do
amp_in[i] = poll.set(amp_src[i])
amp_in[i].time = 0.01
amp_in[i].callback = function(val)
if val > params:get("one_shot_threshold")/10000 then
if rec[rec.focus].state == 0 then
toggle_buffer(rec.focus)
end
amp_in[i]:stop()
end
end
end
-- sharer.setup("cheat_codes_2")
clock.run(check_page_for_k1)
collection_loaded = false
all_loaded = false
ec4_focus = false -- to check for EC4 focus hold
ec4_shift = false -- to check if EC4 fine tune/secondary mode is enabled
for i = 1,3 do
norns.enc.sens(i,2)
end
grid_p = {}
arc_p = {}
midi_p = {}
rec = {}
rec.state = 1
rec.pause = false
rec.clip = 1
rec.start_point = 1
rec.end_point = 9
rec.loop = 1
rec.clear = 0
rec.rate_offset = 1.0
rec.stopped = false
rec.play_segment = 1
rec.focus = 1
for i = 1,3 do
rec[i] = {}
rec[i].state = 0
rec[i].pause = false
rec[i].clip = 1
rec[i].start_point = 1+(8*(i-1))
rec[i].end_point = 9+(8*(i-1))
rec[i].loop = 1
rec[i].clear = 1
rec[i].rate_offset = 1.0
rec[i].waveform_samples = {}
rec[i].queued = false
rec[i].last_purged = 0
end
rec.transport_queued = false
params:add_group("GRID/ARC",6)
params:add_option("LED_style","grid LED style",{"varibright","4-step","grayscale"},1)
params:set_action("LED_style",
function()
grid_dirty = true
if all_loaded then
persistent_state_save()
end
end)
params:add_option("grid_size","grid size",{"128/256","64"},1)
params:set_action("grid_size",
function(x)
if x == 1 then
if g.cols * g.rows == 256 then