-
Notifications
You must be signed in to change notification settings - Fork 1
/
concrete.lua
2321 lines (2041 loc) · 71.2 KB
/
concrete.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
-- concrete v1.1.0 @sonocircuit
-- llllllll.co/t/concrete
--
-- virtual tape exploration
-- ---- | --- --- -- ---- --
-- --- -- ------ | --- -
-- ---- -- | ------ --- | -
--
-- for docs go to:
-- >> github.com
-- /sonocircuit/concrete
--
-- or smb into:
-- >> code/concrete/docs
--
-----------------------------------------------------------------------------------------------------------------------------
-- TODO: add ji scales
-----------------------------------------------------------------------------------------------------------------------------
a = arc.connect()
g = grid.connect()
m = midi.connect()
tx = require 'textentry'
mu = require 'musicutil'
--_lfos = require 'lfo'
_arc = include 'lib/concrete_arc'
_key = include 'lib/concrete_key'
_enc = include 'lib/concrete_enc'
_draw = include 'lib/concrete_draw'
_lfos = include 'lib/concrete_lfo'
_grd = include 'lib/concrete_grid'
-------- variables --------
pset_load = false
default_pset = 1
shift = false
pageNum = 1
focus_page1 = 1
focus_page2 = 0
focus_page3 = 0
param_page3 = 1
focus_page4 = 0
view_message = ""
msg_timer = nil
active_splice = 1
prev_splice = 1
splice_page = 1
play = false
rec = false
is_recording = false
ext_signal = 1
sos_signal = 0
armed = false
save_buffer = false
filename_reel = ""
reel_path = _path.audio .. "concrete/reels/"
splice_path = _path.audio .. "concrete/splices/"
load_reel_ch = 1
load_splice_ch = 1
MAX_REEL = 320
GENE_NUM = 4
ghost_voice = 5
rec_voice = 6
rec_at_threshold = false
reel_has_audio = false
reel_is_full = false
init_recording = true
waveviz_reel = false
waveviz_splice = false
glb_level = 1
glb_pan = 1
glb_cutoff = 1
glb_filter_q = 1
gbl_rate_slew = 0
voice_rate = 1
prev_morph_val = 0
pos_counter = 0
gene_length = 10
morph_freeze = false
morph_clocked = false
mclk_div = 1
gclk_div = 1
rate_rst = false
pan_rst = false
-- variables for midi and keys
midi_channel = 1
midi_root = 60
key_root = -21
crow_is = false
voicetab = {0, 0, 0, 0}
active_notes = {{}, {}, {}, {}}
-- variables for arc
arc_is = false
arc_off = 0
arc_enc1_count = 0
arc_vs_sens = 100
-- variables for grid
g_pos_reset = false
g_rec_mode = false
g_rec_dest = false
g_rec_speed = false
g_slotinit = false
g_slotmod = false
g_interval_chrom = 5
g_interval_scale = 4
g_voice = 0
g_scale_active = false
g_note_val = 0
g_note_rate = 1
g_set_env = false
g_lfo_state = false
g_lfo_rate = false
g_lfo_depth = false
g_lfo_shape = false
dirtygrid = false
-- variable for crow
crow_smoothing = 0.02
crow_val_change = false
crow_prev_value = {}
crow_in_mode = {}
crow_in_thresh = {}
crow_in_done_action = {}
for i = 1, 2 do
crow_prev_value[i] = 0
crow_in_mode[i] = 1
crow_in_thresh[i] = false
crow_in_done_action[i] = false
end
crow_out_mode = {}
for i = 1, 4 do
crow_out_mode[i] = 1
end
-- variables for warble
tau = math.pi * 2
warble_amount = 0
warble_depth = 0
warble_freq = 6
warble_counter = 1
warble_slope = 0
warble_active = false
-- variables for scales
local oct025 = math.pow(2, -24/12) -- speed == 0.25
local p5_025 = math.pow(2, -19/12)
local p4_025 = math.pow(2, -17/12)
local M3_025 = math.pow(2, -16/12)
local m3_025 = math.pow(2, -15/12)
local oct05 = math.pow(2, -12/12) -- speed == 0.5
local p5_05 = math.pow(2, -7/12)
local p4_05 = math.pow(2, -5/12)
local M3_05 = math.pow(2, -4/12)
local m3_05 = math.pow(2, -3/12)
local oct0 = math.pow(2, 0/12) -- speed == 1
local m3 = math.pow(2, 3/12)
local M3 = math.pow(2, 4/12)
local p4 = math.pow(2, 5/12)
local p5 = math.pow(2, 7/12)
local oct1 = math.pow(2, 12/12) -- speed == 2
local m3_1 = math.pow(2, 15/12)
local M3_1 = math.pow(2, 16/12)
local p4_1 = math.pow(2, 17/12)
local p5_1 = math.pow(2, 19/12)
local oct2 = math.pow(2, 24/12) -- speed == 4
-------- tables --------
options = {}
options.scale = {"oct", "oct+p4", "oct+p5", "oct+p4+p5"}
options.crow_input = {"none", "play [trig]", "play [gate]", "restart [trig]", "rec [trig]", "rec [gate]", "add splice [trig]", "next splice [trig]", "prev splice [trig]", "random splice [trig]", "select splice [cv]", "varispeed v/8 [cv]", "slide [cv]", "size [cv]", "morph [cv]"}
options.crow_output = {"none", "ramp [cv]", "loop reset [trig]"}
options.clock_tempo = {"2", "1", "1/2", "1/4", "3/16", "1/6", "1/8", "3/32", "1/12", "1/16","1/32"}
options.clock_value = {2, 1, 1/2, 1/4, 3/16, 1/6, 1/8, 3/32, 1/12, 1/16, 1/32}
options.params_gbl = {"global_level", "global_pan", "global_cutoff_rel", "global_filter_q_rel"}
options.params = {"level", "pan", "cutoff", "filter_q"}
options.params_view = {"level", "pan", "cutoff", "filter q"}
options.rate_slew = {0, 0.05, 0.1, 0.2, 0.5}
scale = {
{-oct2, -oct1, -oct0, -oct05, -oct025, oct025, oct05, oct0, oct1, oct2}, -- octaves
{-oct2, -p4_1, -oct1, -p4, -oct0, -p4_05, -oct05, -p4_025, -oct025, oct025, p4_025, oct05, p4_05, oct0, p4, oct1, p4_1, oct2}, -- octaves and fifths
{-oct2, -p5_1, -oct1, -p5, -oct0, -p5_05, -oct05, -p5_025, -oct025, oct025, p5_025, oct05, p5_05, oct0, p5, oct1, p5_1, oct2}, -- octaves and fifths
{-oct2, -p5_1, -p4_1, -oct1, -p5, -p4, -oct0, -p4_05, -p5_05, -oct05, -p4_025, -p5_025, -oct025, oct025, p5_025, p4_025, oct05, p5_05, p4_05, oct0, p4, p5, oct1, p4_1, p5_1, oct2} -- octaves + fiths + fourths
}
splice = {}
splice[1] = {}
splice[1].s = 1
splice[1].e = MAX_REEL + 1
splice[1].l = MAX_REEL
voice = {}
for i = 1, 6 do
voice[i] = {}
voice[i].active = true
voice[i].s = 1
voice[i].level = 1
voice[i].prev_level = 1
voice[i].pan = 0
voice[i].fc = 18000
voice[i].fq = 2
voice[i].rate_mod = 1
voice[i].trsp_value = 1
voice[i].pos_abs = 1
voice[i].pos_rel = 0
end
g_key = {}
for x = 9, 16 do
g_key[x] = {}
for y = 1, 6 do
g_key[x][y] = {}
g_key[x][y].state = false
g_key[x][y].voice = 1
end
end
state_slot = {}
for i = 1, 8 do
state_slot[i] = {}
state_slot[i].has_data = false
state_slot[i].varispeed = {}
state_slot[i].slide = {}
state_slot[i].morph = {}
state_slot[i].size = {}
end
-------- reels --------
function load_reel(path)
if path ~= "cancel" and path ~= "" then
local ch, len = audio.file_info(path)
if ch > 0 and len > 0 then
filename_reel = path
softcut.buffer_clear()
softcut.buffer_read_mono(path, 0, 1, -1, load_reel_ch, 1, 0, 1)
local l = math.min(len / 48000, MAX_REEL)
init_reel(l)
print("file loaded: "..path.." is "..l.."s")
else
print("not a sound file")
end
params:set("load_reel", "", true)
end
end
function load_splice(path)
local filename_append = path
local ch, len = audio.file_info(filename_append)
if ch > 0 and len > 0 then
if reel_has_audio then
local start_pos = splice[#splice].e
softcut.buffer_read_mono(filename_append, 0, start_pos, -1, load_splice_ch, 1, 0, 1)
local l = math.min(len / 48000, (MAX_REEL - start_pos + 1))
append_splice(start_pos + l)
print("splice added: "..filename_append.." is "..l.."s")
else
softcut.buffer_read_mono(filename_append, 0, 1, -1, load_splice_ch, 1, 0, 1)
local l = math.min(len / 48000, MAX_REEL)
init_reel(l)
print("splice added: "..filename_append.." is "..l.."s")
end
params:set("append_file", "")
else
print("not a sound file")
end
end
function save_splice(txt)
if txt then
local start = splice[active_splice].s
local length = splice[active_splice].e - splice[active_splice].s
softcut.buffer_write_mono(_path.audio.."concrete/splices/"..txt..".wav", start, length, 1)
print("splice saved: " .._path.audio .. "concrete/splices/" .. txt .. ".wav")
else
print("save cancel")
end
end
function save_reel(txt)
if txt then
local length = splice[#splice].e - 1
softcut.buffer_write_mono(_path.audio.."concrete/reels/"..txt..".wav", 1, length, 1)
print("reel saved: " .._path.audio .. "concrete/reels/" .. txt .. ".wav")
else
print("save cancel")
end
end
function clear_reel()
softcut.buffer_clear()
reel_is_full = false
init_recording = true
reel_has_audio = false
active_splice = 1
splice = {}
splice[1] = {}
splice[1].s = 1
splice[1].e = 1 + MAX_REEL
splice[1].l = MAX_REEL
waveviz_reel = true
waveviz_splice = true
softcut.render_buffer(1, 1, MAX_REEL, 128)
set_loops()
set_start_pos()
params:set("load_reel", "", true)
print("cleared reel")
end
function init_reel(dur)
active_splice = 1
splice = {}
splice[1] = {}
splice[1].s = 1
splice[1].e = 1 + dur
splice[1].l = dur
reel_has_audio = true
init_recording = false
waveviz_reel = true
waveviz_splice = true
softcut.render_buffer(1, 1, dur, 128)
set_loops()
set_start_pos()
print("init reel > length: "..dur)
end
function add_splice(pos)
table.insert(splice, active_splice + 1, {})
splice[active_splice + 1].s = pos or voice[1].pos_abs
splice[active_splice + 1].e = splice[active_splice].e
splice[active_splice].e = pos or voice[1].pos_abs
splice[active_splice + 1].l = splice[active_splice + 1].e - splice[active_splice + 1].s
splice[active_splice].l = splice[active_splice].e - splice[active_splice].s
set_loops()
set_start_pos()
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
dirtygrid = true
-- print_markers()
end
function remove_splice()
if active_splice < #splice then
splice[active_splice + 1].s = splice[active_splice].s
splice[active_splice + 1].l = splice[active_splice + 1].e - splice[active_splice].s
table.remove(splice, active_splice)
set_loops()
set_start_pos()
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
dirtygrid = true
end
--print_markers()
end
function append_splice(pos)
table.insert(splice, #splice + 1, {})
splice[#splice].s = splice[#splice - 1].e
splice[#splice].e = pos or voice[rec_voice].pos_abs
splice[#splice].l = splice[#splice].e - splice[#splice].s
waveviz_reel = true
softcut.render_buffer(1, 1, splice[#splice].e - 1, 128)
dirtygrid = true
--print_markers()
end
function nudge_splice_start(d)
local amt = d / 50
if active_splice > 1 then
splice[active_splice].s = util.clamp(splice[active_splice].s + amt, splice[active_splice - 1].s + 0.01, splice[active_splice].e - 0.01)
splice[active_splice - 1].e = splice[active_splice].s
splice[active_splice - 1].l = splice[active_splice - 1].e - splice[active_splice - 1].s
splice[active_splice].l = splice[active_splice].e - splice[active_splice].s
set_loops()
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
end
--print_markers()
end
function nudge_splice_end(d)
local amt = d / 50
if active_splice < #splice then
splice[active_splice].e = util.clamp(splice[active_splice].e + amt, splice[active_splice].s + 0.01, splice[active_splice + 1].e - 0.01)
splice[active_splice + 1].s = splice[active_splice].e
splice[active_splice + 1].l = splice[active_splice + 1].e - splice[active_splice + 1].s
splice[active_splice].l = splice[active_splice].e - splice[active_splice].s
set_loops()
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
end
--print_markers()
end
function nudge_splice_window(d)
local amt = d / 50
if active_splice > 1 and active_splice < #splice then
-- set start
splice[active_splice].s = util.clamp(splice[active_splice].s + amt, splice[active_splice - 1].s + 0.01, splice[active_splice].e - 0.01)
splice[active_splice - 1].e = splice[active_splice].s
splice[active_splice - 1].l = splice[active_splice - 1].e - splice[active_splice - 1].s
-- set end
splice[active_splice].e = util.clamp(splice[active_splice].e + amt, splice[active_splice].s + 0.01, splice[active_splice + 1].e - 0.01)
splice[active_splice + 1].s = splice[active_splice].e
splice[active_splice + 1].l = splice[active_splice + 1].e - splice[active_splice + 1].s
-- set lentgh
splice[active_splice].l = splice[active_splice].e - splice[active_splice].s
-- set loops and viz
set_loops()
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
end
--print_markers()
end
function delete_splice(splice_num)
local active_splice = splice_num or active_splice
if #splice > 1 then
if active_splice == #splice then
local last_splice = active_splice
set_active_splice(-1)
softcut.buffer_clear_region_channel(1, splice[last_splice].s - 0.01, -1, 0.01)
table.remove(splice, #splice)
else
softcut.buffer_clear_region_channel(1, splice[active_splice].s, splice[active_splice].l, 0.01, 0)
local tail = splice[#splice].e - splice[active_splice].e
softcut.buffer_copy_mono(1, 1, splice[active_splice].e, splice[active_splice].s, tail, 0.01, 0, 0)
local pos_shift = splice[active_splice].l
for i = active_splice + 1, #splice do
splice[i].s = splice[i].s - pos_shift
splice[i].e = splice[i].e - pos_shift
splice[i].l = splice[i].e - splice[i].s
end
table.remove(splice, active_splice)
softcut.buffer_clear_region_channel(1, splice[#splice].e, -1, 0.01)
set_loops()
end
if splice[#splice].e < MAX_REEL then
reel_is_full = false
end
-- display waveforms
waveviz_reel = true
softcut.render_buffer(1, 1, splice[#splice].e - 1, 128)
clock.run(
function()
clock.sleep(0.2)
prev_splice = 0
set_active_splice(0)
end
)
dirtygrid = true
--print_markers()
end
end
function flip_splice(splice_num)
local active_splice = splice_num or active_splice
softcut.buffer_copy_mono(1, 2, splice[active_splice].s, splice[active_splice].s, splice[active_splice].l, 0.01, 0, 1)
clock.run(
function()
clock.sleep(0.1)
softcut.buffer_copy_mono(2, 1, splice[active_splice].s, splice[active_splice].s, splice[active_splice].l, 0.01, 0, 0)
set_loops()
waveviz_reel = true
softcut.render_buffer(1, 1, splice[#splice].e - 1, 128)
clock.run(
function()
clock.sleep(0.1)
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
end
)
end
)
--print_markers()
--print("flipped splice "..active_splice)
end
function gain_reduction()
softcut.buffer_clear_region(splice[active_splice].s, splice[active_splice].l, 0.01, 0.794)
waveviz_reel = true
softcut.render_buffer(1, 1, splice[#splice].e - 1, 128)
end
function set_active_splice(inc)
active_splice = util.clamp(active_splice + inc, 1, #splice)
clock.run(
function()
clock.sleep(0.1)
if active_splice ~= prev_splice then
if params:get("morph_mode") == 2 then
voice[1].s = util.clamp(splice[active_splice].s + splice[active_splice].l * params:get("slide"), splice[active_splice].s, splice[active_splice].e)
end
set_loops()
set_start_pos()
prev_splice = active_splice
waveviz_splice = true
softcut.render_buffer(1, splice[active_splice].s, splice[active_splice].l, 128)
end
end
)
dirtygrid = true
end
function set_random_splice()
local inc = math.random(1, #splice) - active_splice
set_active_splice(inc)
end
function select_splice(val)
local segment = 1 / #splice
for i = 1, #splice do
if val <= segment * i then
local inc = i - active_splice
set_active_splice(inc)
break
end
end
end
function clear_all_splice_markers()
clock.sleep(2)
if g_slotmod then
init_reel(splice[#splice].e - 1)
dirtygrid = true
end
end
-- debug stuff
function print_markers()
for i = 1, #splice do
print("splice "..i)
tab.print(splice[i])
end
end
-------- voices / playheads --------
function set_play()
if play then
if rec then
rec = false
set_rec()
set_levels()
else
play = false
pos_counter = 0
set_levels()
end
else
play = true
set_start_pos()
set_rec()
set_levels()
end
--page_redraw(1)
dirtygrid = true
end
function toggle_recording()
if params:get("rec_dest") == 3 then
if not reel_is_full then
rec = not rec
else
rec = false
end
else
rec = not rec
end
set_rec()
--page_redraw(1)
dirtygrid = true
end
function set_rec()
if rec and play then
softcut.rec_level(rec_voice, params:get("rec_level"))
softcut.pre_level(rec_voice, params:get("dub_level"))
if not is_recording then
-- set position
if params:get("rec_dest") ~= 3 then
softcut.position(rec_voice, voice[1].pos_abs)
softcut.loop_start(rec_voice, splice[active_splice].s)
softcut.loop_end(rec_voice, splice[active_splice].e)
else
softcut.position(rec_voice, splice[#splice].e)
softcut.loop_start(rec_voice, splice[#splice].e)
softcut.loop_end(rec_voice, MAX_REEL + 1)
end
-- set rate
local rate = params:get("rec_rate") < 3 and math.abs(voice_rate) or math.abs(voice_rate * 2)
softcut.rate(rec_voice, rate)
is_recording = true
end
elseif rec and not play then
amp_in[1]:start()
amp_in[2]:start()
rec_at_threshold = true
elseif not rec and not play then
amp_in[1]:stop()
amp_in[2]:stop()
rec_at_threshold = false
else
softcut.rec_level(rec_voice, 0)
softcut.pre_level(rec_voice, 1)
if is_recording then
if init_recording then
init_reel(voice[rec_voice].pos_abs - 1)
init_recording = false
is_recording = false
elseif params:get("rec_dest") == 3 then
append_splice()
is_recording = false
else
is_recording = false
waveviz_reel = true
softcut.render_buffer(1, 1, splice[#splice].e - 1, 128)
end
end
if rec_at_threshold then
amp_in[1]:stop()
amp_in[2]:stop()
rec_at_threshold = false
end
end
set_levels()
end
function set_levels()
-- voice levels
for i = 1, GENE_NUM do
local level = voice[i].level * glb_level
if play and voice[i].active then
softcut.level(i, level)
else
softcut.level(i, 0)
end
end
-- rec levels
if params:get("rec_mode") == 1 then
ext_signal = sos_signal
for i = 1, GENE_NUM do
softcut.level_cut_cut(i, rec_voice, 0)
end
set_input_routing()
else
-- set input level
ext_signal = 1 - sos_signal
-- and set levels
if get_active_voices() == 1 then
level_reduction = 0.9
elseif get_active_voices() == 2 then
level_reduction = 0.75
elseif get_active_voices() == 3 then
level_reduction = 0.6
elseif get_active_voices() == 4 then
level_reduction = 0.5
end
for i = 1, GENE_NUM do
if voice[i].active then
softcut.level_cut_cut(i, rec_voice, voice[i].level * sos_signal * level_reduction)
else
softcut.level_cut_cut(i, rec_voice, 0)
end
end
set_input_routing()
end
end
function set_input_routing()
if params:get("rec_input") == 1 then -- L&R
softcut.level_input_cut(1, rec_voice, ext_signal * 0.7)
softcut.level_input_cut(2, rec_voice, ext_signal * 0.7)
elseif params:get("rec_input") == 2 then -- L IN
softcut.level_input_cut(1, rec_voice, ext_signal * 1)
softcut.level_input_cut(2, rec_voice, 0)
elseif params:get("rec_input") == 3 then -- R IN
softcut.level_input_cut(1, rec_voice, 0)
softcut.level_input_cut(2, rec_voice, ext_signal * 1)
elseif params:get("rec_input") == 4 then -- OFF
softcut.level_input_cut(1, rec_voice, 0)
softcut.level_input_cut(2, rec_voice, 0)
if params:get("rec_mode") == 1 then
params:set("rec_mode", 2) -- force to s.o.s mode
end
end
end
function select_filter(i, option)
softcut.post_filter_lp(i, option == 1 and 1 or 0)
softcut.post_filter_hp(i, option == 2 and 1 or 0)
softcut.post_filter_bp(i, option == 3 and 1 or 0)
softcut.post_filter_br(i, option == 4 and 1 or 0)
softcut.post_filter_dry(i, option == 5 and 1 or 0)
end
function set_panning()
for i = 1, GENE_NUM do
local pan = voice[i].pan * glb_pan
softcut.pan(i, pan)
end
end
delta_viz_fc = "< >"
function set_cutoff(d)
local min = math.min(voice[1].fc, voice[2].fc, voice[3].fc, voice[4].fc)
local max = math.max(voice[1].fc, voice[2].fc, voice[3].fc, voice[4].fc)
for i = 1, GENE_NUM do
if d < 0 and params:get("cutoff"..i) > 20 then
params:delta("cutoff"..i, d)
params:set("global_cutoff_rel", 0)
delta_viz_fc = "<<"
elseif d > 0 and params:get("cutoff"..i) < 18000 then
params:delta("cutoff"..i, d)
params:set("global_cutoff_rel", 0)
delta_viz_fc = ">>"
end
end
if d < 0 and min == 20 then
delta_viz_fc = "|<"
elseif d > 0 and max == 18000 then
delta_viz_fc = ">|"
end
end
delta_viz_fq = "< >"
function set_filter_q(d)
local min = math.min(voice[1].fq, voice[2].fq, voice[3].fq, voice[4].fq)
local max = math.max(voice[1].fq, voice[2].fq, voice[3].fq, voice[4].fq)
for i = 1, GENE_NUM do
if d < 0 and params:get("filter_q"..i) > 0.1 then
params:delta("filter_q"..i, d)
params:set("global_filter_q_rel", 0)
delta_viz_fq = "<<"
elseif d > 0 and params:get("filter_q"..i) < 4 then
params:delta("filter_q"..i, d)
params:set("global_filter_q_rel", 0)
delta_viz_fq = ">>"
end
end
if d < 0 and min == 0.1 then
delta_viz_fq = "|<"
elseif d > 0 and max == 4 then
delta_viz_fq = ">|"
end
end
function set_rate(warble)
local warble = warble or 1
for i = 1, GENE_NUM do
local rate = voice_rate * voice[i].rate_mod * voice[i].trsp_value * warble
softcut.rate(i, rate)
--print("voice "..i.." "..voice[i].trsp_value)
end
if params:get("rec_rate") == 1 then
local rate = math.abs(voice_rate)
softcut.rate(rec_voice, rate)
end
end
function get_snap(inc)
local idx = params:get("scale")
for i = 1, #scale[idx] do
if voice_rate > scale[idx][i] - 0.00001 and voice_rate < scale[idx][i] + 0.00001 then
local snap = inc > 0 and i + 1 or i - 1
return snap
elseif voice_rate < scale[idx][i] then
local snap = inc > 0 and i or i - 1
return snap
end
end
end
function set_rate_slew(mode)
for i = 1, GENE_NUM do
softcut.rate_slew_time(i, gbl_rate_slew)
end
if mode < 3 then
warble_amount = 0
warble_depth = 0
elseif mode == 3 then
warble_amount = 12
warble_depth = 8
elseif mode == 4 then
warble_amount = 24
warble_depth = 22
else
warble_amount = 36
warble_depth = 40
end
end
function init_param_state()
params:set("varispeed", 1)
params:set("slide", 0)
params:set("morph", 0)
params:set("gene_size", 1)
set_start_pos()
end
function save_param_state(i)
state_slot[i].has_data = true
state_slot[i].varispeed = params:get("varispeed")
state_slot[i].slide = params:get("slide")
state_slot[i].morph = params:get("morph")
state_slot[i].size = params:get("gene_size")
end
function clear_param_state(i)
state_slot[i].has_data = false
state_slot[i].varispeed = {}
state_slot[i].slide = {}
state_slot[i].morph = {}
state_slot[i].size = {}
end
function load_param_state(i)
params:set("varispeed", state_slot[i].varispeed)
params:set("slide", state_slot[i].slide)
params:set("morph", state_slot[i].morph)
params:set("gene_size", state_slot[i].size)
end
function reset_morph_params()
if not morph_freeze then
local morph = params:get("morph") * 100
if morph > 79 then rate_rst = true end
if morph > 74 then pan_rst = true end
-- reset rate mod
if morph < 80 and rate_rst then
for i = 1, GENE_NUM do
voice[i].rate_mod = 1
end
set_rate()
rate_rst = false
end
-- reset levels and pan
if morph < 75 and pan_rst then
for i = 1, GENE_NUM do
voice[i].level = params:get("level"..i)
voice[i].pan = params:get("pan"..i)
end
set_levels()
set_panning()
pan_rst = false
end
end
end
function set_start_pos()
pos_counter = 0
for i = 1, GENE_NUM do
softcut.position(i, voice[i].s)
end
if params:get("rec_dest") == 1 then
softcut.position(rec_voice, voice[1].s)
end
for i = 1, 4 do
if crow_out_mode[i] == 2 then
crow.output[i].action = "{ to(0, 0), to(8, "..gene_length.."), to(0, 0, 'lin') }"
crow.output[i]()
elseif crow_out_mode[i] == 3 then
crow.output[i].action = "pulse(0.02, 8)"
crow.output[i]()
end
end
set_levels()
--page_redraw(1)
end
function set_loops()
-- calculate start, end and length
if params:get("morph_mode") == 1 then -- --TODO: testing required: you might run into trouble if pset loads into clocked mode as voice[1].s == 1
voice[1].s = util.clamp(splice[active_splice].s + splice[active_splice].l * params:get("slide"), splice[active_splice].s, splice[active_splice].e)
end
gene_length = util.clamp(splice[active_splice].l * params:get("gene_size"), 0.01, splice[active_splice].l)
-- and set loop window to active splice
for i = 1, GENE_NUM do
softcut.loop_start(i, splice[active_splice].s)
softcut.loop_end(i, splice[active_splice].e)
end
-- morph genes according to the morph param
local mval = params:get("morph") * 100
local sval = params:get("morph") * 1.25
if mval < 5 then
-- set all to same start pos
voice[1].active = true
for i = 2, GENE_NUM do
voice[i].s = voice[1].s
voice[i].active = false
end
elseif mval >= 5 and mval <= 30 then
-- shift gene 2 only
local shift_amount = (gene_length / 2) * sval
voice[2].s = voice[1].s + shift_amount
if voice[2].s > splice[active_splice].e then
voice[2].s = voice[2].s - splice[active_splice].l
end
voice[2].active = true
-- keep others aligned
for i = 3, GENE_NUM do
voice[i].s = voice[1].s
voice[i].active = false
end
elseif mval > 30 and mval <= 60 then
-- shift gene 2 + 3
local shift_amount = (gene_length / 3) * sval
voice[2].s = voice[1].s + shift_amount
if voice[2].s > splice[active_splice].e then
voice[2].s = voice[2].s - splice[active_splice].l
end
voice[2].active = true
voice[3].s = voice[2].s + shift_amount
if voice[3].s > splice[active_splice].e then
voice[3].s = voice[2].s - splice[active_splice].l
end
voice[3].active = true
-- keep gene 4 aligned
voice[4].s = voice[1].s
voice[4].active = false
elseif mval > 60 and mval <= 90 then
-- shift gene 2 + 3 + 4
local shift_amount = (gene_length / 4) * sval
voice[2].s = voice[1].s + shift_amount
if voice[2].s > splice[active_splice].e then
voice[2].s = voice[2].s - splice[active_splice].l
end
voice[2].active = true
voice[3].s = voice[2].s + shift_amount
if voice[3].s > splice[active_splice].e then
voice[3].s = voice[3].s - splice[active_splice].l
end
voice[3].active = true
voice[4].s = voice[3].s + shift_amount
if voice[4].s > splice[active_splice].e then
voice[4].s = voice[4].s - splice[active_splice].l
end
voice[4].active = true
elseif mval > 95 then -- if > 95 then max rand and changing start pos will not change the start pos of the other genes.
-- keep things how they are
end
end
function morph_values()
while true do
clock.sync(1/4) --16th notes
local mval = params:get("morph") * 100
if math.random(100) <= params:get("morph_prob") and not morph_freeze and play then
if mval > 74 and params:get("randomize_pan") == 2 then
voice[1].pan = (math.random() * 20 - 10) / 10
voice[2].pan = -voice[1].pan
voice[3].pan = (math.random() * 20 - 10) / 10
voice[4].pan = -voice[3].pan
for i = 1, GENE_NUM do
softcut.pan(i, voice[i].pan)
end
page_redraw(3)
end
if mval >= 75 and params:get("randomize_level") == 2 then
for i = 1, GENE_NUM do
voice[i].level = math.random(25, 100) / 100
set_levels()
end
page_redraw(3)
end
if mval >= 80 and mval < 85 and params:get("randomize_rate") == 2 then
for i = 2, GENE_NUM do
local dice = math.random(-1, 1)
if dice ~= 0 then
voice[i].rate_mod = dice
set_rate()
end
end
elseif mval >= 85 and mval < 90 and params:get("randomize_rate") == 2 then
for i = 2, GENE_NUM do
local dice = math.random(-2, 2)
if dice ~= 0 then
voice[i].rate_mod = dice
set_rate()
end
end
elseif mval >= 90 and mval < 95 and params:get("randomize_rate") == 2 then
for i = 2, GENE_NUM do
local rnd = math.random(#scale[params:get("scale")])
voice[i].rate_mod = scale[params:get("scale")][rnd]