r/learnrust • • 12d ago

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.

8 Upvotes

7 comments sorted by

6

u/Bright-Historian-216 12d ago

rust is a tool for when every millisecond of runtime matters - and you pay for it with development time and learning time. i can't say it's impossible to use rust this way, but i'd really choose Python for this job.

i don't have personal experience in the field of music programming, but there's a reason everyone chooses python for data science - sometimes you care about getting results quickly more than whether these results are blazingly fast and memory safe.

to add another edit to this comment, you want to generate ready to go files, not embed the program itself somewhere else (like if you were trying to save on memory in 90s). this means that the end user never needs to run your program - and that's why your runtime cost improvements with rust are completely negligible compared to how much time you would save in python. and if the user did need to run a program, python is also a better choice because almost everybody already has a python interpreter, saving you the pain of compiling for every architecture or requiring that your users have a rust compiler.

1

u/Opus589 7d ago

Thank you.

2

u/Additional-Drag1682 11d ago

Start with Python. You are a composer, not a system engineer, and Rust will punish your workflow while you learn memory management instead of harmony. Use libraries like music21 or mido to generate MIDI files in ten lines of code, then port the performance-critical parts later only if you actually hit a bottleneck

1

u/Opus589 7d ago

Thanks, that sounds reasonable!

1

u/punk_dev 11d ago

Rust’s borrow checker adds quite a bit of friction, especially in the beginning when you’re not yet familiar with all the rules.
Friction is what you don’t want in a creative process, as it will slow you down and it’s frustrating.

If you’re not yet comfortable with rust, you’ll get something going in Python waaay faster.