Programming with MIDI in Python | Getting started and sending MIDI Messages

  Рет қаралды 26,585

Mo chreach!

Mo chreach!

Күн бұрын

Пікірлер: 100
@carlnicholson5008
@carlnicholson5008 4 ай бұрын
Thanks for getting me started. I can now control my Novation Peak from a Raspberry Pi!!
@mochreach
@mochreach 4 ай бұрын
That's really cool! Glad the video was useful. 😊
@graham287
@graham287 Жыл бұрын
Don't know who these people are that find this simple and clear. Up to 12 minutes in, the info was nice and easy and answered a load of questions I had about midi messages, After that you lost me, I kept askin Why? What's one of those and what does it do? But having said that, you have taken me to the next level. Now I need to know how to trigger messages using input devices
@mochreach
@mochreach Жыл бұрын
😅 Sorry about that, feel free to ask me if you have specific questions . I made a follow up video about listening for MIDI messages from an external device, that might answer some of your questions: kzbin.info/www/bejne/sKG9daqnqMyGpsU
@MrOpaDave
@MrOpaDave Жыл бұрын
That was very simple and clear and helped me a lot. Thank you!
@mochreach
@mochreach Жыл бұрын
You're welcome!
@kekkonenprkl
@kekkonenprkl 13 күн бұрын
Thanks. I'll make myself a little GUI to edit Boss 200-series guitar pedal presets through midi, since Boss never released any official software editors for those.
@mochreach
@mochreach 13 күн бұрын
That's awesome, please share a link when you have made it!
@jamesarthurkimbell
@jamesarthurkimbell Жыл бұрын
This is really cool, man. I'm glad it came up in my recommendations
@mochreach
@mochreach Жыл бұрын
Brilliant, I'm glad you found it useful! Let me know if you have any questions about it.
@lovelivinglife904
@lovelivinglife904 Жыл бұрын
Really appreciated the video. Good job
@mochreach
@mochreach Жыл бұрын
Thanks very much, glad you found it useful!
@jithendra.k.sfirst_yr_b.sc9574
@jithendra.k.sfirst_yr_b.sc9574 9 ай бұрын
This content is seriously useful....❤❤👌👌
@mochreach
@mochreach 9 ай бұрын
Glad to hear that, thanks!
@exceptioncodeinfinity4013
@exceptioncodeinfinity4013 Жыл бұрын
awesome info thanks, and you have a great delivery style that is easy to follow :)
@bobjuice123
@bobjuice123 11 ай бұрын
Great stuff, very helpful. Can you please let me know which USB-midi interfaces work best with python? Roland um one ? Python doesn't see my motu m4 , I'm told that's because it thinks it's an audio interface. Thanks
@mochreach
@mochreach 11 ай бұрын
I've only tried a Behringer one that I have, it's a pretty basic one, works fine.
@goldcoastj
@goldcoastj Жыл бұрын
A great explanation. Thanks!
@artyschopy
@artyschopy Жыл бұрын
Thanks, man. Great vid.
@mochreach
@mochreach Жыл бұрын
Glad you liked it!
@SHLDMusic
@SHLDMusic Жыл бұрын
Thanks for your video! Which Python Midi lib is the best? (easy, well-maintained, etc)
@mochreach
@mochreach Жыл бұрын
You're welcome! If you don't need low level control, then I'd go for Mido. It's much easier to use for most routine tasks.
@SHLDMusic
@SHLDMusic Жыл бұрын
@@mochreach Thanks! Now I have to find a way to edit and run Python scripts from a web browser, and I will have a nice custom MIDI router 😊
@summerjee17
@summerjee17 8 ай бұрын
Great tutorial!
@mochreach
@mochreach 8 ай бұрын
Thanks!
@supernonkey
@supernonkey 11 ай бұрын
Bit of a newbie here, who managed to stumble upon this video. Is it possible to use python running on a raspberry pi 4, in order to route midi messages from a midi-over-usb device to a groove box? I have an akai mpd218 and would like to try to write a script which would allow me to use the velocity sensitive pads, to control a Roland MC101. I think in this instance the Raspberry Pi would be a kind of a host/hub, or an interface -- I am not clued into the lingo unfortunately :/
@mochreach
@mochreach 11 ай бұрын
Yes, that's definitely possible, you can get rtmidi running on Arm. Lots of Raspberry Pi Linux distributions already have python installed, so you should be able to get up and running quite quickly.
@afrigal2420
@afrigal2420 5 ай бұрын
love it!!
@KandMe1
@KandMe1 Жыл бұрын
My question is about a script with some sort of global variable that establishes the channels used by the midi devices used for any one project or song. I don't know much about midi but how to set it up is on my mind.
@mochreach
@mochreach Жыл бұрын
That sounds totally feasible. Have you tried it yet? You could have a python class that manages the connections.
@KandMe1
@KandMe1 Жыл бұрын
@@mochreach I am very keen to try it. Just pulled an old pi zero out and found it gets power from a powered usb hub which I have daisy chained 2 of them together because I get 7 connections that way and this zero has 2 mini usb inputs on it, so things are looking good so far just got to digging this stuff out of my shelves. Had problems finding an app to do it properly on my ipad so very keen to get something working right now. Ok I will start by looking into a python class to start with. Had only a very little experience with code but I did write a factory class at one time in PHP that worked very well just took a few weeks to work out how to do it from the onlne manual.
@MoacyrPradoNeto
@MoacyrPradoNeto Жыл бұрын
Thank you for lesson! Do you know how to code for ble-midi?
@mochreach
@mochreach Жыл бұрын
The midi part would be the same, and after the bluetooth connection is made to the computer, it might just appear like any other midi device, although I've never tested it. I do have a couple of ble devices, so I might give it a go.
@RobbyKilgore
@RobbyKilgore Жыл бұрын
Great vid. Very helpful and clear. Im working on a new version of my midi rotator as a pi zero hardware version. I’m having trouble changing the midi in or out ports from within my software at runtime. What’s the proper way to reassign an in or out? Do I have to del the port and reassign from scratch? Or is there a simpler way?
@mochreach
@mochreach Жыл бұрын
Sounds like a cool project! Yes, as far as I'm aware, the best way is to `del` the port or use the `with` context manager and it'll happen automatically. Edit: also, out of curiosity, what does your midi rotator do?
@xavierchenot2836
@xavierchenot2836 Жыл бұрын
HI, thank you for your great video ! I have a Lk S450 piano, do you know how can I turn on the light with a midi command ?
@mochreach
@mochreach Жыл бұрын
You're welcome! I took a look at the manual and looks like it's possible. If you go into the settings, there's an option called "MIDI In Navigate" that controls this. If you turn it on, you should be able to send MIDI notes to channel 3 and 4 to control the lighting. I don't have that keyboard to test this, but if definitely looks like you can.
@RafaelCosta-ly5jb
@RafaelCosta-ly5jb Жыл бұрын
Hi, awesome video! Do you know any way to play the notes without the MIDI controller? I need to convert frequencies and durations into playable notes on piano or a violin, for example. But all i can do now is work with that 16 bit weird sound rsrsr Thank you
@mochreach
@mochreach Жыл бұрын
Hi @RafaelCosta-ly5jb you'll need some device that accepts MIDI, which could be a hardwae synth, or software like a DAW or VST plugin. There are lots of free VSTs out there with sample based piano and violins.
@Rocketos
@Rocketos Жыл бұрын
I dont have an opz can I use a Akai mpk249?
@mochreach
@mochreach Жыл бұрын
This works with any midi capable device, although the messages if can receive will be different, so you'll need to check the manual. Feel free to message if you need help.
@Rocketos
@Rocketos Жыл бұрын
@@mochreach But i dont get it ): I am supposed to send this messages to Midi In of my controller, how this midi In messages will be sent through the midi out in order (for example) FL studio will recieve them and make a vst sound?
@mochreach
@mochreach Жыл бұрын
You should be able to send to MIDI in of any device connected to your computer, then mpc or maybe even FL Studio directly. If you run this, what's the output? : import rtmidi midiout = rtmidi.MidiOut() print(midiout.get_ports())
@stephen285
@stephen285 Жыл бұрын
can you clarify the with? how often should we open and close the port in our app, if we have a 1 -4 chord progression do we create a function for each chord that includes open and close for the port? or how best to proceed?
@mochreach
@mochreach Жыл бұрын
Hi @Stephen, you an keep the port open the whole time you're using it, no need to close and open it for each chord. For the actual application, it's open it once at the beginning and use it until you're done.
@stephen285
@stephen285 Жыл бұрын
Thanks for your video! any chance you could do a basic rtmidi in howto video? absolutely nothing fancy just a basic python script that sits and listens for input from a keyboard and prints the data to the console?
@mochreach
@mochreach Жыл бұрын
Hi @Stephen, yes I definitely could. I'll see if I have time later this week.
@stephen285
@stephen285 Жыл бұрын
@@mochreach very much appreciated! Thanks Mo
@mochreach
@mochreach Жыл бұрын
Hi Stephen, I've just release a video on this topic, thanks for the suggestion. Let me know if you have any questions.
@RemySedlak
@RemySedlak Ай бұрын
i wanna try to use python to script midi and make visual art with it,
@mochreach
@mochreach Ай бұрын
That sounds awesome!
@Brick_Briceno
@Brick_Briceno Жыл бұрын
Cool video! ✨👌🏻
@JVmaster101
@JVmaster101 Жыл бұрын
I'm having a bit of trouble getting this to work on virtual devices, rtmidi shows no available ports. Not sure if I'm misunderstanding this, but with something like FluidSynth installed, shouldn't I be able to send messages to FluidSynth and have it play through my computer audio? Is there a different process to set this up? Thanks!
@mochreach
@mochreach Жыл бұрын
You might need a bit of software to make "virtual MIDI" ports on your system. There are lots of options for software that does this, but the exact one will depend on your operating system. Let me know if that helps.
@JVmaster101
@JVmaster101 Жыл бұрын
@@mochreach thanks for your response. I eventually got FluidSynth to pop up as an available port, unfortunately I don't remember what I did exactly, but the problem was with FS and its connection to my project rather than with rtmidi. Works great now, your video was very helpful to get my project up and running, thanks!
@qwe-de7xd
@qwe-de7xd Жыл бұрын
Hi, I keep getting "No module named 'rtmidi'" when trying to import rtmidi in ipython. I already have rtmidi installed but still get this message, thank you 😁
@qwe-de7xd
@qwe-de7xd Жыл бұрын
I have python 3.10.6 because other things I'm doing don't work with later versions, Will I have to update python?
@mochreach
@mochreach Жыл бұрын
No that should be fine. I think the most likely explanation is that pip is installing it to another Python install. If you're on Linux or Mac, you could run `which python` and `which pip` just to make sure they're related to the same Python install. Either that or there was an error on install, in which case, there should be an error message in the log.
@impalagasper
@impalagasper Жыл бұрын
Hi, thanks for the video! Is there a way to put a function containing "with" statement inside a while loop? I can't seem to get it working (it stays in the loop and waits, but executes the function only once). If you find the time to answer, thanks!
@mochreach
@mochreach Жыл бұрын
Thanks for watching! It should work, could you post your code please? If you have a GitHub account, you could make a Gist (gist.github.com) and share a link.
@impalagasper
@impalagasper Жыл бұрын
​@@mochreach YT is blocking my link, so I sent you the link directly to your email. Hope you can help me and thanks a lot!
@rolfjohansen5376
@rolfjohansen5376 Жыл бұрын
thanks for the vid: I am sitting and playing with sending CC messages, NOTE_OFF and SOUND_OFF , I have the impression you can "reset" midi-controllers that have gone into bad mode, do you know anything about this ?
@mochreach
@mochreach Жыл бұрын
There is a system reset message, you can add it using a Command controller. What it does depends on the midi device you're connecting to, so check your manual before using it!
@rolfjohansen5376
@rolfjohansen5376 Жыл бұрын
@@mochreach of course, there is a sort of reset message in the beginning of a midi-file (GM, GS reset in Sysex) , but the player has to be in their respective mode to intercept these ...
@mochreach
@mochreach Жыл бұрын
Ah okay. What device are you connecting it to? Edit: sorry I just noticed this was on a different video than I thought, that's why I was talking about commands!
@JahidulislamRuman
@JahidulislamRuman 5 ай бұрын
I want to make a new musical sound piano roll. How do I start?
@mochreach
@mochreach 4 ай бұрын
Hi @JahidulislamRuman, sorry I didn't see this message when it came in. If you want to write it in Python, I would suggest the PyQT library for making the GUI and Mido for handling midi connections. If you're not determined to use Python, you might want to consider using the Godot game engine, it is open source and a pleasure to use, and comes with some MIDI integration (although not MIDI out, but this is easy to implement using an external library).
@octaviop.4870
@octaviop.4870 Жыл бұрын
Hello. this seems very interesting. May i ask you a few questiosn? Would python be a good choice to develope a precisely timed multi track midi sequencer? I currently have a working prototype that runs on ruby (sonic pi) but the timing is inconsistent. Would python be more precise?
@mochreach
@mochreach Жыл бұрын
Hi @octaviop.4870, Python might be a bit better than Ruby, and you could probably make it work, but neither are ideal I'm afraid. You'd be much better off using a fast compiled language like C, C++, Zig or Rust. You'll have much more performance headroom to make sure the timing is tight.
@octaviop.4870
@octaviop.4870 Жыл бұрын
@@mochreachyes...im aware of compiled languages but im not really a programmer. I dont want to spend years to learn c or rust. But thank you :)
@mochreach
@mochreach Жыл бұрын
@octaviop.4870 Well, an alternative might be a game engine like unity or my personal favourite, Godot. Godot's scripting language has a python like syntax and even has built in midi support. Game engines are made for this type of real time application.
@octaviop.4870
@octaviop.4870 Жыл бұрын
@@mochreach but wont they requiere a lot of resources to run?
@mochreach
@mochreach Жыл бұрын
No, they're optimised to be as efficient as possible for real time applications, so they'll be ideal.
@TheCautionwetpaint
@TheCautionwetpaint 8 ай бұрын
Can you write a program that compares the current midi input with a stored midi song from a database?
@mochreach
@mochreach 8 ай бұрын
Yes, that's definitely possible. Using the "mido" library would be the best way to do that, it has lots of functionality for working with midi files.
@TheCautionwetpaint
@TheCautionwetpaint 8 ай бұрын
@@mochreach thanks... Follow up question though, is it possible to write a program that distinguishes song sections from the drum beat and playing sequence... Like if I want to automatically display lyrics on the screen for each song section when the section is actually being played in the input... I understand that the current pattern being played should compare from a stored song pattern and sequence... Or maybe is there a program or device that does that already?
@mochreach
@mochreach 8 ай бұрын
I think the easiest way would be to have a record of the best number the lyrics should be displayed on, maybe a file with the best number and the lyric line to display, then read that in and count the beats while playing. Would that work?
@TheCautionwetpaint
@TheCautionwetpaint 8 ай бұрын
@@mochreach I thought that if it was a live performance chances are the beats may not align... That is why I thought there should be some pattern recognition as well...
@mochreach
@mochreach 8 ай бұрын
🤔 If you just keep track of the current beat of the stored song, that's the only thing that should matter, right? There's a Discord server associated with the channel, you're welcome to chat about this there, might be easier to keep track of things. Link at the top of the channel page.
@geetapuri4973
@geetapuri4973 5 ай бұрын
what if i dont have a midi device connected to my Mac? Can i still program the same way?
@mochreach
@mochreach 5 ай бұрын
Yes, you can use MIDI loopback to control a DAW, for example.
@sedgi404wizard
@sedgi404wizard 11 ай бұрын
boss mate thanks
@Ahmed-b1n1d
@Ahmed-b1n1d 7 ай бұрын
can we create midi file to music script generator
@mochreach
@mochreach 7 ай бұрын
Yes you can, check out the Mido library: mido.readthedocs.io/en/latest/
@Ahmed-b1n1d
@Ahmed-b1n1d 7 ай бұрын
No i have midi file and i wanted to generate music script i have tried this mido but results are not satisfactory by using mido i somehow able to generate xml or html on this I have only Alphabetical representation but i wanted music script how can i do that
@mochreach
@mochreach 7 ай бұрын
No idea I'm afraid!
@leolmx
@leolmx Жыл бұрын
Hey man, why am I getting this error? "AttributeError: module 'rtmidi' has no attribute 'MidiOut'"
@mochreach
@mochreach Жыл бұрын
@Leo Rickli that's very weird, not sure why that's happening. When you installed with pip, were there any errors?
@leolmx
@leolmx Жыл бұрын
​@@mochreach Yeah, very weird. What package do you use, "rtmidi" or "python-rtmidi"? Because I can't even install "python-rtmidi", it says that it encountered an error while installing the package. "rtmidi" was fine though.
@mochreach
@mochreach Жыл бұрын
I install with `pip install python-rtmidi`, that must be the problem. What was the error when you tried to install?
@gorloxian
@gorloxian Ай бұрын
Toys.
@mochreach
@mochreach Ай бұрын
"Where does he get those wonderful toys?"
@carlopernoti3141
@carlopernoti3141 9 ай бұрын
😠It is not working with Windows output port... your video should be named "Programming with MIDI in Python with OP-Z ONLY!!" I lost 15 mn of my time... NEXT video...😤
@mochreach
@mochreach 9 ай бұрын
It's not OP-Z only, you can send MIDI to any device, including virtual MIDI. Maybe there's something unusual with your setup. Best of luck finding a solution.
@JahidulislamRuman
@JahidulislamRuman 5 ай бұрын
I want to make a new musical sound piano roll. How do I start?
@mochreach
@mochreach 5 ай бұрын
Well, if you know Python, I'd recommend looking into a library called Mido for handling midi events and a GUI library (I'd recommend PyQT).
Programming with MIDI in Python | Responding to MIDI Messages
9:32
The MIDI Protocol: MIDI Messages | Simon Hutchinson
11:02
Simon Hutchinson
Рет қаралды 28 М.
Car Bubble vs Lamborghini
00:33
Stokes Twins
Рет қаралды 46 МЛН
Building a MIDI Controller Using Arduino
15:41
Switch & Lever
Рет қаралды 642 М.
Programming MIDI
47:28
javidx9
Рет қаралды 100 М.
How to generate Euclidean Rhythms with Python and Music21
8:31
Code Meowstro
Рет қаралды 365
Anna Wszeborowska - Processing music on the fly with Python
24:27
Epic Python Videos
Рет қаралды 68 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,6 МЛН
EP-133 KO II Tips and Tricks
20:36
Mo chreach!
Рет қаралды 34 М.
How to make a Simple Sound Synthesizer in Python
10:46
FinFET
Рет қаралды 21 М.
Genetic Algorithm in Python generates Music (code included)
11:50