def makeNoteFromScaleIndex(self, scaleIndex): newNote = ArpNote() newNote.pitch = self.key.pitch for intervalIndex in range(0, scaleIndex): newNote.pitch += self.progression[intervalIndex] return newNote
def genScale(self, rootNote): mode = self.progression scale = [] for index in range(0, 7): newNote = ArpNote() newNote.pitch = rootNote.pitch + sum(mode[0:index]) scale.extend([newNote]) return scale
def genBar(self, bpMeasure): volume = 100 notes = [] progIndex = 0 time = self.time # Beats per note, default 1 noteDuration = 1 # Get a random note in the scale myPitch = self.key.pitch newRoot = ArpNote() newRoot.pitch = myPitch + sum(self.progression[0:random.randint(1, 6)]) # Get a scale starting from the new root in the given mode newScale = self.genScale(newRoot) # Now adapt the scale so its in the current key self.adaptScale(newScale) intervalIndex = 0 chordIndex = 0 octave = 0 inverse = False chordType = Chords.triad # New Feature! Sicky Tight. Add the main triad as a chord triad1 = copy.copy(newScale[0]) triad2 = copy.copy(newScale[2]) triad3 = copy.copy(newScale[4]) triad1.pitch -= 24 triad1.time = time triad1.track = 2 triad1.volume = volume triad2.pitch -= 24 triad2.track = 2 triad2.time = time triad2.volume = volume triad3.pitch -= 24 triad3.track = 2 triad3.time = time triad3.volume = volume notes.extend([triad1, triad2, triad3]) startTime = self.time # Arpeggiate up the scale bpMeasure number of times for note in range(0, bpMeasure): noteDuration = random.sample([1, 2, 4], 1)[0] newNote = copy.copy(newScale[chordIndex]) newNote.time = time newNote.duration = noteDuration newNote.volume = volume newNote.track = 1 newNote.pitch += octave * 12 notes.extend([newNote]) # Determine whether we should go up or down # Time to toot my own horn. This is really cool and looks slick because of # python slicing. The chord progression you choose will be rotated like a dial # so a random of -1 will turn [ 2, 2, 3] for example, into [ 3, 3, 2] # Take the 0th element and bam, you have how far to go for the next note updown = random.sample([-1, 1], 1)[0] if updown > 0: chordType = chordType[1:] + chordType[:1] chordIndex -= chordType[0] else: chordType = chordType[-1:] + chordType[:-1] chordIndex += chordType[0] # Handle wraparound if chordIndex > 6: chordIndex -= 7 octave += 1 elif chordIndex < 0: octave -= 1 chordIndex += 7 # Move up the current time time += newNote.duration self.time = time triad1.duration = triad2.duration = triad3.duration = (time - startTime) return notes
def genBar(self, bpMeasure): volume = 100 notes = [] progIndex = 0 time = self.time # Beats per note, default 1 noteDuration = 1 # Get a random note in the scale myPitch = self.key.pitch newRoot = ArpNote() newRoot.pitch = myPitch + sum(self.progression[0:random.randint(1,6)]) # Get a scale starting from the new root in the given mode newScale = self.genScale(newRoot) # Now adapt the scale so its in the current key self.adaptScale(newScale) intervalIndex = 0 chordIndex = 0 octave = 0 inverse = False chordType = Chords.triad # New Feature! Sicky Tight. Add the main triad as a chord triad1 = copy.copy(newScale[0]) triad2 = copy.copy(newScale[2]) triad3 = copy.copy(newScale[4]) triad1.pitch -= 24 triad1.time = time triad1.track = 2 triad1.volume = volume triad2.pitch -= 24 triad2.track = 2 triad2.time = time triad2.volume = volume triad3.pitch -= 24 triad3.track = 2 triad3.time = time triad3.volume = volume notes.extend([triad1,triad2,triad3]) startTime = self.time # Arpeggiate up the scale bpMeasure number of times for note in range(0, bpMeasure): noteDuration = random.sample([1, 2, 4], 1)[0] newNote = copy.copy(newScale[chordIndex]) newNote.time = time newNote.duration = noteDuration newNote.volume = volume newNote.track = 1 newNote.pitch += octave * 12 notes.extend([newNote]) # Determine whether we should go up or down # Time to toot my own horn. This is really cool and looks slick because of # python slicing. The chord progression you choose will be rotated like a dial # so a random of -1 will turn [ 2, 2, 3] for example, into [ 3, 3, 2] # Take the 0th element and bam, you have how far to go for the next note updown = random.sample([-1, 1], 1)[0] if updown > 0 : chordType = chordType[1:] + chordType[:1] chordIndex -= chordType[0] else: chordType = chordType[-1:] + chordType[:-1] chordIndex += chordType[0] # Handle wraparound if chordIndex > 6: chordIndex -= 7 octave += 1 elif chordIndex < 0: octave -= 1 chordIndex += 7 # Move up the current time time += newNote.duration self.time = time triad1.duration = triad2.duration = triad3.duration = (time - startTime) return notes