-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
4226 lines (3358 loc) · 128 KB
/
main.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
--Reform - main.lua--
--[[======TABLE OF CONTENTS======
-- DEBUG CONTROLS --
-- FULL-SCOPE VARIABLES --
-- NOTIFIERS/GETTERS & INITIALIZATION --
reset_variables()
get_theme_data()
set_theme_colors()
update_valuefields()
update_anchor_bitmaps()
update_collision_bitmaps()
update_curve_type_bitmaps() (unused)
update_vol_pan_fx_bitmaps()
reset_view()
deactivate_controls()
activate_controls()
release_document()
new_document()
add_document_notifiers()
add_pattern_length_notifier(p)
pattern_length_notifier
get_pattern_length_at_seq(s)
sequence_count_notifier() - used in get_sequence_length()
get_sequence_length()
track_count_notifier() - used in get_track_count()
get_track_count()
add_visible_note_columns_notifier(t)
visible_note_columns_notifier
get_visible_note_columns(t)
add_visible_effect_columns_notifier(t)
visible_effect_columns_notifier
get_visible_effect_columns(t)
-- MATH/UTILITY FUNCTIONS --
remap_range(val,lo1,hi1,lo2,hi2) - converts a value in range lo1-hi1 to lo2-hi2
sign(number) - returns 1 or -1 depending on the +/- of a number
-- SONG DATA MANIPULTAION --
store_note(s,p,t,c,l,counter)
get_selection()
select_line_at_edit_cursor()
find_selected_notes()
calculate_vol_placements()
calculate_pan_placements()
calculate_fx_placements()
calculate_note_placements()
calculate_all_placements()
get_index(s,t,l,c)
find_correct_index(s,p,t,l,c)
set_track_visibility(t)
set_note_column_values(column,vals)
restore_old_note(counter)
is_wild(index)
get_existing_note(index,counter)
update_current_note_location(counter,new_index)
add_to_placed_notes(index,counter)
apply_curve(placement,type)
place_new_note(counter)
update_start_pos()
-- BEZIER CURVES --
binom(n,k) - BINOMIAL COEFFECIENT
bern(val,v,n) - BERNSTEIN BASIS POLYNOMIAL
get_curve(t,points)
init_buffers(i)
calculate_curve(i)
rasterize_curve(i)
update_curve_grid(i)
update_curve_display(i)
update_all_curve_displays()
-- MAIN PROCESSING --
detect_changes_to_our_note(note)
detect_changes_to_notes()
apply_reform()
apply_reform_notifier()
add_reform_idle_notifier()
queue_processing()
strumify()
update_all_controls() -- belongs in VIEWBUILDER, but is used in hotkeys
-- FOCUSED HOTKEYS --
space_key()
shift_space_key()
up_key()
down_key()
left_key()
right_key()
tab_key()
shift_tab_key()
mod_arrow_key(control, alt_control, multiplier, repeated)
alt_left()
alt_right()
change_anchor(type, orientation)
change_our_collision_mode(bool)
change_wild_collision_mode(bool)
toggle_overflow_mode()
toggle_condense_mode()
toggle_redistribute_mode()
-- VIEWBUILDER --
show_window()
key_handler(dialog,key)
reform_main()
restore_reform_window()
strumify_line_at_edit_cursor()
-- MENU ENTRIES --
Pattern Editor:Reform:Reform Selection...
Pattern Editor:Reform:Restore Reform Window
Pattern Editor:Reform:Strumify Line at Edit Cursor
Main Menu:Tools:Reform:Reform Selection...
Main Menu:Tools:Reform:Restore Reform Window
Main Menu:Tools:Reform:Strumify Line at Edit Cursor
-- ASSIGNABLE HOTKEYS --
Pattern Editor:Selection:Reform Selection
Pattern Editor:Selection:Restore Reform Window
Pattern Editor:Selection:Strumify Line at Edit Cursor
======TABLE OF CONTENTS END====== --]]
--DEBUG CONTROLS-------------------------------
--[[
_AUTO_RELOAD_DEBUG = false
local debugvars = {
extra_curve_controls = false,
print_notifier_attach = false,
print_notifier_trigger = false,
print_queue_processing = false,
print_valuefield = false, --prints info from valuefields when set true
print_clocks = false, --prints out profiling clocks in different parts of the code when set true
clocktotals = {},
tempclocks = {}
}
local function rstclk(num)
if debugvars.print_clocks then
debugvars.clocktotals[num] = 0
end
end
local function stclk(num)
if debugvars.print_clocks then
debugvars.tempclocks[num] = os.clock()
end
end
local function adclk(num)
if debugvars.print_clocks then
debugvars.clocktotals[num] = debugvars.clocktotals[num] + (os.clock() - debugvars.tempclocks[num])
end
end
local function rdclk(num,msg)
if debugvars.print_clocks then
print(msg .. debugvars.clocktotals[num] or "nil")
end
end
--]]
--FULL-SCOPE VARIABLES----------------------------------------------------
local app = renoise.app()
local tool = renoise.tool()
local song = nil
local vb = renoise.ViewBuilder()
local window_obj = nil
local window_content = nil
local vb_notifiers_on
local last_spacebar = 0
local theme = {
selected_button_back = {255,255,255}
}
local tooltips = {
collision_sel = {
"No selected notes are overwriting each other",
"Selected notes are overwriting each other",
"\n[First] to keep earlier notes\n[Last] to keep later notes"
},
collision_wild = {
"No selected notes are overwriting non-selected notes",
"Selected notes are colliding with non-selected notes",
"\n[Sel] to keep selected notes\n[Not] to keep non-selected notes"
}
}
local control_increments = {0.001, 0.05, 0.01, 0.05, 0.25}
local last_arrow_key_time = 0
local previous_time = 0
local idle_processing = false --if apply_reform() takes longer than 40ms, this becomes true
local selected_notes = {} --contains all of our notes to be processed
--[[
the selected_notes "struct" consists of...
[1,2 .. n]{
--the index where the note originated from
original_index = {s,p,t,c,l}
--original values stored from the note
note_value
instrument_value
volume_value
panning_value
delay_value
effect_number_value
effect_amount_value
rel_line_pos --the line difference between current_location and original_index
current_location = {s,p,t,c,l} --the new/current index of the note after processing
--precomputed placement values to use for different types of operations
placement
redistributed_placement_in_note_range
redistributed_placement_in_sel_range
--values stored from last spot this note overwrote
last_overwritten_values = {
note_value
instrument_value
volume_value
panning_value
delay_value
effect_number_value
effect_amount_value
}
flags = {
write --tells whether this note should overwrite whatever is at the same index as it is
vol_re --tells whether the volume was distributed or not previously
pan_re --tells whether the panning was distributed or not previously
fx_re --tells whether the fx amount was distributed or not previously
clear --tells whether this note should clear the index it is at when it leaves
restore --tells whether this note should restore anything next time restoration occurs
}
}
--]]
local selection
local valid_selection
local selected_seq
local selected_pattern
local originally_visible_columns = {{},{},{},{},{}}
local columns_overflowed_into = {}
local column_to_end_on_in_first_track
local is_note_track = {} --bools indicating if the track at that index supports note columns
local total_delay_range
local total_line_range
local earliest_placement
local latest_placement
local placed_notes = {}
local note_collisions = {ours = {}, wild = {}}
local start_pos = renoise.SongPos()
local flags = {
overflow = true,
condense = false,
redistribute = false,
our_notes = false, --true == keep later notes, false == keep earlier notes
wild_notes = true, --true == keep selected notes, false == keep wild notes
vol_changed = false,
pan_changed = false,
fx_changed = false,
vol = false,
vol_re = false,
vol_orig_min = 0,
vol_orig_max = 128,
vol_min = 0,
vol_max = 128,
pan = false,
pan_re = false,
pan_orig_min = 0,
pan_orig_max = 128,
pan_min = 0,
pan_max = 128,
fx = false,
fx_re = false,
fx_orig_min = 0,
fx_orig_max = 255,
fx_min = 0,
fx_max = 255,
}
local pattern_lengths = {} --[pattern_index]{length, valid, notifier}
local seq_length = { length = 0, valid = false }
local visible_note_columns = {} --[track_index]{amount, valid, notifier}
local visible_effect_columns = {} --[track_index]{amount, valid, notifier}
local track_count = {} --{amount, valid, notifier}
local time = 0
local time_multiplier = 1
local time_was_typed = false
local typed_time = 1
local curve_intensity = {0, 0, 0, 0} --time,vol,pan,fx
local curve_type = {1, 1, 1, 1}
local curve_points = {
{ --time
sampled = {},
default = {
points = {{0,1,1},{1,0,1}},
samplesize = 2
},
{
positive = {{0,1,1},{1,1,1},{1,0,1}},
negative = {{0,1,1},{0,0,1},{1,0,1}},
samplesize = 19
},
{
positive = {{0,1,1},{0.5,1,4},{0.5,0,4},{1,0,1}},
negative = {{0,1,1},{0,0.5,4},{1,0.5,4},{1,0,1}},
samplesize = 18
}
},
{ --vol
sampled = {},
default = {
points = {{0,0,1},{1,1,1}},
samplesize = 2
},
{
positive = {{0,0,1},{0,1,1},{1,1,1}},
negative = {{0,0,1},{1,0,1},{1,1,1}},
samplesize = 10
}
},
{ --pan
sampled = {},
default = {
points = {{0,0,1},{1,1,1}},
samplesize = 2
},
{
positive = {{0,0,1},{0,1,1},{1,1,1}},
negative = {{0,0,1},{1,0,1},{1,1,1}},
samplesize = 10
}
},
{ --fx
sampled = {},
default = {
points = {{0,0,1},{1,1,1}},
samplesize = 2
},
{
positive = {{0,0,1},{0,1,1},{1,1,1}},
negative = {{0,0,1},{1,0,1},{1,1,1}},
samplesize = 10
}
},
}
local pascals_triangle = {}
local curve_displays = {
{ xsize = 16, ysize = 16, display = {}, buffer1 = {}, buffer2 = {} }, --time
{ xsize = 11, ysize = 11, display = {}, buffer1 = {}, buffer2 = {} }, --vol
{ xsize = 11, ysize = 11, display = {}, buffer1 = {}, buffer2 = {} }, --pan
{ xsize = 11, ysize = 11, display = {}, buffer1 = {}, buffer2 = {} }, --fx
}
local drawmode = "line"
local offset = 0
local offset_multiplier = 1
local offset_was_typed = false
local typed_offset = 0
local anchor = 0 -- 0 = top, 1 = bottom
local anchor_type = 1 -- 1 = note, 2 = selection
--RESET VARIABLES------------------------------
local function reset_variables()
--get our song reference if we don't have it yet
if not song then song = renoise.song() end
originally_visible_columns = {{},{},{},{},{}}
table.clear(columns_overflowed_into)
table.clear(is_note_track)
table.clear(selected_notes)
table.clear(placed_notes)
start_pos = renoise.SongPos()
flags = {
overflow = true,
condense = false,
redistribute = false,
our_notes = false, --true == keep later notes, false == keep earlier notes
wild_notes = true, --true == keep selected notes, false == keep wild notes
vol = false,
vol_re = false,
vol_orig_min = 0,
vol_orig_max = 128,
vol_min = 0,
vol_max = 128,
pan = false,
pan_re = false,
pan_orig_min = 0,
pan_orig_max = 128,
pan_min = 0,
pan_max = 128,
fx = false,
fx_re = false,
fx_orig_min = 0,
fx_orig_max = 255,
fx_min = 0,
fx_max = 255,
}
time = 0
time_multiplier = 1
time_was_typed = false
typed_time = 1
curve_intensity = {0, 0, 0, 0} --time,vol,pan,fx
curve_type = {1, 1, 1, 1}
offset = 0
offset_multiplier = 1
offset_was_typed = false
typed_offset = 0
anchor = 0
anchor_type = 1
earliest_placement = math.huge
latest_placement = 0
return true
end
--GET THEME DATA--------------------------------
local function get_theme_data()
app:save_theme("Theme.xrnc")
--open/cache the file contents as a string
local themefile = io.open("Theme.xrnc")
local themestring = themefile:read("*a")
themefile:close()
--find the indices where the Selected_Button_Back property begins and ends
local i = {}
i[1], i[2] = themestring:find("<Selected_Button_Back>",0,true)
i[3], i[4] = themestring:find("</Selected_Button_Back>",0,true)
local stringtemp = themestring:sub(i[2]+1,i[3]-1)
i[1], i[2] = stringtemp:find(",",0,true)
theme.selected_button_back[1] = tonumber(stringtemp:sub(0,i[1]-1))
i[2], i[3] = stringtemp:find(",",i[2]+1,true)
theme.selected_button_back[2] = tonumber(stringtemp:sub(i[1]+1,i[2]-1))
theme.selected_button_back[3] = tonumber(stringtemp:sub(i[2]+1,stringtemp:len()))
return true
end
--SET THEME COLORS-----------------------------------------
local function set_theme_colors()
vb.views.overflow_button.color = flags.overflow and theme.selected_button_back or {0,0,0}
vb.views.condense_button.color = flags.condense and theme.selected_button_back or {0,0,0}
vb.views.redistribute_button.color = flags.redistribute and theme.selected_button_back or {0,0,0}
vb.views.vol_re_button.color = flags.vol_re and theme.selected_button_back or {0,0,0}
vb.views.pan_re_button.color = flags.pan_re and theme.selected_button_back or {0,0,0}
vb.views.fx_re_button.color = flags.fx_re and theme.selected_button_back or {0,0,0}
return true
end
--UPDATE VALUEFIELDS---------------------------------
local function update_valuefields()
vb_notifiers_on = false
if time_was_typed then
vb.views.time_text.value = typed_time
else
vb.views.time_text.value = time * time_multiplier + 1
end
if offset_was_typed then
vb.views.offset_text.value = typed_offset
else
vb.views.offset_text.value = offset * offset_multiplier
end
--if debugvars.extra_curve_controls then vb.views.samplesize_text.value = curve_points[1][curve_type[1]].samplesize end
vb_notifiers_on = true
--print("update_valuefields() end")
return true
end
--UPDATE ANCHOR BITMAPS---------------------------------
local function update_anchor_bitmaps()
--anchor -- 0 = top, 1 = bottom
--anchor_type -- 1 = note, 2 = selection
if anchor == 0 then
if anchor_type == 1 then
vb.views.anchorTL.bitmap = "Bitmaps/anchorTL2.bmp"
vb.views.anchorTR.bitmap = "Bitmaps/anchorTR1.bmp"
vb.views.anchorBL.bitmap = "Bitmaps/anchorBL1.bmp"
vb.views.anchorBR.bitmap = "Bitmaps/anchorBR1.bmp"
elseif anchor_type == 2 then
vb.views.anchorTL.bitmap = "Bitmaps/anchorTL1.bmp"
vb.views.anchorTR.bitmap = "Bitmaps/anchorTR2.bmp"
vb.views.anchorBL.bitmap = "Bitmaps/anchorBL1.bmp"
vb.views.anchorBR.bitmap = "Bitmaps/anchorBR1.bmp"
end
elseif anchor == 1 then
if anchor_type == 1 then
vb.views.anchorTL.bitmap = "Bitmaps/anchorTL1.bmp"
vb.views.anchorTR.bitmap = "Bitmaps/anchorTR1.bmp"
vb.views.anchorBL.bitmap = "Bitmaps/anchorBL2.bmp"
vb.views.anchorBR.bitmap = "Bitmaps/anchorBR1.bmp"
elseif anchor_type == 2 then
vb.views.anchorTL.bitmap = "Bitmaps/anchorTL1.bmp"
vb.views.anchorTR.bitmap = "Bitmaps/anchorTR1.bmp"
vb.views.anchorBL.bitmap = "Bitmaps/anchorBL1.bmp"
vb.views.anchorBR.bitmap = "Bitmaps/anchorBR2.bmp"
end
end
return true
end
--UPDATE COLLISION BITMAPS--------------------------------
local function update_collision_bitmaps()
local our_collisions,wild_collisions = false,false
for k,v in pairs(note_collisions.ours) do
if v then our_collisions = true end
end
for k,v in pairs(note_collisions.wild) do
if v then wild_collisions = true end
end
if our_collisions then
vb.views.collision_sel_bmp.tooltip = tooltips.collision_sel[2] .. tooltips.collision_sel[3]
vb.views.collision_sel_bmp.active = true
vb.views.collision_sel_bmp.mode = "button_color"
if not flags.our_notes then vb.views.collision_sel_bmp.bitmap = "Bitmaps/collision_sel_1.bmp"
else vb.views.collision_sel_bmp.bitmap = "Bitmaps/collision_sel_2.bmp"
end
else
vb.views.collision_sel_bmp.tooltip = tooltips.collision_sel[1]
vb.views.collision_sel_bmp.active = false
vb.views.collision_sel_bmp.bitmap = "Bitmaps/collision_sel_0.bmp"
vb.views.collision_sel_bmp.mode = "main_color"
end
if wild_collisions then
vb.views.collision_wild_bmp.tooltip = tooltips.collision_wild[2] .. tooltips.collision_wild[3]
vb.views.collision_wild_bmp.active = true
vb.views.collision_wild_bmp.mode = "button_color"
if flags.wild_notes then vb.views.collision_wild_bmp.bitmap = "Bitmaps/collision_wild_1.bmp"
else vb.views.collision_wild_bmp.bitmap = "Bitmaps/collision_wild_2.bmp"
end
else
vb.views.collision_wild_bmp.tooltip = tooltips.collision_wild[1]
vb.views.collision_wild_bmp.active = false
vb.views.collision_wild_bmp.bitmap = "Bitmaps/collision_wild_0.bmp"
vb.views.collision_wild_bmp.mode = "main_color"
end
end
--UPDATE CURVE TYPE BITMAPS------------------------
-- local function update_curve_type_bitmaps()
-- if curve_type[1] == 1 then
-- vb.views.curve_type_1.bitmap = "Bitmaps/curve1pressed.bmp"
-- vb.views.curve_type_2.bitmap = "Bitmaps/curve2.bmp"
-- else
-- vb.views.curve_type_1.bitmap = "Bitmaps/curve1.bmp"
-- vb.views.curve_type_2.bitmap = "Bitmaps/curve2pressed.bmp"
-- end
-- end
--UPDATE VOL PAN FX BITMAPS--------------------------
local function update_vol_pan_fx_bitmaps()
if flags.vol then
vb.views.volbutton.bitmap = "Bitmaps/volbuttonpressed.bmp"
vb.views.vol_column.visible = true
else
vb.views.volbutton.bitmap = "Bitmaps/volbutton.bmp"
vb.views.vol_column.visible = false
end
if flags.pan then
vb.views.panbutton.bitmap = "Bitmaps/panbuttonpressed.bmp"
vb.views.pan_column.visible = true
else
vb.views.panbutton.bitmap = "Bitmaps/panbutton.bmp"
vb.views.pan_column.visible = false
end
if flags.fx then
vb.views.fxbutton.bitmap = "Bitmaps/fxbuttonpressed.bmp"
vb.views.fx_column.visible = true
else
vb.views.fxbutton.bitmap = "Bitmaps/fxbutton.bmp"
vb.views.fx_column.visible = false
end
end
--RESET VIEW------------------------------------------
local function reset_view()
vb_notifiers_on = false
vb.views.time_text.value = 1
vb.views.time_slider.value = 0
vb.views.time_multiplier_rotary.value = 1
vb.views.curve_text.value = 0
vb.views.curve_slider.value = 0
vb.views.curve_type_1.bitmap = "Bitmaps/curve1pressed.bmp"
vb.views.curve_type_2.bitmap = "Bitmaps/curve2.bmp"
vb.views.offset_text.value = 0
vb.views.offset_slider.value = 0
vb.views.offset_multiplier_rotary.value = 1
vb.views.vol_min_box.value = flags.vol_orig_min
vb.views.vol_slider.value = 0
vb.views.vol_max_box.value = flags.vol_orig_max
vb.views.pan_min_box.value = flags.pan_orig_min
vb.views.pan_slider.value = 0
vb.views.pan_max_box.value = flags.pan_orig_max
vb.views.fx_min_box.value = flags.fx_orig_min
vb.views.fx_slider.value = 0
vb.views.fx_max_box.value = flags.fx_orig_max
vb.views.collision_sel_bmp.bitmap = "Bitmaps/collision_sel_0.bmp"
vb.views.collision_wild_bmp.bitmap = "Bitmaps/collision_wild_0.bmp"
vb.views.vol_column.visible = false
vb.views.volbutton.bitmap = "Bitmaps/volbutton.bmp"
vb.views.pan_column.visible = false
vb.views.panbutton.bitmap = "Bitmaps/panbutton.bmp"
vb.views.fx_column.visible = false
vb.views.fxbutton.bitmap = "Bitmaps/fxbutton.bmp"
set_theme_colors()
update_anchor_bitmaps()
vb_notifiers_on = true
return true
end
--DEACTIVATE CONTROLS-------------------------------------
local function deactivate_controls()
if window_obj then
vb.views.time_text.active = false
vb.views.time_slider.active = false
vb.views.time_multiplier_rotary.active = false
vb.views.curve_text.active = false
vb.views.curve_slider.active = false
vb.views.curve_type_1.active = false
vb.views.curve_type_2.active = false
vb.views.offset_text.active = false
vb.views.offset_slider.active = false
vb.views.offset_multiplier_rotary.active = false
vb.views.vol_max_box.active = false
vb.views.vol_slider.active = false
vb.views.vol_min_box.active = false
vb.views.vol_re_button.active = false
vb.views.pan_max_box.active = false
vb.views.pan_slider.active = false
vb.views.pan_min_box.active = false
vb.views.pan_re_button.active = false
vb.views.fx_max_box.active = false
vb.views.fx_slider.active = false
vb.views.fx_min_box.active = false
vb.views.fx_re_button.active = false
vb.views.overflow_button.active = false
vb.views.condense_button.active = false
vb.views.redistribute_button.active = false
vb.views.collision_sel_bmp.active = false
vb.views.collision_wild_bmp.active = false
vb.views.anchorTL.active = false
vb.views.anchorTR.active = false
vb.views.anchorBL.active = false
vb.views.anchorBR.active = false
vb.views.volbutton.active = false
vb.views.panbutton.active = false
vb.views.fxbutton.active = false
end
return true
end
--ACTIVATE CONTROLS-------------------------------------
local function activate_controls()
if window_obj then
vb.views.time_text.active = true
vb.views.time_slider.active = true
vb.views.time_multiplier_rotary.active = true
vb.views.curve_text.active = true
vb.views.curve_slider.active = true
vb.views.curve_type_1.active = true
vb.views.curve_type_2.active = true
vb.views.offset_text.active = true
vb.views.offset_slider.active = true
vb.views.offset_multiplier_rotary.active = true
vb.views.vol_max_box.active = true
vb.views.vol_slider.active = true
vb.views.vol_min_box.active = true
vb.views.vol_re_button.active = true
vb.views.pan_max_box.active = true
vb.views.pan_slider.active = true
vb.views.pan_min_box.active = true
vb.views.pan_re_button.active = true
vb.views.fx_max_box.active = true
vb.views.fx_slider.active = true
vb.views.fx_min_box.active = true
vb.views.fx_re_button.active = true
vb.views.overflow_button.active = true
vb.views.condense_button.active = true
vb.views.redistribute_button.active = true
vb.views.collision_sel_bmp.active = true
vb.views.collision_wild_bmp.active = true
vb.views.anchorTL.active = true
vb.views.anchorTR.active = true
vb.views.anchorBL.active = true
vb.views.anchorBR.active = true
vb.views.volbutton.active = true
vb.views.panbutton.active = true
vb.views.fxbutton.active = true
end
return true
end
--RELEASE DOCUMENT------------------------------------------
local function release_document()
--if debugvars.print_notifier_trigger then print("release document notifier triggered!") end
--invalidate selection
valid_selection = false
deactivate_controls()
--invalidate recorded sequence length
seq_length.valid = false
--invalidate all recorded pattern lengths
for k, v in pairs(pattern_lengths) do
v.valid = false
end
--invalidate all recorded visible note columns for tracks
for k, v in pairs(visible_note_columns) do
v.valid = false
end
--invalidate all recorded visible effect columns for tracks
for k, v in pairs(visible_effect_columns) do
v.valid = false
end
--invalidate recorded total track count
track_count.valid = false
end
--NEW DOCUMENT------------------------------------------
local function new_document()
--if debugvars.print_notifier_trigger then print("new document notifier triggered!") end
song = renoise.song()
reset_variables()
reset_view()
end
--ADD DOCUMENT NOTIFIERS------------------------------------------------
local function add_document_notifiers()
--add document release notifier if it doesn't exist yet
if not tool.app_release_document_observable:has_notifier(release_document) then
tool.app_release_document_observable:add_notifier(release_document)
--if debugvars.print_notifier_attach then print("release document notifier attached!") end
end
--add new document notifier if it doesn't exist yet
if not tool.app_new_document_observable:has_notifier(new_document) then
tool.app_new_document_observable:add_notifier(new_document)
--if debugvars.print_notifier_attach then print("new document notifier attached!") end
end
return true
end
--ADD PATTERN LENGTH NOTIFIER-----------------------------------
local function add_pattern_length_notifier(p)
--define the notifier function
local function pattern_length_notifier()
--if debugvars.print_notifier_trigger then
--print(("pattern %i's length notifier triggered!!"):format(p))
--end
pattern_lengths[p].valid = false
--remove it from our record of which pattern length notifiers we currently have attached
pattern_lengths[p].notifier = false
song.patterns[p].number_of_lines_observable:remove_notifier(pattern_length_notifier)
end
--then add it to the pattern in question
song.patterns[p].number_of_lines_observable:add_notifier(pattern_length_notifier)
--add it to our record of which pattern length notifiers we currently have attached
pattern_lengths[p].notifier = true
end
--GET PATTERN LENGTH AT SEQ-----------------------------------------
local function get_pattern_length_at_seq(s)
--convert the sequence index to a pattern index
local p = song.sequencer:pattern(s)
--create an entry for this pattern if there is none yet
if not pattern_lengths[p] then
pattern_lengths[p] = {}
end
--update our records of this pattern's length if we don't have the valid data for it
if not pattern_lengths[p].valid then
pattern_lengths[p].length = song.patterns[p].number_of_lines
pattern_lengths[p].valid = true
--add our notifier to invalidate our recorded pattern length if this pattern's length changes
add_pattern_length_notifier(p)
--if debugvars.print_notifier_attach then
--print(("pattern %i's length notifier attached!!"):format(p))
--end
end
return pattern_lengths[p].length
end
--SEQUENCE COUNT NOTIFIER---------------------------------------------------
local function sequence_count_notifier()
--if debugvars.print_notifier_trigger then print("sequence count notifier triggered!!") end
seq_length.valid = false
song.sequencer.pattern_sequence_observable:remove_notifier(sequence_count_notifier)
end
--GET SEQUENCE LENGTH-------------------------------------
local function get_sequence_length()
if not seq_length.valid then
seq_length.length = #song.sequencer.pattern_sequence
seq_length.valid = true
--add our notifier to invalidate our recorded seq length if the sequence length changes
song.sequencer.pattern_sequence_observable:add_notifier(sequence_count_notifier)
--if debugvars.print_notifier_attach then print("sequence count notifier attached!!") end
end
return seq_length.length
end
--TRACK COUNT NOTIFIER---------------------------------------------------
local function track_count_notifier()
--if debugvars.print_notifier_trigger then print("track count notifier triggered!!") end
track_count.valid = false
song.tracks_observable:remove_notifier(track_count_notifier)
end
--GET TRACK COUNT-------------------------------------
local function get_track_count()
if not track_count.valid then
track_count.count = #song.tracks
track_count.valid = true
--add our notifier to invalidate our recorded track count if the amount of tracks changes
song.tracks_observable:add_notifier(track_count_notifier)
--if debugvars.print_notifier_attach then print("track count notifier attached!!") end
end
return track_count.count
end
--ADD VISIBLE NOTE COLUMNS NOTIFIER-----------------------------------
local function add_visible_note_columns_notifier(t)
--define the notifier function
local function visible_note_columns_notifier()
--if debugvars.print_notifier_trigger then
--print(("track %i's visible note columns notifier triggered!!"):format(t))
--end
visible_note_columns[t].valid = false
--remove it from our record of which notifiers we currently have attached
visible_note_columns[t].notifier = false
song:track(t).visible_note_columns_observable:remove_notifier(visible_note_columns_notifier)
end
--then add it to the track in question
song:track(t).visible_note_columns_observable:add_notifier(visible_note_columns_notifier)
--add it to our record of which notifiers we currently have attached