Hi All, I’m wondering is there any way to get MIDI piano/keyboard input into Grasshopper? I googled some discussions which are all years ago that most sources are either too expired or really technical.
Before getting into the technical rabbit hole, I’m wondering is there any simplified method to read MIDI keyboard input in Grasshopper these days?
What I succeed finally was getting the MIDI signal with Python using Mido library.
What stopping me from getting it to GH is:
in Hops I don’t know the method how to keep returning new signal after every hit. It just returns values after recompution of component, but I want to keep sending an information all the time
in RhinoCode (Rhino 8 WiP) currently it’s too early to do anything with it
With the Hops component method, could you use the Trigger component to get it to send requests at a given interval? Ideally fast enough so it feels “instantaneous” from when you hit a key to when you get the value in Grasshopper?
Yes, right now I am trying it, at first it didn’t worked out, because it doesn’t update the output values if the Hops component options to Catche are turned on (which is the default settings). So right now I know how to keep updating it, but currently fighting with Mido itself, as for some reason when I copy-paste Mido library code from normal script into the Hops part - I got an error message that suggests that my Midi port is being used in parallel by another process, which is not true. So trying to figure out this part right now
Timer is connected to the Hops component to keep updating it (in this case it was 10 ms)
It works only if MIDI cable is properly connected (check it in MIDI-OX first if you’re not sure)
It freezes the GH while running. Need to switch off Python script first to unfreeze it
To run it I have to first run Python script, then click the Timer to start, and then hit the drum
Inside the code you can see I filter only “note_on”, because in drums “note_off” doesn’t matter, but if you’re using keyboard, then you might find it useful.
If you want to start slow without Hops, then here is some code to just print the MIDI message with Python and Mido only:
import mido
in_port = mido.open_input()
while True:
for msg in in_port.iter_pending():
if (msg.type == "note_on"):
print(msg)
I’m REALLY keen to get this working, but I’m afraid I’m not too great with programming. Could you possibly explain this to me like I’m 3 year old? Here’s my ideal scenario:
I’m running Reaper with recorded Midi. I can send the Midi out of Reaper via a virtual midi cable (LoopBe1).
I’ve downloaded the Mido library and placed the whole unzipped folder in my ProgramFiles/Rhino7/System folder, but Python doesn’t see it. Could someone help a brother figure this out?
the sample code that was written here is a Python script. You can run it in cmd in a slightly different way, but it will be better if you’d install some sort of code editor / IDE for Python. Personally I’m using Pycharm, but there are also: Atom, Visual Studio Code, Spyder etc. Once it’s installed you can copy paste the shorter example posted and try to run it. But generally I’d recommend checking out some basics of Python, because without it it would be difficult to change script the way you’d like. Or if something won’t work, then without it would be hard to say which part has failed. Good news is Python on a basic level is quite easy to learn.