This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cheat_codes.lua
executable file
·3326 lines (3121 loc) · 112 KB
/
cheat_codes.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
-- a sample playground
--
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- need help?
-- please see [?] menu
-- for in-app instruction manual
-- -------------------------------
local pattern_time = include 'lib/cc_pattern_time'
fileselect = require 'fileselect'
help_menus = include 'lib/help_menus'
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'
math.randomseed(os.time())
tau = math.pi * 2
arc_param = {}
arc_switcher = {}
for i = 1,3 do
arc_param[i] = 1
arc_switcher[i] = 0
end
arc_control = {}
for i = 1,3 do
arc_control[i] = i
end
arc_offset = 0 --IMPORTANT TO REVISIT
clip = {}
for i = 1,3 do
clip[i] = {}
clip[i].length = 90
clip[i].sample_length = nil
clip[i].start_point = nil
clip[i].end_point = nil
clip[i].mode = 1
end
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] = metro.init()
pattern_saver[i].time = 1
pattern_saver[i].count = 1
pattern_saver[i].event = function() test_save(i) end
pattern_saver[i].source = i
pattern_saver[i].save_slot = nil
pattern_saver[i].load_slot = 0
pattern_saver[i].saved = {}
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].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
--[[
grid_pat_quantizer = {}
for i = 1,3 do
grid_pat_quantizer[i] = {}
grid_pat_quantizer[i] = metro.init()
grid_pat_quantizer[i].time = 0.25
grid_pat_quantizer[i].count = -1
--grid_pat_quantizer[i].event = function() grid_pat_q_clock(i) end
grid_pat_quantizer[i].event = function() end
grid_pat_quantizer[i]:start()
end
--]]
function cheat_clock_synced(i)
if #quantize_events[i] > 0 then
for k,e in pairs(quantize_events[i]) do
cheat(i,e)
grid_p[i] = {}
grid_p[i].action = "pads"
grid_p[i].i = i
grid_p[i].id = selected[i].id
grid_p[i].x = selected[i].x
grid_p[i].y = selected[i].y
grid_p[i].rate = bank[i][bank[i].id].rate
grid_p[i].pause = bank[i][bank[i].id].pause
grid_p[i].start_point = bank[i][bank[i].id].start_point
grid_p[i].end_point = bank[i][bank[i].id].end_point
grid_p[i].rate_adjusted = false
grid_p[i].loop = bank[i][bank[i].id].loop
grid_p[i].mode = bank[i][bank[i].id].mode
grid_p[i].clip = bank[i][bank[i].id].clip
grid_pat[i]:watch(grid_p[i])
end
quantize_events[i] = {}
end
end
function set_pattern_mode(bank)
grid_pat[bank].step = grid_pat[bank].start_point
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point
quantized_grid_pat[bank].sub_step = 1
if grid_pat[bank].playmode == 1 then
grid_pat[bank].quantize = 0
grid_pat[bank].auto_snap = 0
if grid_pat[bank].tightened_start == 1 then
grid_pat[bank].tightened_start = 0
grid_pat[bank]:start()
end
elseif grid_pat[bank].playmode == 2 then
grid_pat[bank].quantize = 0
grid_pat[bank].auto_snap = 1
if grid_pat[bank].tightened_start == 1 then
grid_pat[bank].tightened_start = 0
grid_pat[bank]:start()
end
elseif grid_pat[bank].playmode == 3 then
grid_pat[bank].quantize = 1
grid_pat[bank].auto_snap = 0
if grid_pat[bank].play == 1 then
grid_pat[bank]:stop()
grid_pat[bank].tightened_start = 1
end
elseif grid_pat[bank].playmode == 4 then
grid_pat[bank].quantize = 1
grid_pat[bank].auto_snap = 1
if grid_pat[bank].play == 1 then
grid_pat[bank]:stop()
grid_pat[bank].tightened_start = 1
end
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 = (60/bpm)*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 = (((60/bpm)*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
function random_grid_pat(which,mode)
local pattern = grid_pat[which]
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
for i = #pattern.event,2,-1 do
local j = math.random(i)
local original, shuffled = pattern.event[i], pattern.event[j]
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
end
elseif mode == 3 then
if pattern.playmode == 3 or pattern.playmode == 4 then
clock.sync(1/4)
end
local count = math.random(2,24)
if pattern.count > 0 or pattern.rec == 1 then
pattern:rec_stop()
pattern:stop()
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 = math.random(1,16)
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)
}
constructed.rate = new_rates[pattern.random_pitch_range]
local assigning_pad = bank[which][constructed.id]
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
}
assigning_pad.level = new_levels[math.abs(constructed.rate)]
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
pattern.time[i] = (60/bpm) / math.pow(2,math.random(-2,2))
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
pattern:start()
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 save_external_timing(bank,slot)
local dirname = _path.data.."cheat_codes/external-timing/"
if os.rename(dirname, dirname) == nil then
os.execute("mkdir " .. dirname)
end
local file = io.open(_path.data .. "cheat_codes/external-timing/pattern"..selected_coll.."_"..slot.."_external-timing.data", "w+")
io.output(file)
io.write("external clock timing for stored pad pattern: collection "..selected_coll.." + slot "..slot.."\n")
local total_entry_count = 0
local number_of_events = #quantized_grid_pat[bank].event
for i = 1,number_of_events do
total_entry_count = total_entry_count + #quantized_grid_pat[bank].event[i]
end
io.write(total_entry_count.."\n")
io.write(number_of_events.."\n")
for i = 1,number_of_events do
io.write("event: "..i.."\n")
io.write("total entries: "..#quantized_grid_pat[bank].event[i].."\n")
for j = 1,#quantized_grid_pat[bank].event[i] do
io.write(quantized_grid_pat[bank].event[i][j].."\n")
end
end
io.close(file)
print("saved external timing for pattern "..bank.." to slot "..slot)
end
function load_external_timing(bank,slot)
local file = io.open(_path.data .. "cheat_codes/external-timing/pattern"..selected_coll.."_"..slot.."_external-timing.data", "r")
if file then
io.input(file)
if io.read() == "external clock timing for stored pad pattern: collection "..selected_coll.." + slot "..slot then
quantized_grid_pat[bank].event = {}
local total_entry_count = tonumber(io.read())
local number_of_events = tonumber(io.read())
for i = 1,number_of_events do
local event_id = tonumber(string.match(io.read(), '%d+'))
local entry_count = tonumber(string.match(io.read(), '%d+'))
quantized_grid_pat[bank].event[i] = {}
for j = 1,entry_count do
quantized_grid_pat[bank].event[i][j] = io.read()
end
end
end
io.close(file)
else
print("creating external timing file...")
midi_clock_linearize(bank)
save_external_timing(bank,slot)
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] = {}
for k,v in pairs(grid_pat[bank].event[i]) do
original_pattern[bank].event[i][k] = v
end
end
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
if grid_pat[bank].playmode ~= nil then
original_pattern[bank].playmode = grid_pat[bank].playmode
else
original_pattern[bank].playmode = 1
end
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] / ((60/bpm)/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
key1_hold = false
grid.alt = 0
grid.alt_pp = 0
grid.loop_mod = 0
local function crow_flush()
crow.reset()
crow.clear()
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
local lit = {}
function init()
grid_p = {}
arc_p = {}
rec = {}
rec.state = 1
rec.clip = 1
rec.start_point = 1
rec.end_point = 9
rec.loop = 1
rec.clear = 0
params:add_separator("cheat codes params")
params:add_group("collections",4)
params:add_number("collection", "collection", 1,100,1)
params:add{type = "trigger", id = "load", name = "load", action = loadstate}
params:add_option("collect_live","collect Live buffers?",{"no","yes"})
params:add{type = "trigger", id = "save", name = "save", action = savestate}
menu = 1
for i = 1,4 do
crow.output[i].action = "{to(5,0),to(0,0.05)}"
end
crow.count = {}
crow.count_execute = {}
for i = 1,3 do
crow.count[i] = 1
crow.count_execute[i] = 1
end
screen.line_width(1)
local etap = 0
local edelta = 1
local prebpm = 110
clock_counting = 0
grid_pat = {}
for i = 1,3 do
grid_pat[i] = pattern_time.new()
grid_pat[i].process = grid_pattern_execute
grid_pat[i].tightened_start = 0
grid_pat[i].auto_snap = 0
grid_pat[i].quantize = 0
grid_pat[i].playmode = 1
grid_pat[i].random_pitch_range = 4
end
quantized_grid_pat = {}
for i = 1,3 do
quantized_grid_pat[i] = {}
quantized_grid_pat[i].clicks = {}
quantized_grid_pat[i].event = {}
quantized_grid_pat[i].sub_step = 1
quantized_grid_pat[i].current_step = grid_pat[i].start_point
end
step_seq = {}
for i = 1,3 do
step_seq[i] = {}
step_seq[i].active = 1
step_seq[i].current_step = 1
step_seq[i].current_pat = nil
step_seq[i].rate = 1
step_seq[i].start_point = 1
step_seq[i].end_point = 16
step_seq[i].length = (step_seq[i].end_point - step_seq[i].start_point) + 1
step_seq[i].meta_step = 1
step_seq[i].meta_duration = 1
step_seq[i].meta_meta_step = 1
step_seq[i].held = 0
for j = 1,16 do
step_seq[i][j] = {}
step_seq[i][j].meta_meta_duration = 4
step_seq[i][j].assigned = 0 --necessary?
step_seq[i][j].assigned_to = 0
step_seq[i][j].loop_pattern = 1
end
step_seq[i].meta_meta_duration = 4
step_seq[i].loop_held = 0
end
function internal_clocking_tightened(bank)
local current = quantized_grid_pat[bank].current_step
local sub_step = quantized_grid_pat[bank].sub_step
if current == 0 then
current = grid_pat[bank].start_point
end
if grid_pat[bank].tightened_start == 1 and grid_pat[bank].count > 0 then
if quantized_grid_pat[bank].event[current][sub_step] == "something" then
--print(current, sub_step, "+++")
if grid_pat[bank].step == 0 then
grid_pat[bank].step = grid_pat[bank].start_point
end
if quantized_grid_pat[bank].current_step == 0 then
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point
end
grid_pattern_execute(grid_pat[bank].event[quantized_grid_pat[bank].current_step])
elseif quantized_grid_pat[bank].event[current][sub_step] == "nothing" then
-- nothing!
if grid_pat[bank].step == 0 then
grid_pat[bank].step = grid_pat[bank].start_point
end
if quantized_grid_pat[bank].current_step == 0 then
print("if you see this message, tell dan!")
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point
end
elseif quantized_grid_pat[bank].event[current][sub_step] == nil and #quantized_grid_pat[bank].event == grid_pat[bank].end_point then
print(current.." is nil!")
table.remove(quantized_grid_pat[bank].event,current)
grid_pat[bank].end_point = grid_pat[bank].end_point - 1
quantized_grid_pat[bank].current_step = quantized_grid_pat[bank].current_step + 1
quantized_grid_pat[bank].sub_step = 1
end
--increase sub_step now
--if quantized_grid_pat[bank].current_step > #quantized_grid_pat[bank].event or quantized_grid_pat[bank].current_step > #grid_pat[bank].event then
if quantized_grid_pat[bank].current_step > grid_pat[bank].end_point then
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point
end
if quantized_grid_pat[bank].sub_step == #quantized_grid_pat[bank].event[quantized_grid_pat[bank].current_step] then
quantized_grid_pat[bank].sub_step = 0
--if we're at the end of the events in this step, move to the next step
if grid_pat[bank].step == grid_pat[bank].end_point then
grid_pat[bank].step = 0
--quantized_grid_pat[bank].current_step = 0
end
--if quantized_grid_pat[bank].current_step == #quantized_grid_pat[bank].event then
if quantized_grid_pat[bank].current_step == grid_pat[bank].end_point then
quantized_grid_pat[bank].current_step = grid_pat[bank].start_point - 1
end
grid_pat[bank].step = grid_pat[bank].step + 1
quantized_grid_pat[bank].current_step = quantized_grid_pat[bank].current_step +1
--quantized_grid_pat[bank].current_step = quantized_grid_pat[bank].current_step + 1
end
quantized_grid_pat[bank].sub_step = quantized_grid_pat[bank].sub_step + 1
end
end
params:add_number("bpm", "bpm", 1, 480,80)
bpm = params:get("bpm")
params:hide("bpm")
params:add_group("hidden [timing]",6)
params:hide("hidden [timing]")
params:add_option("quantize_pads", "(see [timing] menu)", { "no", "yes" })
params:set_action("quantize_pads", function(x) quantize = x-1 end)
params:add_option("quantize_pats", "(see [timing] menu)", { "no", "yes" })
params:set_action("quantize_pats", function(x)
grid_pat_quantize = x-1
for i = 1,3 do
grid_pat[i].quantize = x-1
end
end)
params:add_number("quant_div", "(see [timing] menu)", 1, 5, 4)
params:add_number("quant_div_pats", "(see [timing] menu)", 1, 5, 4)
params:add_option("lock_pat", "(see [timing] menu)", {"no", "yes"} )
params:add{type = "trigger", id = "sync_pat", name = "(see [timing] menu)"}
params:default()
grid_page = 0
page = {}
page.main_sel = 1
page.loops_sel = 0
page.levels_sel = 0
page.panning_sel = 1
page.filtering_sel = 0
page.arc_sel = 0
page.delay_sel = 0
page.time_sel = 1
page.time_page = {}
page.time_page_sel = {}
page.time_scroll = {}
for i = 1,5 do
page.time_page[i] = 1
page.time_page_sel[i] = 1
page.time_scroll[i] = 1
end
delay_rates = {2,(7/4),(5/3),(3/2),(4/3),(5/4),(1),(4/5),(3/4),(2/3),(3/5),(4/7),(1/2)}
delay = {}
for i = 1,2 do
delay[i] = {}
delay[i].id = 7
delay[i].arc_rate_tracker = 7
delay[i].arc_rate = 7
delay[i].rate = delay_rates[7]
delay[i].start_point = 41 + (30*(i-1))
delay[i].end_point = delay[i].start_point + 0.5
delay[i].divisor = 1
end
index = 0
edit = "all"
start_up.init()
params:add_group("crow utils",2)
params:hide("crow utils")
params:add{type = "trigger", id = "init_crow", name = "initialize crow", action = crow_init}
params:add{type = "trigger", id = "clear_crow", name = "(reset/clear crow)", action = crow_flush}
bank = {}
reset_all_banks(bank)
params:bang()
selected_coll = 0
--GRID
selected = {}
fingers = {}
counter_four = {}
counter_three = {}
counter_two = {}
for i = 1,3 do
selected[i] = {}
selected[i].x = 1 + (5*(i-1))
selected[i].y = 8
selected[i].id = 1
for k = 1,4 do
fingers[k] = {}
fingers[k].dt = 1
fingers[k].t1 = 0
fingers[k].t = 0
fingers[k][i] = {}
fingers[k][i].con = {}
end
end
function record_the_zilchmo(prev,sel,row)
grid_p[sel] = {}
grid_p[sel].i = sel
grid_p[sel].action = "zilchmo"
grid_p[sel].con = fingers[row][sel].con
grid_p[sel].row = row
grid_p[sel].bank = sel
grid_p[sel].id = selected[sel].id
grid_p[sel].x = selected[sel].x
grid_p[sel].y = selected[sel].y
grid_p[sel].previous_rate = prev
grid_p[sel].rate = prev
grid_p[sel].start_point = bank[sel][bank[sel].id].start_point
grid_p[sel].end_point = bank[sel][bank[sel].id].end_point
grid_pat[sel]:watch(grid_p[sel])
end
counter_four.key_up = metro.init()
counter_four.key_up.time = 0.05
counter_four.key_up.count = 1
counter_four.key_up.event = function()
local previous_rate = bank[selected_zilchmo_bank][bank[selected_zilchmo_bank].id].rate
zilchmo(4,selected_zilchmo_bank)
record_the_zilchmo(previous_rate,selected_zilchmo_bank,4)
end
counter_four.key_up:stop()
counter_three = {}
counter_three.key_up = metro.init()
counter_three.key_up.time = 0.05
counter_three.key_up.count = 1
counter_three.key_up.event = function()
zilchmo(3,selected_zilchmo_bank)
end
counter_three.key_up:stop()
counter_two = {}
counter_two.key_up = metro.init()
counter_two.key_up.time = 0.05
counter_two.key_up.count = 1
counter_two.key_up.event = function()
zilchmo(2,selected_zilchmo_bank)
end
counter_two.key_up:stop()
quantized_grid_pat = {}
for i = 1,3 do
quantized_grid_pat[i] = {}
quantized_grid_pat[i].clicks = {}
quantized_grid_pat[i].event = {}
quantized_grid_pat[i].sub_step = 1
quantized_grid_pat[i].current_step = 1
end
arc_pat = {}
for i = 1,3 do
arc_pat[i] = pattern_time.new()
if i ~=4 then
arc_pat[i].process = arc_pattern_execute
else
arc_pat[i].process = arc_delay_pattern_execute
end
end
if g then grid_redraw() end
--/GRID
for i=1,3 do
cheat(i,bank[i].id)
end
hardware_redraw = metro.init(function() grid_redraw() arc_redraw() end, 0.02, -1)
hardware_redraw:start()
softcut.poll_start_phase()
filter_types = {"lp", "hp", "bp", "lp/hp"}
rec_state_watcher = metro.init()
rec_state_watcher.time = 0.05
rec_state_watcher.event = function()
if rec.loop == 0 then
if rec.state == 1 then
if rec.end_point < poll_position_new[1] +0.015 then
rec.state = 0
rec_state_watcher:stop()
redraw()
end
end
end
end
rec_state_watcher.count = -1
already_saved()
params:add_group("OSC setup",3)
params:add_text("osc_IP", "OSC IP", "192.168.")
params:set_action("osc_IP", function() dest = {tostring(params:get("osc_IP")), tonumber(params:get("osc_port"))} end)
params:add_text("osc_port", "OSC port", "9000")
params:set_action("osc_port", function() dest = {tostring(params:get("osc_IP")), tonumber(params:get("osc_port"))} end)
params:add{type = "trigger", id = "refresh_osc", name = "refresh OSC [K3]", action = function()
params:set("osc_IP","none")
params:set("osc_port","none")
osc_communication = false
end}
crow_init()
task_id = clock.run(globally_clocked)
pad_press_quant = clock.run(pad_clock)
random_rec = clock.run(random_rec_clock)
if params:string("clock_source") == "internal" then
clock.internal.start(bpm)
end
end
function pad_clock()
while true do
clock.sync(1)
for i = 1,3 do
cheat_clock_synced(i)
end
end
end
function random_rec_clock()
while true do
local lbr = {1,2,4}
local rler = rec_loop_enc_resolution
local rec_distance = rec.end_point - rec.start_point
local bar_count = params:get("rec_loop_enc_resolution") > 2 and (((rec_distance)/(1/rler)) / (rler))*(2*lbr[params:get("live_buff_rate")]) or 1/4
clock.sync(params:get("rec_loop") == 1 and 4 or bar_count)
local random_rec_prob = params:get("random_rec_clock_prob")
if random_rec_prob > 0 then
local random_rec_comp = math.random(0,100)
if random_rec_comp < random_rec_prob then
if params:get("rec_loop") == 1 then
buff_freeze()
elseif params:get("rec_loop") == 2 then
if not rec_state_watcher.is_running then
softcut.position(1,rec.start_point+0.1)
softcut.rec_level(1,1)
rec.state = 1
rec_state_watcher:start()
if rec.clear == 1 then rec.clear = 0 end
end
end
end
end
end
end
function one_shot_clock()
if rec.state == 1 and rec_state_watcher.is_running then
rec_state_watcher:stop()
end
if params:get("one_shot_clock_div") < 3 then
local divs = {1,4}
local rate = divs[params:get("one_shot_clock_div")]
clock.sync(rate)
end
softcut.position(1,rec.start_point+0.1)
softcut.rec_level(1,1)
rec.state = 1
rec_state_watcher:start()
if rec.clear == 1 then rec.clear = 0 end
end
function compare_rec_resolution(x)
local resolutions =
{ [1] = 10
, [2] = 100
, [3] = 1/((60/bpm)/4)
, [4] = 1/((60/bpm)/2)
, [5] = 1/((60/bpm))
, [6] = (1/((60/bpm)))/2
, [7] = (1/((60/bpm)))/4
}
rec_loop_enc_resolution = resolutions[x]
if x > 2 then
rec.start_point = 1+(8*(rec.clip-1))
local lbr = {1,2,4}
rec.end_point = (1+(8*(rec.clip-1) + (1/rec_loop_enc_resolution))/lbr[params:get("live_buff_rate")])
softcut.loop_start(1,rec.start_point)
softcut.loop_end(1,rec.end_point)
redraw()
end
end
function globally_clocked()
while true do
clock.sync(1/4)
if menu == 7 then
redraw()
end
grid_redraw()
update_tempo()
step_sequence()
for i = 1,3 do
if grid_pat[i].led == nil then grid_pat[i].led = 0 end
if grid_pat[i].rec == 1 then