def generateMelody(bar, length, scale, chords, start=0, theme=None): melody = voice.Voice(start) templength = 0 beat = start #monesko isku menossa spaceInFrase = 0 oddsAndEnds = 0 length = length + beat #append theme to the start # print theme for note in theme: #theme syntax : [[rythm, note],[rythm,note]] # print "beat: "+str(beat) if (length > beat): melody.nextRythm(note[0]) melody.nextNote(note[1]) beat = beat + note[ 0] #Tahan voisi tehda esim. transponoinnin sointuihin. # print note else: break while (length > beat): frase = nextFrase(bar) # print "frase first: "+str(frase) # print "length-beat: "+str(length-beat) if (frase > (length - beat)): frase = length - beat spaceInFrase = frase # print "frase: "+str(frase) while (spaceInFrase > 0): #one frase at a time templength = probabilities.getRythm( spaceInFrase, melody.getLastRythm(), music.respirationAtTheMoment(beat)) spaceInFrase = spaceInFrase - templength melody.nextRythm(templength) melody.nextNote(getNextNote(melody, beat, scale, chords, bar)) if (beat % bar == 0): force = 4 else: force = 0 melody.forceEvent(music.getForce(force, beat)) #beats must be counted in ints, because you can't use a float as the index of chords[] if (templength == int(templength)): beat = beat + templength else: oddsAndEnds = oddsAndEnds + templength beat = beat + int(oddsAndEnds) oddsAndEnds = oddsAndEnds - int( oddsAndEnds ) #remember the remainder of the beat, so we don't mess up calculations return melody.getMusic()
def generateMelody(bar, length, scale, chords, start = 0, theme = None): melody = voice.Voice(start) templength = 0 beat = start #monesko isku menossa spaceInFrase = 0 oddsAndEnds = 0 length = length + beat #append theme to the start # print theme for note in theme: #theme syntax : [[rythm, note],[rythm,note]] # print "beat: "+str(beat) if (length > beat): melody.nextRythm(note[0]) melody.nextNote(note[1]) beat = beat + note[0]#Tahan voisi tehda esim. transponoinnin sointuihin. # print note else: break while (length > beat): frase = nextFrase(bar) # print "frase first: "+str(frase) # print "length-beat: "+str(length-beat) if (frase > (length-beat)): frase = length - beat spaceInFrase = frase # print "frase: "+str(frase) while (spaceInFrase > 0): #one frase at a time templength = probabilities.getRythm(spaceInFrase, melody.getLastRythm(), music.respirationAtTheMoment(beat)) spaceInFrase = spaceInFrase - templength melody.nextRythm(templength) melody.nextNote(getNextNote(melody, beat, scale, chords, bar)) if (beat%bar == 0): force = 4 else: force = 0 melody.forceEvent(music.getForce(force, beat)) #beats must be counted in ints, because you can't use a float as the index of chords[] if (templength == int(templength)): beat = beat + templength else: oddsAndEnds = oddsAndEnds + templength beat = beat + int(oddsAndEnds) oddsAndEnds = oddsAndEnds - int(oddsAndEnds)#remember the remainder of the beat, so we don't mess up calculations return melody.getMusic()
def generateTheme(bar, length, scale, chords):#does not use all info at the moment global lastInterval theme = [] space = length lastnote = 0 note = 0 while (space > 0): if (theme == []): rythm = 0 lastnote = scale[0] else: rythm = probabilities.getRythm(space, theme[-1][0]) lastnote = theme[-1][1] space = space - rythm while True: interval = probabilities.getInterval(lastInterval) note = lastnote + interval lastInterval = interval if (note%1200 in scale and note > -1000 and note < 3000): break theme.append([rythm, note]) lastnote = note return theme
def generateTheme(bar, length, scale, chords): #does not use all info at the moment global lastInterval theme = [] space = length lastnote = 0 note = 0 while (space > 0): if (theme == []): rythm = 0 lastnote = scale[0] else: rythm = probabilities.getRythm(space, theme[-1][0]) lastnote = theme[-1][1] space = space - rythm while True: interval = probabilities.getInterval(lastInterval) note = lastnote + interval lastInterval = interval if (note % 1200 in scale and note > -1000 and note < 3000): break theme.append([rythm, note]) lastnote = note return theme