-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdreamsequence.lua
executable file
·7559 lines (6139 loc) · 284 KB
/
dreamsequence.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
-- Dreamsequence
-- 1.4 240910 Dan Stroud
-- llllllll.co/t/dreamsequence
--
-- Chord-based sequencer,
-- arpeggiator, and harmonizer
-- for Monome Norns+Grid
--
-- K1: Alt (hold)
-- K2: Pause/Stop(2x)
-- K3: Play
--
-- E1: Scroll Grid
-- E2: Select
-- E3: Edit (+K1 to defer)
--
-- Crow IN 1: CV in
-- Crow IN 2: Trigger in
-- Crow OUT 1: CV out
-- Crow OUT 2: Envelope out
-- Crow OUT 3: Events out
-- Crow OUT 4: Clock out
-- stuff needed by includes
dreamsequence = {}
-- layout and palette
xy = {
dash_x = 93,
header_x = 0,
header_y = 8,
menu_y = 8,
scrollbar_y = 12
}
local lvl_normal = {
menu_selected = 15,
menu_deselected = 4,
pane = 15,
pane_selected = 0, -- also chart black
pane_deselected = 3,
pane_dark = 7,
chart_deselected = 3,
}
local lvl_dimmed = {
menu_selected = 7,
menu_deselected = 2,
pane = 7,
pane_selected = 1,
pane_deselected = 3, -- not dimmed
pane_dark = 3,
chart_deselected = 2,
}
lvl = lvl_normal -- required for includes:dashboards.lua
blinky = 0 -- must be global for dashboards.lua todo look into this
local led_high = 15
local led_med = 7
local led_low = 3
local led_high_blink = 15 - blinky * 4
local led_med_blink = 7 - blinky * 2
local led_low_blink = 3 - blinky
led_pulse = 0 -- must be global for dashboards.lua todo look into this
max_seqs = 3
max_seq_cols = 15 - max_seqs
max_seq_patterns = 4
max_seq_pattern_length = 16
-- base scales used to define triads
dreamsequence.scales = {
-- canonical scales
"Major", -- "Ionian",
"Natural Minor", -- "Aeolian",
"Harmonic Minor",
"Melodic Minor",
"Dorian",
"Phrygian",
"Lydian",
"Mixolydian",
"Locrian",
-- -- some nice additions that work, too, but needs to think about handling degree readout
-- "Altered Scale", -- double flats in F, might wait for norns.ttf
-- "Harmonic Major", -- double flats in Db, might wait for norns.ttf
-- "Overtone",
}
-- pre-init bits n bobs
norns.version.required = 231114 -- rolling back for Fates but 240221 is required for link support
g = grid.connect()
include(norns.state.shortname.."/lib/includes")
-- load global scale mask file if present
local filepath = norns.state.data
masks = {} -- has to be global because of pset write function. todo p2 fix
if util.file_exists(filepath) then
if util.file_exists(filepath.."masks.data") then
masks = tab.load(filepath.."masks.data")
print("table >> read: " .. filepath.."masks.data")
else
masks = gen_default_masks()
end
end
theory.masks = masks
clock.link.stop() -- transport won't start if external link clock is already running
-- pre-init locals
local latest_strum_coroutine = coroutine.running()
--#region init
function init()
-----------------------------
-- todo p0 prerelease ALSO MAKE SURE TO UPDATE ABOVE!
local version = 010400 --1.4.0
-----------------------------
function read_prefs()
prefs = {}
local filepath = norns.state.data
if util.file_exists(filepath) then
if util.file_exists(filepath.."prefs.data") then
local p = tab.load(filepath.."prefs.data")
if (tonumber(p.last_version) or 0) >= 010400 then -- todo p0 prerelease UPDATE if prefs have changed
print("table >> read: " .. filepath.."prefs.data")
prefs = p
else
print("Ignoring obsolete prefs.data")
end
else
print("table >> missing: " .. filepath.."prefs.data")
end
else
print("table >> missing: " .. filepath.."prefs.data")
end
end
read_prefs()
if prefs ~= nil then
nb.voice_count = prefs.voice_instances or 1
print("nb.voice_count set to " .. nb.voice_count)
end
nb:init()
------------------------------------
-- redefine system functions/actions
------------------------------------
-- update MIDI clock ports on add/remove/clock param change. Restored on script init
for i = 1,16 do
local old_action = params.params[params.lookup["clock_midi_out_" .. i]].action
params:set_action("clock_midi_out_"..i,
function(x)
old_action(x)
transport_midi_update()
end
)
end
function midi.add(dev) -- Restored on script init
transport_midi_update()
end
function midi.remove(dev) -- Restored on script init
transport_midi_update()
end
-- thanks @dndrks for this little bit of magic to check ^^crow^^ version!!
norns.crow.events.version = function(...)
crow_version = ...
end
crow.version() -- Uses redefined crow.version() function to set crow_version global var
crow_version_clock = clock.run(
function()
clock.sleep(.05) -- a small hold for usb round-trip
local major, minor, patch = string.match(crow_version or "v9.9.9", "(%d+)%.(%d+)%.(%d+)")
local crow_version_num = major + (minor /10) + (patch / 100) -- this feels like it's gonna break lol
if crow_version ~= nil then print("Crow version " .. crow_version) end
if crow_version_num < 4.01 then
print("Crow compatibility mode enabled per https://github.com/monome/crow/pull/463")
crow_trigger_in = function()
if crow_div == 0 then
crow.send("input[1].query = function() stream_handler(1, input[1].volts) end")
crow.input[1].query()
end
end
else
crow_trigger_in = function()
-- todo p2 could just overwrite function so nothing happens. Not sure how to do that and maintain crow clock_source though
if crow_div == 0 then
crow.input[1].query()
end
end
end
crow.input[1].stream = sample_crow
crow.input[1].mode("none")
-- todo idea: could do a gate with "both" for ADSR envelope so this can do passthrough note duration
if params:get("clock_source") ~= 4 then
crow.input[2].mode("change", 2 , 0.1, "rising") -- voltage threshold, hysteresis, "rising", "falling", or “both"
crow.input[2].change = crow_trigger_in
end
end
)
crow.ii.jf.event = function(e, value)
if e.name == "mode" then
-- print("preinit jf.mode = "..value)
preinit_jf_mode = value
elseif e.name == "time" then
jf_time = value
-- print("jf_time = " .. value)
end
end
------------------------------------
-- save and restore pre-init state
------------------------------------
function capture_preinit()
preinit_jf_mode = clock.run(
function()
clock.sleep(0.005) -- a small hold for usb round-trip -- not sure this is needed any more
crow.ii.jf.get ("mode") -- will trigger the above .event function
-- Activate JF Synthesis mode here so it happens after the hold
crow.ii.jf.mode(1)
end
)
end
capture_preinit()
-- Reverts changes to crow and jf that might have been made by DS
function cleanup()
seq_lattice:destroy()
nb:stop_all()
note_players = {} -- clears bundled crow/midi players for next script
clock.link.stop()
if preinit_jf_mode == 0 then
crow.ii.jf.mode(preinit_jf_mode)
print("Restoring jf.mode to " .. preinit_jf_mode)
end
end
-------------
-- Read prefs
-------------
read_prefs()
init_generator()
---------------------
-- Initialize Events
---------------------
local events_lookup_names = {}
local events_lookup_ids = {}
local event_categories = {}
function init_events()
events_lookup_names = {} -- locals defined outside of function
events_lookup_ids = {}
for i = 1, #events_lookup do
events_lookup_names[i] = events_lookup[i].name
events_lookup_ids[i] = events_lookup[i].id
end
events_lookup_index = tab.invert(events_lookup_ids)
-- Used to derive the min and max indices for the selected event category (Song, Chord, Seq, etc...)
-- local event_categories = {}
event_categories = {}
for i = 1, #events_lookup do
event_categories[i] = events_lookup[i].category
end
event_categories_unique = {}
for i = 1, #event_categories do
if i == 1 then
table.insert(event_categories_unique, event_categories[i])
elseif event_categories[i] ~= event_categories_unique[#event_categories_unique] then
table.insert(event_categories_unique, event_categories[i])
end
end
-- Generate subcategories lookup tables
gen_event_tables()
-- Derivatives:
-- event_subcategories: Unique, ordered event subcategories for each category. For generating subcategories
-- event_indices: key = conctat category_subcategory with first_index and last_index values
end
--------------------
-- PARAMS
--------------------
-- functions and globals used by params
pattern_name = {"A","B","C","D"}
-- show or hide midi channel param/menu
local function set_channel_vis(id, channel_param)
local old_visible = params:visible(channel_param)
local player = nb.players[id]
local new_visible = player and player.channel
if old_visible ~= new_visible then
if new_visible then
params:show(channel_param)
else
params:hide(channel_param)
end
_menu.rebuild_params()
gen_menu()
end
end
----------------------------------------
params:add_separator ("DREAMSEQUENCE")
------------------
-- PREFERENCES PARAMS --
------------------
-- Persistent settings saved to prefs.data and managed outside of .pset files
params:add_group("preferences", "PREFERENCES", 16 + 16) -- 16 midi ports
-- params:add_separator("pset","pset")
params:add_option("default_pset", "Default song", {"New", "Last PSET", "Template"}, 1)
params:set_save("default_pset", false)
-- param_option_to_index is used rather than set_param_string to handle any invalid/changed saved values
params:set("default_pset", param_option_to_index("default_pset", prefs.default_pset) or 1)
params:set_action("default_pset", function() save_prefs() end)
params:add_trigger("save_template", "Save template")
params:set_save("save_template", false)
params:set_action("save_template", function() params:write(00,"template") end)
params:add_trigger("save_masks", "Save masks")
params:set_save("save_masks", false)
params:set_action("save_masks", function() write_global_scales() end)
-- params:add_separator("interaction","interaction")
params:add_option("sync_views", "Sync views", {"Off", "On"}, 2)
params:set_save("sync_views", false)
params:set("sync_views", param_option_to_index("sync_views", prefs.sync_views) or 2)
params:set_action("sync_views", function() save_prefs() end)
params:add_option("notifications", "Notifications", {"Off", "Momentary", "Brief", "Extended"}, 3)
params:set_save("notifications", false)
params:set("notifications", param_option_to_index("notifications", prefs.notifications) or 3)
params:set_action("notifications", function() save_prefs() end)
params:add_option("preview_notes", "Preview notes", {"Off", "On"}, 2)
params:set_save("preview_notes", false)
params:set("preview_notes", param_option_to_index("preview_notes", prefs.preview_notes) or 2)
params:set_action("preview_notes", function() save_prefs() end)
-- params:add_separator("dashboard","dashboard")
local defaults = {"Metro T+", "Arranger chart", "Chord progress", "Chord name"}
-- todo probably a better way to do this rather than having these dummy funcs being called
local function init_dummy_funcs()
function calc_seconds_remaining() end
function calc_seconds_elapsed() end
function gen_dash_chord_viz() end
end
init_dummy_funcs()
xy.dash_x = 129 -- kinda silly but in case user has no dashboards, shift over the scrollbar
max_dashboards = 4
for dash_no = 1, max_dashboards do -- limiting to 4 dashboards for now
params:add_option("dash_" .. dash_no, "Dash " .. dash_no, dash_name, 1)
params:set_save("dash_" .. dash_no, false)
params:set("dash_" .. dash_no, param_option_to_index("dash_" .. dash_no, prefs["dash_" .. dash_no] or defaults[dash_no]) or 1 )
params:set_action("dash_" .. dash_no,
function(val)
save_prefs()
dash_list[dash_no] = dash_functions[dash_ids[val]]
-- redefine dash functions depending on selection
-- init functions in inactive states
init_dummy_funcs()
seconds_remaining = "00:00"
seconds_elapsed_raw = 0
for dash_no = 1, max_dashboards do -- check every param each time one is changed
local dash = params:string("dash_" .. dash_no)
if dash == "Metro T-" then
function calc_seconds_remaining()
if arranger_state == "on" then
percent_step_elapsed = (arranger_position == 0 and 0 or sprocket_chord.phase) / (sprocket_chord.division * 4 * seq_lattice.ppqn) -- ppc
seconds_remaining = chord_steps_to_seconds(steps_remaining_in_arrangement - (percent_step_elapsed or 0))
else
seconds_remaining = chord_steps_to_seconds(steps_remaining_in_arrangement - (steps_remaining_in_active_pattern or 0))
end
seconds_remaining = s_to_min_sec(math.ceil(seconds_remaining))
end
xy.dash_x = 93
elseif dash == "Metro T+" then --redefine function if needed
function calc_seconds_elapsed()
seconds_elapsed_raw = seconds_elapsed_raw + .1
seconds_elapsed = s_to_min_sec(seconds_elapsed_raw)
end
xy.dash_x = 93
elseif dash == "Chord kbd" then -- generate chord keyboard diagram for dash
function gen_dash_chord_viz()
local txp = params:get("tonic")
local w = {0, 2, 4, 5, 7, 9, 11} -- white keys
local b = {1, 3, 6, 8, 10} -- black keys
local keystate = {}
dash_keys_white = {}
dash_keys_black = {}
for i = 1, #chord_raw do
keystate[util.wrap(chord_raw[i] + txp, 0, 11)] = true
end
for i = 1, 7 do
dash_keys_white[i] = keystate[w[i]]
end
for i = 1, 5 do
dash_keys_black[i] = keystate[b[i]]
end
end
elseif dash ~= "Off" then
xy.dash_x = 93
end
end
end)
end
params:add_option("crow_pullup", "Crow pullup", {"Off", "On"}, 2)
params:set_save("crow_pullup", false)
params:set("crow_pullup", param_option_to_index("crow_pullup", prefs.crow_pullup) or 2)
params:set_action("crow_pullup", function(val) crow_pullup(val); save_prefs() end)
params:add_number("voice_instances", "Voice instances", 1, 4, 1)
params:set_save("voice_instances", false)
params:set("voice_instances", (prefs.voice_instances or 1))
params:set_action("voice_instances", function() save_prefs() end)
local function config_enc(enc, val)
local accel = 1 - (val % 2)
local val = (9 - val + accel) / 2
-- print("enc " .. enc .. ": sens " .. util.round(val) .. ", accel " .. (accel == 1 and "on" or "off"))
norns.enc.sens(enc, val)
norns.enc.accel(enc, accel == 1)
end
for i = 1, 3 do
params:add_option("config_enc_" .. i, "Enc " .. i, {"Slower -accel", "Slower +accel", "Slow, -accel", "Slow +accel", "Normal -accel", "Normal +accel", "Fast -accel", "Fast +accel"}, 6)
params:set_save("config_enc_" .. i, false)
params:set("config_enc_" .. i, ((prefs["config_enc_" .. i]) or 6))
params:set_action("config_enc_" .. i, function(val) save_prefs(); config_enc(i, val) end)
end
params:add_separator ("MIDI CLOCK OUT") -- todo hide if no MIDI devices
for i = 1, 16 do
local id = "midi_continue_" .. i
params:add_option(id, id, {"pattern", "song"}, 2)
params:set_save(id, false)
params:set(id, param_option_to_index(id, prefs.id) or 2)
params:set_action(id, function()
save_prefs()
end)
end
transport_midi_update() -- renames midi_continue_ params
------------------
-- ARRANGER PARAMS --
------------------
params:add_group("arranger_group", "ARRANGER", 2)
params:add_option("arranger", "Arranger", {"Off", "On"}, 1) -- action set post-bang
params:add_option("playback", "Playback", {"1-shot", "Loop"}, 2)
params:set_action("playback", function() update_arranger_next() end)
------------------
-- SONG PARAMS --
------------------
params:add_group("song", "SONG", 13)
params:add_number("tonic", "Tonic", -12, 12, 0, function(param) return transpose_string(param:get()) end)
params:set_action("tonic", function() gen_chord_readout() end)
local scales = {}
for i = 1, #dreamsequence.scales do
scales[i] = dreamsequence.scales[i]:gsub("%f[%a]Minor%f[%A]", "Min")
end
params:add_option("scale", "Scale", scales, 1) -- post-bang action
params:add_number("ts_numerator", "Beats per bar", 1, 99, 4) -- Beats per bar
params:add_option("ts_denominator", "Beat length", {1, 2, 4, 8, 16}, 3) -- Beat length
params:add_option("crow_out_1", "Crow out 1", {"Off", "CV", "Env", "Events"}, 2)
params:set_action("crow_out_1",function() gen_voice_lookups(); update_voice_params() end)
params:add_option("crow_out_2", "Crow out 2", {"Off", "CV", "Env", "Events"}, 3)
params:set_action("crow_out_2",function() gen_voice_lookups(); update_voice_params() end)
params:add_option("crow_out_3", "Crow out 3", {"Off", "CV", "Env", "Events"}, 4)
params:set_action("crow_out_3",function() gen_voice_lookups(); update_voice_params() end)
params:add_option("crow_out_4", "Crow out 4", {"Off", "CV", "Env", "Events", "Clock"}, 5)
params:set_action("crow_out_4",function() gen_voice_lookups(); update_voice_params() end)
-- Crow clock uses hybrid notation/PPQN
params:add_number("crow_clock_index", "Crow clk", 1, 58, 7,function(param) return crow_clock_string(param:get()) end)
params:add_number("crow_clock_swing", "Crow swing", 50, 99, 50, function(param) return percent(param:get()) end)
params:add_number("dedupe_threshold", "Dedupe <", 0, 10, div_to_index("1/32"), function(param) return divisions_string(param:get()) end)
params:set_action("dedupe_threshold", function() dedupe_threshold() end)
-- deprecated
-- params:add_number("chord_preload", "Chord preload", 0, 10, div_to_index("1/64"), function(param) return divisions_string(param:get()) end)
-- params:set_action("chord_preload", function(x) chord_preload(x) end)
-- figured better here since generators can touch things outside of the chord/seq space
params:add_option("chord_generator", "C-gen", chord_algos["name"], 1)
params:add_option("seq_generator", "S-gen", seq_algos["name"], 1)
------------------
-- CHORD PARAMS --
------------------
params:add_group("chord", "CHORD", 18)
nb:add_param("chord_voice_raw", "Voice raw")
params:hide("chord_voice_raw")
gen_voice_lookups() -- required to build front-end voice selectors (chord_voice_raw dependency)
params:add_option("chord_voice", "Voice", voice_param_options, 1)
params:set_action("chord_voice",
function(index)
params:set("chord_voice_raw", voice_param_index[index])
set_channel_vis(params:string("chord_voice_raw"), "chord_channel")
end
)
params:add_number("chord_channel", "Channel", 1, 16, 1)
params:hide("chord_channel")
params:add_option("chord_mute", "Play/mute", {"Play", "Mute"}, 1)
params:add_number("chord_octave","Octave", -4, 4, 0)
params:add_number("chord_range", "Range", 0, 64, 0,
function(param)
local val = param:get()
if val == 0 then
return("Chord")
-- elseif params:get("chord_notes") > params:get("chord_range") then -- circle back on this. might keep
-- return(val .. "*")
else
return(val)
end
end
)
params:add_number("chord_notes", "Max notes", 1, 25, 25,
function(param)
local val = param:get()
if val == 25 then
return("Range")
else
return(val)
end
end
)
params:add_number("chord_inversion", "Inversion", 0, 16, 0) -- todo negative inversion
params:add_option("chord_style", "Strum", {"Off", "Low-high", "High-low"}, 1)
params:add_number("chord_strum_length", "Strum length", 1, 15, 15, function(param) return strum_length_string(param:get()) end)
params:add_number("chord_timing_curve", "Strum curve", -100, 100, 0, function(param) return percent(param:get()) end)
params:add_number("chord_div_index", "Step length", 5, 57, 15, function(param) return divisions_string(param:get()) end)
-- action required here for pset loading. Will then be redefined post-bang with action for lattice
params:set_action("chord_div_index",function(val) chord_div = division_names[val][1] end)
-- chord_div needs to be set *before* the bang happens
chord_div = division_names[params:get("chord_div_index")][1]
params:add_number("chord_duration_index", "Duration", 0, 57, 0, function(param) return durations_string(param:get()) end)
params:set_action("chord_duration_index",function(val) chord_duration = val == 0 and chord_div or division_names[val][1] end)
params:add_number("chord_swing", "Swing", 50, 99, 50, function(param) return percent(param:get()) end)
params:add_number("chord_dynamics", "Dynamics", 0, 100, 70, function(param) return percent(param:get()) end)
params:add_number("chord_dynamics_ramp", "Ramp", -100, 100, 0, function(param) return percent(param:get()) end) --todo p1 update param and docs to "Tracking"
-- will act on current pattern unlike numbered seq param
max_chord_pattern_length = 16
params:add_number("chord_pattern_length", "Pattern length", 1, max_chord_pattern_length, 4)
params:set_action("chord_pattern_length", function(val) chord_pattern_length[active_chord_pattern] = val end)
------------------
-- SEQ PARAMS --
------------------
local note_map = {"Triad", "Chord raw", "Chord extd.", "Chord dense", "Scale", "Scale+tr.", "Chromatic", "Chromatic+tr.", "Kit"} -- used by all but chord
for i = 1, 8 do
table.insert(note_map, "Mask " .. i)
table.insert(note_map, "Mask " .. i .. "+tr.")
end
for seq_no = 1, max_seqs do
params:add_group("seq"..seq_no, "SEQ "..seq_no, 37)
params:add_option("seq_note_map_"..seq_no, "Notes", note_map, 1)
params:add_option("seq_grid_"..seq_no, "Grid", {"Mono", "Pool L→", "Pool ←R", "Pool Random"}, 1)
params:add_number("seq_polyphony_"..seq_no, "Polyphony", 1, max_seq_cols, 1)
params:add_option("seq_start_on_"..seq_no, "Start", {"Loop", "Every step", "Chord steps", "Empty steps", "Measure", "Off/trigger"}, 1)
params:add_option("seq_reset_on_"..seq_no, "Reset", {"Every step", "Chord steps", "Empty steps", "Measure", "Off/trigger"}, 4)
params:add_binary("seq_start_"..seq_no, "Trigger start", "trigger")
params:set_action("seq_start_"..seq_no, function() play_seq[seq_no] = true end)
params:add_binary("seq_reset_"..seq_no, "Trigger reset", "trigger")
params:set_action("seq_reset_"..seq_no, function() reset_seq_pattern(seq_no) end)
params:add_option("seq_pattern_change_"..seq_no, "Change", {"Instantly", "On loop", "On reset"}, 1)
params:set_action("seq_pattern_change_"..seq_no,
function(val) -- immediately switch to any pending pattern q
if val == 1 and seq_pattern_q[seq_no] then
params:set("seq_pattern_" .. seq_no, seq_pattern_q[seq_no])
seq_pattern_q[seq_no] = false
end
end
)
params:add_number("seq_div_index_"..seq_no, "Step length", 1, 57, 8, function(param) return divisions_string(param:get()) end)
nb:add_param("seq_voice_raw_"..seq_no, "Voice raw")
params:hide("seq_voice_raw_"..seq_no)
params:add_option("seq_voice_"..seq_no, "Voice", voice_param_options, 1)
params:set_action("seq_voice_"..seq_no,
function(index)
params:set("seq_voice_raw_"..seq_no, voice_param_index[index])
set_channel_vis(params:string("seq_voice_raw_"..seq_no), "seq_channel_"..seq_no)
end
)
params:add_number("seq_channel_"..seq_no, "Channel", 1, 16, 1)
params:hide("seq_channel_"..seq_no)
params:add_option("seq_mute_"..seq_no, "Play/mute", {"Play", "Mute"}, 1)
params:add_number("seq_duration_index_"..seq_no, "Duration", 0, 57, 0, function(param) return durations_string(param:get()) end)
params:set_action("seq_duration_index_"..seq_no, function(val) seq_duration[seq_no] = val == 0 and division_names[params:get("seq_div_index_"..seq_no)][1] or division_names[val][1] end)
params:add_number("seq_pattern_rotate_"..seq_no, "Pattern ↑↓", 0, max_seq_pattern_length - 1, 0, nil, true) -- endless but confusing
params:set_action("seq_pattern_rotate_"..seq_no, function(val) seq_pattern_rotate_abs(seq_no, val) end)
for pattern = 1, max_seq_patterns do
params:add_number("prev_seq_pattern_rotate_"..seq_no .. "_" .. pattern, "prev_seq_pattern_rotate_"..seq_no .. "_" .. pattern, (max_seq_pattern_length * -1), max_seq_pattern_length, 0)
params:hide("prev_seq_pattern_rotate_"..seq_no .. "_" .. pattern)
end
params:add_number("seq_loop_rotate_"..seq_no, "Loop ↑↓", -9999, 9999, 0) -- can't use math.huge or is breaks random event values
params:set_action("seq_loop_rotate_"..seq_no, function(val) seq_loop_rotate_abs(seq_no, val) end)
for pattern = 1, max_seq_patterns do
params:add_number("prev_seq_loop_rotate_"..seq_no .. "_" .. pattern, "prev_seq_loop_rotate_"..seq_no .. "_" .. pattern, -math.huge, math.huge, 0)
params:hide("prev_seq_loop_rotate_"..seq_no .. "_" .. pattern)
end
params:add_number("seq_shift_"..seq_no, "Pattern ←→", 0, max_seq_cols - 1, 0, nil, true)
params:set_action("seq_shift_"..seq_no, function(val) seq_shift_abs(seq_no, val) end)
for pattern = 1, max_seq_patterns do
params:add_number("prev_seq_shift_"..seq_no .. "_" .. pattern, "prev_seq_shift_"..seq_no .. "_" .. pattern, -max_seq_cols, max_seq_cols, 0)
params:hide("prev_seq_shift_"..seq_no .. "_" .. pattern)
end
params:add_option("seq_pattern_"..seq_no, "Pattern", pattern_name, 1)
params:set_action("seq_pattern_"..seq_no,
function(val)
active_seq_pattern[seq_no] = val -- store in table so we don't need x4 params
params:set("seq_pattern_length_"..seq_no, seq_pattern_length[seq_no][val])
local current_pattern_rotation = params:get("seq_pattern_rotate_" .. seq_no)
if current_pattern_rotation ~= params:get("prev_seq_pattern_rotate_" .. seq_no .. "_" .. val) then
seq_pattern_rotate_abs(seq_no, current_pattern_rotation)
end
local current_loop_rotation = params:get("seq_loop_rotate_" .. seq_no)
if current_loop_rotation ~= params:get("prev_seq_loop_rotate_" .. seq_no .. "_" .. val) then
seq_loop_rotate_abs(seq_no, current_loop_rotation)
end
local current_shift = params:get("seq_shift_" .. seq_no)
if current_shift ~= params:get("prev_seq_shift_" .. seq_no .. "_" .. val) then
seq_shift_abs(seq_no, current_shift)
end
grid_dirty = true
end
)
-- issue: if an event runs this before changing pattern, it won't operate on the new pattern. might be confusing
params:add_number("seq_pattern_length_"..seq_no, "Pattern length", 1, max_seq_pattern_length, 8)
params:set_action("seq_pattern_length_"..seq_no,
function(val)
seq_pattern_length[seq_no][active_seq_pattern[seq_no]] = val -- store in table so we don't need x4 params
grid_dirty = true
end
)
params:add_number("seq_octave_"..seq_no, "Octave", -4, 4, 0)
params:add_number("seq_swing_"..seq_no, "Swing", 50, 99, 50, function(param) return percent(param:get()) end)
params:add_number("seq_dynamics_"..seq_no, "Dynamics", 0, 100, 70, function(param) return percent(param:get()) end)
params:add_number("seq_accent_"..seq_no, "Accent", -100, 100, 0, function(param) return percent(param:get()) end)
params:add_number("seq_probability_"..seq_no, "Probability", 0, 100, 100, function(param) return percent(param:get()) end)
end
------------------
-- MIDI HARMONIZER PARAMS --
------------------
params:add_group("midi_harmonizer", "MIDI HARMONIZER", 9)
params:add_option("midi_note_map", "Notes", note_map, 1)
nb:add_param("midi_voice_raw", "Voice raw")
params:hide("midi_voice_raw")
params:add_option("midi_voice", "Voice", voice_param_options, 1)
params:set_action("midi_voice",
function(index)
params:set("midi_voice_raw", voice_param_index[index])
set_channel_vis(params:string("midi_voice_raw"), "midi_channel")
end
)
params:add_number("midi_channel", "Channel", 1, 16, 1)
params:hide("midi_channel")
params:add_number("midi_harmonizer_in_port", "Port in",1,#midi.vports,1)
params:set_action("midi_harmonizer_in_port", function(value)
in_midi.event = nil
in_midi = midi.connect(params:get("midi_harmonizer_in_port"))
in_midi.event = midi_event
end)
-- set in_midi port once before params:bang()
in_midi = midi.connect(params:get("midi_harmonizer_in_port"))
in_midi.event = midi_event
params:add_number("midi_duration_index", "Duration", 1, 57, 10, function(param) return durations_string(param:get()) end)
params:set_action("midi_duration_index", function(val) midi_duration = division_names[val][1] end) -- pointless?
params:add_number("midi_octave", "Octave", -4, 4, 0)
params:add_number("midi_dynamics", "Dynamics", 0, 100, 70, function(param) return percent(param:get()) end)
------------------
-- CV HARMONIZER PARAMS --
------------------
params:add_group("cv_harmonizer", "CV HARMONIZER", 11)
nb:add_param("crow_voice_raw", "Voice raw")
params:hide("crow_voice_raw")
params:add_option("crow_voice", "Voice", voice_param_options, 1)
params:set_action("crow_voice",
function(index)
params:set("crow_voice_raw", voice_param_index[index])
set_channel_vis(params:string("crow_voice_raw"), "crow_channel")
end
)
params:add_number("crow_channel", "Channel", 1, 16, 1)
params:hide("crow_channel")
params:add_number("crow_div_index", "Trigger", 0, 57, 0, function(param) return crow_trigger_string(param:get()) end)
params:set_action("crow_div_index", function(val) crow_div = val == 0 and 0 or division_names[val][1] end) -- overwritten
params:add_option("crow_note_map", "Notes", note_map, 1)
params:add_option("crow_auto_rest", "Auto-rest", {"Off", "On"}, 1)
params:add_number("crow_duration_index", "Duration", 0, 57, 10, function(param) return durations_string(param:get()) end)
params:set_action("crow_duration_index", function(val)
if val == 0 then -- if in "Step" mode
if crow_div ~= 0 then -- and not triggering via Crow IN 2
crow_duration = crow_div -- set duration to div
end
else -- not in "Step" mode so just apply the value
crow_duration = division_names[val][1]
end
end)
params:add_number("crow_octave", "Octave", -4, 4, 0)
params:add_number("cv_harm_swing", "Swing", 50, 99, 50, function(param) return percent(param:get()) end)
params:add_number("crow_dynamics", "Dynamics", 0, 100, 70, function(param) return percent(param:get()) end)
------------------
-- EVENT-SPECIFIC PARAMS --
------------------
params:add_number("next_arranger_pos", "Next Arranger Position", 1, 64, 1) -- event action as we need to bang even if index hasn't changed and don't want to bang on init/pset load
params:hide("next_arranger_pos")
------------------
-- NB PARAMS --
------------------
params:add_separator("VOICES")
nb:add_player_params() -- modified to also add nb.indices
-- insert MIDI events for active MIDI ports
-- program change
for port = 1, 16 do
if midi.vports[port].connected then
for ch = 1, 16 do
-- generate param for each port/channel
local name = "midi_bank_msb_" .. port .. "_" .. ch
params:add_number(name, name, 1, 128, 1)
params:set_save(name, false)
params:hide(name)
-- using event action rather than param action since:
-- 1. we don't want this being sent at param bang and
-- 2. we do want it to bang every time event fires, even if param index hasn't changed
table.insert(events_lookup, {
category = "MIDI port " .. port,
subcategory = "Channel " .. ch,
event_type = "param",
id = name,
name = "Bank select",
action = 'midi.vports[' .. port .. ']:cc(0, params:get("' .. name .. '"), ' .. ch .. ')'
})
-- generate param for each port/channel
local name = "midi_bank_lsb_" .. port .. "_" .. ch
params:add_number(name, name, 1, 128, 1)
params:set_save(name, false)
params:hide(name)
-- using event action rather than param action since:
-- 1. we don't want this being sent at param bang and
-- 2. we do want it to bang every time event fires, even if param index hasn't changed
table.insert(events_lookup, {
category = "MIDI port " .. port,
subcategory = "Channel " .. ch,
event_type = "param",
id = name,
name = "Bank select (fine)",
action = 'midi.vports[' .. port .. ']:cc(32, params:get("' .. name .. '"), ' .. ch .. ')'
})
-- generate param for each port/channel
local name = "midi_program_change_" .. port .. "_" .. ch
params:add_number(name, name, 1, 128, 1)
params:set_save(name, false)
params:hide(name)
-- using event action rather than param action since:
-- 1. we don't want this being sent at param bang and
-- 2. we do want it to bang every time event fires, even if param index hasn't changed
table.insert(events_lookup, {
category = "MIDI port " .. port,
subcategory = "Channel " .. ch,
event_type = "param",
id = name,
name = "Program change",
action = 'midi.vports[' .. port .. ']:program_change(params:get("' .. name .. '") - 1, ' .. ch .. ')'
})
end
end
end
-- -- bank select MSB
-- for port = 1, 16 do
-- if midi.vports[port].connected then
-- for ch = 1, 16 do
-- -- generate param for each port/channel
-- local name = "midi_bank_msb_" .. port .. "_" .. ch
-- params:add_number(name, name, 1, 128, 0)
-- params:set_save(name, false)
-- params:hide(name)
-- -- using event action rather than param action since:
-- -- 1. we don't want this being sent at param bang and
-- -- 2. we do want it to bang every time event fires, even if param index hasn't changed
-- table.insert(events_lookup, {
-- category = "MIDI port " .. port,
-- subcategory = "Channel " .. ch,
-- event_type = "param",
-- id = name,
-- name = "Bank select",
-- action = 'midi.vports[' .. port .. ']:cc(0, params:get("' .. name .. '"), ' .. ch .. ')'
-- })
-- end
-- end
-- end
-- -- bank select LSB
-- for port = 1, 16 do
-- if midi.vports[port].connected then
-- for ch = 1, 16 do
-- -- generate param for each port/channel
-- local name = "midi_bank_lsb_" .. port .. "_" .. ch
-- params:add_number(name, name, 1, 128, 0)
-- params:set_save(name, false)
-- params:hide(name)
-- -- using event action rather than param action since:
-- -- 1. we don't want this being sent at param bang and
-- -- 2. we do want it to bang every time event fires, even if param index hasn't changed
-- table.insert(events_lookup, {
-- category = "MIDI port " .. port,
-- subcategory = "Channel " .. ch,
-- event_type = "param",
-- id = name,
-- name = "Bank select (fine)",
-- action = 'midi.vports[' .. port .. ']:cc(32, params:get("' .. name .. '"), ' .. ch .. ')'
-- })
-- end
-- end
-- end
-- due to crow_ds adding *all* shared params for Crow outs 1-4 in one player, break them up:
local function subdivide_indices(string)
local category
local indices = nb.indices[string]
for i = indices.start_index, indices.end_index do
local param = params.params[i]
if param.t == 7 then -- group
category = param.name
nb.indices[category] = {start_index = i}
else
nb.indices[category].end_index = i
end
end
nb.indices[string] = nil
end
subdivide_indices("crow_ds 1/0") -- cv params
subdivide_indices("crow_ds 1/2") -- env params