Tags: posts polarity-music Bitwig Grid

Using Markov Chains and Probabilistic Sequencing in Bitwig Grid

Tutorial | Jul 04, 2022

In this video, I explain how to use a probabilistic graph to generate melodies in the Bitwig grid. I demonstrate how to input a scale of nodes, as well as dial in probabilities of which node follows which. I explain how this type of feedback loop is used in machine learning, and how it can be used to generate chords and even switch instruments. I share my code on Github for free, and invite viewers to have fun with it and extend it in any way they can.

You can watch the Video on Youtube - support me on Patreon

Questions & Answers

Maybe you dont watch the video, here are some important takeaways:

What is a Markov chain probabilistic melody generator?

A Markov chain probabilistic melody generator is a type of algorithm that uses probability to generate musical sequences. It works by assigning different probabilities to different musical notes, and then using those probabilities to determine the most likely next note in the sequence. The system is based on the idea of Markov chains, which are used to model the behavior of complex systems.

How can I implement a Markov chain probabilistic melody generator in the Bitwig Grid?

To implement a Markov chain probabilistic melody generator in the Bitwig Grid, you need to create a Note Grid with the major scale of C, D, E, F, G, A and B. Then, you need to create a probabilistic graph that assigns different probabilities to each note. This graph will determine which note is the most likely to be played next. Finally, you can use a clock signal to step through the graph and generate the melody.

What other types of algorithms can be used to generate melodies?

Other types of algorithms that can be used to generate melodies include genetic algorithms, Markov


This is what im talking about in this video. The text is transcribed by AI, so it might not be perfect. If you find any mistakes, please let me know.
You can also click on the timestamps to jump to the right part of the video, which should be helpful.

