Demo entry 6344627

Random Chords

   

Submitted by anonymous on Jan 17, 2017 at 22:58
Language: Python. Code size: 1.2 kB.

#!/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. """
    print(m)
    sys.exit(1)

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

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



##########################

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

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))

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).