This module is in alpha stage, but I suspect I'll have VERY little time to update this after university begins next week.
[B]WHAT IS IT?[/B]
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:
[img]http://www.muzoborudovanie.ru/equip/studio/homekeyb/pict/psr640.gif[/img]
No joke, this is actually the one I have. It's from 1998 :D.
And Garry's mod would [I]know[/I] which notes you are playing.
[B]HOW TO USE[/B]
As of this moment, the module has two functions and one hook. You gotta keep it simple.
[lua]
require("midi")
-- 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
print("opening midi")
midi.Open()
end
print(midi.Open())
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, ...)
end)
-- Only listen for 10 minutes
timer.Simple(600, function()
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.
end)
[/lua]
These are standard MIDI codes. [url=https://ccrma.stanford.edu/~craig/articles/linuxmidi/misc/essenmidi.html]Read more about the MIDI protocol[/url]
[b]MEDIA[/b]
Here's a screenshot of me pressing and releasing (I believe) c' with the above sample code.
[img]http://i.imgur.com/0Un4PzL.png[/img]
[media]http://www.youtube.com/watch?v=Yuihwxvq-0Q[/media]
[b]HOW TO INSTALL/API DOCUMENTATION[/b]
[url=https://github.com/FPtje/gmcl_midi/blob/master/README.md]All in the readme.[/url]
[b]DOWNLOAD AND SOURCE[/b]
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.
Download:
[url=https://github.com/FPtje/gmcl_midi/releases]Windows[/url]
Source:
[url]https://github.com/FPtje/gmcl_midi[/url]
FUCK! I just sold my keyboard a week ago!
Really good job ftpje
Well what would this be used for other then the piano from the workshop?
[QUOTE=Chibby;45851334]Well what would this be used for other then the piano from the workshop?[/QUOTE]
Playing Gmod with a musical keyboard instead of a computer keyboard
This is very cool Falco, I would be surprised if you can get it to work under Linux though (I could be wrong of course) because I've never seen midi work in Linux and I've been using it for 15 years.
[QUOTE=Chibby;45851334]Well what would this be used for other then the piano from the workshop?[/QUOTE]
Extra keybinds (bind toolmodes to keyboard keys!) music gamemodes, guitar hero shit. Recording and sharing music.
You could use the pitch bend as a one dimensional joystick.
Fuck you could create a gamemode where you teach people to play piano.
Now I just need a mini midi controller so I can make a guitar hero gamemode
I was just thinking and brain storming on how to do this the other day...
I fucking love you...
Guitar hero multi player on gmod here we come!
Time to buy a new keyboard.
You're literally my hero
[QUOTE=LennyPenny;45853186]Now I just need a mini midi controller so I can make a guitar hero gamemode[/QUOTE]
If you wanted to do this the best way would be to get an xbox 360 wireless controller adapter with an xbox 360 guitar hero controller and use the xbox KEY_ enums, I actually want to go buy a controller and do this now!
I compiled a Linux version and added it to the v0.0.3 release. I can't get my keyboard to work on Linux. Someone please try it:
[url]https://github.com/FPtje/gmcl_midi/releases/tag/v0.0.3[/url]
I have a library that's supposed to be cross platform. I'm not recoding the entire thing for another (hugely bloated) library.
Module updated to send time information with each key.
Playing music is a VERY time sensitive thing. 100ms off can sound terrible. That's why I added a time parameter to the MIDI hook. Regardless of your FPS, you will accurately know when a note was played.
The time is based on SysTime, which might make it somewhat harder to network, but it's simply the most accurate time measurement.
Can you share your 'gmcl_midi on MacDGUy's playable piano' script?
can you run midi files through this and pretend you're a keyboard wizard?
Important update with important fixes:
[url]https://github.com/FPtje/gmcl_midi/releases/tag/v0.1.1[/url]
Holy shit.
I am totally going to use this for multiplayer.
Is this also updated for linux?
I just uploaded the linux version. It's completely untested, I don't have the time to make it work.
Okay, so I got the script you posted to recognize my midi input, play the keys on the piano, and show the floating 8th notes, but there's no sound yet.
I pasted the script in the shared.lua file under the gmt_instrument_piano folder. Is there something else I should do?
You don't hear the notes you play yourself. I should make that a toggle option some day.
I turned it off because there's a huge delay between pressing keys and hearing the sound. I use my Keyboard's sound for direct feedback.
[QUOTE=FPtje;46986324]You don't hear the notes you play yourself. I should make that a toggle option some day.
I turned it off because there's a huge delay between pressing keys and hearing the sound. I use my Keyboard's sound for direct feedback.[/QUOTE]
Oh okay. Well, then awesome!
So, can I play with my midi keyboard on a multiplayer server now this way, or does it only work if the server has the script and .dll installed?
It works if the server allows you to run the script (allowcslua 1) and the server has the piano.
Any way of opening a .midi file to gmod piano? Either that or just emulating midi input..
Wow, I can't believe I've never seen this before. Does this have pedal support?
Sorry, you need to Log In to post a reply to this thread.