Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Generation
diff options
context:
space:
mode:
authorOli2 <olivier.belanger@umontreal.ca>2007-03-20 08:29:22 (GMT)
committer Oli2 <olivier.belanger@umontreal.ca>2007-03-20 08:29:22 (GMT)
commit413885de99b69e13b29a1daea54dbce5682b97c8 (patch)
treef1daa61fc8f522ec102350b2e23949b9d6fa788b /Generation
parentfb75c8c382ebd2260a2600c6bfdfc0efefe6449d (diff)
algo little speed-up
Diffstat (limited to 'Generation')
-rw-r--r--Generation/GenerationPitch.py7
-rw-r--r--Generation/GenerationRythm.py60
-rwxr-xr-xGeneration/Generator.py41
3 files changed, 67 insertions, 41 deletions
diff --git a/Generation/GenerationPitch.py b/Generation/GenerationPitch.py
index 7bfe2ff..99fceaa 100644
--- a/Generation/GenerationPitch.py
+++ b/Generation/GenerationPitch.py
@@ -34,8 +34,10 @@ class GenerationPitch:
numberOfPitch = int( ( 1 - (parameters.pitchRegularity*.8) ) * 10 + 1 )
step = -(8 - (int(parameters.step * 8)))
max = len(table_pitch)-1
+ nextValue = self.pitchMethod.getNextValue
+ tonique = GenerationConstants.DEFAULT_TONIQUE
for i in range(numberOfPitch):
- append((table_pitch[self.pitchMethod.getNextValue(step, max)]) + GenerationConstants.DEFAULT_TONIQUE)
+ append((table_pitch[nextValue(step, max)]) + tonique)
restOfNotes = range( length - numberOfPitch )
for i in restOfNotes:
position = i % numberOfPitch
@@ -46,8 +48,9 @@ class GenerationPitch:
pitchSequence = []
append = pitchSequence.append
max = len(drumPitch) - 1
+ rand = random.randint
for i in range(length):
- append(drumPitch[ random.randint( 0, max ) ] )
+ append(drumPitch[ rand( 0, max ) ] )
return pitchSequence
# def harmonicPitchSequence( self, rythmSequence, parameters, table_pitch, harmonicSequence ):
diff --git a/Generation/GenerationRythm.py b/Generation/GenerationRythm.py
index d3d1e62..56e9199 100644
--- a/Generation/GenerationRythm.py
+++ b/Generation/GenerationRythm.py
@@ -95,62 +95,76 @@ class GenerationRythm:
countDown = 0
onsetTime = None
beatsPerPage = int( barLength / Config.TICKS_PER_BEAT )
+ randInt = random.randint
+
+ upBeatsAppend = upBeats.append
if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.PUNCH:
registerDensity = 0.5
downBeatRecurence = 4
+ upBeatOffset = Config.TICKS_PER_BEAT / 2
downBeats = [x for x in GenerationConstants.DRUM_PUNCH_ACCENTS[ beatsPerPage ]]
for downBeat in downBeats:
- upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 )
+ upBeatsAppend( downBeat + upBeatOffset )
- if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.LOW:
+ elif Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.LOW:
registerDensity = 1.5
downBeatRecurence = 4
+ upBeatOffset = Config.TICKS_PER_BEAT / 2
downBeats = [x for x in GenerationConstants.DRUM_LOW_ACCENTS[ beatsPerPage ]]
for downBeat in downBeats:
- upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 )
+ upBeatsAppend( downBeat + upBeatOffset )
- if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.MID:
+ elif Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.MID:
registerDensity = 1
downBeatRecurence = 1
+ upBeatOffset = Config.TICKS_PER_BEAT / 4
downBeats = [x for x in GenerationConstants.DRUM_MID_ACCENTS[ beatsPerPage ]]
for downBeat in downBeats:
- upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 )
+ upBeatsAppend( downBeat + upBeatOffset )
- if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.HIGH:
+ elif Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.HIGH:
registerDensity = 1.5
downBeatRecurence = 1
+ upBeatOffset = Config.TICKS_PER_BEAT / 4
downBeats = [x for x in GenerationConstants.DRUM_HIGH_ACCENTS[ beatsPerPage ]]
for downBeat in downBeats:
- upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 )
-
- for i in range( int( density * registerDensity * len( downBeats ) ) ):
- if random.random() < ( parameters.rythmRegularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ):
- binSelection.append( 1 )
+ upBeatsAppend( downBeat + upBeatOffset )
+
+ list = range( int( density * registerDensity * len( downBeats ) ) )
+ rand = random.random
+ binCount = binSelection.count
+ binAppend = binSelection.append
+ for i in list:
+ if rand() < ( parameters.rythmRegularity * downBeatRecurence ) and binCount( 1 ) < len( downBeats ):
+ binAppend( 1 )
else:
- if binSelection.count( 0 ) < len( downBeats ):
- binSelection.append( 0 )
+ if binCount( 0 ) < len( downBeats ):
+ binAppend( 0 )
else:
- binSelection.append( 1 )
+ binAppend( 1 )
- countDown = binSelection.count( 1 )
+ countDown = binCount( 1 )
+ seqAppend = rythmSequence.append
length = len(downBeats) - 1
+ downPop = downBeats.pop
for i in range( countDown ):
- ran1 = random.randint(0, length)
- ran2 = random.randint(0, length)
+ ran1 = randInt(0, length)
+ ran2 = randInt(0, length)
randMin = min(ran1, ran2)
- onsetTime = downBeats.pop(randMin)
- rythmSequence.append( onsetTime )
+ onsetTime = downPop(randMin)
+ seqAppend( onsetTime )
length -= 1
length = len(upBeats) - 1
+ upPop = upBeats.pop
for i in range( len( binSelection ) - countDown ):
- ran1 = random.randint(0, length)
- ran2 = random.randint(0, length)
+ ran1 = randInt(0, length)
+ ran2 = randInt(0, length)
randMin = min(ran1, ran2)
- onsetTime = upBeats.pop(randMin)
- rythmSequence.append( onsetTime )
+ onsetTime = upPop(randMin)
+ seqAppend( onsetTime )
length -= 1
rythmSequence.sort()
diff --git a/Generation/Generator.py b/Generation/Generator.py
index 2da4725..066aab7 100755
--- a/Generation/Generator.py
+++ b/Generation/Generator.py
@@ -52,16 +52,19 @@ def generator1(
def makeGainSequence( onsetList ):
gainSequence = []
+ append = gainSequence.append
+ rand = random.uniform
max = GenerationConstants.GAIN_MAX_BOUNDARY
midMax = GenerationConstants.GAIN_MID_MAX_BOUNDARY
+ midMin = GenerationConstants.GAIN_MID_MIN_BOUNDARY
+ min = GenerationConstants.GAIN_MIN_BOUNDARY
for onset in onsetList:
if onset == 0:
- gain = random.uniform(GenerationConstants.GAIN_MID_MAX_BOUNDARY, GenerationConstants.GAIN_MAX_BOUNDARY)
+ append(rand(midMax, max))
elif ( onset % Config.TICKS_PER_BEAT) == 0:
- gain = random.uniform(GenerationConstants.GAIN_MID_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MAX_BOUNDARY)
+ append(rand(midMin, midMax))
else:
- gain = random.uniform(GenerationConstants.GAIN_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MIN_BOUNDARY)
- gainSequence.append(gain)
+ append(rand(min, midMin))
return gainSequence
def makeDurationSequence( onsetList, parameters, table_duration, barLength, currentInstrument ):
@@ -71,13 +74,14 @@ def generator1(
durationSequence = [duration] * len(onsetList)
return durationSequence
+ append = durationSequence.append
+ proba = Utils.prob2
if len( onsetList ) > 1:
for i in range(len(onsetList) - 1):
- duration = (onsetList[i+1] - onsetList[i]) * Utils.prob2( table_duration )
- durationSequence.append(duration)
- durationSequence.append(( barLength - onsetList[-1]) * Utils.prob2( table_duration ))
+ append((onsetList[i+1] - onsetList[i]) * proba( table_duration ))
+ append(( barLength - onsetList[-1]) * proba( table_duration ))
elif len( onsetList ) == 1:
- durationSequence.append( ( barLength - onsetList[0] ) * Utils.prob2( table_duration ))
+ append( ( barLength - onsetList[0] ) * proba( table_duration ))
return durationSequence
def pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch = None ):
@@ -98,17 +102,21 @@ def generator1(
durationSequence = makeDurationSequence(rythmSequence, parameters, table_duration, barLength, currentInstrument)
numOfNotes = range(len(rythmSequence))
+ rand = random.random
+ append = trackNotes.append
+ pan = GenerationConstants.DEFAULT_PAN
+ instrument_id = Config.INSTRUMENTS[instrument[trackId]].instrumentId
for i in numOfNotes:
if drumPitch:
- if ( random.random() * fillDrum ) > ( parameters.silence * .5 ):
+ if ( rand() * fillDrum ) > ( parameters.silence * .5 ):
if fillDrum != 1:
if rythmSequence[i] not in trackOnsets or pitchSequence[i] not in trackPitchs:
- trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], GenerationConstants.DEFAULT_PAN, durationSequence[i], trackId, Config.INSTRUMENTS[instrument[ trackId ]].instrumentId, 0.002, 0.098, 0.1, 0, 1000, False, 'edit' ) )
+ append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], pan, durationSequence[i], trackId, instrument_id, 0.002, 0.098, 0.1, 0, 1000, False, 'edit' ) )
else:
- trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], GenerationConstants.DEFAULT_PAN, durationSequence[i], trackId, Config.INSTRUMENTS[instrument[ trackId ]].instrumentId, 0.002, 0.098, 0.1, 0, 1000, False, 'edit' ) )
+ append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], pan, durationSequence[i], trackId, instrument_id, 0.002, 0.098, 0.1, 0, 1000, False, 'edit' ) )
else:
- if random.random() > parameters.silence:
- trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], GenerationConstants.DEFAULT_PAN, durationSequence[i], trackId, Config.INSTRUMENTS[instrument[ trackId ]].instrumentId, 0.002, 0.1, 0.1, 0, 1000, False, 'edit' ) )
+ if rand() > parameters.silence:
+ append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], pan, durationSequence[i], trackId, instrument_id, 0.002, 0.1, 0.1, 0, 1000, False, 'edit' ) )
trackDictionary[ trackId ][ pageId ] = trackNotes
@@ -137,10 +145,11 @@ def generator1(
for pageId in pageIds:
barLength = Config.TICKS_PER_BEAT * nbeats[ pageId ]
trackOfNotes = []
+ pageCycle = selectedPageCount % 4 # this should be fix in the meta algo
if instrument[ trackId ][0:4] == 'drum':
- if ( selectedPageCount % 4 ) in [1,2]:
+ if pageCycle in [1,2]:
trackDictionary[ trackId ][ pageId ] = [ n for n in trackDictionary[ trackId ][ lastPageId ] ]
- elif ( selectedPageCount % 4 ) == 3:
+ elif pageCycle == 3:
trackOfNotes = [ n for n in trackDictionary[ trackId ][ lastPageId ] ]
trackOnsets = [n.onset for n in trackOfNotes]
trackPitchs = [n.pitch for n in trackOfNotes]
@@ -150,7 +159,7 @@ def generator1(
for drumPitch in GenerationConstants.DRUM_COMPLEXITY4:
pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch )
parameters.rythmRegularity = rythmRegTemp
- elif ( selectedPageCount % 4 ) == 0:
+ elif pageCycle == 0:
fillDrum = 1
for drumPitch in streamOfPitch:
pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch )