pySchö: algorithmic music composition
In a previous post, I have talked about a python script used to generate random music starting from a single number (a "seed").
So, today I'd like to share with you pyScho.
The name is a contraction of "Python" and "Schönberg" (from Arnold Franz Walther Schönberg, the father dodecaphony [3]): although I'm italian, I don't realized that the italian pronunciation might be awkward.
Despite the project name contains the name of a musician well-known for dodecaphonic composition, pyScho [1] currently allows only the creation of diathonic melodies.
So, I started with a dictionary with common musical scales:
scales = { "major" : [0, 2, 4, 5, 7, 9, 11], "minor" : [0, 2 , 3, 5, 7, 10, 11], "dorian" : [0, 2, 3, 5, 7, 9, 10, 12], "phrygian" : [0, 1, 3, 5, 7, 8, 10, 12], "minor_pentatonic" : [0, 3, 5, 7, 10], "major_pentatonic" : [0, 2, 4, 7, 9], "harmonic_minor" : [0, 2, 3, 5, 7, 8, 10, 12], "mixolydian": [0, 2, 4, 5, 7, 9, 10], "minor_blues" : [0, 3, 5, 6, 7, 10], "locrian" : [0, 1, 3, 5, 6, 8, 10, 12], "lydian" :[0, 2, 4, 6, 7, 9, 11, 12], }
And a simple function to create an array containing a 2 octave scale:
def get_notes(start, intervals): return_array = [] for x in range(0, 2): for y in range(0,len(intervals)): return_array.append(start + (intervals[y] + (12 * x))) return return_array
Then, using random python lib, the script generates two arrays, containing notes and duration.
Finally, the script uses midiutil [2] lib to save the generated melody on a .mid file.
The result is a basic command line tool, below the usage:
usage: pyscho.py [-h] [--scale SCALE] [--start START] [--bars BARS] seed outputfile positional arguments: seed Algorithm seed outputfile output file name optional arguments: -h, --help show this help message and exit --scale SCALE musical scale: major, minor, dorian, phrygian, minor_pentatonic, major_pentatonic, harmonic_minor, mixolydian, minor_blues, locrian, lydian (default: major) --start START first note (default: 60 - C4) --bars BARS number of bars (default: 10)
and here a screenshot:
the generated melody can be open with any musical editor, like Musecore: