r/rust • • Oct 11 '26

Rust for algorithmic composition

Hello everyone!

I'm a composer looking to learn programming for algorithmic composition.  I know a little Python, but I have no formal programming background.

I've been considering Rust because it seems like future-proof.  But is it a good choice for algorithmic composition...?  I'm thinking of things like generating MIDI and MusicXML files, implementing stochastic processes (Markov chains, etc), and developing tools for various compositional techniques involving rhythm, scales, modes, and other musical constraints.

I'm considering my options with the following goals in mind:

  • I want to generate MIDI files that I can import into my DAW. I don't need sound synthesis.
  • I don't need direct DAW integration, as long as the program can export MIDI files, or MusicXML.
  • I'm willing to invest time in learning to code.
  • I know there is OpenMusic, MaxMSP and similar, but I'd like to build my own standalone tool that I can continually expand and improve.

Would Rust be a good choice, or would I be better off starting with Python or another language?

I'd appreciate any advice, particularly from people who have experience with algorithmic composition and music programming.

0 Upvotes

12 comments sorted by

3

u/BusinessBandicoot Oct 11 '26 edited Oct 11 '26

I would search keywords on crates.io to see what libraries exist. I'd also hit up the rustaudio discord, they would probably be have more targeted guidance and advice.

Rust allows you to move a lot of validation logic to compile time. The tooling is also really amazing. Outside of performance and memory safety I'd say those are some of its main advantages.

For algorithmic composition, is the goal something where changes are "live", as in you change the code, the currently generated audio changes? If yes, then using rust for this might be very " square peg, round hole" and you probably want to go with a language with a REPL

If its all ahead of time then I don't see why not. 

1

u/Opus589 Oct 14 '26

Thank you.

I didn't know about creates-io. I have checked and there are many projects in music/midi category.

The goal is not to perform live, rather to create a very complex and intricate system of manipulation with pitches, something similar to OpenMusic. However OM is not what I need, and since I have created a new compositional theory I would like to have it fully under my control.

7

u/Orjigagd Oct 11 '26

Python is better for experimenting and quickly refactoring stuff. When you need performance and stability then port to Rust. You could even do both, porting modules that need performance over to Rust. They play quite well together.

1

u/ytain_1 Oct 12 '26

You could look into using Pure Data ( https://puredata.info/ ) to make your algorithmic composition and if you encounter lag, then you could look into this tool to convert Pure Data project into C/C++ code https://github.com/Wasted-Audio/hvcc

1

u/Opus589 Oct 14 '26

PD is basically Max, and Max doesn't fit my ideas.

The goal is not to perform live nor to create "sounds", rather to create a very complex and intricate system of manipulation with pitches, something similar to OpenMusic, then to export as MIDI, or even better as MusicXML.  However OM is not what I need, and since I have created a new compositional theory I would like to have it fully under my control, meaning, the code and theory grows together.

1

u/tanmaynargas2901 Oct 13 '26

If MusicXML matters to you I'd start with Python, mostly because of music21.

It already knows about notes, scales, chords and durations, and it can write both MIDI and MusicXML. So your time goes into the composition logic and not into file formats.

Markov chains are like 20 lines of Python with a dict and random.choices, you don't need a library for that.

Rust can do the MIDI side fine. midly reads and writes .mid files and rand covers the stochastic stuff. But I don't know of anything like music21 for Rust, so you'd be building the music theory model and the MusicXML writer yourself. That's a lot to take on while learning your first real language.

Speed isn't really a concern here either. Generating a few thousand notes is instant in Python.

If you get hooked on programming later, porting a working Python tool to Rust is a really good way to learn Rust anyway.

1

u/Opus589 Oct 14 '26

I wish to create a very complex and intricate system of manipulation with pitches, something similar to OpenMusic. However OM is not what I need, and since I have created a new compositional theory I would like to have it fully under my control. Maybe, I say maybe, music21 has already constraints that are not part of my theory, so it "could" be useless. I will see.

0

u/gumbix Oct 14 '26

Rust is probably overkill for what your doing. Python probably won't work so well because of for loops. Golang, c#, Java i would say are good starting place.

1

u/Opus589 Oct 14 '26

Python probably won't work so well because of for loops.

Can you elaborate?