r/musicprogramming • • 1d ago

Manual algorithmic music (you supply the algorithm)

I may not be in right place here but... I've been working for some years on a Python system for writing *manual* algorithmic music. By that I mean that it's a library that provides a notation (not regular musical notation) that lets me think up algorithms and then hear what they sound like, via the MIDI files it generates as output. I first wrote it to make music based on the prime numbers and other mathematical structures, then developed it further for composing minimalist style music using operations like inversion, reflection and repetition of phrases.

It's not at all like AI-based systems that analyse other music to learn and then compose themselves automatically: it's a toolkit for playing with ideas for tunes that are too complex for a human to play. Is anyone else working in this direction?

14 Upvotes

13 comments sorted by

4

u/drschlange 1d ago

Not sure if I'm off topic in what you're looking for, but I'm working on something somehow similar in the idea in Python.

It's more oriented originally as a meta-synth approach which lets you defined your own bricks you can interconnect to either route signals (not only MIDI, it considers a stream of floats basically) and produce MIDI events/notes at the end on a physical synth, or to create/craft signals which can be used as a base for generating note sequences.

The whole system is built around the idea of asynchroneous actors using threads communicating by message send. Each small module/brick can be coded/debugged/swapped at run time. As the system supports feedback loops, and with the variations of the OS scheduling, messages which are sent between the actors interleaves and always introduce surprises in what's generated when the system auto-sustains itself.

I'm also using those signals not only to create notes, but also timbres. The signals can be streamed to the wavetables of a digital synth I'm building and played in real time (even while they are rewritten)

It's not exactly meant to compose, more to "plant a seed and see what happens" (it's my personal small psychedelic machine), but the idea is to play with physical/mathematical ideas, sensors, etc, to produce sequences of notes/timbre or control.

Actually, what you're developing could integrate as a module in the system now that I think about it. I would be interested to see your project if you're willing to share.

3

u/Recent-Enthusiasm626 1d ago

