-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoooooo.lua
executable file
·1993 lines (1863 loc) · 61.1 KB
/
oooooo.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
-- oooooo v1.10.2
-- 6 x digital tape loops
--
-- llllllll.co/t/oooooo
--
--
--
-- ▼ instructions below ▼
--
-- E1 selects loops
-- E2 changes mode/parameter
--
-- in tape mode:
-- K2 stops
-- K2 again resets
-- K3 plays
-- K1+K2 clears
-- K1+K2 again resets
-- K1+K3 primes recording
-- K1+K3 again records
--
-- in other modes:
-- K2 or K3 activates or lfos
-- E3 adjusts parameter
local Formatters=require 'formatters'
local grido=include("oooooo/lib/grido")
local MusicUtil = require "musicutil"
local monosong_=include("oooooo/lib/monosong")
engine.name="SimpleDelay"
-- from https://github.com/monome/norns/blob/main/lua/lib/intonation.lua
local intonation = {1/1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8, 2*1/1, 2*16/15, 2*9/8, 2*6/5, 2*5/4, 2*4/3, 2*45/32, 2*3/2, 2*8/5, 2*5/3, 2*16/9, 2*15/8}
oooooo_grid = nil
kolor_grid = nil
-- user parameters
uP={
-- initialized in init
}
-- user state
uS={
recording={0,0,0,0,0,0},-- 0 = not recording, 1 = armed, 2 = recording
recordingTime={0,0,0,0,0,0},
recordingLoopNum={0,0,0,0,0,0},
updateUI=false,
updateParams=0,
updateUserParam=0,
updateTape=false,
shift=false,
loopNum=1,-- 7 = all loops
selectedPar=0,
flagClearing={false,false,false,false,false,false,false},
flagSpecial=0,
message="",
currentBeat=0,
currentTime=0,
lagActivated=false,
timeSinceArming=0,
lastOnset=0,
toneRates = {},
}
-- user constants
uC={
bufferMinMax={
{1,1,80},
{1,82,161},
{1,163,243},
{2,1,80},
{2,82,161},
{2,163,243},
},
loopMinMax={0.2,78},
radiiMinMax={3,160},
widthMinMax={8,124},
heightMinMax={0,64},
centerOffsets={
{0,0},
{0,0},
{0,0},
{0,0},
{0,0},
{0,0},
},
updateTimerInterval=0.05,
recArmThreshold=0.03,
backupNumber=1,
lfoTime=1,
discreteRates= {-400,-200,-150,-100,-75,-50,-25,-12.5,12.5,25,50,75,100,150,200,400},
discreteBeats={1/4,1/2,1,2},
pampfast=0.02,
timeUntilLagInitiates=0.1,
availableModes={"select one","default","stereo looping","delaylaylay"}
}
DATA_DIR=_path.data.."oooooo/"
PATH=_path.audio..'oooooo/'
local scale_names={}
function init()
-- engine.delay(0.1)
-- engine.volume(0.0)
setup_sharing("oooooo")
params:add_separator("oooooo")
-- add variables into main menu
params:add_group("startup",6)
params:add_option("load on start","load on start",{"no","yes"},1)
params:set_action("load on start",update_parameters)
params:add_option("play on start","play on start",{"no","yes"},1)
params:set_action("play on start",update_parameters)
params:add_option("start lfos random","start lfos random",{"no","yes"},2)
params:set_action("start lfos random",update_parameters)
params:add_control("start length","start length",controlspec.new(0,64,'lin',1,16,'beats'))
params:set_action("start length",update_parameters)
params:add_option("use kolor","use kolor (restart req)",{"no","yes"},1)
params:set_action("use kolor",update_parameters)
params:add_option("use middy","use middy (restart req)",{"no","yes"},1)
params:set_action("use middy",update_parameters)
params:add_group("recording",7)
params:add_control("pre level","pre level",controlspec.new(0,1,"lin",0.01,1,"",0.01))
params:add_control("rec level","rec level",controlspec.new(0,1,"lin",0.01,0.5,"",0.01))
params:add_control("rec thresh","rec thresh",controlspec.new(-70,-32,'lin',1,-60,'dB'))
params:set_action("rec thresh",function (x)
engine.threshold(x)
update_parameters()
end)
params:add_option("rec thru loops","rec thru loops",{"no","yes"},1)
params:set_action("rec thru loops",update_parameters)
params:add_control("stop rec after","stop rec after",controlspec.new(1,64,"lin",1,1,"loops"))
params:set_action("stop rec after",update_parameters)
params:add_option("input type","input type",{"line-in L","line-in R","tape","line-in (L+R)+tape","split L/R+tape"},4)
params:set_action("input type",function(x)
update_softcut_input()
end)
params:add_option("sync lengths to first","sync lengths to first",{"no","yes"},1)
params:set_action("sync lengths to first",update_parameters)
params:add_group("save/load",3)
params:add_text('save_name',"save as...","")
params:set_action("save_name",function(y)
-- prevent banging
local x=y
params:set("save_name","")
if x=="" then
do return end
end
-- save
print(x)
backup_save(x)
params:set("save_message","saved as "..x)
end)
print("DATA_DIR "..DATA_DIR)
local name_folder=DATA_DIR.."names/"
print("name_folder: "..name_folder)
params:add_file("load_name","load",name_folder)
params:set_action("load_name",function(y)
-- prevent banging
local x=y
params:set("load_name",name_folder)
if #x<=#name_folder then
do return end
end
-- load
print("load_name: "..x)
pathname,filename,ext=string.match(x,"(.-)([^\\/]-%.?([^%.\\/]*))$")
print("loading "..filename)
backup_load(filename)
params:set("save_message","loaded "..filename..".")
end)
params:add_text('save_message',">","")
for i = 1, #MusicUtil.SCALES do
table.insert(scale_names, string.lower(MusicUtil.SCALES[i].name))
end
params:add_group("all loops",10)
params:add_option("pause lfos","pause lfos",{"no","yes"},1)
params:add_control("destroy loops","destroy loops",controlspec.new(0,100,'lin',1,0,'% prob'))
params:add_control("vol ramp","vol ramp",controlspec.new(-1,1,'lin',0,0,'',0.01/2))
params:add_option("randomize all on reset","randomize on reset",{"no","params","loops","both"},1)
params:set_action("randomize all on reset",function(x)
for i=1,6 do
params:set(i.."randomize on reset",x)
end
end)
params:add_control("reset all every","reset all every",controlspec.new(0,64,"lin",1,0,"beats"))
params:set_action("reset all every",function(x)
for i=1,6 do
params:set(i.."reset every beat",x)
end
end)
params:add_option("continous rate","continous rate",{"no","yes"},1)
params:set_action("continous rate",update_parameters)
params:add_control("slew rate","slew rate",controlspec.new(0,30,'lin',0.1,(60/clock.get_tempo())*4,"s",0.1/30))
params:add_control("tape warble","tape warble",controlspec.new(0,100,'lin',1,0,'%'))
params:set_action("slew rate",function(x)
for i=1,6 do
softcut.level_slew_time(i,x)
softcut.rate_slew_time(i,x)
end
end)
params:add{type = "option", id = "scale_mode", name = "scale mode",
options = scale_names, default = 1,
action = function()
build_ji_rates()
uS.rateUpdate=true
end}
params:add_option("expert mode","expert mode",{"no","yes"},1)
params:set_action("expert mode",update_parameters)
-- add parameters
filter_resonance=controlspec.new(0.05,1,'lin',0,1,'')
filter_freq=controlspec.new(20,20000,'exp',0,20000,'Hz')
for i=1,6 do
params:add_group("loop "..i,41)
-- id name min max default k units
params:add_control(i.."start","start",controlspec.new(0,uC.loopMinMax[2],"lin",0.01,0,"s",0.01/uC.loopMinMax[2]))
params:add_control(i.."start lfo amp","start lfo amp",controlspec.new(0,1,"lin",0.01,0.2,"",0.01))
params:add_control(i.."start lfo period","start lfo period",controlspec.new(0,60,"lin",0.1,0,"s",0.1/60))
params:add_control(i.."start lfo offset","start lfo offset",controlspec.new(0,60,"lin",0.1,0,"s",0.1/60))
params:add_control(i.."length","length",controlspec.new(uC.loopMinMax[1],uC.loopMinMax[2],"lin",0.01,(60/clock.get_tempo())*i*4,"s",0.01/uC.loopMinMax[2]))
params:add_control(i.."length lfo amp","length lfo amp",controlspec.new(0,1,"lin",0.01,0.2,"",0.01))
params:add_control(i.."length lfo period","length lfo period",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."length lfo offset","length lfo offset",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."vol","vol",controlspec.new(0,1,"lin",0.01,0.1,"",0.01))
params:add_control(i.."vol lfo amp","vol lfo amp",controlspec.new(0,1,"lin",0.01,0.25,"",0.01))
params:add_control(i.."vol lfo period","vol lfo period",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."vol lfo offset","vol lfo offset",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_option(i.."rate","rate (%)",uC.discreteRates,#uC.discreteRates)
params:add_control(i.."rate adjust","rate adjust (%)",controlspec.new(-400,400,"lin",0.1,0,"%",0.1/800))
params:add_control(i.."rate tone","rate tone",controlspec.new(0,16,"lin",1,0,""))
params:set_action(i.."rate tone",function(v) uP[i].rateUpdate = true end)
params:add_option(i.."rate reverse","reverse rate",{"on","off"},2)
params:add_option(i.."rate lfo center","rate lfo center (%)",uC.discreteRates,#uC.discreteRates)
params:add_control(i.."rate lfo amp","rate lfo amp",controlspec.new(0,1,"lin",0.01,0.25,"",0.01))
params:add_control(i.."rate lfo period","rate lfo period",controlspec.new(0,60,"lin",0,0,"s",0.01/60))
params:add_control(i.."rate lfo offset","rate lfo offset",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."pan","pan",controlspec.new(-1,1,"lin",0.01,0,"",0.01/2))
params:add_control(i.."pan lfo amp","pan lfo amp",controlspec.new(0,1,"lin",0.01,0.2,"",0.01))
params:add_control(i.."pan lfo period","pan lfo period",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."pan lfo offset","pan lfo offset",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."reset every beat","reset every",controlspec.new(0,64,"lin",1,0,"beats"))
params:add_option(i.."randomize on reset","randomize on reset",{"no","params","loops","both"},1)
local loop_options = {"none"}
for j=i+1,6 do
table.insert(loop_options,"loop "..j)
end
params:add_option(i.."sync tape with","sync tape with",loop_options,1)
params:add {
type='control',
id=i..'filter_frequency',
name='filter cutoff',
controlspec=filter_freq,
formatter=Formatters.format_freq,
action=function(value)
uP[i].filterUpdate=true
end
}
-- TODO: add filter LFO!
params:add {
type='control',
id=i..'filter_reso',
name='filter resonance',
controlspec=filter_resonance,
action=function(value)
softcut.post_filter_rq(i,value)
end
}
params:add_control(i.."filter lfo amp","filter lfo amp",controlspec.new(0,1,"lin",0.01,0.25,"",0.01))
params:add_control(i.."filter lfo period","filter lfo period",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."filter lfo offset","filter lfo offset",controlspec.new(0,60,"lin",0,0,"s",0.1/60))
params:add_control(i.."crossfade","crossfade",controlspec.new(1,1000,'exp',0.1,150,'ms'))
params:set_action(i.."crossfade",function(x)
softcut.fade_time(i,x/1000)
softcut.recpre_slew_time(i,x/1000)
end)
params:add_control(i.."warble seed","warble seed",controlspec.new(0,128,"lin",1,1,""))
params:add{type='binary',name="play trig",id=i..'play trig',behavior='momentary',
action=function(v)
if v==1 then
tape_play(i)
uS.updateUI=true
end
end
}
params:add{type='binary',name="stop trig",id=i..'stop trig',behavior='momentary',
action=function(v)
if v==1 then
tape_stop_reset(i)
uS.updateUI=true
end
end
}
params:add{type='binary',name="recording trig",id=i..'recording trig',behavior='momentary',
action=function(v)
if v==1 then
if uS.recording[i]>0 then
tape_stop_rec(i)
else
tape_rec(i)
end
uS.updateUI=true
end
end
}
params:add{type='binary',name="arming trig",id=i..'arming trig',behavior='momentary',
action=function(v)
if v==1 then
if uS.recording[i]>0 then
tape_stop_rec(i)
else
tape_arm_rec(i)
end
uS.updateUI=true
end
end
}
params:add{type='binary',name="reset trig",id=i..'reset trig',behavior='momentary',
action=function(v)
if v==1 then
if uS.recording[i]>0 then
tape_stop_rec(i)
end
tape_reset(i)
uS.updateUI=true
end
end
}
params:add_file(i.."load_file","load audio",_path.audio)
params:set_action(i.."load_file",function(x)
if #x<=#_path.audio then
do return end
end
print("load_file",i,x)
loop_load_wav(i,x)
tape_play(i)
uS.updateUI=true
end)
params:add_option(i.."isempty","is empty",{"false","true"},2)
params:hide(i.."isempty")
end
params:add_option("choose mode","choose mode",uC.availableModes,1)
params:add{type='binary',name="activate mode",id='activate mode',behavior='trigger',
action=function(v)
if params:get("choose mode") == 1 then
do return end
end
activate_mode()
uS.updateUI=true
end
}
-- setup monosong parameters
monosong=monosong_:new()
params:set("root note",48)
params_read_silent(DATA_DIR.."oooooo.pset")
params:set('save_message',"")
params:set('load_name',name_folder)
init_loops(7)
-- make data directory
if not util.file_exists(PATH) then util.make_dir(PATH) end
-- initialize timer for updating screen
timer=metro.init()
timer.time=uC.updateTimerInterval
timer.count=-1
timer.event=update_timer
timer:start()
-- -- osc input
osc.event = osc_in
-- position poll
softcut.event_phase(update_positions)
softcut.poll_start_phase()
-- -- and initiate recording on incoming audio on input 1
-- p_amp_in=poll.set("amp_in_l")
-- -- set period low when primed, default 1 second
-- p_amp_in.time=1
-- p_amp_in.callback=function(val)
-- for i=1,6 do
-- if uS.recording[i]==1 and (params:get("input type")==1 or params:get("input type")>=4) then
-- -- print("incoming signal = "..val)
-- if val>params:get("rec thresh")/10000 then
-- tape_rec(i)
-- end
-- end
-- end
-- end
-- p_amp_in:start()
-- -- and initiate recording on incoming on audio input 2
-- p_amp_in2=poll.set("amp_in_r")
-- -- set period low when primed, default 1 second
-- p_amp_in2.time=1
-- p_amp_in2.callback=function(val)
-- for i=1,6 do
-- if uS.recording[i]==1 and (params:get("input type")==2 or params:get("input type")>=4) then
-- -- print("incoming signal = "..val)
-- if val>params:get("rec thresh")/10000 then
-- tape_rec(i)
-- end
-- end
-- end
-- end
-- p_amp_in2:start()
for i=1,6 do
params:set_action(i.."vol",function(x) uP[i].volUpdate=true end)
params:set_action(i.."length",function(x) uP[i].loopUpdate=true end)
params:set_action(i.."start",function(x) uP[i].loopUpdate=true end)
params:set_action(i.."pan",function(x) uP[i].panUpdate=true end)
params:set_action(i.."rate",function(x) uP[i].rateUpdate=true end)
params:set_action(i.."rate reverse",function(x) uP[i].rateUpdate=true end)
params:set_action(i.."rate adjust",function(x) uP[i].rateUpdate=true end)
params:set_action(i.."filter_frequency",function(x) uP[i].filterUpdate=true end)
end
redraw()
if params:get("start lfos random")==2 then
randomize_lfos()
end
-- end of init
if params:get("load on start")==2 then
-- backup_load()
if params:get("play on start")==2 then
tape_play(7)
end
else
for i=1,6 do
tape_stop(i)
tape_reset(i)
end
end
update_softcut_input()
update_softcut_input_lag(false)
-- setup middy
if params:get("use middy") == 2 and util.file_exists("/home/we/dust/code/middy") then
print("using middy")
local middy=include("middy/lib/middy")
local m1 = middy:init()
-- these lines of code are if you want to autoload
-- a specific file on startup:
-- m1:init_midi()
-- m1:init_map('/home/we/dust/data/middy/maps/nanokontrol-oooooo.json')
end
-- setup grids
if params:get("use kolor")==2 and util.file_exists(_path.code.."kolor")then
print("using kolor engine and allowing toggling")
engine.load("SimpleDelayKolor",function()
engine.name="SimpleDelayKolor"
oooooo_grid = grido:new({grid_on=true,toggleable=true})
local kolor = include("kolor/lib/kolor")
kolor_grid = kolor:new({grid_on=false,toggleable=true})
kolor_grid:toggle_grid(false)
oooooo_grid:toggle_grid(true)
kolor_grid:set_toggle_callback(function()
oooooo_grid:toggle_grid()
end)
oooooo_grid:set_toggle_callback(function()
kolor_grid:toggle_grid()
end)
show_message("loaded kolor")
end)
else
-- simply setup oooooo grid
oooooo_grid = grido:new()
end
-- bang some special parameters
params:delta("rec thresh",1)
params:delta("rec thresh",-1)
-- DEV comment this out
-- params:set("scale_mode",9)
-- params:set("choose mode",3)
-- activate_mode()
-- END INIT FUNCTION
end
-- switch between grids on kolor and oooooo
function switch_kolor_oooooo()
if oooooo_grid ~= nil and kolor_grid ~= nil then
local on = oooooo_grid.grid_on
oooooo_grid:toggle_grid(not on)
kolor_grid:toggle_grid(on)
end
end
function init_loops(j,ignore_pan)
audio.level_adc(1) -- input volume 1
i1=j
i2=j
if j==7 then
i1=1
i2=7
end
previous_uP = {table.unpack(uP)}
for i=i1,i2 do
print("initializing "..i)
uP[i]={}
uP[i].loopStart=0
uP[i].loopLength=(60/clock.get_tempo())*i*4
if params:get("start length")>0 then
uP[i].loopLength=(60/clock.get_tempo())*params:get("start length")
end
uP[i].loopUpdate=false
uP[i].position=0
uP[i].fc=20000
uP[i].recordedLength=0
uP[i].isStopped=true
uP[i].vol=0.5
uP[i].volUpdate=false
uP[i].rate=1
uP[i].rateUpdate=false
if ignore_pan == nil or not ignore_pan then
uP[i].pan=0
else
uP[i].pan = previous_uP[i].pan
end
uP[i].panUpdate=false
uP[i].filterUpdate=false
uP[i].lfoWarble={}
uP[i].destroying=false
if i<7 then
params:set(i.."start",0)
params:set(i.."start lfo amp",0.2)
params:set(i.."start lfo period",0)
params:set(i.."start lfo offset",0)
params:set(i.."length",uP[i].loopLength)
params:set(i.."length lfo amp",0.2)
params:set(i.."length lfo period",0)
params:set(i.."length lfo offset",0)
params:set(i.."vol",0.5)
params:set(i.."vol lfo amp",0.3)
params:set(i.."vol lfo period",0)
params:set(i.."vol lfo offset",0)
params:set(i.."rate",13)
params:set(i.."rate adjust",0)
params:set(i.."rate reverse",2)
params:set(i.."rate lfo center",10)
params:set(i.."rate lfo amp",0.2)
params:set(i.."rate lfo period",0)
params:set(i.."rate lfo offset",0)
if ignore_pan == nil or not ignore_pan then
params:set(i.."pan",0)
end
params:set(i.."pan lfo amp",0.5)
params:set(i.."pan lfo period",0)
params:set(i.."pan lfo offset",0)
params:set(i.."filter lfo amp",0.5)
params:set(i.."filter lfo period",0)
params:set(i.."filter lfo offset",0)
params:set(i.."reset every beat",0)
params:set(i.."isempty",2)
params:set(i.."play trig",0)
params:set(i.."arming trig",0)
params:set(i.."recording trig",0)
params:set(i.."reset trig",0)
params:set(i.."stop trig",0)
params:set(i.."rate tone",0)
end
for j=1,3 do
uP[i].lfoWarble[j]=math.random(1,60)
end
if i<7 then
-- update softcut
softcut.level(i,0.5)
softcut.pan(i,0)
softcut.play(i,0)
softcut.rate(i,1)
softcut.loop_start(i,uC.bufferMinMax[i][2])
softcut.loop_end(i,uC.bufferMinMax[i][2]+uP[i].loopLength)
softcut.loop(i,1)
softcut.rec(i,0)
-- fade time is redundant with recpre
-- softcut.fade_time(i,params:get("vol pinch")/1000)
softcut.level_slew_time(i,params:get("slew rate"))
softcut.rate_slew_time(i,params:get("slew rate"))
softcut.recpre_slew_time(i,params:get(i.."crossfade")/1000)
softcut.fade_time(i,params:get(i.."crossfade")/1000)
softcut.rec_level(i,params:get("rec level"))
softcut.pre_level(i,params:get("pre level"))
softcut.buffer(i,uC.bufferMinMax[i][1])
softcut.position(i,uC.bufferMinMax[i][2])
softcut.enable(i,1)
softcut.phase_quant(i,0.025)
softcut.post_filter_dry(i,0.0)
softcut.post_filter_lp(i,1.0)
softcut.post_filter_rq(i,1.0)
softcut.post_filter_fc(i,18000)
softcut.pre_filter_dry(i,1.0)
softcut.pre_filter_lp(i,1.0)
softcut.pre_filter_rq(i,1.0)
softcut.pre_filter_fc(i,18000)
end
end
build_ji_rates()
end
function build_ji_rates()
notes = MusicUtil.generate_scale_of_length(60, params:get("scale_mode"), 24)
tones = intonation
uS.toneRates = {}
for i,note in ipairs(notes) do
ratio_index = note - 60 + 1
if ratio_index > #tones then
break
end
table.insert(uS.toneRates,tones[ratio_index])
end
end
function activate_mode()
print(uC.availableModes[params:get("choose mode")])
if uC.availableModes[params:get("choose mode")]=="stereo looping" then
activate_mode_default()
for i=1,6 do
params:set(i.."pan",((i+1)%2+1)*2-3+math.floor(i/2)/10*(((i)%2+1)*2-3))
end
params:set("1sync tape with",2)
params:set("3sync tape with",2)
params:set("5sync tape with",2)
params:set("input type",5)
elseif uC.availableModes[params:get("choose mode")]=="delaylaylay" then
activate_mode_default()
for i=1,5 do
params:set(i.."sync tape with",2)
end
params:set("stop rec after",64)
params:set("rec level",0.5)
params:set("pre level",0.4)
for i=1,6 do
params:set(i.."length",math.random()*2)
randomize_parameters(7)
randomize_loops(7)
randomize_lfos(7)
tape_rec(i)
params:set(i.."length lfo period",math.random()*30+5)
params:set(i.."length lfo offset",math.random()*60)
end
elseif uC.availableModes[params:get("choose mode")]=="default" then
activate_mode_default()
end
params:set("choose mode",1)
end
function activate_mode_default()
for i=1,6 do
params:set(i.."sync tape with",1)
tape_stop(i)
tape_reset(i)
end
default_global_parameters = {
["pre level"]=1,
["rec level"]=1,
["rec thresh"]=85,
["rec thru loops"]=1,
["stop rec after"]=1,
["input type"]=4,
["sync lengths to first"]=1,
["pause lfos"]=1,
["destroy loops"]=0,
["vol ramp"]=0,
["randomize all on reset"]=1,
["reset all every"]=0,
["continous rate"]=1,
["slew rate"]=(60/clock.get_tempo())*4,
}
for k,v in pairs(default_global_parameters) do
params:set(k,v)
end
init_loops(7)
end
function randomize_parameters(j)
i1=j
i2=j
if j==7 then
i1=1
i2=6
end
for i=i1,i2 do
params:set(i.."rate adjust",0)
-- randomize rates between 25%, 50%, 100%, 200%, 400%
-- params:set(i.."rate",math.random(#uC.discreteRates))
-- randomize rates between 25%, 50%, 100%
params:set(i.."rate",math.random(3)+5)
params:set(i.."rate reverse",math.floor(math.random()*2)+1)
uP[i].rateUpdate=true
params:set(i.."vol",math.random()*0.6+0.2)
uP[i].volUpdate=true
params:set(i.."pan",math.random()*2-1)
uP[i].panUpdate=true
end
end
function randomize_loops(j)
i1=j
i2=j
if j==7 then
i1=1
i2=6
end
for i=i1,i2 do
params:set(i.."length",util.clamp(params:get(i.."length")+math.random()*2-1,uC.loopMinMax[1],uC.loopMinMax[2]))
uP[i].loopUpdate=true
end
end
function toggle_reverse()
for i=1,6 do
params:set(i.."rate reverse",3-params:get(i.."rate reverse"))
end
end
function randomize_lfos()
for i=1,6 do
-- params:set(i.."length lfo period",math.random()*30+5)
-- params:set(i.."length lfo offset",math.random()*60)
params:set(i.."vol lfo period",round_time_to_nearest_beat(math.random()*20+2))
params:set(i.."vol lfo offset",round_time_to_nearest_beat(math.random()*60))
params:set(i.."vol lfo amp",math.random()*0.25+0.1)
params:set(i.."pan lfo amp",math.random()*0.6+0.2)
params:set(i.."pan lfo period",round_time_to_nearest_beat(math.random()*20+2))
params:set(i.."pan lfo offset",round_time_to_nearest_beat(math.random()*60))
end
end
--
-- updaters
--
function update_softcut_input()
for i=1,6 do
if params:get("input type")==1 then
-- print("input L only channel "..i)
softcut.level_input_cut(1,i,1)
softcut.level_input_cut(2,i,0)
audio.level_adc_cut(1)
audio.level_tape_cut(0)
elseif params:get("input type")==2 then
-- print("input R only channel "..i)
softcut.level_input_cut(1,i,0)
softcut.level_input_cut(2,i,1)
audio.level_adc_cut(1)
audio.level_tape_cut(0)
elseif params:get("input type")==3 then
print("tape only")
audio.level_tape_cut(1)
audio.level_adc_cut(0)
elseif params:get("input type")==5 then
-- print("stereo "..i)
if i%2==0 then
softcut.level_input_cut(1,i,1)
softcut.level_input_cut(2,i,0)
else
softcut.level_input_cut(1,i,0)
softcut.level_input_cut(2,i,1)
end
audio.level_adc_cut(1)
audio.level_tape_cut(1)
else
-- print("tape+input L+R "..i)
softcut.level_input_cut(1,i,1)
softcut.level_input_cut(2,i,1)
audio.level_adc_cut(1)
audio.level_tape_cut(1)
end
end
end
function update_softcut_input_lag(on)
if params:get("input type")==3 or on==uS.lagActivated then
-- do nothing if using just tape or already activated
do return end
end
uS.lagActivated=on
if on then
print("update_softcut_input_lag: activated")
-- engine.volume(1.0)
-- add lag to recording using a simple delay engine
audio.level_monitor(0) -- turn off monitor to keep from hearing doubled audio
audio.level_eng_cut(1)
audio.level_adc_cut(0)
else
print("update_softcut_input_lag: deactivated")
-- engine.volume(0.0)
audio.level_monitor(1) -- turn on monitor
audio.level_eng_cut(0)
audio.level_adc_cut(1)
end
end
function update_parameters(x)
params:write(DATA_DIR.."oooooo.pset")
end
function update_positions(i,x)
-- adjust position so it is relative to loop start
currentPosition=uP[i].position
uP[i].position=x-uC.bufferMinMax[i][2]
if currentPosition==uP[i].position then
do return end
end
if uP[i].position<0 then
uP[i].position=uP[i].loopStart
end
uS.updateUI=true
end
function update_timer()
if params:get("pause lfos")==1 then
uS.currentTime=uS.currentTime+uC.updateTimerInterval
end
-- -- update the count for the lfos
-- uC.lfoTime=uC.lfoTime+uC.updateTimerInterval
-- if uC.lfoTime>376.99 then -- 60 * 2 * pi
-- uC.lfoTime=0
-- end
-- tape_warble()
if uS.updateUI then
redraw()
end
for i=1,6 do
if uS.recording[i]==2 then
previousRecordingTime=uS.recordingTime[i]
uS.recordingTime[i]=uS.recordingTime[i]+uC.updateTimerInterval
if uS.recordingTime[i]>=uP[i].loopLength then
uS.recordingLoopNum[i]=uS.recordingLoopNum[i]+1
-- print("uS.recordingLoopNum[i]: "..uS.recordingLoopNum[i])
if uS.recordingLoopNum[i]>=params:get("stop rec after") and uS.recordingLoopNum[i]<64 then
-- stop recording when reached a full loop
tape_stop_rec(i,false)
else
uS.recordingTime[i]=0
end
-- elseif params:get("vol pinch") > 0 and uS.recordingTime[i]>=uP[i].loopLength/2 and previousRecordingTime<uP[i].loopLength/2 then
-- clock.run(function()
-- softcut_add_postroll(i)
-- end)
end
end
end
if math.floor(clock.get_beats())~=uS.currentBeat then
-- a beat has been hit
if params:get("vol ramp")~=0 then
for i=1,6 do
params:set(i.."vol",util.clamp(params:get(i.."vol")+params:get("vol ramp")/10,0,1))
end
end
if params:get("destroy loops")>0 and math.random()*100<params:get("destroy loops") then
-- cause destruction to moving non empty loops
nonEmptyLoops={}
for i=1,6 do
if params:get(i.."isempty")==1 and uP[i].isStopped==false and uP[i].destroying==false then
table.insert(nonEmptyLoops,i)
end
end
if #nonEmptyLoops>0 then
-- select a loop at random
loopDestroy=nonEmptyLoops[math.random(#nonEmptyLoops)]
clock.run(function()
numBeats=uC.discreteBeats[math.random(#uC.discreteBeats)]
preLevel=math.random()
print("destroying "..loopDestroy.." for "..numBeats.." at "..preLevel.." pre level")
uP[loopDestroy].destroying=true
softcut.rec_level(loopDestroy,0)
softcut.pre_level(loopDestroy,preLevel)
softcut.rec(loopDestroy,1)
clock.sync(numBeats)
softcut.rec_level(loopDestroy,1)
softcut.pre_level(loopDestroy,1)
softcut.rec(loopDestroy,0)
uP[loopDestroy].destroying=false
end)
end
end
uS.currentBeat=math.floor(clock.get_beats())
for i=1,6 do
if params:get(i.."reset every beat")>0 then
if uS.currentBeat%params:get(i.."reset every beat")==0 then
tape_reset(i)
end
end
end
end
for i=1,6 do
if uP[i].volUpdate or (params:get(i.."vol lfo period")>0 and params:get("pause lfos")==1 and params:get(i.."vol lfo amp")>0) then
uS.updateUI=true
uP[i].volUpdate=false
uP[i].vol=params:get(i.."vol")
if uP[i].vol>0 and params:get(i.."vol lfo period")>0 and params:get("pause lfos")==1 then
uP[i].vol=uP[i].vol+params:get(i.."vol lfo amp")*calculate_lfo(uS.currentTime,params:get(i.."vol lfo period"),params:get(i.."vol lfo offset"))
uP[i].vol=util.clamp(uP[i].vol,0,1)
end
softcut.level(i,uP[i].vol)
end
if uP[i].rateUpdate or (params:get("tape warble")>0 and params:get(i.."warble seed")>0) or (params:get(i.."rate lfo period")>0 and params:get("pause lfos")==1 and params:get(i.."rate lfo amp")>0) or
uP[i].rate~=(uC.discreteRates[params:get(i.."rate")]+params:get(i.."rate adjust"))*(params:get(i.."rate reverse")*2-3)/100.0 then
uS.updateUI=true
uP[i].rateUpdate=false
local currentRateIndex=params:get(i.."rate")
if params:get(i.."rate lfo period")>0 and params:get(i.."rate lfo amp")>0 and params:get("pause lfos")==1 then
currentRateIndex=util.clamp(params:get(i.."rate lfo center")+round(util.linlin(-1,1,-#uC.discreteRates,#uC.discreteRates,params:get(i.."rate lfo amp")*calculate_lfo(uS.currentTime,params:get(i.."rate lfo period"),params:get(i.."rate lfo offset")))),1,#uC.discreteRates)
-- currentRateIndex=util.clamp(round(util.linlin(-1,1,0,1+#uC.discreteRates,params:get(i.."rate lfo amp")*calculate_lfo(uS.currentTime,params:get(i.."rate lfo period"),params:get(i.."rate lfo offset")))),1,#uC.discreteRates)
end
local toneRate = uS.toneRates[params:get(i.."rate tone")%#uS.toneRates+1]
uP[i].rate=(uC.discreteRates[currentRateIndex]+params:get(i.."rate adjust"))*(params:get(i.."rate reverse")*2-3)/100.0*toneRate
if params:get("tape warble")>0 and params:get(i.."warble seed")>0 then
local warbleAmount=0
math.randomseed(params:get(i.."warble seed"))
for j=1,4 do
warbleAmount=warbleAmount+math.sin(2*math.pi*uS.currentTime/math.random(1,60))*math.random()/4
end
math.randomseed( os.time() )
softcut.rate(i,uP[i].rate*(1+params:get("tape warble")/200*warbleAmount))
else
softcut.rate(i,uP[i].rate)
end
end
if uP[i].panUpdate or (params:get(i.."pan lfo period")>0 and params:get("pause lfos")==1 and params:get(i.."pan lfo amp")>0) then
uS.updateUI=true
uP[i].panUpdate=false
uP[i].pan=params:get(i.."pan")
if params:get(i.."pan lfo period")>0 and params:get("pause lfos")==1 then
uP[i].pan=uP[i].pan+params:get(i.."pan lfo amp")*calculate_lfo(uS.currentTime,params:get(i.."pan lfo period"),params:get(i.."pan lfo offset"))
end
uP[i].pan=util.clamp(uP[i].pan,-1,1)
softcut.pan(i,uP[i].pan)
end
if uP[i].loopUpdate or (params:get(i.."length lfo period")>0 and params:get("pause lfos")==1 and params:get(i.."length lfo amp")>0) or
(params:get(i.."start lfo period")>0 and params:get("pause lfos")==1 and params:get(i.."start lfo amp")>0) then
uS.updateUI=true
uP[i].loopUpdate=false
uP[i].loopStart=params:get(i.."start")
if params:get(i.."start lfo period")>0 and params:get("pause lfos")==1 then
uP[i].loopStart=params:get(i.."start")+uP[i].loopLength*params:get(i.."start lfo amp")*((1+calculate_lfo(uS.currentTime,params:get(i.."start lfo period"),params:get(i.."start lfo offset")))/2)
uP[i].loopStart=util.clamp(uP[i].loopStart,params:get(i.."start"),uP[i].loopLength+params:get(i.."start"))
end
uP[i].loopLength=params:get(i.."length")
if params:get(i.."length lfo period")>0 and params:get("pause lfos")==1 then
uP[i].loopLength=uP[i].loopLength*(1+params:get(i.."length lfo amp")*calculate_lfo(uS.currentTime,params:get(i.."length lfo period"),params:get(i.."length lfo offset")))/2
end
if uP[i].loopLength+uP[i].loopStart>uC.loopMinMax[2] then
-- loop length is too long, shorten it
uP[i].loopLength=uC.loopMinMax[2]-uP[i].loopStart
end
-- move to start of loop if position is outside of loop
if (uP[i].position<uP[i].loopStart or uP[i].position>uP[i].loopStart+uP[i].loopLength) then
uP[i].position=uP[i].loopStart
softcut.position(i,uP[i].position+uC.bufferMinMax[i][2])
end
softcut.loop_start(i,uP[i].loopStart+uC.bufferMinMax[i][2])
softcut.loop_end(i,uP[i].loopStart+uC.bufferMinMax[i][2]+uP[i].loopLength)
end
if uP[i].filterUpdate or (params:get(i.."filter lfo period")>0 and params:get("pause lfos")==1 and params:get(i.."filter lfo amp")>0) then
uP[i].filterUpdate=false
local fc=params:get(i.."filter_frequency")
if fc>0 and params:get(i.."filter lfo period")>0 and params:get("pause lfos")==1 then
fc = util.linlin(50,18000,-1,1,fc)
fc=fc+params:get(i.."filter lfo amp")*calculate_lfo(uS.currentTime,params:get(i.."filter lfo period"),params:get(i.."filter lfo offset"))
fc = util.linlin(-1,1,50,18000,util.clamp(fc,-1,1))
end
uP[i].fc = fc
softcut.post_filter_fc(i,fc)
end
end
end
--
-- saving and loading
--
function loop_load_wav(i,fname)