I have the following list:
60, 62, 63, 65, 66, 68, 69, 71, 73, 74, 76, 77, 79, 80, 82, 83, 85, 87, 88
and I need to have pitches chosen from the list with these conditions:
100 pitches need to be chosen
First a random pitch from the list needs to be chosen, and the following pitches chosen from the list would be determined through weighted probabilities.
What I am trying to accomplish is, after the first pitch is randomly chosen from the list (71), the next pitch chosen would be determined by weighted probability according to its proximity to 71 (69 and 73 would have the most probability of being chosen, followed by 68 and 74, etc.)
Supposing 68 would be chosen as the pitch following 71, then the next pitch following 68 would be determined by weighted probability according to its proximity to 68 (66 and 69 would have the most probability of being chosen, followed by 65 and 71, etc.)
My main concern is that, although the program runs without errors (that is, at least an error message doesn't interrupt its execution), I am still not convinced if it is running the way I intended. The reason I say this is because, even though I want the program to choose 100 notes, it always chooses exactly 5050 notes. Why 5050?
Here is my code:
from music import *
from random import *
solo = Phrase()
solo.setTempo(100)
durations = []
pitches = []
pitchIndex = ()
numberOfNotesInSolo = 0
listOfAvailablePitches = [60, 62, 63, 65, 66, 68, 69, 71, 73, 74, 76, 77, 79, 80, 82, 83, 85, 87, 88]
pitch = choice(listOfAvailablePitches)
pitchIndex = listOfAvailablePitches.index(pitch)
while numberOfNotesInSolo < 100:
weightedProbabilitiesForPitches = [pitchIndex + 1] * 20 + [pitchIndex - 1] * 20 + [pitchIndex + 2] * 15 + [pitchIndex - 2] * 15 + [pitchIndex + 3] * 12 + [pitchIndex - 3] * 12 + [pitchIndex + 4] * 8 + [pitchIndex - 4] * 8 + [pitchIndex + 5] * 5 + [pitchIndex - 5] * 5 + [pitchIndex + 6] * 3 + [pitchIndex - 6] * 3
pitchIndex = choice(weightedProbabilitiesForPitches)
while pitchIndex > 18 or pitchIndex < 0:
pitchIndex = choice(weightedProbabilitiesForPitches)
pitch = listOfAvailablePitches[pitchIndex]
weightedProbabilitiesForDurations = [SN] * 1 + [EN] * 1 + [DEN] * 1 + [QN] * 1 + [DQN] * 1
duration = choice(weightedProbabilitiesForDurations)
pitches.append(pitch)
durations.append(duration)
solo.addNoteList(pitches, durations)
numberOfNotesInSolo = numberOfNotesInSolo + 1
print solo