-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.lua
1723 lines (1452 loc) · 49.9 KB
/
plugin.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
---@diagnostic disable: lowercase-global, need-check-nil, param-type-mismatch, undefined-global
--- @class HitObjectInfo
--- @field StartTime number
--- @field Lane number
--- @field EndTime number
--- @field HitSound any
--- @field EditorLayer integer
--- @class ScrollVelocityInfo
--- @field StartTime number
--- @field Multiplier number
local lastStartTimeOfFirstNote = 0
local lastPosition = { 1635, 95 }
local lastLaneOfFirstNote = 0
local lastSize = { 0, 200 }
local lastSelectables = {}
local lastCustomFunction
local lastCustomString
local lastSelected = 0
local lastShow = false
local lastPeriod = 0
local lastCount = 0
local lastEase = ""
local lastFrom = 0
local lastMode = 0
local lastTerm = 0
local heightValues
local lastOp = 0
local lastAmp = 0
local lastTo = 0
local heightMax
local heightMin
local textFlags
local lastOrder
local lastSort
local dirs = { "in", "out", "inOut", "outIn" }
local modes = { "absolute", "relative" }
local inclusives = { "unfiltered", "within", "not within" }
local ops = {
"multiply", "add", "subtract", "divide",
"modulo", "pow", "replace"
}
local orders = { "ascending", "descending" }
local terms = { "sort nm", "sort nsv" }
local sorts = { "time", "position" }
local types = {
"linear", "quad", "cubic", "quart", "quint", "sine",
"expo", "circ", "elastic", "back", "bounce", "custom"
}
local keybinds = read()
if not keybinds then
keybinds = {
swap = "U",
section = "I",
note = "O",
["eat mulch"] = "P",
}
write(keybinds)
end
for _, value in pairs(keybinds) do
if not keys[value] then
error("Unrecognized key: " .. value)
end
end
--- The main function
function draw()
textFlags = imgui_input_text_flags.CharsScientific
imgui.Begin("mulch", imgui_window_flags.AlwaysAutoResize)
Theme()
local padding = 10
local dropdownWidth = 100
local from = get("from", 0) ---@type number
local to = get("to", 1) ---@type number
local count = get("count", 2) ---@type integer
local type = get("type", 0) ---@type integer
local direction = get("direction", 0) ---@type integer
local amp = get("amp", 1) ---@type number
local period = get("period", 1) ---@type number
local op = get("op", 0) ---@type number
local show = get("show", false) ---@type boolean
local advanced = get("advanced", false) ---@type boolean
local mulchmax = get("mulchmax", false) ---@type boolean
local custom = get("custom", "") ---@type string
local ssf = get("ssf", false) ---@type boolean
imgui.BeginTabBar("mode", imgui_tab_bar_flags.NoTooltip)
if imgui.BeginTabItem("simple") then
imgui.EndTabItem()
advanced = false
mulchmax = false
end
if imgui.BeginTabItem("advanced") then
imgui.EndTabItem()
advanced = true
mulchmax = false
end
if imgui.BeginTabItem("mulchmax") then
imgui.EndTabItem()
mulchmax = true
end
imgui.EndTabBar()
if not mulchmax then
if advanced then
ActionButton(
"swap",
keybinds.swap,
function()
from, to = to, from
end,
{ },
"Swaps the parameters for the 'from' and 'to' values."
)
imgui.SameLine(0, padding)
end
imgui.PushItemWidth(150)
local _, ft = imgui.InputFloat2("", { from, to }, "%.2f", textFlags)
imgui.PopItemWidth()
from = ft[1]
to = ft[2]
local ease
if advanced then
imgui.PushItemWidth(dropdownWidth)
_, type = imgui.Combo("##type", type, types, #types)
imgui.PopItemWidth()
if not ({ custom = 0, linear = 0 })[types[type + 1]] then
imgui.SameLine(0, padding)
imgui.PushItemWidth(dropdownWidth)
_, direction = imgui.Combo("##direction", direction, dirs, #dirs)
imgui.PopItemWidth()
end
if types[type + 1] == "elastic" then
imgui.PushItemWidth(150)
local _, vs = imgui.InputFloat2(
"amp/period",
{ amp, period },
"%.2f",
textFlags
)
imgui.PopItemWidth()
Tooltip("The elasticity severity, and frequency, respectively.")
amp = vs[1]
period = vs[2]
end
if types[type + 1] == "custom" then
Tooltip(
"Specify a custom easing function here.\n" ..
"$t = time: [0, 1]\n" ..
"$b = begin: 'from' parameter\n" ..
"$c = change: 'to' - 'from'\n" ..
"$d = duration: always 1\n" ..
"$v = velocity: current SV multiplier"
)
_, custom = imgui.InputTextMultiline("", custom, 1000, {240, 70})
end
imgui.Separator()
imgui.PushItemWidth(dropdownWidth)
_, op = imgui.Combo("##op", op, ops, #ops)
imgui.PopItemWidth()
if advanced then
imgui.SameLine(0, padding)
_, ssf = imgui.Checkbox("ssf", ssf)
Tooltip("Apply changes to SSFs instead of SVs.")
end
ease = fulleasename(type, direction)
else
Tooltip(
"The left field is 'from', which is used at the start of the " ..
"selection. The right value is 'to', for the end. Within the " ..
"selection, the value used is an interpolation between the " ..
"'from' and 'to' values."
)
ease = "linear"
end
imgui.Separator()
ActionButton(
"section",
keybinds.section,
section,
{ from, to, op, amp, period, ease, custom, ssf },
"'from' is applied from the start of the selection.\n" ..
"'to' is applied to the end of the selection."
)
imgui.SameLine(0, padding)
ActionButton(
"note",
keybinds.note,
perNote,
{ from, to, op, amp, period, ease, custom, ssf },
"'from' is applied from the selected note.\n" ..
"'to' is applied just before next selected note."
)
Plot(from, to, op, amp, period, ease, count, custom)
else
imgui.PushItemWidth(170)
_, count = imgui.InputInt("count", count, 1, 1, textFlags)
imgui.PopItemWidth()
Tooltip("The number of SVs to place between each SV in 'sv'")
count = clamp(count, 1, 2000)
imgui.Separator()
ActionButton(
"eat mulch",
keybinds["eat mulch"],
perSV,
{ from, to, op, ease, amp, period, count, custom, ssf },
"Smear tool, adds SVs in-between existing SVs." ..
"'from' and 'to' function identically to 'section'."
)
end
if advanced or mulchmax then
imgui.SameLine(0, padding)
_, show = imgui.Checkbox("info", show)
ShowNoteInfo(show)
end
state.SetValue("from", from)
state.SetValue("to", to)
state.SetValue("count", count)
state.SetValue("type", type)
state.SetValue("direction", direction)
state.SetValue("amp", amp)
state.SetValue("period", period)
state.SetValue("op", op)
state.SetValue("show", show)
state.SetValue("advanced", advanced)
state.SetValue("mulchmax", mulchmax)
state.SetValue("custom", custom)
state.SetValue("ssf", ssf)
imgui.End()
end
--- Applies the tween over the entire selected region.
--- @param from number
--- @param to number
--- @param op number
--- @param ease string
--- @param ssf boolean
function section(from, to, op, amp, period, ease, custom, ssf)
local offsets = uniqueSelectedNoteOffsets()
local svs = getSVsBetweenOffsets(offsets[1], offsets[#offsets], ssf)
if not svs[1] then
print("Please select the region to modify before pressing this button.")
return
end
local svsToAdd = {}
svsToAdd[#svs] = nil
for i, sv in ipairs(svs) do
local f = (sv.StartTime - svs[1].StartTime) /
(svs[#svs].StartTime - svs[1].StartTime)
local fm = tween(f, from, to, amp, period, ease, sv.Multiplier, custom)
local v = handleOperation(sv.Multiplier, fm, op)
if ssf then
svsToAdd[i] = utils.CreateScrollSpeedFactor(sv.StartTime, v)
else
svsToAdd[i] = utils.CreateScrollVelocity(sv.StartTime, v)
end
end
actions.PerformBatch({
utils.CreateEditorAction(ternary(ssf, action_type.RemoveScrollSpeedFactorBatch, action_type.RemoveScrollVelocityBatch), svs),
utils.CreateEditorAction(ternary(ssf, action_type.AddScrollSpeedFactorBatch, action_type.AddScrollVelocityBatch), svsToAdd)
})
end
--- Applies the tween over each note selected.
--- @param from number
--- @param to number
--- @param op number
--- @param ease string
--- @param ssf boolean
function perNote(from, to, op, amp, period, ease, custom, ssf)
local offsets = uniqueSelectedNoteOffsets()
local svs = getSVsBetweenOffsets(offsets[1], offsets[#offsets], ssf)
if not svs[1] then
print("Please select the region to modify before pressing this button.")
return
end
local svsToAdd = {}
svsToAdd[#svs] = nil
for i, sv in ipairs(svs) do
local b, e = findAdjacentNotes(sv, offsets)
local f = (sv.StartTime - b) / (e - b)
local fm = tween(f, from, to, amp, period, ease, sv.Multiplier, custom)
local v = handleOperation(sv.Multiplier, fm, op)
if ssf then
svsToAdd[i] = utils.CreateScrollSpeedFactor(sv.StartTime, v)
else
svsToAdd[i] = utils.CreateScrollVelocity(sv.StartTime, v)
end
end
actions.PerformBatch({
utils.CreateEditorAction(ternary(ssf, action_type.RemoveScrollSpeedFactorBatch, action_type.RemoveScrollVelocityBatch), svs),
utils.CreateEditorAction(ternary(ssf, action_type.AddScrollSpeedFactorBatch, action_type.AddScrollVelocityBatch), svsToAdd)
})
end
--- Applies the tween over each SV selected.
--- @param from number
--- @param to number
--- @param op number
--- @param ease string
--- @param count integer
--- @param ssf boolean
function perSV(from, to, op, ease, amp, period, count, custom, ssf)
local offsets = uniqueSelectedNoteOffsets()
local svs = getSVsBetweenOffsets(offsets[1], offsets[#offsets], ssf)
if not svs[2] then
print("The selected region must contain at least 2 SV points.")
return
end
local svsToAdd = {}
local last = 0
for i, sv in ipairs(svs) do
local multiplier = sv.Multiplier
local n = svs[i + 1]
if not n then
break
end
svsToAdd[last + count + 1] = nil
for j = 0, count - 1, 1 do
local gEase = "linear"
local f = j / (count - 1.0)
local g = j / (count - 0.0)
local fm = tween(f, from, to, amp, period, ease, multiplier, custom)
local gm = tween(g, sv.StartTime, n.StartTime, 0, 0, gEase, 0, "")
local v = handleOperation(sv.Multiplier, fm, op)
last = last + 1
if ssf then
svsToAdd[last] = utils.CreateScrollSpeedFactor(gm, v)
else
svsToAdd[last] = utils.CreateScrollVelocity(gm, v)
end
end
end
local final = svs[#svs]
if ssf then
svsToAdd[#svsToAdd + 1] = utils.CreateScrollSpeedFactor(
final.StartTime,
final.Multiplier
)
else
svsToAdd[#svsToAdd + 1] = utils.CreateScrollVelocity(
final.StartTime,
final.Multiplier
)
end
actions.PerformBatch({
utils.CreateEditorAction(ternary(ssf, action_type.RemoveScrollSpeedFactorBatch, action_type.RemoveScrollVelocityBatch), svs),
utils.CreateEditorAction(ternary(ssf, action_type.AddScrollSpeedFactorBatch, action_type.AddScrollVelocityBatch), svsToAdd)
})
end
--- Creates a function that steps through the SVs to return the position for the
--- note passed as milliseconds. If `nsv` is `false`, you must pass each number
--- in ascending order, or else the function will return incorrect values.
--- @param nsv boolean
--- @param relative boolean
--- @return function
function positionMarkers(nsv, relative)
local first
if not relative then
first = 0
end
if nsv then
return function(time)
first = first or time
return math.floor(utils.ToFloat((time - first) * 100))
end
end
-- We pay for the cost of loading SVs up-front, however we are assuming the
-- caller will not call this function in a loop or without using the
-- returned function at least once. If this changes, consider removing the
-- initialization and putting `svs = svs or map.ScrollVelocities` as the
-- first statement in the returned function.
local svs = map.ScrollVelocities
local initial = map.InitialScrollVelocity
local index = 2
local pos
return function(time)
if not first and relative then
while index < #svs and time >= svs[index].StartTime do
index = index + 1
end
end
if #svs == 0 or time < svs[1].StartTime then
first = first or time
local next = utils.ToFloat((time - first) * initial)
return math.floor(utils.ToFloat(next * 100))
end
if not pos then
if relative then
pos = 0
else
pos = math.floor(utils.ToFloat(svs[1].StartTime * 100))
end
end
while index < #svs and time >= svs[index].StartTime do
local prev = svs[index - 1]
local next = utils.ToFloat(svs[index].StartTime - prev.StartTime)
next = utils.ToFloat(next * prev.Multiplier)
next = utils.ToFloat(next * 100)
pos = math.floor(utils.ToFloat(pos + next))
index = index + 1
end
local sv = svs[index - 1] or svs[#svs]
local t = utils.ToFloat(time - sv.StartTime)
t = utils.ToFloat(t * sv.Multiplier)
local ret = pos + math.floor(utils.ToFloat(t * 100))
first = first or ret
return ret - first
end
end
--- Removes duplicates from a table.
--- @param list table
--- @return table
function removeDuplicateValues(list)
local hash = {}
local newList = {}
for _, value in ipairs(list) do
if not hash[value] then
newList[#newList + 1] = value
hash[value] = true
end
end
return newList
end
--- Returns the list of unique offsets (in increasing order) of selected notes
--- @return number[]
function uniqueSelectedNoteOffsets()
local offsets = {}
for i, hitObject in ipairs(state.SelectedHitObjects) do
offsets[i] = hitObject.StartTime
end
offsets = removeDuplicateValues(offsets)
return offsets
end
--- Returns the chronologically ordered list of SVs between two offsets/times
--- @param startOffset number
--- @param endOffset number
--- @param ssf boolean
--- @return ScrollVelocityInfo[]
function getSVsBetweenOffsets(startOffset, endOffset, ssf)
if startOffset == nil or endOffset == nil then
return {}
end
local svsBetweenOffsets = {}
local svs
if ssf then
svs = map.ScrollSpeedFactors
else
svs = map.ScrollVelocities
end
if not svs then
return {}
end
for _, sv in ipairs(svs) do
if sv.StartTime >= startOffset and sv.StartTime < endOffset then
table.insert(svsBetweenOffsets, sv)
end
end
return svsBetweenOffsets
end
--- Constructs the clipboard from the last selected objects.
--- @param field string
--- @param message string
--- @param inclusive number
--- @param min number
--- @param max number
function fullClipboard(field, message, inclusive, min, max)
if #lastSelectables == 0 then
print("Nothing to copy. Please select notes first.")
return
end
local first = lastSelectables[1]
local clipboard = ""
if first and (inclusive == 0 or ((inclusive == 1) ==
(first.position >= min and first.position <= max))) then
clipboard = first[field]
if field == "time" then
clipboard = clipboard .. "|" .. first.lane
end
end
if #lastSelectables == 1 then
imgui.SetClipboardText(clipboard)
print(message)
return clipboard
else
local separator = "\n"
if field == "time" then
separator = ","
end
for i = 2, #lastSelectables, 1 do
local next = lastSelectables[i]
if next and (inclusive == 0 or ((inclusive == 1) ==
(next.position >= min and next.position <= max))) then
clipboard = clipboard .. separator .. next[field]
if field == "time" then
clipboard = clipboard .. "|" .. next.lane
end
end
end
end
if #clipboard == 0 then
if inclusive == 1 then
print(
"Nothing to copy. Please select notes " ..
"from within the time frame first."
)
elseif inclusive == 2 then
print(
"Nothing to copy. Please select notes " ..
"outside of the time frame first."
)
else
error("Not implemented: " .. inclusive)
end
return
end
imgui.SetClipboardText(clipboard)
print("Copied all " .. message .. " to clipboard.")
end
--- Finds the closest note to a scroll velocity point.
--- @param sv ScrollVelocityInfo
--- @param notes HitObjectInfo
--- @return HitObjectInfo
--- @return HitObjectInfo
function findAdjacentNotes(sv, notes)
local p = notes[1]
for _, n in pairs(notes) do
if n > sv.StartTime then
return p, n
end
p = n
end
return p, p
end
--- Calculates the tween between a range.
--- @param f number
--- @param from number
--- @param to number
--- @param ease string
--- @param sv number
--- @param custom string
--- @return number
function tween(f, from, to, amp, period, ease, sv, custom)
if ease == "custom" then
if not lastCustomFunction or custom ~= lastCustomString then
lastCustomString = custom
lastCustomFunction = easer[ease](custom)
end
return lastCustomFunction(f, from, to - from, 1, sv)
end
-- Lossless path: This prevents slight floating point inaccuracies.
if from == to then
return from
end
return easer[ease](f, from, to - from, 1, amp, period)
end
--- Gets the full ease name applicable in `easing`.
--- @param type string
--- @param direction number
--- @return string
function fulleasename(type, direction)
local t = types[type + 1]
if ({ custom = 0, linear = 0 })[types[type + 1]] then
return t
end
return dirs[direction + 1] .. t:gsub("^%l", string.upper)
end
--- Handles the binary operation of two numbers.
--- @param x number
--- @param y number
--- @param op number
--- @return number
function handleOperation(x, y, op)
if op == 0 then
return x * y
end
if op == 1 then
return x + y
end
if op == 2 then
return x - y
end
if op == 3 then
return x / y
end
if op == 4 then
return x % y
end
if op == 5 then
return x ^ y
end
if op == 6 then
return y
end
error("Not implemented: " .. op)
end
--- Converts a note to a string.
--- @param obj HitObjectInfo
--- @param pos number
--- @param fromEnd boolean
function noteString(obj, pos, fromEnd)
if fromEnd then
return obj.EndTime .. "^ = " .. pos .. " msx"
end
return obj.StartTime .. "|" .. obj.Lane .. " = " .. pos .. " msx"
end
--- Converts a note to a string.
--- @param obj HitObjectInfo
--- @param fromEnd boolean
function noteRawString(obj, fromEnd)
local time = obj.StartTime
if fromEnd then
time = obj.EndTime
end
return time .. "|" .. obj.Lane
end
--- Gets the RGBA object of the provided hex value.
--- @param hex string
--- @return number[]
function rgb(hex)
hex = hex:gsub("#", "")
local alpha
if #hex > 6 then
alpha = tonumber("0x" .. hex:sub(7, 8), 16) / 255.0
else
alpha = 255
end
return {
tonumber("0x" .. hex:sub(1, 2), 16) / 255.0,
tonumber("0x" .. hex:sub(3, 4), 16) / 255.0,
tonumber("0x" .. hex:sub(5, 6), 16) / 255.0,
alpha
}
end
--- Clamps the value between a minimum and maximum value.
--- @param value number
--- @param min number
--- @param max number
--- @return number
function clamp(value, min, max)
if value < min then
return min
end
if value > max then
return max
end
return value
end
--- Performs the ternary operation.
--- @generic T
--- @param condition boolean
--- @param consequent T
--- @param alternative T
--- @return T
function ternary(condition, consequent, alternative)
if condition then
return consequent
end
return alternative
end
--- Gets the value from the current state.
--- @param identifier string
--- @param defaultValue any
--- @return any
function get(identifier, defaultValue)
return state.GetValue(identifier) or defaultValue
end
--- Returns the argument (identity function).
--- @param x any
--- @return any
function id(x)
return x
end
--- Creates a button that runs a function using `from` and `to`.
--- @param label string
--- @param key string
--- @param fn function
--- @param tbl table
--- @param msg string
function ActionButton(label, key, fn, tbl, msg)
if imgui.Button(label) or utils.IsKeyPressed(keys[key]) then
fn(table.unpack(tbl))
end
Tooltip(
msg .. " Alternatively, press " .. key .. " to perform this action."
)
end
--- Creates a plot with the given parameters.
--- @param from number
--- @param to number
--- @param op number
--- @param ease string
--- @param count number
--- @param custom string
function Plot(from, to, op, amp, period, ease, count, custom)
if ease == "linear" then
return
end
imgui.Begin("mulch plot", imgui_window_flags.AlwaysAutoResize)
count = 256
if from ~= lastFrom or to ~= lastTo or op ~= lastOp or
amp ~= lastAmp or period ~= lastPeriod or ease ~= lastEase or
count ~= lastCount or custom ~= lastCustomString then
lastFrom = from
lastTo = to
lastOp = op
lastAmp = amp
lastPeriod = period
lastEase = ease
lastCount = count
heightValues = {}
heightValues[count + 1] = nil
heightMax = -1 / 0
heightMin = 1 / 0
for i = 0, count, 1 do
local f = i / count
local fm = tween(f, from, to, amp, period, ease, 1, custom)
local v = handleOperation(1, fm, op)
heightValues[i + 1] = v
if v > heightMax then
heightMax = v
end
if v < heightMin then
heightMin = v
end
end
-- Custom needs to be updated after the calls to 'tween', because
-- it compares the assigned value, however it doesn't update the
-- value if we have a different ease other than 'custom'.
lastCustomString = custom
end
imgui.PlotLines(
"",
heightValues,
#heightValues,
0,
ease .. ", " .. math.floor(heightMin * 100 + 0.5) / 100 .. " to " ..
math.floor(heightMax * 100 + 0.5) / 100,
heightMin,
heightMax,
{ 300, 150 }
)
imgui.End()
end
--- Shows the note info window.
--- @param show boolean
function ShowNoteInfo(show)
local refresh = show and not lastShow
lastShow = show
if not show then
return
end
local objects = state.SelectedHitObjects
local name = "mulch measure"
imgui.PushStyleVar(imgui_style_var.WindowMinSize, { 235, 465 })
imgui.Begin(name)
imgui.PopStyleVar(imgui_style_var.WindowMinSize)
if #objects ~= lastSelected then
imgui.SetWindowPos(name, lastPosition)
imgui.SetWindowSize(name, lastSize)
end
local term = get("term", 0) ---@type number
local mode = get("mode", 0) ---@type number
local order = get("order", 0) ---@type number
local sort = get("sort", 0) ---@type number
local inclusive = get("inclusive", 0) ---@type number
local from = get("positionFrom", 0) ---@type number
local to = get("positionTo", 1000) ---@type number
imgui.PushItemWidth(120)
_, term = imgui.Combo("by", term, terms, #terms)
Tooltip("Whether distance is measured with or without considering SVs.")
local modeLabel = "time in##mode"
if term == 0 then
modeLabel = "##mode"
end
_, mode = imgui.Combo(modeLabel, mode, modes, #modes)
Tooltip(
"Refers to categorization of 0. Either the first note's position, " ..
"which is considered relative, or from the start of the chart, " ..
"which is considered absolute."
)
if term == 0 then
_, sort = imgui.Combo("in", sort, sorts, #sorts)
Tooltip(
"Whether to sort based on the time of each note, or the " ..
"position in which a note is placed in the chart."
)
end
_, order = imgui.Combo("order", order, orders, #orders)
Tooltip(
"Ascending refers to lowest to highest, " ..
"while descending refers to highest to lowest."
)
_, inclusive = imgui.Combo("##include", inclusive, inclusives, #inclusives)
Tooltip("Allows filtering of notes based on position.")
imgui.PopItemWidth()
if inclusive ~= 0 then
imgui.PushItemWidth(170)
local _, vs = imgui.InputFloat2("msx", { from, to }, "%.2f", textFlags)
imgui.PopItemWidth()
from = vs[1]
to = vs[2]
end
local min, max
if from <= to then
min = from
max = to
else
min = to
max = from
end
imgui.Separator()
local selectCountLabel
if #objects == 0 then
selectCountLabel = "No hit objects selected."
elseif #objects == 1 then
selectCountLabel = "1 hit object selected."
else
selectCountLabel = #objects .. " hit objects selected."
end
if imgui.Selectable(selectCountLabel) then
fullClipboard("position", "msx values", inclusive, min, max)
elseif imgui.IsItemClicked(1) then
fullClipboard("time", "object timestamps", inclusive, min, max)
elseif imgui.IsItemClicked(2) then
fullClipboard("string", "text", inclusive, min, max)
end
Tooltip(
"Any of the numbers below can be left-clicked to copy their msx " ..
"value onto your clipboard. Use the right mouse button to copy the " ..
"note instead, usable in \"Tools\" > \"Go To Objects\", and the " ..
"middle button to copy the whole text. Clicking this label will " ..
"perform the listed action on every selected note."
)
imgui.Separator()
if sort ~= lastSort or order ~= lastOrder then
lastSort = sort