Тёмный
No video :(

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

Mo chreach!
Подписаться 1,3 тыс.
Просмотров 24 тыс.
50% 1

In this video, we're going to explore how MIDI works and write some simple programmes in Python to control a MIDI device. Please feel free to ask me questions in the comments or join our Discord server ( / discord . If you'd like to follow along, you can find links to some resources below.
David van Brinks MIDI guide: www.cs.cmu.edu/~music/cmsip/r...
Anaconda Python distribution: www.anaconda.com/products/dis...
If you'd like to support the channel:
- Become a Patron: / mochreach
- Tip me: ko-fi.com/mochreach
X/Twitter: / mochreachmusict

Опубликовано:

 

1 дек 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 94   
@carlnicholson5008
@carlnicholson5008 22 дня назад
Thanks for getting me started. I can now control my Novation Peak from a Raspberry Pi!!
@mochreach
@mochreach 22 дня назад
That's really cool! Glad the video was useful. 😊
@exceptioncodeinfinity4013
@exceptioncodeinfinity4013 Год назад
awesome info thanks, and you have a great delivery style that is easy to follow :)
@MrOpaDave
@MrOpaDave Год назад
That was very simple and clear and helped me a lot. Thank you!
@mochreach
@mochreach Год назад
You're welcome!
@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.
@goldcoastj
@goldcoastj Год назад
A great explanation. Thanks!
@lovelivinglife904
@lovelivinglife904 Год назад
Really appreciated the video. Good job
@mochreach
@mochreach Год назад
Thanks very much, glad you found it useful!
@afrigal2420
@afrigal2420 Месяц назад
love it!!
@Brick_Briceno
@Brick_Briceno Год назад
Cool video! ✨👌🏻
@summerjee17
@summerjee17 5 месяцев назад
Great tutorial!
@mochreach
@mochreach 5 месяцев назад
Thanks!
@artyschopy
@artyschopy 9 месяцев назад
Thanks, man. Great vid.
@mochreach
@mochreach 9 месяцев назад
Glad you liked it!
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-zpZDwqsgSpc.html
@jithendra.k.sfirst_yr_b.sc9574
@jithendra.k.sfirst_yr_b.sc9574 5 месяцев назад
This content is seriously useful....❤❤👌👌
@mochreach
@mochreach 5 месяцев назад
Glad to hear that, thanks!
@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.
@bobjuice123
@bobjuice123 7 месяцев назад
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 7 месяцев назад
I've only tried a Behringer one that I have, it's a pretty basic one, works fine.
@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.
@RafaelCosta-ly5jb
@RafaelCosta-ly5jb 10 месяцев назад
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 10 месяцев назад
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.
@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!
@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 😊
@sedgi404wizard
@sedgi404wizard 7 месяцев назад
boss mate thanks
@supernonkey
@supernonkey 8 месяцев назад
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 8 месяцев назад
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.
@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.
@MoacyrPradoNeto
@MoacyrPradoNeto 10 месяцев назад
Thank you for lesson! Do you know how to code for ble-midi?
@mochreach
@mochreach 10 месяцев назад
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.
@JVmaster101
@JVmaster101 8 месяцев назад
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 8 месяцев назад
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 8 месяцев назад
@@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!
@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.
@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!
@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())
@JahidulislamRuman
@JahidulislamRuman Месяц назад
I want to make a new musical sound piano roll. How do I start?
@mochreach
@mochreach Месяц назад
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).
@geetapuri4973
@geetapuri4973 2 месяца назад
what if i dont have a midi device connected to my Mac? Can i still program the same way?
@mochreach
@mochreach 2 месяца назад
Yes, you can use MIDI loopback to control a DAW, for example.
@octaviop.4870
@octaviop.4870 11 месяцев назад
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 11 месяцев назад
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 11 месяцев назад
@@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 11 месяцев назад
@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 10 месяцев назад
@@mochreach but wont they requiere a lot of resources to run?
@mochreach
@mochreach 10 месяцев назад
No, they're optimised to be as efficient as possible for real time applications, so they'll be ideal.
@TheCautionwetpaint
@TheCautionwetpaint 4 месяца назад
Can you write a program that compares the current midi input with a stored midi song from a database?
@mochreach
@mochreach 4 месяца назад
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 4 месяца назад
@@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 4 месяца назад
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 4 месяца назад
@@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 4 месяца назад
🤔 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.
@qwe-de7xd
@qwe-de7xd 10 месяцев назад
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 10 месяцев назад
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 9 месяцев назад
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.
@user-mc2el9nm6b
@user-mc2el9nm6b 4 месяца назад
can we create midi file to music script generator
@mochreach
@mochreach 4 месяца назад
Yes you can, check out the Mido library: mido.readthedocs.io/en/latest/
@user-mc2el9nm6b
@user-mc2el9nm6b 4 месяца назад
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 4 месяца назад
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?
@carlopernoti3141
@carlopernoti3141 6 месяцев назад
😠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 6 месяцев назад
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 Месяц назад
I want to make a new musical sound piano roll. How do I start?
@mochreach
@mochreach Месяц назад
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).
Далее
Building a MIDI Controller Using Arduino
15:41
Просмотров 629 тыс.
Китайка Шрек всех Сожрал😂😆
00:20
Армия США вошла в Зангезур
04:17
Просмотров 263 тыс.
The MIDI Protocol: MIDI Messages | Simon Hutchinson
11:02
Programming MIDI
47:28
Просмотров 98 тыс.
Can I Code a Calculator with a Piano?
5:31
Просмотров 2,9 тыс.
Stop, Intel’s Already Dead!
13:47
Просмотров 242 тыс.
AI-Powered MIDI Generation: Advanced Mode
14:30
Просмотров 137 тыс.
Why The Windows Phone Failed
24:08
Просмотров 279 тыс.
The Clever Way to Count Tanks - Numberphile
16:45
Просмотров 763 тыс.