Exploring Algorithmic Composition and MIDI Programming with Python

In summary, there are various resources available for someone looking to learn about MIDI and algorithmic composition using Python. These include the PythonInMusic wiki page, which lists different Python MIDI packages such as pygame.midi and pyMIDI. There are also MIDI classes and functions available in modules such as MIDI.py and PMIDI, which allow for the generation and manipulation of MIDI sequences in Python code. Additionally, there are books available on the topic, such as "MIDI Power!: The Comprehensive Guide" and "Algorithmic Composition: A Guide to Composing Music with Nyquist."
  • #1
Avatrin
245
6
Python is the only programming language I know, and I know there is a huge library of MIDI music out there.

I want to play around with machine learning and algorithmic composition to see what I can produce.

So, what books should I read to be able to do this? What I am looking for is:

Books to learn about MIDI, and how to use it the way I want to use it.

Books to learn about algorithmic composition.
 
  • Like
Likes Pepper Mint
Technology news on Phys.org
  • #2
Some python / audio packages:

https://wiki.python.org/moin/PythonInMusic

with a section on Python MIDI packages:

MIDI Mania
  • pygame.midi - is a portmidi wrapper orginally based on the pyportmidi wrapper. Also pygame.music can play midi files. Can get input from midi devices and can output to midi devices. For osx, linux and windows. New with pygame 1.9.0. python -m pygame.examples.midi --output
  • pyMIDI - Provides object oriented programmatic manipulation of MIDI streams. Using this framework, you can read MIDI files from disk, build new MIDI streams, process, or filter preexisting streams, and write your changes back to disk. If you install this package on a Linux platform with alsalib, you can take advantage of the ALSA kernel sequencer, which provides low latency scheduling and receiving of MIDI events. SWIG is required to compile the ALSA extension sequencer extension. Although OS-X and Windows provide similar sequencer facilities, the current version of the API does not yet support them. Some buggs are remaining in this package (for example when trying to delete a track), it has not been updated since 2006. This package is by Giles Hall. A sourceforge download.
  • midi.py - (DEAD LINK) - Python MIDI classes: meaningful data structures that represent MIDI events and other objects. You can read MIDI files to create such objects, or generate a collection of objects and use them to write a MIDI file.
  • MIDI.py - This module offers functions: concatenate_scores(), grep(), merge_scores(), mix_scores(), midi2opus(), midi2score(), opus2midi(), opus2score(), play_score(), score2midi(), score2opus(), score2stats(), score_type(), segment(), timeshift() and to_millisecs(). Uses Python3. There is a call-compatible Lua module.
  • PMIDI - The PMIDI library allows the generation of short MIDI sequences in Python code.The interface allows a programmer to specify songs, instruments, measures, and notes. Playback is handled by the Windows MIDI stream API so proper playback timing is handled by the OS rather than by client code. The library is especially useful for generating earcons.
... more are listed in the article...
 
  • Like
Likes Avatrin and Pepper Mint

1. How can I use Python to program MIDI?

Python has a powerful library called "python-midi" that allows you to create, edit, and play MIDI files. This library provides functions for creating and manipulating MIDI events, controlling the timing and tempo of the music, and even synthesizing sound. Additionally, there are many online resources and tutorials available to help you get started with programming MIDI in Python.

2. Can I use Python to control external MIDI devices?

Yes, you can use Python to send and receive MIDI messages to and from external devices such as synthesizers, drum machines, and MIDI controllers. This can be done by using libraries such as "rtmidi" or "mido" which provide an interface for communicating with MIDI devices. However, you would need to have a basic understanding of MIDI protocol and how to use these libraries in your code.

3. Are there any limitations to programming MIDI with Python?

While Python is a versatile programming language, there are some limitations when it comes to programming MIDI. For example, Python is not a real-time language, so it may not be suitable for creating live performances or real-time music applications. Additionally, some advanced MIDI features may not be available in the python-midi library, so you may need to use other libraries or tools to achieve those functionalities.

4. Can I use Python to convert MIDI files into other formats?

Yes, there are libraries such as "midi2audio" and "midiutil" that allow you to convert MIDI files into other audio formats like WAV or MP3. These libraries use sound fonts or synthesizers to generate audio from MIDI data. However, the quality of the converted audio may vary depending on the sound font or synthesizer used.

5. Is programming MIDI in Python suitable for beginners?

It depends on your level of programming knowledge and experience. Python is generally considered an easy language to learn, but programming MIDI requires some understanding of music theory and MIDI protocol. If you are new to both programming and music, it may be challenging to get started. However, with dedication and practice, anyone can learn to program MIDI with Python.

Similar threads

  • Programming and Computer Science
Replies
1
Views
730
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
7
Views
484
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
2
Views
760
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
Back
Top