This module is in alpha stage, but I suspect I’ll have VERY little time to update this after university begins next week.
WHAT IS IT?
This module redirects MIDI events to Garry’s mod and calls a simple MIDI hook.
That means that you could play music on a keyboard or digital piano such as this one:
No joke, this is actually the one I have. It’s from 1998 :D.
And Garry’s mod would know which notes you are playing.
HOW TO USE
As of this moment, the module has two functions and one hook. You gotta keep it simple.
– You MUST call this function before the MIDI hook will work. You need to connect to the actual MIDI device.
– The default value for the “port” parameter is 0. An error will be thrown if there are no MIDI devices connected to the PC. Hence the check.
if table.Count(midi.GetPorts()) > 0 then – use table.Count here, the first index is 0
hook.Add(“MIDI”, “print midi events”, function(time, code, par1, par2, …)
print("A midi event happened at "… time … “, which is " … SysTime() - time … " seconds ago!”)
– The code is a byte (number between 0 and 254).
print(“MIDI EVENT”, code, par1, par2, …)
print(“Event code:”, midi.GetCommandCode(code))
print(“Event channel:”, midi.GetCommandChannel(code))
print(“Event name:”, midi.GetCommandName(code))
-- The parameters of the code print("parameters", par1, par2, ...)
– Only listen for 10 minutes
if not midi.IsOpened() then return end – closing MIDI will error if it isn’t opened
midi.Close() – Call midi.Close when you want to stop receiving MIDI events. Closing is NOT obligatory.
These are standard MIDI codes. Read more about the MIDI protocol
Here’s a screenshot of me pressing and releasing (I believe) c’ with the above sample code.
HOW TO INSTALL/API DOCUMENTATION
All in the readme.
DOWNLOAD AND SOURCE
The design has cross platform in mind. However, the machine I’m currently on runs Windows right now. I might reboot in Linux later to compile it there.