-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrategySequencer.lua
1489 lines (1346 loc) · 60.4 KB
/
strategySequencer.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
--------------------------------------------------------------------------------
-- Strategy Sequencer
--------------------------------------------------------------------------------
local gem = require "includes.common"
local notes = require "includes.notes"
local scales = require "includes.scales"
local resolutions = require "includes.resolutions"
local subdivision = require "includes.subdivision"
local backgroundColour = "4c4c4c" -- Light or Dark
local widgetBackgroundColour = "2E0249" -- Dark
local widgetTextColour = "9f02ACFE" -- Light
local labelTextColour = "AEFEFF" -- Light
local menuBackgroundColour = "01011F"
local menuArrowColour = "66" .. labelTextColour
local labelBackgoundColour = widgetBackgroundColour
local menuOutlineColour = "5f" .. widgetTextColour
local sliderColour = "5FB5FF"
local selectedPartColour = "cc33cc44"
local backgroundColourOff = "ff084486"
local backgroundColourOn = "ff02ACFE"
local textColourOff = "ff22FFFF"
local textColourOn = "efFFFFFF"
local isPlaying = false
local seqIndex = 0 -- Holds the unique id for the sequencer
local heldNotes = {}
local notePosition = 0 -- Holds the current note position
local partToStepMap = {1} -- Holds the starting step for each part
local totalNumSteps = 8
local paramsPerPart = {}
local partSelect = {}
local numParts = 1
local scaleDefinitions = scales.getScaleDefinitions()
local scaleNames = scales.getScaleNames()
local noteNames = notes.getNoteNames()
-- Strategies are ways to play chords and scales
local strategies = {
{}, -- Randomize next note position +/- 1 oct
{1}, -- Up
{-1}, -- Down
{2,-1}, -- Alternate up
{-2,1}, -- Alternate down
{-1,1,-2,-1,3}, -- Generated 1
{3,1,-1,2}, -- Generated 2
{-3,2}, -- Generated 3
{2,2,3}, -- Up v 2
{-3,-2,-2}, -- Down v 2
{3,-2,7},
{-5,4,4},
{7,7,-5},
{7,5,6},
{-7,2,7},
{7,0,-7},
{4,0,-4},
{0},
{4,-2},
{3,-2},
}
local strategyIndex = gem.getRandom(#strategies) -- Holds the selected strategy - start with a random strategy
local structureMemory = {} -- Holds the most recent structure memory
local maxStoredStructures = 100 -- Max stored structures
local noteNumberToNoteName = notes.getNoteMapping()
setBackgroundColour(backgroundColour)
--------------------------------------------------------------------------------
-- Scale and note functions
--------------------------------------------------------------------------------
function getNotePositionFromHeldNotes(partPos, scale)
local minNote = paramsPerPart[partPos].minNote.value
local maxNote = paramsPerPart[partPos].maxNote.value
local noteInput = notes.transpose(notes.getNoteAccordingToScale(scale, heldNotes[#heldNotes].note), minNote, maxNote)
local index = gem.getIndexFromValue(noteInput, scale)
print("Resetting to noteInput/notePosition", noteInput, index)
return index
end
function getNoteFromStrategy(notePosition, strategyIndex, strategyPos, partPos)
local scale = paramsPerPart[partPos].fullScale
local minNote = notes.getNoteAccordingToScale(scale, paramsPerPart[partPos].minNote.value)
local maxNote = notes.getNoteAccordingToScale(scale, paramsPerPart[partPos].maxNote.value)
local strategy = {}
local input = paramsPerPart[partPos].strategyInput
if input.enabled == true and string.len(input.text) > 0 then
for w in string.gmatch(input.text, "-?%d+") do
table.insert(strategy, w)
print("Add to strategy", w)
end
print("Get strategy from input", #strategy)
end
if #strategy == 0 then
strategy = strategies[strategyIndex]
end
-- Reset strategy position
if strategyPos > #strategy then
strategyPos = 1
if paramsPerPart[partPos].strategyRestart.value == 3 or paramsPerPart[partPos].strategyRestart.value == 4 then
notePosition = 0 -- Reset counter for note position
print("Reset counter for note position")
end
end
print("Get strategy strategyIndex/strategyPos", strategyIndex, strategyPos)
if notePosition == 0 then
-- Start at the last held note
notePosition = getNotePositionFromHeldNotes(partPos, scale)
if paramsPerPart[partPos].strategyRestart.value == 1 then
strategyPos = 1
end
else
-- Get next notePosition from strategy
if #strategy == 0 then -- Strategy random
local offset = gem.getRandom(-12,12) -- 1 oct +/-
local note = scale[notePosition] -- Get the current note from scale
note = note + offset -- Change within the offset
note = notes.transpose(notes.getNoteAccordingToScale(scale, note), minNote, maxNote) -- Endure within scale and limits
notePosition = gem.getIndexFromValue(note, scale)
print("Set increment by random notePosition/note/offset(in semitones)/#scale", notePosition, note, offset, #scale)
else
notePosition = notePosition + strategy[strategyPos]
print("Set notePosition/strategyPos", notePosition, strategy[strategyPos])
end
if type(scale[notePosition]) == "nil" then
-- This is just a safeguard if scale is changed while playing
notePosition = 1
return minNote, notePosition, strategyPos
end
if scale[notePosition] > maxNote then
print("Reset scale[notePosition] > maxNote", scale[notePosition], maxNote)
-- TODO Param for options
-- Option 1: Transpose to lowest octave in range
--local transposedNote = transpose(scale[notePosition], minNote, (minNote+12))
--notePosition = gem.getIndexFromValue(transposedNote, scale)
-- Option 2: Reset to the input note from heldnotes
notePosition = getNotePositionFromHeldNotes(partPos, scale)
if paramsPerPart[partPos].strategyRestart.value == 2 then
strategyPos = 1
end
elseif scale[notePosition] < minNote then
print("Reset scale[notePosition] < minNote", scale[notePosition], minNote)
-- TODO Param for options
-- Option 1: Transpose to top octave
local transposedNote = notes.transpose(scale[notePosition], (maxNote-12), maxNote)
notePosition = gem.getIndexFromValue(transposedNote, scale)
-- Option 2: Reset to the input note from heldnotes
--notePosition = getNotePositionFromHeldNotes(partPos, scale)
if paramsPerPart[partPos].strategyRestart.value == 2 then
strategyPos = 1
end
else
-- Increment strategy pos
if #strategy > 1 then
strategyPos = strategyPos + 1
print("Increment strategy pos", strategyPos)
end
end
end
local note = scale[notePosition]
return note, notePosition, strategyPos
end
function getFilteredScale(part, minNote, maxNote)
local filteredScale = {}
if type(minNote) ~= "number" then
minNote = paramsPerPart[part].minNote.value
end
if type(maxNote) ~= "number" then
maxNote = paramsPerPart[part].maxNote.value
end
if #paramsPerPart[part].fullScale > 0 then
-- Filter out notes outside min/max
for i=1,#paramsPerPart[part].fullScale do
if paramsPerPart[part].fullScale[i] >= minNote and paramsPerPart[part].fullScale[i] <= maxNote then
table.insert(filteredScale, paramsPerPart[part].fullScale[i])
end
end
end
--print("Filtered scale contains notes:", #paramsPerPart[part].filteredScale)
return filteredScale
end
function createFullScale(part)
-- Find scale definition
local definition = scaleDefinitions[paramsPerPart[part].scale.value]
-- Find root note
local root = paramsPerPart[part].key.value - 1
-- Create scale
paramsPerPart[part].fullScale = scales.createScale(definition, root)
end
function getVelocity(part, step, skipRandomize)
local seqVelTable = paramsPerPart[part].seqVelTable
local velocity = seqVelTable:getValue(step) -- get velocity
-- Skip randomize
if skipRandomize == true then
return velocity
end
-- Randomize velocity
return gem.randomizeValue(velocity, seqVelTable.min, seqVelTable.max, paramsPerPart[part].velRandomization.value)
end
function getGate(part, step, skipRandomize)
local seqGateTable = paramsPerPart[part].seqGateTable
local gate = seqGateTable:getValue(step)
-- Skip randomize
if skipRandomize == true then
return gate
end
-- Randomize gate
return gem.randomizeValue(gate, seqGateTable.min, seqGateTable.max, paramsPerPart[part].gateRandomization.value)
end
function createStrategy(part)
local numSteps = paramsPerPart[part].numStepsBox.value
local maxLength = math.min(math.ceil(numSteps * 0.75), 9) -- TODO Param
local strategy = {} -- Table to hold strategy
local ln = gem.getRandom(maxLength) -- Length
for i=1, ln do
local value = gem.getRandom(-7,7)
table.insert(strategy, value)
print("Add value to strategy", value)
end
return strategy
end
--------------------------------------------------------------------------------
-- Sequencer Panel
--------------------------------------------------------------------------------
local tableWidth = 700
local tableX = 0
local boxWidth = 108
local sequencerPanel = Panel("Sequencer")
sequencerPanel.backgroundColour = backgroundColour
sequencerPanel.x = 10
sequencerPanel.y = 10
sequencerPanel.width = tableWidth
sequencerPanel.height = 380
local label = sequencerPanel:Label("Label")
label.text = "Strategy Sequencer"
label.alpha = 0.5
label.backgroundColour = labelBackgoundColour
label.textColour = labelTextColour
label.fontSize = 22
label.position = {0,0}
label.size = {170,25}
local channels = {"Omni"}
for j=1,16 do
table.insert(channels, "" .. j)
end
local channelInput = sequencerPanel:Menu("ChannelInput", channels)
channelInput.tooltip = "Only listen to incoming notes on this channel"
channelInput.arrowColour = menuArrowColour
channelInput.showLabel = false
channelInput.backgroundColour = menuBackgroundColour
channelInput.textColour = widgetTextColour
channelInput.size = {90,22}
channelInput.x = (sequencerPanel.width / 2) - 25
channelInput.y = 0
local focusButton = sequencerPanel:OnOffButton("FocusPartOnOff", false)
focusButton.backgroundColourOff = backgroundColourOff
focusButton.backgroundColourOn = backgroundColourOn
focusButton.textColourOff = textColourOff
focusButton.textColourOn = textColourOn
focusButton.displayName = "Focus Part"
focusButton.tooltip = "When focus is active, only the part selected for editing is shown and played"
focusButton.size = channelInput.size
focusButton.x = channelInput.x + channelInput.width + 5
focusButton.y = 0
focusButton.changed = function(self)
setTableWidths()
end
local holdButton = sequencerPanel:OnOffButton("HoldOnOff", false)
holdButton.backgroundColourOff = backgroundColourOff
holdButton.backgroundColourOn = backgroundColourOn
holdButton.textColourOff = textColourOff
holdButton.textColourOn = textColourOn
holdButton.displayName = "Hold"
holdButton.size = channelInput.size
holdButton.x = focusButton.x + focusButton.width + 5
holdButton.y = 0
holdButton.changed = function(self)
if self.value == false then
heldNotes = {}
clearPosition()
end
end
local muteButton = sequencerPanel:OnOffButton("MuteOnOff", false)
muteButton.backgroundColourOff = backgroundColourOff
muteButton.backgroundColourOn = backgroundColourOn
muteButton.textColourOff = textColourOff
muteButton.textColourOn = textColourOn
muteButton.displayName = "Mute"
muteButton.tooltip = "Mute all incoming notes"
muteButton.size = channelInput.size
muteButton.x = holdButton.x + holdButton.width + 5
muteButton.y = 0
muteButton.changed = function(self)
heldNotes = {}
end
local editPartMenu = sequencerPanel:Menu("EditPart", partSelect)
editPartMenu.backgroundColour = menuBackgroundColour
editPartMenu.textColour = widgetTextColour
editPartMenu.arrowColour = menuArrowColour
editPartMenu.outlineColour = menuOutlineColour
editPartMenu.displayName = "Edit part"
editPartMenu.showLabel = false
editPartMenu.y = 65
editPartMenu.x = 0
editPartMenu.width = boxWidth / 2
editPartMenu.height = 20
editPartMenu.changed = function(self)
for i,v in ipairs(paramsPerPart) do
local isVisible = self.value == i
if isVisible then
v.partsTable.backgroundColour = selectedPartColour
elseif i % 2 == 0 then
v.partsTable.backgroundColour = "3c" .. sliderColour
else
v.partsTable.backgroundColour = "1a" .. sliderColour
end
v.numStepsBox.visible = isVisible
v.stepResolution.visible = isVisible
v.minNoteSteps.visible = isVisible
v.maxNoteSteps.visible = isVisible
v.minNote.visible = isVisible
v.maxNote.visible = isVisible
v.key.visible = isVisible
v.scale.visible = isVisible
v.strategyInput.visible = isVisible
v.createStrategyButton.visible = isVisible
v.autoStrategyButton.visible = isVisible
v.slotStrategyButton.visible = isVisible
v.strategyPropbability.visible = isVisible
v.strategyRestart.visible = isVisible
v.strategyActions.visible = isVisible
v.velRandomization.visible = isVisible
v.gateRandomization.visible = isVisible
v.subdivisionProbability.visible = isVisible
v.subdivisionRepeatProbability.visible = isVisible
v.subdivisionDotProbability.visible = isVisible
v.subdivisionTieProbability.visible = isVisible
v.stepRepeatProbability.visible = isVisible
v.structureMemoryMenu.visible = isVisible
v.subdivisionMinResolution.visible = isVisible
for _,s in ipairs(v.subdivisions) do
s.visible = isVisible
end
for _,s in ipairs(v.strategySlots) do
s.visible = isVisible
end
end
setTableWidths()
end
local numPartsBox = sequencerPanel:NumBox("Parts", 1, 1, 8, true)
numPartsBox.tooltip = "The number of parts in the sequence"
numPartsBox.backgroundColour = menuBackgroundColour
numPartsBox.textColour = widgetTextColour
numPartsBox.width = (boxWidth / 2) - 2
numPartsBox.height = 20
numPartsBox.x = editPartMenu.x + editPartMenu.width + 2
numPartsBox.y = editPartMenu.y
numPartsBox.changed = function(self)
for _,v in ipairs(paramsPerPart) do
v.partsTable.visible = false
v.positionTable.visible = false
v.seqVelTable.visible = false
v.seqGateTable.visible = false
end
numParts = self.value
for i=1,numParts do
setNumSteps(i)
end
local partSelect = {}
for i=1,numParts do
-- Add item to part select table
table.insert(partSelect, "Part " .. i)
if paramsPerPart[i].init == false then
-- Copy initial settings from prev part
local prev = paramsPerPart[i-1]
paramsPerPart[i].key.value = prev.key.value
paramsPerPart[i].scale.value = prev.scale.value
paramsPerPart[i].strategyInput.value = prev.strategyInput.value
paramsPerPart[i].strategyPropbability.value = prev.strategyPropbability.value
paramsPerPart[i].strategyRestart.value = prev.strategyRestart.value
paramsPerPart[i].autoStrategyButton.value = prev.autoStrategyButton.value
paramsPerPart[i].slotStrategyButton.value = prev.slotStrategyButton.value
paramsPerPart[i].minNote.value = prev.minNote.value
paramsPerPart[i].maxNote.value = prev.maxNote.value
paramsPerPart[i].minNoteSteps.value = prev.minNoteSteps.value
paramsPerPart[i].maxNoteSteps.value = prev.maxNoteSteps.value
paramsPerPart[i].numStepsBox.value = prev.numStepsBox.value
paramsPerPart[i].stepResolution.value = prev.stepResolution.value
paramsPerPart[i].fullScale = prev.fullScale
paramsPerPart[i].velRandomization.value = prev.velRandomization.value
paramsPerPart[i].gateRandomization.value = prev.gateRandomization.value
paramsPerPart[i].subdivisionProbability.value = prev.subdivisionProbability.value
paramsPerPart[i].subdivisionRepeatProbability.value = prev.subdivisionRepeatProbability.value
paramsPerPart[i].subdivisionDotProbability.value = prev.subdivisionDotProbability.value
paramsPerPart[i].subdivisionTieProbability.value = prev.subdivisionTieProbability.value
paramsPerPart[i].stepRepeatProbability.value = prev.stepRepeatProbability.value
paramsPerPart[i].structureMemoryMenu.value = prev.structureMemoryMenu.value
paramsPerPart[i].subdivisionMinResolution.value = prev.subdivisionMinResolution.value
paramsPerPart[i].init = prev.init
end
end
clearPosition()
editPartMenu.items = partSelect
editPartMenu:setValue(#partSelect)
end
local partRandBox = sequencerPanel:NumBox("PartRandomization", 0, 0, 100, true)
partRandBox.backgroundColour = menuBackgroundColour
partRandBox.textColour = widgetTextColour
partRandBox.displayName = "Part Order"
partRandBox.tooltip = "Amount of radomization applied to the order of playing parts"
partRandBox.unit = Unit.Percent
partRandBox.width = boxWidth
partRandBox.x = editPartMenu.x
partRandBox.y = editPartMenu.y + editPartMenu.height + 5
--------------------------------------------------------------------------------
-- Functions
--------------------------------------------------------------------------------
local function isRootNote(note, partPos)
-- Find root note index
local rootIndex = paramsPerPart[partPos].key.value
local noteIndex = note + 1 -- note index is 1 higher than note number
return noteNumberToNoteName[rootIndex] == noteNumberToNoteName[noteIndex]
end
function clearPosition()
for _,v in ipairs(paramsPerPart) do
for i=1,v.numStepsBox.value do
v.positionTable:setValue(i, 0)
end
v.partsTable:setValue(1, 0)
end
end
function startPlaying()
if isPlaying == true then
return
end
isPlaying = true
seqIndex = gem.inc(seqIndex)
spawn(arpeg, seqIndex)
end
function stopPlaying()
if isPlaying == false then
return
end
isPlaying = false
clearPosition()
end
function setNumSteps(index)
local numSteps = paramsPerPart[index].numStepsBox.value
partToStepMap = {} -- Reset map
totalNumSteps = 0
for i=1, numPartsBox.value do
table.insert(partToStepMap, (totalNumSteps + 1))
totalNumSteps = totalNumSteps + paramsPerPart[i].numStepsBox.value
end
setTableWidths()
end
function setTableWidths()
local focusSelectedPart = focusButton.value
local widthPerStep = tableWidth / totalNumSteps
local x = 0
for i=1, numPartsBox.value do
--local isVisible = true
local isVisible = (focusSelectedPart == true and i == editPartMenu.value) or focusSelectedPart == false
local partTableWidth = paramsPerPart[i].numStepsBox.value * widthPerStep
if focusSelectedPart then
partTableWidth = tableWidth
x = 0
end
paramsPerPart[i].partsTable.visible = isVisible
paramsPerPart[i].partsTable.width = partTableWidth
paramsPerPart[i].partsTable.x = x
paramsPerPart[i].positionTable.length = paramsPerPart[i].numStepsBox.value
paramsPerPart[i].positionTable.visible = isVisible
paramsPerPart[i].positionTable.width = partTableWidth
paramsPerPart[i].positionTable.x = x
paramsPerPart[i].seqVelTable.length = paramsPerPart[i].numStepsBox.value
paramsPerPart[i].seqVelTable.visible = isVisible
paramsPerPart[i].seqVelTable.width = partTableWidth
paramsPerPart[i].seqVelTable.x = x
paramsPerPart[i].seqGateTable.length = paramsPerPart[i].numStepsBox.value
paramsPerPart[i].seqGateTable.visible = isVisible
paramsPerPart[i].seqGateTable.width = partTableWidth
paramsPerPart[i].seqGateTable.x = x
x = x + partTableWidth
end
end
function getStrategyInputText(strategy)
if #strategy == 0 then
return "Randomize"
end
return table.concat(strategy, ",")
end
local subdivisionProbabilityLabel = sequencerPanel:Label("SubdivisionProbabilityLabel")
subdivisionProbabilityLabel.text = "Subdivision"
local strategyLabel = sequencerPanel:Label("StrategyLabel")
strategyLabel.text = "Strategy"
-- Add params that are to be editable per part
for i=1,numPartsBox.max do
local storedStructures = {} -- Used to store rythmic structures
local storedStructuresPos = 1 -- Menu position for storing structure
local partsTable = sequencerPanel:Table("Parts" .. i, 1, 0, 0, 1, true)
partsTable.enabled = false
partsTable.persistent = false
partsTable.fillStyle = "solid"
partsTable.backgroundColour = "#1f09A3F4"
partsTable.sliderColour = sliderColour
partsTable.width = tableWidth
partsTable.height = 10
partsTable.x = 0
partsTable.y = label.height + 10
local positionTable = sequencerPanel:Table("Position" .. i, totalNumSteps, 0, 0, 1, true)
positionTable.enabled = false
positionTable.persistent = false
positionTable.fillStyle = "solid"
positionTable.backgroundColour = widgetTextColour
positionTable.sliderColour = sliderColour
positionTable.width = partsTable.width
positionTable.height = partsTable.height
positionTable.x = partsTable.x
positionTable.y = partsTable.y + partsTable.height
local seqVelTable = sequencerPanel:Table("Velocity" .. i, totalNumSteps, 100, 1, 127, true)
seqVelTable.tooltip = "Set step velocity. Randomization available in settings."
seqVelTable.showPopupDisplay = true
seqVelTable.showLabel = true
seqVelTable.fillStyle = "solid"
seqVelTable.sliderColour = sliderColour
seqVelTable.width = positionTable.width
seqVelTable.height = 70
seqVelTable.x = positionTable.x
seqVelTable.y = partRandBox.y + 136
local seqGateTable = sequencerPanel:Table("Gate" .. i, totalNumSteps, 100, 0, 120, true)
seqGateTable.tooltip = "Set step gate length. Randomization available in settings."
seqGateTable.showPopupDisplay = true
seqGateTable.showLabel = true
seqGateTable.fillStyle = "solid"
seqGateTable.sliderColour = sliderColour
seqGateTable.width = seqVelTable.width
seqGateTable.height = seqVelTable.height
seqGateTable.x = seqVelTable.x
seqGateTable.y = seqVelTable.y + seqVelTable.height + 5
local generateMinNoteStepsPart = sequencerPanel:NumBox("GenerateMinNoteSteps" .. i, 1, 1, totalNumSteps, true)
generateMinNoteStepsPart.displayName = "Min Steps"
generateMinNoteStepsPart.tooltip = "The minimum number of steps can a note last"
generateMinNoteStepsPart.backgroundColour = menuBackgroundColour
generateMinNoteStepsPart.textColour = widgetTextColour
generateMinNoteStepsPart.enabled = false
generateMinNoteStepsPart.width = boxWidth
generateMinNoteStepsPart.x = editPartMenu.x + boxWidth + 10
generateMinNoteStepsPart.y = editPartMenu.y
local generateMaxNoteStepsPart = sequencerPanel:NumBox("GenerateMaxNoteSteps" .. i, 1, 1, totalNumSteps, true)
generateMaxNoteStepsPart.displayName = "Max Steps"
generateMaxNoteStepsPart.tooltip = "The maximium number of steps can a note last"
generateMaxNoteStepsPart.backgroundColour = menuBackgroundColour
generateMaxNoteStepsPart.textColour = widgetTextColour
generateMaxNoteStepsPart.width = generateMinNoteStepsPart.width
generateMaxNoteStepsPart.x = generateMinNoteStepsPart.x
generateMaxNoteStepsPart.y = generateMinNoteStepsPart.y + generateMinNoteStepsPart.height + 5
generateMaxNoteStepsPart.changed = function(self)
generateMinNoteStepsPart:setRange(1, self.value)
generateMinNoteStepsPart.enabled = self.value > 1
end
local stepResolution = sequencerPanel:Menu("StepResolution" .. i, resolutions.getResolutionNames())
stepResolution.displayName = "Step Duration"
stepResolution.tooltip = "The duration of each step in the part"
stepResolution.selected = 20
stepResolution.showLabel = false
stepResolution.height = 20
stepResolution.width = generateMaxNoteStepsPart.width
stepResolution.x = generateMinNoteStepsPart.x + generateMinNoteStepsPart.width + 10
stepResolution.y = generateMinNoteStepsPart.y
stepResolution.backgroundColour = menuBackgroundColour
stepResolution.textColour = widgetTextColour
stepResolution.arrowColour = menuArrowColour
stepResolution.outlineColour = menuOutlineColour
stepResolution.changed = function(self)
setNumSteps(i)
end
local numStepsBox = sequencerPanel:NumBox("Steps" .. i, totalNumSteps, 1, 32, true)
numStepsBox.displayName = "Steps"
numStepsBox.tooltip = "The Number of steps in the part"
numStepsBox.backgroundColour = menuBackgroundColour
numStepsBox.textColour = widgetTextColour
numStepsBox.width = stepResolution.width
numStepsBox.x = stepResolution.x
numStepsBox.y = stepResolution.y + stepResolution.height + 5
numStepsBox.changed = function(self)
setNumSteps(i)
generateMinNoteStepsPart:setRange(1, self.value)
generateMaxNoteStepsPart:setRange(1, self.value)
end
local generateMinPart = sequencerPanel:NumBox("GenerateMin" .. i, 24, 0, 127, true)
generateMinPart.unit = Unit.MidiKey
generateMinPart.showPopupDisplay = true
generateMinPart.showLabel = true
generateMinPart.backgroundColour = menuBackgroundColour
generateMinPart.textColour = widgetTextColour
generateMinPart.displayName = "Min Note"
generateMinPart.tooltip = "Lowest note"
generateMinPart.x = stepResolution.x + stepResolution.width + 10
generateMinPart.y = stepResolution.y
generateMinPart.width = stepResolution.width
local generateMaxPart = sequencerPanel:NumBox("GenerateMax" .. i, 84, 0, 127, true)
generateMaxPart.unit = Unit.MidiKey
generateMaxPart.showPopupDisplay = true
generateMaxPart.showLabel = true
generateMaxPart.backgroundColour = menuBackgroundColour
generateMaxPart.textColour = widgetTextColour
generateMaxPart.displayName = "Max Note"
generateMaxPart.tooltip = "Highest note"
generateMaxPart.x = generateMinPart.x
generateMaxPart.y = generateMinPart.y + generateMinPart.height + 5
generateMaxPart.width = generateMinPart.width
generateMinPart.changed = function(self)
generateMaxPart:setRange(self.value, 127)
end
generateMaxPart.changed = function(self)
generateMinPart:setRange(0, self.value)
end
local generateKeyPart = sequencerPanel:Menu("GenerateKey" .. i, noteNames)
generateKeyPart.tooltip = "Key"
generateKeyPart.showLabel = false
generateKeyPart.height = 20
generateKeyPart.width = boxWidth
generateKeyPart.x = generateMinPart.x + generateMinPart.width + 10
generateKeyPart.y = stepResolution.y
generateKeyPart.backgroundColour = menuBackgroundColour
generateKeyPart.textColour = widgetTextColour
generateKeyPart.arrowColour = menuArrowColour
generateKeyPart.outlineColour = menuOutlineColour
generateKeyPart.changed = function(self)
createFullScale(i)
end
local generateScalePart = sequencerPanel:Menu("GenerateScale" .. i, scaleNames)
generateScalePart.tooltip = "Scale"
generateScalePart.showLabel = false
generateScalePart.height = 20
generateScalePart.width = boxWidth
generateScalePart.hierarchical = true
generateScalePart.x = generateKeyPart.x
generateScalePart.y = generateKeyPart.y + generateKeyPart.height + 5
generateScalePart.backgroundColour = menuBackgroundColour
generateScalePart.textColour = widgetTextColour
generateScalePart.arrowColour = menuArrowColour
generateScalePart.outlineColour = menuOutlineColour
generateScalePart.changed = function(self)
createFullScale(i)
end
local velRandomization = sequencerPanel:NumBox("VelocityRandomization" .. i, 0, 0, 100, true)
velRandomization.displayName = "Velocity"
velRandomization.tooltip = "Amount of radomization applied to sequencer velocity"
velRandomization.unit = Unit.Percent
velRandomization.width = boxWidth
velRandomization.x = generateKeyPart.x + generateKeyPart.width + 10
velRandomization.y = editPartMenu.y
velRandomization.backgroundColour = menuBackgroundColour
velRandomization.textColour = widgetTextColour
local gateRandomization = sequencerPanel:NumBox("GateRandomization" .. i, 0, 0, 100, true)
gateRandomization.displayName = "Gate"
gateRandomization.tooltip = "Amount of radomization applied to sequencer gate"
gateRandomization.unit = Unit.Percent
gateRandomization.width = boxWidth
gateRandomization.x = velRandomization.x
gateRandomization.y = velRandomization.y + velRandomization.height + 5
gateRandomization.backgroundColour = menuBackgroundColour
gateRandomization.textColour = widgetTextColour
if i == 1 then
subdivisionProbabilityLabel.width = boxWidth
subdivisionProbabilityLabel.x = generateMinPart.x
subdivisionProbabilityLabel.y = partRandBox.y + partRandBox.height + 10
end
local subdivisions = {}
for j=1,3 do
local subdivisionSelect = sequencerPanel:OnOffButton("SubdivisionSelect" .. i .. j, (j<3))
subdivisionSelect.backgroundColourOff = backgroundColourOff
subdivisionSelect.backgroundColourOn = backgroundColourOn
subdivisionSelect.textColourOff = textColourOff
subdivisionSelect.textColourOn = textColourOn
subdivisionSelect.displayName = "" .. j
if j == 1 then
subdivisionSelect.tooltip = "Activate base - subdivision bases will divide until the minimum resolution is reached"
else
subdivisionSelect.tooltip = "When base 1 is active, subdivisions will stop when 1 is selected, either by random, or if probability is 0"
end
subdivisionSelect.height = 20
subdivisionSelect.width = 33
subdivisionSelect.x = subdivisionProbabilityLabel.x + ((j-1) * (subdivisionSelect.width+4))
subdivisionSelect.y = subdivisionProbabilityLabel.y + subdivisionProbabilityLabel.height + 5
table.insert(subdivisions, subdivisionSelect)
end
local subdivisionProbability = sequencerPanel:NumBox("SubdivisionProbability" .. i, 25, 0, 100, true)
subdivisionProbability.displayName = "Probability"
subdivisionProbability.tooltip = "Probability that active subdivisions will be selected by random - if set to 0, the first selected subdivision will be used"
subdivisionProbability.unit = Unit.Percent
subdivisionProbability.width = boxWidth
subdivisionProbability.x = subdivisionProbabilityLabel.x
subdivisionProbability.y = subdivisions[1].y + subdivisions[1].height + 5
subdivisionProbability.backgroundColour = menuBackgroundColour
subdivisionProbability.textColour = widgetTextColour
local subdivisionRepeatProbability = sequencerPanel:NumBox("SubdivisionRepeatProbability" .. i, 0, 0, 100, true)
subdivisionRepeatProbability.displayName = "Note Repeat"
subdivisionRepeatProbability.tooltip = "What is the probability that the same note will be played in the subdivision, meaning that the same note is repeated?"
subdivisionRepeatProbability.unit = Unit.Percent
subdivisionRepeatProbability.width = boxWidth
subdivisionRepeatProbability.x = subdivisionProbability.x
subdivisionRepeatProbability.y = subdivisionProbability.y + subdivisionProbability.height + 5
subdivisionRepeatProbability.backgroundColour = menuBackgroundColour
subdivisionRepeatProbability.textColour = widgetTextColour
local subdivisionMinResolution = sequencerPanel:Menu("SubdivisionMinResolution" .. i, resolutions.getResolutionNames())
subdivisionMinResolution.displayName = "Min Resolution"
subdivisionMinResolution.showLabel = false
subdivisionMinResolution.height = 20
subdivisionMinResolution.tooltip = "This is the lowest resolution when using subdivisions"
subdivisionMinResolution.selected = 23
subdivisionMinResolution.x = subdivisionProbabilityLabel.x + subdivisionProbabilityLabel.width + 10
subdivisionMinResolution.y = subdivisions[1].y --subdivisionProbabilityLabel.y
subdivisionMinResolution.width = boxWidth
subdivisionMinResolution.backgroundColour = menuBackgroundColour
subdivisionMinResolution.textColour = widgetTextColour
subdivisionMinResolution.arrowColour = menuArrowColour
subdivisionMinResolution.outlineColour = menuOutlineColour
local subdivisionDotProbability = sequencerPanel:NumBox("SubdivisionDotProbability" .. i, 25, 0, 100, true)
subdivisionDotProbability.displayName = "Dotted"
subdivisionDotProbability.tooltip = "What is the probability that there will be dotted subdivisions?"
subdivisionDotProbability.unit = Unit.Percent
subdivisionDotProbability.width = boxWidth
subdivisionDotProbability.x = subdivisionMinResolution.x
subdivisionDotProbability.y = subdivisionMinResolution.y + subdivisionMinResolution.height + 5
subdivisionDotProbability.backgroundColour = menuBackgroundColour
subdivisionDotProbability.textColour = widgetTextColour
local subdivisionTieProbability = sequencerPanel:NumBox("SubdivisionMultistepProbability" .. i, 25, 0, 100, true)
subdivisionTieProbability.displayName = "Ties"
subdivisionTieProbability.tooltip = "What is the probability that there will be ties in subdivisions?"
subdivisionTieProbability.unit = Unit.Percent
subdivisionTieProbability.width = boxWidth
subdivisionTieProbability.x = subdivisionDotProbability.x
subdivisionTieProbability.y = subdivisionDotProbability.y + subdivisionDotProbability.height + 5
subdivisionTieProbability.backgroundColour = menuBackgroundColour
subdivisionTieProbability.textColour = widgetTextColour
local stepRepeatProbability = sequencerPanel:NumBox("StepRepeatProbability" .. i, 90, 0, 100, true)
stepRepeatProbability.displayName = "Memory"
stepRepeatProbability.tooltip = "Probability that the rythmic structure of a previous step will be repeated."
stepRepeatProbability.unit = Unit.Percent
stepRepeatProbability.width = boxWidth
stepRepeatProbability.x = subdivisionMinResolution.x + subdivisionMinResolution.width + 10
stepRepeatProbability.y = subdivisionMinResolution.y
stepRepeatProbability.backgroundColour = menuBackgroundColour
stepRepeatProbability.textColour = widgetTextColour
local structureMemoryMenu = sequencerPanel:Menu("StructureMemoryMenu" .. i, {"Load memory..."})
structureMemoryMenu.displayName = "Structure"
structureMemoryMenu.enabled = false
structureMemoryMenu.showLabel = false
structureMemoryMenu.height = 20
structureMemoryMenu.tooltip = "Load a stored structure to memory"
structureMemoryMenu.x = stepRepeatProbability.x
structureMemoryMenu.y = stepRepeatProbability.y + stepRepeatProbability.height + 5
structureMemoryMenu.width = boxWidth
structureMemoryMenu.backgroundColour = menuBackgroundColour
structureMemoryMenu.textColour = widgetTextColour
structureMemoryMenu.arrowColour = menuArrowColour
structureMemoryMenu.outlineColour = menuOutlineColour
structureMemoryMenu.changed = function(self)
local memoryIndex = self.value - 1
if memoryIndex > 0 then
structureMemory = paramsPerPart[i].storedStructures[memoryIndex]
stepRepeatProbability:setValue(100)
print("Loaded structure " .. memoryIndex, #paramsPerPart[i].storedStructures)
end
end
if i == 1 then
strategyLabel.x = editPartMenu.x
strategyLabel.y = subdivisionProbabilityLabel.y
strategyLabel.width = boxWidth
--strategyLabel.backgroundColour = "red"
end
-- TODO Add param for strategy probability decay?
local strategyPropbability = sequencerPanel:NumBox("StrategyPropbability" .. i, 100, 0, 100, true)
strategyPropbability.displayName = "Probability"
strategyPropbability.tooltip = "Set the probability that a playing strategy will be used to select the next note. Otherwise notes will be selected by random from the current scale."
strategyPropbability.unit = Unit.Percent
strategyPropbability.height = 20
strategyPropbability.width = boxWidth
strategyPropbability.x = strategyLabel.x
strategyPropbability.y = strategyLabel.y + strategyLabel.height + 5
strategyPropbability.backgroundColour = menuBackgroundColour
strategyPropbability.textColour = widgetTextColour
local strategyRestart = sequencerPanel:Menu("StrategyRestart" .. i, {"Restart each round", "Out of range", "When finished", "Finished+round"})
strategyRestart.tooltip = "Choose when a strategy restarts"
strategyRestart.showLabel = false
strategyRestart.height = 20
strategyRestart.width = strategyPropbability.width
strategyRestart.x = strategyPropbability.x
strategyRestart.y = strategyPropbability.y + strategyPropbability.height + 5
strategyRestart.backgroundColour = menuBackgroundColour
strategyRestart.textColour = widgetTextColour
strategyRestart.arrowColour = menuArrowColour
strategyRestart.outlineColour = menuOutlineColour
local strategyInput = sequencerPanel:Label("StrategyInput" .. i)
strategyInput.text = getStrategyInputText(strategies[strategyIndex])
strategyInput.tooltip = "Strategies are ways to play chords and scales. Numbers represent steps up or down the scale or chord that is currently playing. Feel free to type your own strategies here."
strategyInput.editable = true
strategyInput.backgroundColour = menuBackgroundColour
strategyInput.backgroundColourWhenEditing = "black"
strategyInput.textColour = labelTextColour
strategyInput.textColourWhenEditing = "white"
strategyInput.x = generateMaxNoteStepsPart.x
strategyInput.y = strategyPropbability.y
strategyInput.width = boxWidth * 2.1
strategyInput.height = 45
strategyInput.fontSize = 30
local actions = {"Actions..."}
local strategySlots = {}
for j=1,9 do
local strategySlot = sequencerPanel:OnOffButton("StrategySlot" .. i .. j)
strategySlot.backgroundColourOff = backgroundColourOff
strategySlot.backgroundColourOn = backgroundColourOn
strategySlot.textColourOff = textColourOff
strategySlot.textColourOn = textColourOn
strategySlot.displayName = "" .. j
strategySlot.enabled = false
strategySlot.tooltip = "Unused"
strategySlot.height = 20
strategySlot.width = 24
strategySlot.x = strategyInput.x + ((j-1) * (strategySlot.width+1.2))
strategySlot.y = strategyInput.y + strategyInput.height + 5
strategySlot.changed = function(self)
strategyInput.text = strategySlot.tooltip
self.value = false
end
table.insert(strategySlots, strategySlot)
table.insert(actions, "Save to " .. j)
end
table.insert(actions, "--- Load ---")
for _,v in ipairs(strategies) do
table.insert(actions, getStrategyInputText(v))
end
local strategyActions = sequencerPanel:Menu("StrategyActions" .. i, actions)
strategyActions.tooltip = "Choose when a strategy restarts"
strategyActions.showLabel = false
strategyActions.height = 20
strategyActions.width = strategyRestart.width
strategyActions.x = strategyRestart.x
strategyActions.y = strategyRestart.y + strategyRestart.height + 5
strategyActions.backgroundColour = menuBackgroundColour
strategyActions.textColour = widgetTextColour
strategyActions.arrowColour = menuArrowColour
strategyActions.outlineColour = menuOutlineColour
strategyActions.changed = function(self)
-- 1 is the menu label...
if self.value == 1 then
return
end
local actionIndex = self.value - 1
-- Save strategy
if actionIndex <= #strategySlots then
if string.len(strategyInput.text) > 0 then
strategySlots[actionIndex].tooltip = strategyInput.text
strategySlots[actionIndex].enabled = true
else
strategySlots[actionIndex].tooltip = "Unused"
strategySlots[actionIndex].enabled = false
end
print("Strategy saved to slot", strategyInput.text, actionIndex)
elseif actionIndex > #strategySlots + 1 then
strategyInput.text = self.selectedText
strategyIndex = actionIndex - #strategySlots - 1
print("Strategy index selected", strategyIndex)
end
-- Must be last
self.selected = 1
end
local autoStrategyButton = sequencerPanel:OnOffButton("AutoStrategyButton" .. i, false)
autoStrategyButton.displayName = "Auto"
autoStrategyButton.tooltip = "Strategies are automatically created and randomly changed while playing."
autoStrategyButton.backgroundColourOff = backgroundColourOff
autoStrategyButton.backgroundColourOn = backgroundColourOn
autoStrategyButton.textColourOff = textColourOff
autoStrategyButton.textColourOn = textColourOn
autoStrategyButton.width = boxWidth / 2 - 2
autoStrategyButton.x = generateMaxNoteStepsPart.x
autoStrategyButton.y = strategyLabel.y
local slotStrategyButton = sequencerPanel:OnOffButton("SlotStrategyButton" .. i, false)
slotStrategyButton.displayName = "Slots"
slotStrategyButton.tooltip = "Strategies are selected from the slots."
slotStrategyButton.backgroundColourOff = backgroundColourOff
slotStrategyButton.backgroundColourOn = backgroundColourOn
slotStrategyButton.textColourOff = textColourOff
slotStrategyButton.textColourOn = textColourOn
slotStrategyButton.width = boxWidth / 2 - 2
slotStrategyButton.x = autoStrategyButton.x + autoStrategyButton.width + 5
slotStrategyButton.y = autoStrategyButton.y
local createStrategyButton = sequencerPanel:Button("CreateStrategyButton" .. i)
createStrategyButton.displayName = "Create"
createStrategyButton.tooltip = "Replace the current strategy with a new one."
createStrategyButton.persistent = false
createStrategyButton.width = slotStrategyButton.width
createStrategyButton.x = slotStrategyButton.x + slotStrategyButton.width + 5
createStrategyButton.y = slotStrategyButton.y
autoStrategyButton.changed = function(self)
slotStrategyButton:setValue(false, false)
notePosition = 0 -- Reset note position
strategyInput.enabled = self.value == false
createStrategyButton.enabled = self.value == false
end
slotStrategyButton.changed = function(self)
autoStrategyButton:setValue(false, false)
notePosition = 0 -- Reset note position
strategyInput.enabled = true
createStrategyButton.enabled = true
end
createStrategyButton.changed = function()
local strategy = createStrategy(i)
strategyInput.text = table.concat(strategy, ",")
end
table.insert(paramsPerPart, {storedStructures=storedStructures,storedStructuresPos=storedStructuresPos,strategySlots=strategySlots,strategyActions=strategyActions,strategyRestart=strategyRestart,subdivisionProbability=subdivisionProbability,subdivisions=subdivisions,structureMemoryMenu=structureMemoryMenu,stepRepeatProbability=stepRepeatProbability,subdivisionTieProbability=subdivisionTieProbability,subdivisionDotProbability=subdivisionDotProbability,subdivisionRepeatProbability=subdivisionRepeatProbability,subdivisionMinResolution=subdivisionMinResolution,velRandomization=velRandomization,gateRandomization=gateRandomization,partsTable=partsTable,positionTable=positionTable,seqVelTable=seqVelTable,seqGateTable=seqGateTable,numStepsBox=numStepsBox,stepResolution=stepResolution,fullScale={},scale=generateScalePart,key=generateKeyPart,createStrategyButton=createStrategyButton,strategyInput=strategyInput,autoStrategyButton=autoStrategyButton,slotStrategyButton=slotStrategyButton,strategyPropbability=strategyPropbability,minNote=generateMinPart,maxNote=generateMaxPart,minNoteSteps=generateMinNoteStepsPart,maxNoteSteps=generateMaxNoteStepsPart,init=i==1})