Tuesday, January 17, 2017

Random chords

One of my friends did a little song in which he created the chord sequence by rolling dice. He then assigned different chords to the bars based on the results. Cool, I thought (even though he is using BiaB and not MMA to create his music). But, dice? Oh, so primitive! I figured a little python program would be much easier!

For the discussion and the song, jump over to the Kara-Moon forum.

So, here is a quick program (this listing was created using pygments, a very useful program).

To use, just create a sequence and then cut/paste the result into a text file. Add some groove names, tempo, etc. and you've got an original song. If only life had been this easy for guys like Bach and Beethoven.

Here's the code (you should be able to cut/paste this to your computer and run it with python):

#!/usr/bin/env python

# This program will generate a mma compatible
# set of chords generated at "random".

# The chords are generated based on a major scale in Ionian mode.
# Using roman numeral results permits easy key changes, but different
# chord tables can be used. 

import sys, os, random

def error(m):
    """ Abort on error with message. """

def usage():
    """ Print usage message and exit. """

Mma-rndchords, (c) Bob van der Poel
USAGE: mma-rndchords  nn
  nn == the number of chords to generate.


if len(sys.argv[1:]) != 1:
    print("mma-rndchords: number of requested bars.")

bcount = int(sys.argv[1])

# This is the weighted table.
# Using roman numerals
#chords={ "i": 4, "ii7": 2, "iii7": 3, "IV": 3, "V7": 4, "vi7": 2, "viiO": 1 }
# Using traditional chord names. Feel free to roll your own.
chords={ "C": 3, "Dm7":2,  "Em7": 3,  "F":4,   "G":5,   "Am7":2,  "Bdim7": 1}
# Convert to an expanded list. It'll look like ["i", "i", "i", ...]
chords = [k for k in chords for _ in range(chords[k])]

for a in range(bcount):
    print "%s %s" % (a+1, random.choice(chords)) 
Simple enough? If you need more options, etc. feel free to add to the program or contact me here via comments and I'll see what I can do.

No comments:

Post a Comment

Yet another "final" development release

Sorry fans, I know I promised a new stable series over a year ago. Unfortunately life got in the way. Some minor health issues (mostly solve...