Jump to content

generative MIDI for fun and profit


 Share

Recommended Posts

During the past year I have found it really useful to have a bunch of tricks to generate a melody out of some random numbers generated by my friendly computer. It's nice for kickstarting inspiration and also for just discovering new melodies and rhythms that you otherwise would not have figured out.

Here's a plugin I made this week out of Live built in MIDI stuff.

https://www.dropbox.com/s/a7329u4qhugs7et/Mondo Generator.adg?dl=0

 

And here's the track I made with it:

 

Screenshot_2021-01-06_at_21.27.57.png

  • Like 3
  • Burger 1
Link to comment
Share on other sites

Thanks, I hope I find time to check out SuperCollider as well. The only problem is that looks like the same code I stare at all day and this instantly makes it feel like work.

 

By the way, I wanted to clarify that so far I have got no profit out of the generative things, only loads of fun!

  • Haha 1
Link to comment
Share on other sites

I'm slowly working on some stuff too. Just web things for now, but eventually I'd like to have a small "suite" of generative MIDI VSTs.. or at least, M4L patches.

Bounce - A "sequencer" inspired by the best Electroplankton level where you bounce balls off lines to make a melody

Window - Basic generative pattern sequencer where the note and timing data are decoupled

  • Like 3
Link to comment
Share on other sites

7 hours ago, modey said:

I'm slowly working on some stuff too. Just web things for now, but eventually I'd like to have a small "suite" of generative MIDI VSTs.. or at least, M4L patches.

Bounce - A "sequencer" inspired by the best Electroplankton level where you bounce balls off lines to make a melody

Window - Basic generative pattern sequencer where the note and timing data are decoupled

Getting some insane The Incredible Machine flashbacks from Bounce. I wish the balls would not disappear when they hit the bottom edge, all the other "borders" seem solid and bouncy. Also in some cases I have seen the ball go through the lines without bouncing!

Because I am a quantization type of person, I would actually implement a grid version of this, so that you could still aim the balls wherever you want and mess with the speed, but the sounds would be quantized in time (you could optionally change the grid size too of course to make it more or less granular). Then you could build up your bouncy sound castle and add more ball guns etc etc.

Window's concept is pretty much exactly what I whipped up in Pure Data 2019 early 2020, to have notes and timings cycling separately. I kind of want to start to incorporate this kind of thing again but it is a bit difficult to integrate well with Live (no I don't want to build a M4L device). Anyway I think this approach is really good for being able to play and transition from one rhythm or melody to another - you just keep the timing part the same and switch out the melody or vice versa.

By the way, what did you use to make these?

Link to comment
Share on other sites

thx! They were built in p5js so things like the balls moving through the lines are somewhat unavoidable (or my code sucks haha) but yeah, those suggestions sound good. I'm very slowly learning juce so maybe they'll be a bit more robust in VST form, where I can possibly use the audio engine to calculate the bounces etc. 

Different sounds/MIDI channels could be implemented as well. 

Edited by modey
Link to comment
Share on other sites

9 minutes ago, modey said:

thx! They were built in p5js so things like the balls moving through the lines are somewhat unavoidable (or my code sucks haha) but yeah, those suggestions sound good. I'm very slowly learning juce so maybe they'll be a bit more robust in VST form, where I can possibly use the audio engine to calculate the bounces etc. 

Different sounds/MIDI channels could be implemented as well. 

I am thinking that it would be more interesting/useful if the apps came with:

  • ability to select incoming outgoing MIDI port and channel (no need to support multichannel stuff)
  • ability to receive sync over MIDI

At this point I and anyone else can just plug it into their DAW as a source of MIDI notes, and already they would be pretty well usable for performances and many other cool things. Putting it in a VST is great too of course, but I feel it's orders of magnitude more work and since you are only passing on MIDI information, it's quite lightweight and JavaScript can handle that OK.

As for the collision stuff, yeah it's a fuck to implement properly because even AAA games get clipping problems. Once again using a grid (even if only in the backend) you can cheat and solve this simply - you check if the center of the ball is in a grid square that is noted for containing a line and then you play the ding dong sound. Of course it all depends how you have done it so far, but really it's not a big deal even if you get it 95% working because who the hell cares really it is an inspirational art tool. 🙂

AFAIK there is a browser MIDI support that has existed in Chrome (at least) for some time, I know because the Livid Instruments configuration app for my Code v2 came with a browser app.

Link to comment
Share on other sites

I've been doing some generative stuff for a good while (check my signature if interested, especially AAP). Mostly it's with Renoise that allows random events and sort of selection of event with weighted probabilities. Like 50% this will be kick, 25% snare, 25 hihat. And so on. And you can layer them using phrases. Renoise also has Lua support so you could generate the sequences in the patterns and save them. That way you won't have the annoying thing that the track sounds different every time even though it was randomized.

I did some Python code that played randomized music some years ago also. It worked through General MIDI but I tried it with a synth also by just changing the MIDI device number and it worked fine. Using MIDI in Python is really easy. Just a couple of commands to initialize and then note_on, note_off, etc.