[00:00.000] Hey folks, welcome back to another video. Someone in my Discord actually asked me
[00:06.200] how to
[00:07.680] implement some kind of Markov
[00:09.760] Sequencers or Markov chain probabilistic melody generating or
[00:15.000] Sequencing selecting stuff inside the Bitwig grid and this was kind of my solution to that
[00:21.320] and I want to explain you first how it works or how we can read this and
[00:25.920] Then maybe how I build it and how the
[00:30.400] Yeah, the theory behind is right. So first the setup here. It's just in a Note Grid
[00:36.800] So everything you see here is in this Note Grid and it outputs nodes to this Polysynth here
[00:43.280] Which is just a regular
[00:45.120] synthesizer you can of course use VST or you can record also the node outputs here to a different
[00:51.440] track if you want to and
[00:53.440] And inside this Note Grid here, we have
[00:57.840] The scale of C major so C D E F G a and
[01:03.040] B also here the same on the same nodes and in the middle here we have
[01:09.320] Yeah, a probabilistic
[01:13.240] Graph we can use dial in some things
[01:17.000] So let's say we have C we start at 3 or we have the node of C 3 you can dial in now here
[01:24.600] Which node follows C C 3 by which probability so let's say
[01:33.280] D which is the second one so let's dial in your second draw a
[01:39.520] Probability by 60%
[01:41.520] Okay, and then we can say
[01:49.720] Maybe or we are currently at B. So let's dial in C. So we're back here. Okay, so now we are at D and D
[01:58.560] Maybe as the second or as the following up node. We want to have a C
[02:03.480] So we go back to see you with the probability of 50% so now you can see the node switching between C and D
[02:09.960] So this is basically how it works you say by a probabilistic
[02:17.920] Value which node follows which node
[02:22.440] So another example would be maybe switch this year back to see
[02:27.000] We are at C and we want to go to every other node here except C
[02:32.760] So we dial in your probability by some random value maybe we can say we want to have these a bit lower and
[02:41.720] The fourth and the fifth is maybe a bit higher and these are pretty low here and
[02:49.440] Then
[02:50.720] From all the other nodes we want to have a following up node of C
[02:55.560] So we want to go to a random node from C
[02:58.640] So C to a random node and then all the other nodes go back to C. So we can dial in here C
[03:05.640] with the high probability
[03:08.560] So now every other node is basically a C
[03:11.680] So you switch between C the root node and the random node or not. It's not really random. It's probabilistic, right?
[03:18.680] So you go to the fifth and the fourth a bit more often than all the other nodes
[03:24.760] So and then you just hit play
[03:54.880] So you can create melodies this way and can say you want to have these nodes following these nodes by this
[04:03.040] probability and you can create melody generators with this or you can also
[04:08.720] maybe analyze
[04:11.120] popular music and
[04:15.160] Basically get the nodes out and analyze which node follows which node by which probability and then you can dial it in here and
[04:23.200] Then you can recreate this melody in kind of the same way, but with different iterations of it
[04:30.000] So this is how it's used and I think a lot of machine learning is also
[04:35.560] Utilizing this kind of behavior
[04:37.960] So you have an input step and then you have a probability of the outcome and then the outcome defines the new input and
[04:45.440] Then you go back and forth in kind of a
[04:48.840] feedback loop of this
[04:50.600] So this is pretty easy to implement as you can see here and how this works is basically that these gates here are not gates
[04:59.440] these are actually probabilities
[05:02.360] modules, right and
[05:05.000] I'm using a clock signal here to step through this
[05:08.840] step mod and this step mod decides which
[05:12.480] node is
[05:14.480] selected here on this
[05:16.560] merge module
[05:18.280] so when we go here to you let's let's say I have a value here and instead of this and
[05:26.320] This I can select your input signal. Let's say C and
[05:32.160] this one is stepping through this and
[05:35.280] We have no output here. There's no gate output as you can see here. This is not
[05:41.080] There's no gate signal coming out of this
[05:44.320] Because there's no probability died in
[05:46.320] So and every time we are at this position here
[05:50.640] In this loop, right?
[05:52.640] So you can see we I'm switching here with the clock through this and every time we are at this position here
[05:57.680] You can dial in a gate signal with the probability
[06:01.680] You can see we have here now
[06:04.320] fluctuating
[06:05.480] LED lighting up because every time we pass this step here
[06:10.560] this gate module or this probability module decides to
[06:14.520] output the gate signal and holding this value which is exactly the same step and this step puts out the value of
[06:22.920] this step here, which is then
[06:26.640] G3
[06:28.400] So it's here one two three four five six and then it's the sixth position here, right?
[06:33.840] So this is how you can read this basically so this output as you can see a signal
[06:44.360] the value of this step and then
[06:48.640] We get here pretty fluctuating signal if I paint in here all the values kind of this and
[06:55.640] It's not like that. You want to have a melody that switches, you know between the nodes this fast
[07:00.400] so I'm
[07:02.920] Using here a sample and hold and the sample and hold is
[07:07.400] Using basically at the gates from the trigger and this is basically outputting here at the gate or that the
[07:12.800] Rhythmic the rhythm of the melody
[07:16.080] So I'm sample and holding here
[07:19.000] This value and then selecting or collapsing basically the decision on a note
[07:24.040] So this is how it works and instead of selecting here the input
[07:29.360] I'm using the output of this
[07:33.160] Right the position of this with a long delay and feeding back into the input
[07:38.560] So I'm selecting here the input based on the output
[07:43.080] also here
[07:45.080] and then you have this endless loop of
[07:50.000] Having a different
[07:52.000] Having a different
[07:54.040] Output the output decides to change the input the input then goes to the probabilistic
[08:00.600] Generator here selects and the next node on a probability
[08:04.640] the next now then goes back into it and you know and then you can go back and forth and build melodies this way and
[08:12.640] You not only can use this to create melodies as an input you where you use
[08:18.520] Note pitches as an input. You can also use modulation values as an input
[08:23.920] You can decide when I have this modulation value as an input
[08:27.480] Then I want to follow up with this modulation value
[08:30.160] And when I have this modulation value, then I go back in here and use that to decide on the next step, right?
[08:36.920] It's also possible to use this for chords chord progression. So you have probably in
[08:42.440] Let's say a minor or major
[08:44.560] You have different probabilities of which chord follows which other note other chord and then you can build something based on this
[08:56.680] Or maybe you can switch to different instruments on a probabilistic
[09:03.280] Way in a probabilistic way, right? So we can not only use this for notes. You can use this for all kinds of different stuff
[09:09.880] You can also just paint paint in your different things. You don't need to actually make an
[09:17.440] Science out of this, right? You can just go in and paint in and stick with something you really like
[09:24.040] then hit play
[09:26.520] And then maybe let this generate a melody for you. Maybe push records record all the notes and then
[09:33.280] Cut out certain parts you like and use it for your music
[09:40.120] Okay, so I put this here on my github for free. You can download this in the description and maybe can build
[09:47.440] something out of this. I
[09:49.720] Just have some fun with it, right?
[09:52.200] It's pretty simple layout here laid out and
[09:55.680] It's not much to it so you can extend this or changing up in every kind of way possible
[10:03.560] Okay, I think that's it if you liked the video like the video and subscribe to the channel. Thanks for watching and see you in the next video. Bye