Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
111 changes: 70 additions & 41 deletions plugin.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@diagnostic disable: lowercase-global
debug = "hi"

function draw()
Expand All @@ -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)
Expand All @@ -45,46 +47,17 @@ 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
vibratoSetup(group.startTime, group.endTime, amplitude, increment, stopamplitude, tp_increment, oneSided, preserveNotePositions, useSnap)
end
end
end

imgui.Text(debug)
Expand All @@ -93,6 +66,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)
Expand Down