local Height = 0
local Width = 0

local myMath = require("source.modules.math")
local myTypes = require("source.modules.types")
local conductor = require("source.modules.conductor")
local json = require("source.modules.json")
local files = require("source.modules.files")
local socket = require("socket")

local newVector2 = myTypes.Vector2(10, 10)

local startTime = socket.gettime()

local songName = "high"
local songDifficulty = "erect"

local chartString = files.read_file(string.format("charts/%s/%s-%s.json", songName, songName, songDifficulty))

if not chartString then
    error("Chart couldn't be loaded!")
end

print(chartString)
local chart = json.parse(chartString).song

local inst = love.audio.newSource(string.format("songs/%s/Inst.ogg", chart.song), "stream")
local voices = love.audio.newSource(string.format("songs/%s/Voices.ogg", chart.song), "stream")

conductor:setBpm(chart.bpm)
conductor:mapBpmChanges(chart)

inst:play()
voices:play()

local step = 0
local beat = 0


function love.draw()
    local currentTime = socket.gettime()
    local elapsed = math.floor((currentTime - startTime) * 1000)

    local oldStep = step
    local oldBeat = beat

    step = conductor:getStepRounded(elapsed)
    beat = conductor:getBeatRounded(elapsed)

    if step ~= oldStep then
        print("Step", step)
    end

    if beat ~= oldBeat then
        print("Beat", beat)
    end
end