Randomly Generated Motif

Skip to the bottom

  • @saumera  Feb 9

    I thought it would be fun to make a song based around a motif consisting of a series of random notes, then I thought hey I'm a coder why don't I open this challenge up! So I wrote a small script that will randomly generate a musical motif that's 4 to 10 notes in length.

    Want a motif of your own? Give me a key (or it can be chromatic for an extra challenge) and I'll create one for you. It can be in any key and the scales available are:
    - Major
    - Minor
    - Minor blues
    - Whole Tone
    - Octatonic (whole/half)
    - Octatonic (half/whole)

    When you get your motif, you can use it any way you can come up with:
    it can be a bass line, it can outline your main melody, it can even be the roots of your chord progression, whatever you can make work. When you're done tag your song #motif and post it here!

    EDIT: @quillwraith created a quick little website that uses my script, and will generate one for you! Check it out!


  • @saumera  Feb 9

    For my fellow coders out there, here's the code! (I wrote it in Javascript to be executed by node lol):

    const notes = [ 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B', ];
    const MIN = 4;
    const MAX = 10;

    const scales = {
    major: [ 0, 2, 4, 5, 7, 9, 11 ],
    minor: [ 0, 2, 3, 5, 7, 8, 10, 11 ],
    blues: [ 0, 2, 3, 5, 6, 7, 10 ],
    halfWhole: [ 0, 1, 3, 4, 6, 7, 9, 10 ],
    wholeHalf: [ 0, 2, 3, 5, 6, 8, 9, 11 ],
    wholeTone: [ 0, 2, 4, 6, 8, 10 ],
    chromatic: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ],

    const getRand = (array) => array[Math.floor(Math.random() * (array.length))];

    const createGetNote = (baseIndex, scale) => {
    return () => notes[(baseIndex + getRand(scale)) % notes.length];

    const generate = (key='', scaleType='') => {
    const baseIndex = notes.indexOf(key.toUpperCase()) || 0;
    const scale = scales[scaleType] || scales.chromatic;

    const len = Math.floor(Math.random() * (MAX - MIN)) + MIN;
    const getNote = createGetNote(baseIndex, scale);
    return Array.from({ length: len }, getNote);

    const [ key, scaleType ] = process.argv.slice(2);

    const motif = generate(key, scaleType);
    console.log('Motif: ', motif.join(', '));

  • @valeriecox  Feb 9

    That sounds fun! Please generate me one in C Major.

  • @saumera  Feb 9

    Sure thing!

    @valeriecox your motif consists of the notes A, B, G, F, E, D, E

    Sounds like a fun one!

  • @vomvorton  Feb 9

    This sounds fun, and I'm desperate for some inspiration! D major please.

  • @saumera  Feb 9

    @vomvorton your motif consists of the notes G, D, F#, B. Seems like a cool bass line!

  • @vomvorton  Feb 9

    @saumera thanks, I will attempt to create something using that right away!

  • @saumera  Feb 9

    I decided to do a chromatic one and looks like I got G, A, C, F, C#, D, G, F#

  • @pearlmanhattan  Feb 9


    I'll take one, please? In G major

  • @saumera  Feb 9

    @pearlmanhattan your motif consists of the notes B, F#, E, G, F#, E, B

  • @krayzie003  Feb 9

    This is cool. I'll take a motif.

    I'm not a coder but I would like to know how to run this code. This could be great for future inspiration.

  • @saumera  Feb 9

    @krayzie003 any key?

  • @krayzie003  Feb 9

    @saumera. Something major. Don't care which.

  • @saumera  Feb 9

    @krayzie003 I picked Ab major. Here's your motif:

    C, Db, Ab, Eb, Bb, Bb, Ab, C, Ab

    And as for your running that code on your own, it's a little tricky just because of the language I chose. Computers don't come pre-loaded with something that can run it, so you would have to install node.js on the command line and then run "node motif_generator.js C major."

    If there's enough interest, I can rewrite it in something like python or perl that every computer has and the command could be run from the command line of any machine.

  • @sherrycanary  Feb 9

    I would like one in G
    Thank you

  • @saumera  Feb 10

    @sherrycanary your motif has the notes G, C, F#, A, D. That tritone might be tricky!

  • @gbg2016  Feb 12

    I'd love one. Chromatic please!

  • @quillwraith  Feb 12

    @sherrycanary "And as for your running that code on your own, it's a little tricky just because of the language I chose. Computers don't come pre-loaded with something that can run it, so you would have to install node.js on the command line and then run "node motif_generator.js C major.""

    JavaScript runs in the browser, and the only node specific thing here is process.argv. It would be pretty simple to do a webpage version: https://forrestweiswolf.github.io/ran...

    ( I'll take it down if you want, or hand over the repository - I don't mean to take your work! Just seemed like a quick way to make it more usable for people.)

  • @saumera  Feb 12

    @quillwraith nah this looks great! I forget, does github have some service that allows you to host a simple webpage like this? It'd be pretty cool to get it up somewhere.

  • @saumera  Feb 12

    Oh disregard that you're already hosting it, I missed the link!

  • @powerstars Feb 13

    Ooh! I couldn't think of a key so I picked one at random. Can I get one in G Minor?

  • @krayzie003  Feb 13

    Along these same lines I found a website where you can type in you name (or any phrase) and it will generate music from it. http://www.clarallel.com/

  • @owl  Feb 13

    May I have one in A minor?

  • @musicsongwriter Feb 13

    I'd like a motif please. Thank you.

  • @saumera  Feb 13

    @powerstars: F, A, Eb, Gb, Bb

    @owl: D, A, C, B, A

    @musicsongwriter: you didn't give me a key so I picked chromatic. F#, A#, C#, F

  • @pearlmanhattan  Feb 13

    https://fawm.org/songs/94058/ My contribution based on my random generated motif. thank you.

  • @musicsongwriter Feb 13

    Thank you for your motif. Here is my take:

  • @krayzie003  Feb 14

    Here is what I created with my random motif... https://fawm.org/songs/94209/

    This was really fun.

  • @vomvorton  Feb 14

    Here's my motif song! The notes I was generated formed the verse bassline (which is also played by the keyboard), everything else spiralled out from there.


  • @splittybooms  Feb 14

    That's super cool...and I love motifs.
    I'll take one in Eb minor, please!

  • @saumera  Feb 14

    This is so awesome, guys! I'm so glad to see the motif idea is working out for some of you.

    @splittybooms here's your Motif in Eb minor: Db, F, Cb, Gb, Gb, Gb, Bb, F

  • @fearlessflight2014  Feb 14

    I would like something in my favourite key of Bb? Thanks!

  • @saumera  Feb 14

    @fearlessflight2014 your motif is Bb, Eb, G, D, Bb, G, C, C

  • @erikleppen Feb 14

    Shouldn't scales.minor be [0, 2, 3, 5, 7, 8, 10], without the 11?

    As far as I know, C-Minor is C, D, Eb, F, G, Ab, Bb. Without B.

    But I really like the idea 😁

  • @saumera  Feb 14

    @erikleppen I included the leading tone as an available note so dominant chords could be used. It's a note in the harmonic minor scale.

  • @erikleppen Feb 14

    Aha. Guess I learned something new today 😀 Thanks!

  • @splittybooms  Feb 14

    Am I understanding correctly, that we have to use the notes in the order given to us, @saumera?

  • @saumera  Feb 15

    @splittybooms I wouldn't say there are any hard and fast rules with using motifs, I would say the general idea is to use them as the groundwork for a line or chord progression. For instance in yours there are three notes that repeat, which might be kind of tricky. But if you make them emphasized notes and then put a couple neighboring tones in between them, it would still get the idea across that those three notes were the important ones.

    You could do the same thing with a bass line where each note in the motif falls on the down beat and everything else in between can be whatever you want. Just play around with it and see what you come up with!

  • @splittybooms  Feb 15

    Ah yes, ok - i just wanted to see how free we were with the notes you gave; if there were indeed 'hard and fast' rules lol
    I kept to the order given on all but the pad and the lead, though the lead strays only somewhat for the most part.
    Bass, and a melody pluck, and the root of all the chords follow the motif in order.
    Geez, thanks a lot, CODING, for giving me that wonderful GbGbGb! lol

Leave a Message. Log in to FAWM or sign up first...