-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
70 lines (62 loc) · 1.75 KB
/
main.lua
File metadata and controls
70 lines (62 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--[[
Entrypoint
]]
local MIDI = require 'MIDI'
function Initialise()
local File = io.open("test.txt", "w+")
local Score = ReadMidi("test.mid")
for k, Table in ipairs(Score) do
if k ~= 1 and k ~= 2 then
print(TableToString(Table))
end
end
end
function ReadMidi(FileName)
local File = io.open(FileName)
local MidiString = File:read("*all")
File:close()
return MIDI.opus2score(MIDI.to_millisecs(MIDI.midi2opus(MidiString)))
end
function WriteMidi(Score, FileName)
local File = io.open(FileName, "w+")
File:write(MIDI.score2midi(Score))
File:close()
end
-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function TableToString(tbl, indent)
local Lines = {}
if not indent then
table.insert(Lines, "{")
indent = 1
end
for k, v in pairs(tbl) do
if type(k) == "string" then
formatting = string.rep(" ", indent) .. "[\"" .. k .. "\"]" .. " = "
else
formatting = string.rep(" ", indent) .. k .. " = "
end
if type(v) == "table" then
table.insert(Lines, formatting .. "{")
table.insert(Lines, TableToString(v, indent+1))
table.insert(Lines, string.rep(" ", indent) .. "}" .. ",")
elseif type(v) == 'boolean' then
if v then
table.insert(Lines, formatting .. "true" .. ",")
else
table.insert(Lines, formatting .. "false" .. ",")
end
elseif type(v) == 'string' then
table.insert(Lines, formatting .. [["]] .. v .. [[",]])
elseif type(v) == 'number' then
table.insert(Lines, formatting .. v .. ",")
else
table.insert(Lines, formatting .. tostring(v) .. ",")
end
end
if indent == 1 then
table.insert(Lines, "}")
end
return table.concat(Lines, "\r\n")
end
Initialise()