Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I add lots of comments; everywhere. I took the time to write out what logic is happening in human-readable form for every single line of my 500 line music-generation algorithm, and it saved me so much time, and my other friends who were helping.</p> <p>Here's what I did (as a start):</p> <pre><code>def __init__(self): self.chromatic = ['C', ['C#', 'Db'], 'D', ['D#', 'Eb'], 'E', 'F', ['F#', 'Gb'], 'G', ['G#', 'Ab'], 'A', ['A#', 'Bb'], 'B'] self.steps = {} self.steps['major'] = [2, 2, 1, 2, 2, 2, 1] self.steps['natural minor'] = [2, 1, 2, 2, 1, 2, 2] self.steps['harmonic minor'] = [2, 1, 2, 2, 1, 3] self.steps['melodic minor up'] = [2, 1, 2, 2, 2, 2, 1] self.steps['melodic minor down'] = [2, 2, 1, 2, 2, 1, 2] self.steps['dorian'] = [2, 1, 2, 2, 2, 1, 2] self.steps['mixolydian'] = [2, 2, 1, 2, 2, 1, 2] self.steps['ahava raba'] = [1, 3, 1, 2, 1, 2, 2] self.steps['minor penatonic blues'] = [3, 2, 2, 3, 2] self.list = [] def scale(self, note, name): # Function to generate a scale from the required base note. if re.sub('[^0-9]', '', note) == '': # Checks for nonexistent octave number octave = 5 # Defaults to 5 else: # If octave number exists octave = int(re.sub('[^0-9]', '', note)) # Extracts octave number from note note = re.sub('[0-9]', '', note) # Strips all numbers from note scale = [] # Initializes the scale to be empty for i in rlen(self.chromatic): # Loops through all elements of the Chromatic scale if self.chromatic[i] is not list: # If the note is just a natural if note == self.chromatic[i]: scale = [i + 1] # Check if the note is in the chromatic. If it is, add it. else: if note in self.chromatic[i]: scale = [i + 1] # If the note is in a key of the chromatic, add it too. It is a sharp/flat. for i in rlen(self.steps[name]): # Loops through desired scale scale.append(self.steps[name][i] + scale[i]) # Adds string notes following the algorithm of the scale scale[i + 1] = scale[i + 1] % len(self.chromatic) # Modulo length of Chromatic scale </code></pre> <p>It's a start (and an example with cruddy code), but it helps me debug code <em>really</em> quickly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload