Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
def generateAccompaniment0(bar, length, scale, chords, starttime):
	accompaniment = voice.Voice(starttime)
	note = None
	beat = starttime
	starttime = int(starttime/bar) #because the chords are ordered by bar
	for i in range (starttime, starttime+int(length/bar)):#process one chord and bar at a time
		for j in range (0, bar*4):
			note = scale[chords[i]]
			accompaniment.nextNote(note)
			accompaniment.nextRythm(0.25)
			if (j == 0 or j == 7 or j==3 or j == 10):			
				force = -4	
			else:
				force = -11
			force = music.getForce(force, beat)
			beat = beat + 0.25	
			accompaniment.forceEvent(force)
	return accompaniment.getMusic()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def generateAccompaniment2(bar, length, scale, chords, starttime):
	accompaniment = voice.Voice(starttime)
	acc = 0
	note = None
	beat = starttime
	starttime = int(starttime/bar) #because the chords are ordered by bar
	for i in range (starttime, starttime+int(length/bar)):#process one chord and bar at a time
		for j in range (0, bar):
			note = scale[chords[i]+acc]
			accompaniment.nextNote(note)
			acc = acc + 4
			if (acc >= 4):	
				acc = 0
			accompaniment.nextRythm(1)
			beat = beat + 1	
			force = -6
			force = music.getForce(force, beat)
			accompaniment.forceEvent(force)
	return accompaniment.getMusic()
Ejemplo n.º 5
0
def generateAccompaniment1(bar, length, scale, chords, starttime):
	accompaniment = voice.Voice(starttime)
	acc = 0
	beat = starttime
	note = None
	starttime = int(starttime/bar) #because the chords are ordered by bar
	for i in range (starttime, starttime+int(length/bar)):#process one chord and bar at a time
		for j in range (0, bar*2):
			note = scale[chords[i]+acc]
			accompaniment.nextNote(note)
			acc = acc + 2
			if (acc == 6):	
				acc = 0
			accompaniment.nextRythm(0.5)
			if (beat%bar == 0):
				force = 2
			else:
				force = -8	
			force = music.getForce(force, beat)
			beat = beat + 0.5
			accompaniment.forceEvent(force)
	return accompaniment.getMusic()