I dont know how MIDI files can be ran without lag in other software but in roblox, its heavy on lag.
basically when i load midi files into the game, over 10k ImageButtons are created
and the the render system would become redundant as i might as well loop through all to see if the playhead collides with each note.
In every ImageButton(note)
[runs when it gets created
local mod = require(game.ReplicatedStorage.RENDERMODULE)
local tbl = mod.getRecipes()
table.insert(tbl,script.Parent)
in the touch script:
local RunService = game:GetService("RunService")
local Collectionservice = game:GetService("CollectionService")
local play = game.ReplicatedStorage.Remotes.Playsound2
local stop = game.ReplicatedStorage.Remotes.StopSound
local mod = require(game.ReplicatedStorage.RENDERMODULE)
local tbl = mod.getRecipes()
function OnTouch(b)
local MusicianID = b.Parent.Parent.Parent.Parent.Parent.Parent.ID.Value
local a = b.Parent.Parent.Parent.Parent.DragableFrame
local posx = b.AbsolutePosition.X
if a.AbsolutePosition.X >= b.AbsolutePosition.X and a.AbsolutePosition.X <= b.AbsolutePosition.X+b.AbsoluteSize.X then
if b.UIStroke.Enabled == true then return end
local velocity = b.assets.Velocity.Value
play:FireServer(b.Parent.Key.Value,b.Parent.Octave.Value,b.Parent.Pitch.Value,b.AbsolutePosition.X,b.AbsolutePosition.Y,MusicianID,velocity,b.Name)
b.UIStroke.Enabled = true
else
b.UIStroke.Enabled = false
stop:FireServer(b.Name)
end
end
local function isInScreen(b)
local pos = b.AbsolutePosition
return pos.X <= b.Parent.Parent.Parent.Parent.Parent.AbsoluteSize.X and pos.X >= 0
end
local RATE_PER_SECOND = 2
function tag(d)
if isInScreen(d) then
Collectionservice:AddTag(d,"regions")
d.Visible = true
else
if Collectionservice:HasTag(d,"Selected") then return end
Collectionservice:RemoveTag(d,"regions")
stop:FireServer(d.Name)
d.Visible = false
end
end
RunService.RenderStepped:Connect(function(step)
local increment = RATE_PER_SECOND * step
task.wait(increment)
for k=1, #tbl do local b = tbl[k]
--if not Collectionservice:HasTag(b,"regions") then continue end
coroutine.wrap(tag)(b)
coroutine.wrap(OnTouch)(b)
end
end)
in the Module
local RenderModule = {}
local IsInScreen = {}
function RenderModule.getRecipes()
return IsInScreen
end
return RenderModule
I wish UI had Streaming enabled so i woulnt have to code a render system