I'm utilizing Reaktor now more, but so far haven't got too deeply into the generative stuff with it. Just synth design with some S&H parameters. Then load the Reaktor instruments in Renoise and let Renoise do the (semi-)randomized sequencing.

Link to comment
Share on other sites

15 hours ago, thawkins said:

I am thinking that it would be more interesting/useful if the apps came with:

  • ability to select incoming outgoing MIDI port and channel (no need to support multichannel stuff)
  • ability to receive sync over MIDI

At this point I and anyone else can just plug it into their DAW as a source of MIDI notes, and already they would be pretty well usable for performances and many other cool things. Putting it in a VST is great too of course, but I feel it's orders of magnitude more work and since you are only passing on MIDI information, it's quite lightweight and JavaScript can handle that OK.

As for the collision stuff, yeah it's a fuck to implement properly because even AAA games get clipping problems. Once again using a grid (even if only in the backend) you can cheat and solve this simply - you check if the center of the ball is in a grid square that is noted for containing a line and then you play the ding dong sound. Of course it all depends how you have done it so far, but really it's not a big deal even if you get it 95% working because who the hell cares really it is an inspirational art tool. 🙂

AFAIK there is a browser MIDI support that has existed in Chrome (at least) for some time, I know because the Livid Instruments configuration app for my Code v2 came with a browser app.

Yeah, good point. JUCE is a whole world of pain in terms of even just getting things set up. I'm at the point with Window now though where it works as a straightforward 16th note sequencer in VST form, so it's only a matter of adding the remaining features and a few others. And I did want to make some basic synth engines to go along with these, but that's a long way down the line. Standalone with MIDI I/O only would be a breeze though 😄 

Yeah the collision stuff is maybe not the best implementation. At every frame for each ball and for each line it measures the distance from each point, and if the distance between the ball and each point of a line adds up to the line's length (+/- a certain amount), it bounces. It doesn't work at high speeds, due to it measuring every frame (ie. it could miss the threshold) and for some reason I've noticed it doesn't work on a particular part on a line (not sure why!) so it's not 100% accurate, but hey, it works most of the time! I coded most of it up by hand so there's likely a much more efficient way to do it that I just don't know of yet, due to my limited math (trig? physics?) knowledge!

I was actually tempted to make a Unity version because I know that it'd handle the physics pretty well, and I could get away with all kinds of things, even 3d. But I'm not sure if Unity is capable of rock solid MIDI timing lol.

And yeah, I have WebMIDI support in one version of Window, just commented out, I should get back on that! Ideally though I'd love to be able to just save to a MIDI file. I'm not even sure how I'd do that in p5js though.

Link to comment
Share on other sites

10 hours ago, modey said:

Yeah, good point. JUCE is a whole world of pain in terms of even just getting things set up. I'm at the point with Window now though where it works as a straightforward 16th note sequencer in VST form, so it's only a matter of adding the remaining features and a few others. And I did want to make some basic synth engines to go along with these, but that's a long way down the line. Standalone with MIDI I/O only would be a breeze though 😄 

Yeah the collision stuff is maybe not the best implementation. At every frame for each ball and for each line it measures the distance from each point, and if the distance between the ball and each point of a line adds up to the line's length (+/- a certain amount), it bounces. It doesn't work at high speeds, due to it measuring every frame (ie. it could miss the threshold) and for some reason I've noticed it doesn't work on a particular part on a line (not sure why!) so it's not 100% accurate, but hey, it works most of the time! I coded most of it up by hand so there's likely a much more efficient way to do it that I just don't know of yet, due to my limited math (trig? physics?) knowledge!

I was actually tempted to make a Unity version because I know that it'd handle the physics pretty well, and I could get away with all kinds of things, even 3d. But I'm not sure if Unity is capable of rock solid MIDI timing lol.

And yeah, I have WebMIDI support in one version of Window, just commented out, I should get back on that! Ideally though I'd love to be able to just save to a MIDI file. I'm not even sure how I'd do that in p5js though.

Yeah, Unity would solve your physics issues quite well, but then you would have a full blown game engine running in a thing that is supposed to generate MIDI. Whoops. 🙂 Not sure how game engines deal with real-time requirements for rock solid MIDI timing either, so I would absolutely avoid this.

IIRC the deal with JUCE was that you needed to write your things in C++, which can have a terrifying learning curve and comes with some obscure gotchas too. I assume they have most of that covered in the tutorials by now though.

I'm only egging on the MIDI compatibility because I get all my sounds from the hardware modules and I use almost no VST or plugins for sound generation at all.

By the way your description of that collision checking now explains why sometimes I got the balls all over the place while I thought they would be bouncing off the first "wall". 🙂

10 hours ago, modey said:

And yeah, I have WebMIDI support in one version of Window, just commented out, I should get back on that! Ideally though I'd love to be able to just save to a MIDI file. I'm not even sure how I'd do that in p5js though.

