-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhills.lua
executable file
·1686 lines (1563 loc) · 58.4 KB
/
hills.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
-- hills
--
-- __/\______/\\___
-- ____/\\\\\___/\_
-- /\///_____/\\\__
-- replace this string with your computer's IP to
-- send OSC to an external instance of Kildare:
-- osc_echo = "224.0.0.1"
-- osc_echo = "169.254.64.84"
-- osc_echo = "224.0.0.1"
-- osc_echo = "169.254.202.238"
-- osc_echo = "192.168.0.137"
-- osc_echo = "169.254.111.133"
osc_echo = "192.168.2.1"
function full_PSET_swap()
clock.run(
function()
clock.sleep(0.1)
if PSET_SWAPPING == nil then
PSET_SWAPPING = true
for i = 1,7 do
params:set(i..'_voice_state',0)
end
clock.sleep(0.1)
_polyparams.reset_polyparams()
_ccparams.reset_polyparams()
clock.sleep(0.1)
send_to_engine('reset',{})
clock.sleep(0.3)
params:read()
clock.sleep(1)
params:read()
end
end
)
end
if tonumber(norns.version.update) < 220802 then
norns.script.clear()
norns.script.load('code/hills/lib/fail_state.lua')
end
kildare = include('kildare/lib/kildare')
function kildare.restart_needed_callback()
norns.script.clear()
norns.script.load('code/hills/lib/restart_notify.lua')
end
engine.name = "Kildare"
if osc_echo ~= nil then
-- osc.send({osc_echo,57120},"/command",{'establish_engine'})
osc.send({osc_echo,57120},"/engine/load/name",{'Kildare'})
end
number_of_hills = 7
number_of_patterns = 8
hill_names = {
"1: bd",
"2: sd",
"3: tm",
"4: cp",
"5: rs",
"6: cb",
"7: hh",
"8: saw"
}
pre_step_page = 'play'
aubiodone=function(args)
local id=tonumber(args[1])
local data_s=args[2]
print('aubiodone',id,data_s)
end
osc_fun={
progressbar=function(args)
print(args[1],tonumber(args[2]))
end,
aubiodone=function(args)
local id=tonumber(args[1])
stuff=args[2]
local data=kildare.json.parse(stuff)
if data==nil then
print("error getting onset data!")
do return end
end
if data.error~=nil then
print("error getting onset data: "..data.error)
do return end
end
if data.result==nil then
print("no onset results!")
do return end
end
cursors=data.result
-- self:do_move(0)
-- show_message(string.format("[%d] loaded",self.id),2)
-- -- save the top_slices
-- print("writing cursor file",self.path_to_cursors)
-- local file=io.open(self.path_to_cursors,"w+")
-- io.output(file)
-- io.write(json.encode({cursors=self.cursors}))
-- io.close(file)
end,
}
local make_sound = false
function externalIterator(noteNum)
local j = noteNum - 35
if hills[j].highway then
_htracks.tick(j)
else
local k = hills[j].segment
if hills[j][k].note_num.pool[hills[j][k].index] ~= nil then
pass_note(j,k,hills[j][k],hills[j][k].note_num.pool[hills[j][k].index],hills[j][k].index,0)
end
hills[j][k].index = util.wrap(hills[j][k].index + 1, hills[j][k].low_bound.note,hills[j][k].high_bound.note)
end
if params:string('hill_'..j..'_iterator_midi_record') == 'yes' then
for k = 1,16 do
local table_to_record =
{
["event"] = "midi_trig",
["id"] = k,
["hill"] = j,
["segment"] = hills[j].segment,
["legato"] = params:get('hill_'..j..'_legato') == 1
}
write_pattern_data(k,table_to_record,false)
end
end
end
osc.event=function(path,args,from)
-- if string.sub(path,1,1)=="/" then
-- path=string.sub(path,2)
-- end
-- print('osc path: '..path)
-- if osc_fun[path] ~= 'progressbar' or 'aubiodone' then
-- osc_fun[path](args)
-- end
-- params:delta(path, args[1])
-- print(args[1])
-- local d = args[1] == 1 and 1 or -1
-- if path == '/Velocity1' and args[1] > 0 then
-- make_sound = true
-- end
-- if path == '/Note1' and make_sound then
-- print(args[1])
-- externalIterator(args[1])
-- make_sound = false
-- end
-- params:delta(path, args[1])
end
_sequins = require 'sequins'
mu = require 'musicutil'
euclid = require 'er'
pt = include 'lib/hills_new_pt'
curves = include 'lib/easing'
_midi = include 'lib/midi'
prms = include 'lib/parameters'
_t = include 'lib/transformations'
_a = include 'lib/actions'
_g = include 'lib/grid_lib'
_e = include 'lib/enc_actions'
_k = include 'lib/key_actions'
_s = include 'lib/screen_actions'
local _flow = include 'lib/flow'
_song = include 'lib/song'
_ca = include 'lib/clip'
_cp = include 'lib/copy-paste'
_surveyor = include 'lib/surveyor'
_snapshots = include 'lib/snapshot'
_fkprm = include 'lib/fkprm'
_polyparams = include 'lib/polyparams'
_ccparams = include 'lib/ccparams'
_hsteps = include 'lib/highway_steps'
_htracks = include 'lib/highway_tracks'
r = function()
norns.script.load("code/hills/hills.lua")
end
development_state = function()
-- song_atoms.transport_active = true
for i = 1,number_of_hills do
-- DIAMOND HOLLOW/
-- params:set('hill_'..i..'_mode', 2)
-- params:set('hill_'..i..'_iterator',2)
-- params:set('hill_'..i..'_iterator_midi_device',6)
-- params:set('hill_'..i..'_iterator_midi_note',35+util.wrap(i,1,4))
-- -- /DIAMOND HOLLOW
-- params:set('hill_'..i..'_iterator_midi_record',2)
-- BERLIN
params:set('hill_'..i..'_flatten',0)
params:set('voice_model_'..i, 14)
params:set('hill '..i..' MIDI output', 2)
--/BERLIN
end
_htracks.sync_playheads()
screen_dirty = true
end
function grid.add(dev)
grid_dirty = true
end
for i = 1,3 do
norns.enc.sens(i,2)
end
function midi_to_hz(note)
return (440 / 32) * (2 ^ ((note - 9) / 12))
end
local pre_note = {}
midi_device = {}
local util_round = util.round
local lin_lin = util.linlin
function init()
print('starting: '..util.time())
for i = 1,6 do
softcut.enable(i,0)
end
kildare.init(number_of_hills, true)
_ca.init() -- initialize clips
_snapshots.init()
_flow.init()
print('initializing song: '..util.time())
_song.init()
math.randomseed(os.time())
_g.init()
key1_hold = false
key2_hold = false
-- pulled this down:
-- _hsteps.init()
-- for i = 1,10 do
-- _htracks.init(i,1)
-- end
print('initialized tracks: '..util.time())
key2_hold_counter = metro.init()
key2_hold_counter.time = 0.25
key2_hold_counter.count = 1
key2_hold_counter.event =
function()
key2_hold = true
screen_dirty = true
end
ui = {}
ui.control_set = "play"
ui.display_style = "single"
ui.edit_note = {}
ui.hill_focus = 1
ui.menu_focus = 1
ui.screen_controls = {}
ui.seq_menu_focus = 1
ui.seq_menu_layer = "nav"
ui.seq_controls = {}
ui.pattern_focus = {"s1","s1","s1","s1"}
hills = {}
for i = 1,#midi.vports do -- query all ports
midi_device[i] = midi.connect(i) -- connect each device
midi_device[i].event = function(data)
local d = midi.to_msg(data)
if d.type == 'note_on' then
for j = 1,number_of_hills do
-- if d.note == params:get('hill_'..j..'_iterator_midi_note')
-- and d.vel >= params:get('hill_'..j..'_iterator_midi_velocity_lo')
-- and d.vel <= params:get('hill_'..j..'_iterator_midi_velocity_hi')
if d.note == _midi.iterator.note[j]
and d.vel >= _midi.iterator.velocity_lo[j]
and d.vel <= _midi.iterator.velocity_hi[j]
and params:string('hill_'..j..'_iterator') == 'external MIDI'
and params:get('hill_'..j..'_iterator_midi_device') == i
then
if hills[j].highway then
_htracks.tick(j)
else
local k = hills[j].segment
if hills[j][k].note_num.pool[hills[j][k].index] ~= nil then
pass_note(j,k,hills[j][k],hills[j][k].note_num.pool[hills[j][k].index],hills[j][k].index,0)
end
hills[j][k].index = util.wrap(hills[j][k].index + 1, hills[j][k].low_bound.note,hills[j][k].high_bound.note)
end
if params:string('hill_'..j..'_iterator_midi_record') == 'yes' then
for k = 1,16 do
local table_to_record =
{
["event"] = "midi_trig",
["id"] = k,
["hill"] = j,
["segment"] = hills[j].segment,
["legato"] = params:get('hill_'..j..'_legato') == 1
}
write_pattern_data(k,table_to_record,false)
end
end
end
end
end
end
end
scale_names = {}
local scale_count = 1
for i = 1,#mu.SCALES do
scale_names[scale_count] = mu.SCALES[i].name
scale_count = scale_count + 1
end
prms.init()
_fkprm.init()
_polyparams.init()
_ccparams.init()
_midi.init()
-- prms.reload_engine(params:string("global engine"),true)
for i = 1,number_of_hills do
ui.edit_note[i] = {}
hills[i] = {}
hills[i].mode = "iterate"
hills[i].highway = false
hills[i].active = false
hills[i].crow_change_queued = false
hills[i].segment = 1
hills[i].looper = {["clock"] = nil}
hills[i].snapshot = {["partial_restore"] = false}
hills[i].snapshot.restore_times = {["beats"] = {1,2,4,8,16,32,64,128}, ["time"] = {1,2,4,8,16,32,64,128}, ["mode"] = "beats"}
hills[i].snapshot.mod_index = 0
hills[i].snapshot.focus = 0
hills[i].iter_links = {}
hills[i].iter_pulses = {}
hills[i].iter_counter = {}
for j = 1,number_of_hills do
hills[i].iter_links[j] = false
hills[i].iter_pulses[j] = 1
hills[i].iter_counter[j] = 1
end
ui.seq_controls[i] =
{
["seq"] = {["focus"] = 1}
, ["trig_detail"] = {["focus"] = 1, ["max"] = 3}
}
ui.screen_controls[i] = {}
ui.screen_controls[i] =
{
["seq"] = {["focus"] = 1}
}
hills[i].note_ocean = mu.generate_scale_of_length(params:get("hill "..i.." base note"),params:get("hill "..i.." scale"),127) -- the full range of notes
for j = 1,8 do
hills[i][j] = {}
hills[i][j].duration = util_round(clock.get_beat_sec() * 16,0.01)
hills[i][j].eject = hills[i][j].duration
hills[i][j].base_step = 0
hills[i][j].population = math.random(10,100)/100
hills[i][j].current_val = 0
hills[i][j].step = 0
hills[i][j].index = 1
hills[i][j].timing = {}
hills[i][j].shape = params:string("hill ["..i.."]["..j.."] shape")
hills[i][j].low_bound = {}
hills[i][j].low_bound.note = 1
hills[i][j].high_bound = {}
hills[i][j].high_bound.note = nil
hills[i][j].high_bound.time = hills[i][j].duration
hills[i][j].bound_mode = "note"
hills[i][j].loop = false
hills[i][j].looper = {
["clock"] = nil,
["runner"] = 1,
["mode"] = "phase",
["clock_time"] = 0
}
hills[i][j].playmode = "momentary"
hills[i][j].counter_div = 1
hills[i][j].perf_led = false
hills[i][j].iterated = true
hills[i][j].note_num = -- this is where we track the note entries for the constructed hill
{
["min"] = 1, -- defines the lowest note degree
["max"] = 15, -- defines the highest note degree
["pool"] = {}, -- gets filled with the constructed hill's notes
["active"] = {}, -- tracks whether the note should play
["chord_degree"] = {}, -- defines the shell voicing chord degree
}
hills[i][j].note_velocity = {}
hills[i][j].sample_controls = -- this is where we track the slices for the constructed hill
{
["loop"] = {}, -- gets filled with the constructed hill's loop states
["rate"] = {} -- gets filled with the constructed hill's rates
}
hills[i][j].note_timestamp = {}
hills[i][j].note_timedelta = {}
hills[i][j].mute = false
-- construct(i,j,true)
ui.edit_note[i][j] = 1
ui.screen_controls[i][j] =
{
["hills"] = {["focus"] = 1, ["max"] = 12}
, ["bounds"] = {["focus"] = 1, ["max"] = 2}
, ["notes"] = {["focus"] = 1, ["max"] = 12, ["transform"] = "mute step", ["velocity"] = false}
, ["loop"] = {["focus"] = 1, ["max"] = 2}
, ["samples"] = {["focus"] = 1, ["max"] = 12, ["transform"] = "shuffle"}
}
end
hills[i].counter = clock.run(function() _G[hills[i].mode](i) end)
hills[i].screen_focus = 1
startup_animation = clock.run(
function()
while true do
clock.sleep(1/15)
redraw()
end
end
)
menu_rebuild_clock = clock.run(function()
while true do
clock.sleep(1/15)
if screen_dirty then
redraw()
end
if menu_rebuild_queued then
_menu.rebuild_params()
menu_rebuild_queued = false
end
end
end)
end
print('built hills: '..util.time())
params.action_preread = function(filename,name,number)
-- readingPSET = true
-- for i = 1,7 do params:set(i..'_voice_state',0) end
-- _polyparams.reset_polyparams()
-- send_to_engine('reset',{})
end
params.action_read = function(filename,name,number)
readingPSET = true
print("loading hills data for PSET: "..number)
for i = 1,number_of_hills do
if params:get(i..'_voice_state') == 0 then
_menu.m.PARAMS.on[params.lookup[i..'_voice_state']] = 0
else
_menu.m.PARAMS.on[params.lookup[i..'_voice_state']] = 1
end
end
-- for i = 1,7 do params:set(i..'_voice_state',0) end
local this_filepath = _path.data..'hills/'..number..'/'
for i = 1,number_of_hills do
if hills[i].active then
stop(i,true)
end
hills[i] = tab.load(this_filepath.."data/"..i..".txt")
-- // TODO: this is temporary for luck dragon performance loading...
-- shouldn't be needed for release.
if hills[i].iter_pulses == nil then
hills[i].iter_pulses = {}
hills[i].iter_counter = {}
for j = 1,number_of_hills do
hills[i].iter_pulses = 1
hills[i].iter_counter = 1
end
end
for j = 1,8 do
if hills[i][j].mute == nil then
hills[i][j].mute = false
end
end
-- //
if hills[i].active then
stop(i,true)
end
end
for j = 1,16 do
if grid_pattern[j].play == 1 then
_g.stop_pattern_playback(j)
end
local to_inherit = tab.load(this_filepath.."patterns/"..j..".txt")
local inheritances = {'end_point', 'count', 'event', 'loop'}
for adj = 1, #inheritances do
grid_pattern[j][inheritances[adj]] = to_inherit[inheritances[adj]]
end
end
for j = 1,#song_atoms do
song_atoms[j] = tab.load(this_filepath.."song/"..j..".txt")
end
snapshots = tab.load(this_filepath.."snapshots/all.txt")
snapshot_overwrite = tab.load(this_filepath.."snapshots/overwrite_state.txt")
_fkprm.adjusted_params = tab.load(this_filepath.."per-step/_fkprm.txt")
-- _fkprm.adjusted_params_lock_trigs = tab.load(this_filepath.."per-step/_fkprm-lock_trigs.txt")
if util.file_exists(this_filepath.."per-voice/_polyparams.txt") then
_polyparams.adjusted_params = tab.load(this_filepath.."per-voice/_polyparams.txt")
end
for j = 1,number_of_hills do
track[j] = tab.load(this_filepath.."track/"..j..".txt")
for subs = 1,#track[j] do
local collect_sequins = {}
for data_steps = 1,track[j][subs].page_chain.length do
collect_sequins[data_steps] = track[j][subs].page_chain.data[data_steps]
end
track[j][subs].page_chain = _sequins{table.unpack(collect_sequins)}
end
end
-- params:bang() -- TODO VERIFY IF THIS IS OKAY TO LEAVE OUT
grid_dirty = true
print('loading pset!'..this_filepath)
if util.file_exists(this_filepath.."poly-params.txt") then
print('loading poly params!')
-- kildare.queued_read_file = this_filepath.."poly-params.txt"
engine.load_poly_params(this_filepath.."poly-params.txt")
end
full_PSET_swap()
clock.run(
function()
clock.sleep(0.3)
readingPSET = false
if PSET_LOOP == nil then PSET_LOOP = 0 end
PSET_LOOP = PSET_LOOP + 1
print('PSET NOT READING')
if PSET_LOOP == 3 then
PSET_LOOP = 0
PSET_SWAPPING = nil
end
end
)
end
local function params_write_silent(filename,name)
print("pset >>>>>>> write: "..filename)
local fd = io.open(filename, "w+")
if fd then
io.output(fd)
io.write("-- "..name.."\n")
for _,param in ipairs(params.params) do
if param.id and param.save and param.t ~= params.tTRIGGER and param.t ~= params.tSEPARATOR then
io.write(string.format("%s: %s\n", quote(param.id), param:get()))
end
end
io.close(fd)
end
end
params.action_write = function(filename,name,number)
-- local pset_string = string.sub(filename,string.len(filename) - 6, -1)
-- local pset_number = pset_string:gsub(".pset","")
print("saving hills data for PSET: "..number)
kildare.move_audio_into_perm(_path.audio..'kildare/'..number..'/')
util.make_dir(_path.data.."hills/"..number.."/data")
util.make_dir(_path.data.."hills/"..number.."/patterns")
util.make_dir(_path.data.."hills/"..number.."/song")
util.make_dir(_path.data.."hills/"..number.."/snapshots")
util.make_dir(_path.data.."hills/"..number.."/track")
util.make_dir(_path.data.."hills/"..number.."/per-step")
util.make_dir(_path.data.."hills/"..number.."/per-voice")
for i = 1,number_of_hills do
tab.save(hills[i],_path.data.."hills/"..number.."/data/"..i..".txt")
tab.save(track[i],_path.data.."hills/"..number.."/track/"..i..".txt")
end
for i = 1,16 do
tab.save(grid_pattern[i],_path.data.."hills/"..number.."/patterns/"..i..".txt")
end
for i = 1,#song_atoms do
tab.save(song_atoms[i],_path.data.."hills/"..number.."/song/"..i..".txt")
end
tab.save(snapshots,_path.data.."hills/"..number.."/snapshots/all.txt")
tab.save(snapshot_overwrite, _path.data.."hills/"..number.."/snapshots/overwrite_state.txt")
tab.save(_fkprm.adjusted_params, _path.data.."hills/"..number.."/per-step/_fkprm.txt")
-- tab.save(_fkprm.adjusted_params_lock_trigs, _path.data.."hills/"..number.."/per-step/_fkprm-lock_trigs.txt")
tab.save(_polyparams.adjusted_params, _path.data.."hills/"..number.."/per-voice/_polyparams.txt")
params_write_silent(filename,name)
os.execute('touch '.._path.data..'hills/'..number..'/poly-params.txt')
engine.save_poly_params(_path.data..'hills/'..number..'/poly-params.txt')
end
params.action_delete = function(filename, name, pset_number)
local delete_this_folder = _path.audio..'kildare/'..pset_number..'/'
if util.file_exists(delete_this_folder) then
os.execute('rm -r '..delete_this_folder)
end
delete_this_folder = _path.data..'hills/'..pset_number..'/'
if util.file_exists(delete_this_folder) then
os.execute('rm -r '..delete_this_folder)
end
end
function kildare.voice_param_callback(voice, param, val)
if snapshot_overwrite_mod then
local d_voice = type(voice) ~= 'string' and selectedVoiceModels[voice] or voice
if util.string_starts(voice, 'sample') then
voice = tonumber(string.sub(voice,-1)) + 7 -- TODO: CONFIRM CPU OKAY
end
for i = 1,8 do
local should_overwrite = snapshot_overwrite[voice][d_voice][i]
if should_overwrite and params:string('lfo_snapshot_'..voice) == 'off' then
-- print('overwriting', snapshots[voice][d_voice][i][param])
snapshots[voice][d_voice][i][param] = val
end
end
end
for i = 1,16 do
if (grid_pattern[i].rec == 1 or grid_pattern[i].overdub == 1) and params:string('pattern_'..i..'_parameter_change_restore') == 'yes' then
grid_pattern[i]:watch_mono(
{
['event'] = 'parameter_value_change',
['voice'] = voice,
['param'] = param,
['value'] = val,
['model'] = selectedVoiceModels[voice],
['id'] = i
}
)
end
if grid_pattern[i].clear_mono == 1 then
grid_pattern[i]:clear_mono_events(
{
['voice'] = voice,
['param'] = param,
['value'] = val,
['model'] = selectedVoiceModels[voice],
['id'] = i
}
)
end
end
end
function kildare.model_change_callback(hill,model)
hill_names[hill] = hill..': '..model
prms.change_UI_name('hill_'..hill..'_group', hill_names[hill])
prms.change_UI_name('hill_'..hill..'_note_header', 'note management '..hill_names[hill])
prms.change_UI_name('hill_'..hill..'_kildare_header', 'Kildare management '..hill_names[hill])
prms.change_UI_name('hill_'..hill..'_sample_header', 'sample management '..hill_names[hill])
prms.change_UI_name('hill_'..hill..'_MIDI_header', 'MIDI management '..hill_names[hill])
prms.change_UI_name('hill_'..hill..'_crow_header', 'crow management '..hill_names[hill])
prms.change_UI_name('hill_'..hill..'_JF_header', 'JF management '..hill_names[hill])
prms.change_UI_name('snapshot_crossfade_header_'..hill, 'crossfader '..hill_names[hill])
grid_dirty = true
for i = 1,8 do
snapshot_overwrite[hill][model][i] = false
end
if model == 'sample' then
params:set('hill '..hill..' sample output',2)
end
-- snapshot_overwrite_mod = false
end
_hsteps.init()
for i = 1,number_of_hills do
_htracks.init(i,1)
end
print('wrapped with startup: '..util.time())
clock.run(
function()
clock.sleep(2)
development_state()
if kildare.queued_read_file ~= nil then
print('!!!!!!!!!!!!!!!!!!!!!!!!queud read')
engine.load_poly_params(kildare.queued_read_file)
kildare.queued_read_file = nil
end
-- print('dev state: '..util.time())
-- print('starting from toggle')
clock.run(function() clock.sleep(1) loading_done = true clock.cancel(startup_animation) end)
end
)
for i = 1,number_of_hills do
for j = 1, number_of_patterns do
hodgepodge(i,j)
end
end
print('done: '..util.time())
last_voice_param = params.lookup[number_of_hills..'_sample_feedbackSend']
end
function pass_data_into_storage(i,j,index,data)
if data[1] ~= data[1] then
print('woulda been nan', i,j, index)
hills[i][j].note_num.pool[index] = math.random(hills[i][j].note_num.min, hills[i][j].note_num.max)
else
hills[i][j].note_num.pool[index] = data[1]
end
hills[i][j].note_timestamp[index] = data[2]
hills[i][j].high_bound.note = #hills[i][j].note_num.pool
hills[i][j].note_num.active[index] = true
hills[i][j].note_num.chord_degree[index] = util.wrap(hills[i][j].note_num.pool[index], 1, 7)
hills[i][j].note_velocity[index] = 127
hills[i][j].sample_controls.loop[index] = false
hills[i][j].sample_controls.rate[index] = 9
end
-- construct = function(i,j,shuffle)
-- local h = hills[i]
-- local seg = h[j]
-- local total_notes = util_round(#h.note_ocean*seg.population)
-- local index = 0
-- local reasonable_max = seg.note_num.min ~= seg.note_num.max and seg.note_num.max or seg.note_num.min+1
-- for k = 0,seg.duration*100 do
-- local last_val = seg.current_val
-- seg.current_val = math.floor(util.wrap(curves[seg.shape](k/100,1,total_notes-1,seg.duration),seg.note_num.min,reasonable_max))
-- local note_num = seg.note_num.min ~= seg.note_num.max and seg.current_val or seg.note_num.min
-- if util_round(last_val) ~= util_round(seg.current_val) then
-- if i == 1 and j == 1 then print(k/100) end
-- index = index + 1
-- pass_data_into_storage(i,j,index,{note_num,k/100})
-- end
-- end
-- calculate_timedeltas(i,j)
-- if shuffle then
-- _t['shuffle notes'](i,j,hills[i][j].low_bound.note,hills[i][j].high_bound.note)
-- end
-- -- TODO: redraws for every construct
-- screen_dirty = true
-- end
stepOffset = 0
hodgepodge = function(i,j)
local h = hills[i]
local seg = h[j]
local populous = params:get("hill ["..i.."]["..j.."] population")/100
local total_notes = util.clamp(util_round(48*populous),10,inf)
-- print(i,j,params:get("hill ["..i.."]["..j.."] population")/100)
local index = 0
local reasonable_max = seg.note_num.min ~= seg.note_num.max and seg.note_num.max or seg.note_num.min+1
-- just generate times
local splitter = {}
local splits = 5
local tests = {}
for stuff = 1,splits do
splitter[stuff] = math.floor(total_notes / splits)
end
for stuff = 1,total_notes % splits do
splitter[stuff] = splitter[stuff] + 1
end
-- splitter[1] = math.floor(total_notes/3)
-- local nt = (total_notes - splitter[1])
-- splitter[2] = math.floor(nt/2)
-- splitter[3] = math.floor((nt - splitter[2]))
easedTimes = {}
easedNotes = {}
-- for steps = 1,total_notes do
for splitsteps = 1,#splitter do
seg.shape = easingNames[math.random(#easingNames)] -- change shape
easedTimes[splitsteps] = {}
easedNotes[splitsteps] = {}
for steps = 1,splitter[splitsteps] do
easedTimes[splitsteps][steps] = util.linlin(
curves[seg.shape](
util.clamp(stepOffset, 0, total_notes-1),
0,
seg.duration,
total_notes
),
seg.duration,
0,
seg.duration/2,
curves[seg.shape](
util.clamp((steps-1) + stepOffset, 0, total_notes-1),
0,
seg.duration,
total_notes
)
)
easedNotes[splitsteps][steps] = math.floor(
util.wrap(
curves[seg.shape](
util.clamp((steps-1) + stepOffset, 0, total_notes-1),
1,
total_notes-1,
seg.duration
),
seg.note_num.min,
reasonable_max
)
)
easedNotes[splitsteps][steps] = seg.note_num.min ~= seg.note_num.max and easedNotes[splitsteps][steps] or seg.note_num.min
if steps > 1 then
if easedTimes[splitsteps][steps] < 0
or easedTimes[splitsteps][steps] <= easedTimes[splitsteps][steps-1]
or easedTimes[splitsteps][steps] - easedTimes[splitsteps][steps-1] < 0.01 then
easedTimes[splitsteps][steps] = easedTimes[splitsteps][steps-1] + (math.random(1,6)/100)
end
end
end
-- print(seg.shape, seg.population)
-- tab.print(easedTimes[splitsteps])
end
allTimes = {}
allNotes = {}
for times = 1,#easedTimes[1] do
allTimes[times] = easedTimes[1][times]
allNotes[times] = easedNotes[1][times]
end
local currentCount = #allTimes
for finalCount = 2,#easedTimes do
-- print('there are '..finalCount)
for times = 2,#easedTimes[finalCount] do
local thisLast = easedTimes[finalCount][#easedTimes[finalCount]]
local prevLast = allTimes[currentCount]
allTimes[#allTimes+1] = util.linlin(
0,
thisLast,
prevLast,
prevLast + thisLast,
easedTimes[finalCount][times]
)
allNotes[#allNotes+1] = easedNotes[finalCount][times]
end
currentCount = #allTimes
end
-- for times = 2,#easedTimes[2] do
-- -- allTimes[#allTimes+1] = easedTimes[2][times] + allTimes[#allTimes]
-- local thisLast = easedTimes[2][#easedTimes[2]]
-- local prevLast = allTimes[currentCount]
-- allTimes[#allTimes+1] = util.linlin(
-- 0,
-- thisLast,
-- prevLast,
-- prevLast + thisLast,
-- easedTimes[2][times]
-- )
-- allNotes[#allNotes+1] = easedNotes[2][times]
-- end
-- currentCount = #allTimes
-- for times = 2,#easedTimes[3] do
-- local thisLast = easedTimes[3][#easedTimes[3]]
-- local prevLast = allTimes[currentCount]
-- -- allTimes[#allTimes+1] = easedTimes[3][times] + allTimes[#allTimes]
-- allTimes[#allTimes+1] = util.linlin(
-- 0,
-- thisLast,
-- prevLast,
-- prevLast + thisLast,
-- easedTimes[3][times]
-- )
-- allNotes[#allNotes+1] = easedNotes[3][times]
-- end
-- tab.print(allTimes)
for index = 1,#allTimes do
if allTimes[index] < 0 then print('WOAHHH') end
pass_data_into_storage(i,j,index,{allNotes[index],allTimes[index]})
end
calculate_timedeltas(i,j)
_t['shuffle notes'](i,j,hills[i][j].low_bound.note,hills[i][j].high_bound.note)
screen_dirty = true
-- print(i,j,total_notes,populous, #allTimes)
end
reconstruct = function(i,j,new_shape)
local h = hills[i]
local seg = h[j]
-- keep min and max timestamps the same...
local beginVal = seg.note_timestamp[seg.low_bound.note]
local endVal = seg.note_timestamp[seg.high_bound.note]
local change = endVal - beginVal
local duration = endVal - beginVal
for k = seg.low_bound.note,seg.high_bound.note do
print('reconstructing curves '..curves[new_shape](seg.note_timestamp[k],beginVal,change,duration))
local new_timestamp = curves[new_shape](seg.note_timestamp[k],beginVal,change,duration)
seg.note_timestamp[k] = new_timestamp
end
calculate_timedeltas(i,j)
screen_dirty = true
end
calculate_timedeltas = function(i,j)
for k = 1,#hills[i][j].note_timestamp do
if k < #hills[i][j].note_timestamp then
hills[i][j].note_timedelta[k] = util.clamp(hills[i][j].note_timestamp[k+1] - hills[i][j].note_timestamp[k], 0.1, inf)
else
hills[i][j].note_timedelta[k] = 0.06
end
end
end
iterate = function(i)
while true do
clock.sync(1/(32*hills[i][hills[i].segment].counter_div))
if hills[i].active then
local h = hills[i]
local seg = h[h.segment]
if seg.loop then
if seg.high_bound.note ~= seg.low_bound.note then
if seg.note_timestamp[seg.index] ~= nil then
if util_round(seg.note_timestamp[seg.index],0.01) == util_round(seg.step,0.01) then
pass_note(i,hills[i].segment,seg,seg.note_num.pool[seg.index],seg.index,0)
seg.index = seg.index + 1
seg.perf_led = true
end
seg.step = util_round(seg.step + 0.01,0.01)
-- local reasonable_max = seg.note_timestamp[seg.high_bound.note+1] ~= nil and seg.note_timestamp[seg.high_bound.note+1] or seg.note_timestamp[seg.high_bound.note] + seg.note_timedelta[seg.high_bound.note]
local reasonable_max = seg.note_timestamp[seg.high_bound.note]
if util_round(seg.step,0.01) >= util_round(reasonable_max,0.01) then
if seg.looper.mode == "phase" then
_a.start(i,h.segment)
else
stop(i)
end
end
grid_dirty = true
end
else
if util_round(seg.note_timestamp[seg.index+1],0.01) == util_round(seg.step,0.01) then
pass_note(i,hills[i].segment,seg,seg.note_num.pool[seg.index],seg.index,0)
seg.step = seg.note_timestamp[seg.index]
seg.perf_led = true
else
seg.step = util_round(seg.step + 0.01,0.01)
end
grid_dirty = true
end
else
seg.iterated = false
if seg.index <= seg.high_bound.note then
if util_round(seg.note_timestamp[seg.index],0.01) == util_round(seg.step,0.01) then
pass_note(i,hills[i].segment,seg,seg.note_num.pool[seg.index],seg.index,0)
seg.index = seg.index + 1
seg.perf_led = true
end
seg.step = util_round(seg.step + 0.01,0.01)
local comparator;
if seg.bound_mode == "time" then
comparator = util_round(seg.step,0.01) > util_round(seg.high_bound.time,0.01)
elseif seg.bound_mode == "note" then
comparator = seg.index > seg.high_bound.note
end
if comparator then -- if `>` then this get us a final tick, which is technically duration + 0.01
stop(i,true)
end
grid_dirty = true
end
end
end
end
end
stop = function(i,clock_synced_loop)