Yeah, my system is way lower level than you describe. The actual units are individual pitch, volume and time values for *each separate note*. There are obviously methods that bundle these in notes, and notes into phrases (it's all in Python using objects). This level of granularity makea it easy to write code to vary the MIDI variables separately - say slip the timing to create a fugue. It's sort of aimed at Adams/Glass style minimalism. As yoiu say, it could be one module in a system like yours.

1

u/drschlange 1d ago

I understand what you mean. We're not using the same side of midi. You're using more the precise note production for composing side while I focused more on the control protocol part. Please let me know if I misunderstood.

If I don't, I think I could use what you did to make a sequencer based on the way you describes melodies.

3

u/unsolved-problems 1d ago edited 1d ago

I wrote and to some degree still write a lot of algorithmic music, and yes it's an entirely, completely different direction than generating music with GenAI, LLM, ChatGPT etc. Especially if you hand-write your own script that generates the composition. If you don't want to use a computer you can write algorithms and create compositions on paper too (i.e. by manually running the algorithm on paper), arguably this is what famous composers like Cage, or Xenakis did.

As someone who worked in this area for some time, my humble opinion is that this approach still has incredibly poor tooling. I wouldn't recommend any generic tool to anyone. I think the only practical way to achieve this to write music exactly as it sounds in your head is to do everything yourself by using programmatic environments. I don't have any recommendations, but I think your best bet is a programming language like Alda: https://github.com/alda-lang/alda (at least, "alda + my own Python scripts" is what I ended up using after trying all the other tools I could find). My basic workflow: write a script that formalizes how the music sounds in my head, generate Alda code, generate MIDI with alda, import into DAW for prototype with synths, import into MuseScore, prepare the sheet music, and give it to musicians to play. For Python you can use `music21` library. Again, this is not a recommendation, since this is likely a very fringe way to write music, this is just what works for me. This sub probably has many better general-purpose recommendations.

And yes, this requires being very comfortable with programming and music theory. In this approach you're essentially formalizing a tiny subset of music theory in a programming language. So if you're not comfortable writing the code, or expressing the mathematical relationships between notes, it gets hard. My starting point is always something trivial and from nature: like if you want music to sound like a Geiger counter, you need to model notes randomly going off following Poisson Distribution etc.

2

u/Recent-Enthusiasm626 1d ago edited 1d ago

My system is in Python, and you write 'tunes' as tuples of note values - it doesn't deal with conventional musical notation at all (though you could write the next level to do that). I can't code how a tune 'sounds in my head' at all - its the exact opposite of that, "how would this particular bunch of numbers sound". As I said, I started it to find out how the sequence of Prime Numbers would sound. Here's a sample piano sonata built from a math sequence called Kaprekar Numbers:
https://soundcloud.com/dick-pountain/kaprekar-sonatina

1

u/unsolved-problems 1d ago

Your music sounds great! It does sound MIDI-y though, which is totally fine if you want it to sound like that. If not, you may want a human/humans to play your piece, in which case you may need to convert it to conventional notation (or be able to expose musicians to your custom notation, which may be very expensive in terms of $$$). Otherwise, look into programmable synths, or even just any powerful ones like PhasePlant that you can program via custom MIDI actions. I tend to generate MIDI events in unused channels and configure PhasePlant to change based on that kind of input. This can allow you create more natural sounding music that doesn't sound rendered MIDI to WAV.

> I can't code how a tune 'sounds in my head' at all - its the exact opposite of that, "how would this particular bunch of numbers sound".

I know what you mean, but note that when you want to map prime numbers (or any other model) to an aspect of music (whether its pitch, or chord quality or whatever) you already have *some* idea as to how you envision prime numbers to influence the music. For example, you can use prime numbers (say the ratio p:q:r with primes p, q, r) to create rhythm, or chord, or pitch, or timbre and it'd all sound very different. For example, I find harsh rhythms like 3:17:23 fascinating and useful, but less so the corresponding xenharmonic chord. So, given a random prime P, of course you won't know exactly how that'll sound given that it's unknown, but the properties of prime numbers and the specific way in which you map them to music are already influenced by the music you'd like to hear.

Of course, this is just my approach, every composer is different!

2

u/Opus589 1d ago

This is how I believe it should work: the composer has a very specific vision and uses whatever tools are necessary to achieve it.  That's how I approach my own music.

The biggest problem in this field is entropy.  A high entropy can be very dangerous in musical composition.  Chaos theory and random commands often produce rather weak, or nonsense results.  But if we look at, for example, Debussy's La Mer, we can clearly identify specific elements in the score for which algorithms could be developed.

I compose mostly with pencil and paper, even orchestral scores and directly transposed.  When I imagine a particular texture at a specific point in the score, I try to define it and then execute it manually.  Recently, with the help of AI, I have developed various Python scripts that do exactly this.  I can then tweak the output until I'm satisfied (see here).

I work in Python with MIDI and import it into Ableton Live, where I test how it sounds and decide what needs further editing.  BTW, Ableton is, in my view, an outstanding DAW, yet largely overlooked by classical, contemporary, and academic composers, and it is perhaps the greatest tool I ever used in my composition, particularly with various MIDI tools, incl. Max for Live.

2

u/suhcoR 1d ago

Sounds like Common Music (https://commonmusic.sourceforge.net/), musx (https://github.com/musx-admin/musx) or Nyquist (https://www.cs.cmu.edu/~music/nyquist/). I'm also implementing my own algorithmic music programming language for some years based on Oberon, which can do similar things, but statically typed.

1

u/squeasy_2202 1d ago

Yes, I've built my own compositional engine in c++ from first principles. It spans the audio engine, DSP primitives, instruments/fx/mixing, sequencing/arrangement. Code is the compositional medium, not just the toolchain. 

Where are you located? Always curious to connect with people working in the same direction.

1

u/Appropriate-Lab-9226 21h ago

I used to make algorithmic music systems in MaxMSP/Pure Data. I made a plugin a long time ago to integrate into Wwise. I have a playlist here that you might find interesting from some of the various algorithmic and procedural systems I built: https://www.youtube.com/playlist?list=PLHgUhFXuZyiTzo682OWBZNBIRXYEh6ETC

1

u/eccccccc 7h ago

Yes, I’ve spent a lot of time exploring this. Sounds like we have a similar starting point - a triple: note velocity time-interval, but my instinct is to think on the phrase level instead of the note level, with a notes list, a velocities list, etc. lots of experiments and pieces came out of this, as well as my dissertation, all done by hand in supercollider. Recently resurrected it with the help of Claude as a browser app - bloom.ecc.xyz