Hi there, I have a midi player I am working on, which plays notes through a json table. The issue is, is that I do not know how to get the dictionary of instrument before a table of notes. I’ve tried indexing a dictionary by index (e.g: instrument[1]
) however I only get carries with errors saying index nil. In the json table below, I basically want it so that the notes played print out the instrument name of the dictionary before the table its in.
Midi Player:
local owner = game.Players.LocalPlayer
local http = game:GetService('HttpService')
local response = http:GetAsync("https://vxsqi.tk/song.lua")
local jsondecoded = http:JSONDecode(response)
local function notetopitch(note)
return (440/32)*math.pow(2,((note-0)/12))/440
end
local sounds = {}
function PlayMIDI(b)
task.spawn(function()
for i,w in ipairs(b.tracks) do
task.spawn(function()
for j,v in ipairs(w.notes) do
task.spawn(function()
task.wait(v.time)
local s = Instance.new("Sound",owner.Character.Head)
local ReverbSoundEffect = Instance.new("ReverbSoundEffect",s)
s.Volume = 10
ReverbSoundEffect.Density = 0
ReverbSoundEffect.WetLevel = 5
ReverbSoundEffect.DryLevel = -5
ReverbSoundEffect.DecayTime = 5
s.SoundId = "rbxassetid://584691395"
s.RollOffMaxDistance = 25
s.PlaybackSpeed = notetopitch(v.midi)
s.PlayOnRemove = true
game:GetService("Debris"):AddItem(s,1)
end)
end
end)
end
end)
end
PlayMIDI(jsondecoded)
Example of json table (note it gets converted anyway):
"tracks" : [
"instrument": {
"family": "piano",
"name": "Grand Piano"
},
"notes" : [
{
"midi" : 67
}
],
"instrument": {
"family": "reed",
"name": "Clarinet"
},
"notes" : [
{
"midi" : 50
}
]