I think I would record some MIDI with a DAW, export it and see how the file looks like, then try to get p5js output something similar.

Link to comment
Share on other sites

I know I'm kind of a broken record about this lately but this yet another thing I'd definitely use SuperCollider for. If only because I'm lazy and it's easy.

(Pbind(
    \scale, Scale.harmonicMinor,
    \degree, Pbrown(0, Scale.harmonicMinor.size, 3),
    \octave, Pbrown(3, 6, 2, inf),
    \dur, Pwrand(
        (1..4) / 8,
        [3, 5, 2, 1].normalizeSum,
        inf
    ),
).play)

Edited by sweepstakes
  • Like 1
Link to comment
Share on other sites

8 hours ago, sweepstakes said:

I know I'm kind of a broken record about this lately but this yet another thing I'd definitely use SuperCollider for. If only because I'm lazy and it's easy.

(Pbind(
    \scale, Scale.harmonicMinor,
    \degree, Pbrown(0, Scale.harmonicMinor.size, 3),
    \octave, Pbrown(3, 6, 2, inf),
    \dur, Pwrand(
        (1..4) / 8,
        [3, 5, 2, 1].normalizeSum,
        inf
    ),
).play)

I'm interested in trying this out - could I ask you to share a minimal project or some code I can copy and paste, hit play and get started?

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, thawkins said:

I'm interested in trying this out - could I ask you to share a minimal project or some code I can copy and paste, hit play and get started?

For sure! That snippet right there should be runnable although I don't think it sounds great or anything, plus it will use the (super bland) default piano instrument.

I'll see if I can find some other cool sequences, but it might be faster for me to whip something up if you have some suggestions/prompts? 

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, sweepstakes said:

For sure! That snippet right there should be runnable although I don't think it sounds great or anything, plus it will use the (super bland) default piano instrument.

I'll see if I can find some other cool sequences, but it might be faster for me to whip something up if you have some suggestions/prompts? 

If it should work like that, then I'll just give it a shot - I am just unfamiliar to SuperCollider and I figured you would need to set up some scaffolding for sounds and MIDI connections or something who knows!

Link to comment
Share on other sites

57 minutes ago, thawkins said:

If it should work like that, then I'll just give it a shot - I am just unfamiliar to SuperCollider and I figured you would need to set up some scaffolding for sounds and MIDI connections or something who knows!

Nope, that's part of why I love SC - I'm lazy :) The only "scaffolding" you should need to do (as long as your sound is properly configured) is booting the server.

  • Like 1
Link to comment
Share on other sites

Side note - the classes are worth introspecting for their properties (e.g. Scale.harmonicMinor) and also reading up on the docs in the SC IDE (by pressing Ctrl/Command+D on top of a class/property/method). It's easy to get started and there is also a lot to explore.

  • Like 1
Link to comment
Share on other sites

14 hours ago, sweepstakes said:

Nope, that's part of why I love SC - I'm lazy 🙂 The only "scaffolding" you should need to do (as long as your sound is properly configured) is booting the server.

Yeah, tried it out yesterday and it's much faster to get started than with the TidalCycles thing (which did not work half the time too). If I have some more time I will try to implement some ideas in SuperCollider once I get it hooked up to Live properly with MIDI timecode sync etc.

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, thawkins said:

Yeah, tried it out yesterday and it's much faster to get started than with the TidalCycles thing (which did not work half the time too). If I have some more time I will try to implement some ideas in SuperCollider once I get it hooked up to Live properly with MIDI timecode sync etc.

IIRC TidalCycles is a Haskell process talking to the SuperCollider server, no?

Link to comment
Share on other sites

1 hour ago, rhmilo said:

IIRC TidalCycles is a Haskell process talking to the SuperCollider server, no?

Yes, but at least the last time I tried, it was a headache to set it up so that you can easily open a project and have your basic things work out of the box (i.e. after you set up some template stuff). I used it strictly as a MIDI sequencer too so that may have been my mistake - the general workflow seems to be to use TidalCycles sounds with it as well.

Maybe one of the things that put me off about TidalCycles was the sheer amount of Stuff it required to install - some Haskell things, SuperCollider. And all that for a MIDI sequencer? Overkill!

However I should stop hating on TidalCycles and just give it another shot to see if I get better results now. Who knows, maybe even learn me a Haskell for great good!

Link to comment
Share on other sites

1 hour ago, thawkins said:

Maybe one of the things that put me off about TidalCycles was the sheer amount of Stuff it required to install - some Haskell things, SuperCollider. And all that for a MIDI sequencer? Overkill!

Shh ... don’t let @Nil hear you.

  • Haha 3
  • Burger 1
Link to comment
Share on other sites

Haha, agreed though!

@thawkins man you're going to love Note probability and Velocity range in Live 11. Add some macro snapshots (killer new feature) and Follow Actions et boom!

Built-in  MIDI devices are indeed super powerful, I often use similar tricks when teaching synthesis (to avoid repetitive loops).

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...