From 96ffd06c3c374a3ec4464408612deb8f9f594e0a Mon Sep 17 00:00:00 2001 From: Quaver-SV-Enthusiast Date: Sat, 10 Feb 2024 15:41:53 -0800 Subject: [PATCH 1/2] Keybinds, section vibrato, current button changes Added keybinds to automate vibrato workflow: Q - Select first note in selected group and assign it to start ms W - Select last note in selected group and assign it to start ms E - Execute Vibrato R - Execute Vibrato per Note Section Vibrato per note section does the same thing as vibrato, but executes the standard vibrato within every note section. Ignores start and stop ms (might change this later). Changed the current button for the stop ms to select the last note in the group of notes selected, instead of the first. --- .gitignore | 1 + plugin.lua | 112 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/plugin.lua b/plugin.lua index 438524b..0524cc1 100644 --- a/plugin.lua +++ b/plugin.lua @@ -1,3 +1,4 @@ +---@diagnostic disable: lowercase-global debug = "hi" function draw() @@ -21,9 +22,10 @@ function draw() local oneSided = state.GetValue("oneSided") if oneSided == nil then oneSided = false end - if imgui.Button("Current") then start = state.SelectedHitObjects[1] and state.SelectedHitObjects[1].StartTime or state.SongTime end imgui.SameLine() + if (imgui.Button("Current") or utils.IsKeyPressed(keys.Q)) then start = state.SelectedHitObjects[1] and state.SelectedHitObjects[1].StartTime or state.SongTime end imgui.SameLine() _, start = imgui.InputFloat("Start", start, 1) - if imgui.Button("Current##1") then stop = state.SelectedHitObjects[1] and state.SelectedHitObjects[1].StartTime or state.SongTime end imgui.SameLine() + lastNoteIndex = #state.SelectedHitObjects + if (imgui.Button("Current##1") or utils.IsKeyPressed(keys.W)) then stop = state.SelectedHitObjects[lastNoteIndex] and state.SelectedHitObjects[lastNoteIndex].StartTime or state.SongTime end imgui.SameLine() _, stop = imgui.InputFloat("Stop", stop, 1) _, amplitude = imgui.InputFloat("Start Amplitude", amplitude, 1) _, stopamplitude = imgui.InputFloat("Stop Amplitude", stopamplitude, 1) @@ -45,46 +47,18 @@ function draw() state.SetValue("preserveNotePositions", preserveNotePositions) state.SetValue("oneSided", oneSided) - if imgui.Button("vibe") then - --store old positions - local noteTimes = getNoteTimesDuringPeriod(start, stop) - local notePositions = {} - - if preserveNotePositions then - for _, time in pairs(noteTimes) do - table.insert(notePositions, getPositionFromTime(time)) - end - - debug = notePositions[1] or "error" - end - - --vibe - increment = useSnap and 60000 / map.GetTimingPointAt(state.SongTime).Bpm / increment or increment - vibe(start, stop, amplitude, increment, stopamplitude, tp_increment, oneSided) - - --restore positions - if preserveNotePositions then - local old_sv_count = #map.ScrollVelocities - - performQueue() - resetQueue() - resetCache() - - --with enough SVs, the game is unable to sort added SVs in time - --local sorted_svs = correctSVIndexsAtEnd(map.ScrollVelocities, old_sv_count + 1) - local sorted_svs = table.sort(map.ScrollVelocities, function(a, b) return a.StartTime < b.StartTime end) - - local newPositions = {} - for _, time in pairs(noteTimes) do - table.insert(newPositions, getPositionFromTime(time, sorted_svs)) - end - - debug = debug .. ", " .. newPositions[1] or "error" - - for i = 1, #noteTimes do - displace(noteTimes[i], (notePositions[i] - newPositions[i]) / 100, tp_increment, sorted_svs) - end + if imgui.Button("vibe") or utils.IsKeyPressed(keys.E) then + vibratoSetup(start, stop, amplitude, increment, stopamplitude, tp_increment, oneSided, preserveNotePositions, useSnap) + end + imgui.SameLine(); + if imgui.Button("vibe per section (selected notes only)") or utils.IsKeyPressed(keys.R) then + if (#state.SelectedHitObjects >= 2) then + groups = convertObjectsToRanges(state.SelectedHitObjects) + for _, group in pairs(groups) do + imgui.Text(group.startTime .. ' my nuts ' .. group.endTime) + vibratoSetup(group.startTime, group.endTime, amplitude, increment, stopamplitude, tp_increment, oneSided, preserveNotePositions, useSnap) end + end end imgui.Text(debug) @@ -93,6 +67,62 @@ function draw() imgui.End() end +function convertObjectsToRanges(hitObjects) + noteTimes = {} + for _, v in pairs(hitObjects) do + table.insert(noteTimes, v.startTime) + end + + groups = {} + for i=1, #noteTimes - 1 do + table.insert(groups, {startTime = noteTimes[i], endTime = noteTimes[i + 1]}) + end + + return groups +end + +function vibratoSetup(start, stop, amplitude, increment, stopamplitude, tp_increment, oneSided, preserveNotePositions, useSnap) + --store old positions + local noteTimes = getNoteTimesDuringPeriod(start, stop) + local notePositions = {} + + if preserveNotePositions then + for _, time in pairs(noteTimes) do + table.insert(notePositions, getPositionFromTime(time)) + end + + debug = notePositions[1] or "error" + end + + --vibe + increment = useSnap and 60000 / map.GetTimingPointAt(state.SongTime).Bpm / increment or increment + vibe(start, stop, amplitude, increment, stopamplitude, tp_increment, oneSided) + + --restore positions + if preserveNotePositions then + local old_sv_count = #map.ScrollVelocities + + performQueue() + resetQueue() + resetCache() + + --with enough SVs, the game is unable to sort added SVs in time + --local sorted_svs = correctSVIndexsAtEnd(map.ScrollVelocities, old_sv_count + 1) + local sorted_svs = table.sort(map.ScrollVelocities, function(a, b) return a.StartTime < b.StartTime end) + + local newPositions = {} + for _, time in pairs(noteTimes) do + table.insert(newPositions, getPositionFromTime(time, sorted_svs)) + end + + debug = debug .. (", " .. (newPositions[1] or "error")) + + for i = 1, #noteTimes do + displace(noteTimes[i], (notePositions[i] - newPositions[i]) / 100, tp_increment, sorted_svs) + end + end +end + function sv(time, multiplier) return utils.CreateScrollVelocity(time, multiplier) end function vibe(start, stop, amplitude, increment, stopamplitude, tp_increment, oneSided) From 235bca8ed3b1b8e078a2b250b8becd6414b15640 Mon Sep 17 00:00:00 2001 From: Quaver-SV-Enthusiast Date: Sat, 10 Feb 2024 15:45:54 -0800 Subject: [PATCH 2/2] Removed unnecessary debug line --- plugin.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin.lua b/plugin.lua index 0524cc1..15df838 100644 --- a/plugin.lua +++ b/plugin.lua @@ -55,7 +55,6 @@ function draw() if (#state.SelectedHitObjects >= 2) then groups = convertObjectsToRanges(state.SelectedHitObjects) for _, group in pairs(groups) do - imgui.Text(group.startTime .. ' my nuts ' .. group.endTime) vibratoSetup(group.startTime, group.endTime, amplitude, increment, stopamplitude, tp_increment, oneSided, preserveNotePositions, useSnap) end end