Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Generation
diff options
context:
space:
mode:
authorOli <olivier.belanger@umontreal.ca>2007-08-15 20:36:49 (GMT)
committer Oli <olivier.belanger@umontreal.ca>2007-08-15 20:36:49 (GMT)
commit2d3fcf6b982f5f62665562ca8cc2047a50cead99 (patch)
tree3ec8990953ea3b93623051941ecc7db17788e761 /Generation
parenta9b53a11130bf2509c9a2627612ce7fb13f1f631 (diff)
generate preview melody in Generation Palette
Diffstat (limited to 'Generation')
-rw-r--r--Generation/GenerationRythm.py54
-rwxr-xr-xGeneration/Generator.py27
2 files changed, 37 insertions, 44 deletions
diff --git a/Generation/GenerationRythm.py b/Generation/GenerationRythm.py
index 9b611d4..5dc4bfa 100644
--- a/Generation/GenerationRythm.py
+++ b/Generation/GenerationRythm.py
@@ -6,7 +6,7 @@ from Generation.GenerationConstants import GenerationConstants
class GenerationRythm:
- def celluleRythmSequence(self, parameters, barLength, trackInstrument ):
+ def celluleRythmSequence(self, parameters, barLength, trackInstrument=None ):
rythmSequence = [0, ]
self.count = 0
lastOnsetTime = 0
@@ -26,7 +26,7 @@ class GenerationRythm:
listLen = range( int( barLength / Config.TICKS_PER_BEAT * 8 ) )
randInt = random.randint
for i in listLen:
- if self.count == 0:
+ if self.count == 0:
currentOnsetValue = onsetValue + ( randInt( 0, onsetDeviation ) - ( onsetDeviation / 2 ) )
if currentOnsetValue < 0:
currentOnsetValue = 0
@@ -40,45 +40,45 @@ class GenerationRythm:
if self.count < (GenerationConstants.DOUBLE_HOW_MANY - 1):
self.count += 1
else:
- self.count = 0
- onsetTime = onsetDelta + lastOnsetTime
- lastOnsetTime = onsetTime
+ self.count = 0
+ onsetTime = onsetDelta + lastOnsetTime
+ lastOnsetTime = onsetTime
if onsetTime < barLength:
rythmSequence.append(onsetTime)
continue
else:
- break
+ break
elif onsetDelta == GenerationConstants.HALF_TRIPLET_TICK_DUR:
if self.count < (GenerationConstants.HALF_TRIPLET_HOW_MANY - 1):
self.count += 1
else:
- self.count = 0
- onsetTime = onsetDelta + lastOnsetTime
- lastOnsetTime = onsetTime
+ self.count = 0
+ onsetTime = onsetDelta + lastOnsetTime
+ lastOnsetTime = onsetTime
if onsetTime < barLength:
rythmSequence.append(onsetTime)
continue
else:
- break
+ break
elif onsetDelta == GenerationConstants.HOLE_TRIPLET_TICK_DUR:
if self.count < (GenerationConstants.HOLE_TRIPLET_HOW_MANY - 1):
self.count += 1
else:
- self.count = 0
- onsetTime = onsetDelta + lastOnsetTime
- lastOnsetTime = onsetTime
+ self.count = 0
+ onsetTime = onsetDelta + lastOnsetTime
+ lastOnsetTime = onsetTime
if onsetTime < barLength:
rythmSequence.append(onsetTime)
continue
else:
- break
+ break
- onsetTime = onsetDelta + lastOnsetTime
- lastOnsetTime = onsetTime
+ onsetTime = onsetDelta + lastOnsetTime
+ lastOnsetTime = onsetTime
if onsetTime < barLength:
rythmSequence.append(onsetTime)
else:
- break
+ break
return rythmSequence
def xnoiseRythmSequence(self, parameters, barLength ):
@@ -88,7 +88,7 @@ class GenerationRythm:
# need radioButton with 0 for random choose and each generator independant
whichRandomGenerator = random.randint(0, 4)
maximumNumberOfNotes = int( (parameters.density) * GenerationConstants.MAX_NOTES_PER_BAR)
-
+
for i in range(maximumNumberOfNotes):
while onsetTime in rythmSequence:
if whichRandomGenerator == 0:
@@ -96,13 +96,13 @@ class GenerationRythm:
elif whichRandomGenerator == 1:
onsetTime = 1 - random.expovariate(GenerationConstants.RANDOM_EXPO_PARAM * randomParamScaler)
elif whichRandomGenerator == 2:
- onsetTime = random.gauss(GenerationConstants.RANDOM_GAUSS_PARAM1,
+ onsetTime = random.gauss(GenerationConstants.RANDOM_GAUSS_PARAM1,
GenerationConstants.RANDOM_GAUSS_PARAM2 * (3 - randomParamScaler))
elif whichRandomGenerator == 3:
- onsetTime = random.betavariate(GenerationConstants.RANDOM_BETA_PARAM * randomParamScaler,
+ onsetTime = random.betavariate(GenerationConstants.RANDOM_BETA_PARAM * randomParamScaler,
GenerationConstants.RANDOM_BETA_PARAM * randomParamScaler)
elif whichRandomGenerator == 4:
- onsetTime = random.weibullvariate(GenerationConstants.RANDOM_WEIBULL_PARAM1,
+ onsetTime = random.weibullvariate(GenerationConstants.RANDOM_WEIBULL_PARAM1,
GenerationConstants.RANDOM_WEIBULL_PARAM2 * randomParamScaler)
onsetTime = int(onsetTime * (int(( barLength - 1) / GenerationConstants.DOUBLE_TICK_DUR))) * GenerationConstants.DOUBLE_TICK_DUR
@@ -117,7 +117,7 @@ class GenerationRythm:
rythmSequence.append(onsetTime)
rythmSequence.sort()
- return rythmSequence
+ return rythmSequence
def drumRythmSequence(self, parameters, trackInstrument, barLength ):
density = sqrt(parameters.density)
@@ -128,7 +128,7 @@ class GenerationRythm:
beats = []
countDown = 0
onsetTime = None
- beatsPerPage = int( barLength / Config.TICKS_PER_BEAT )
+ beatsPerPage = int( barLength / Config.TICKS_PER_BEAT )
randInt = random.randint
upBeatsAppend = upBeats.append
@@ -170,10 +170,10 @@ class GenerationRythm:
binCount = binSelection.count
binAppend = binSelection.append
for i in list:
- if rand() < ( parameters.rythmRegularity * downBeatRecurence ) and binCount( 1 ) < len( downBeats ):
- binAppend( 1 )
+ if rand() < ( parameters.rythmRegularity * downBeatRecurence ) and binCount( 1 ) < len( downBeats ):
+ binAppend( 1 )
else:
- if binCount( 0 ) < len( downBeats ):
+ if binCount( 0 ) < len( downBeats ):
binAppend( 0 )
else:
binAppend( 1 )
@@ -210,4 +210,4 @@ class GenerationRythm:
if self.count < threshold:
self.count += 1
else:
- self.count = 0
+ self.count = 0
diff --git a/Generation/Generator.py b/Generation/Generator.py
index 8cce48d..f12ef26 100755
--- a/Generation/Generator.py
+++ b/Generation/Generator.py
@@ -6,14 +6,12 @@ import Drunk
import Config
from Util.CSoundNote import CSoundNote
-from Generation.VariationPitch import *
-from Generation.VariationRythm import *
from Generation.GenerationConstants import GenerationConstants
from Generation.GenerationRythm import GenerationRythm
from Generation.GenerationPitch import GenerationPitch
class GenerationParameters:
- def __init__( self,
+ def __init__( self,
density = GenerationConstants.DEFAULT_DENSITY,
rythmRegularity = GenerationConstants.DEFAULT_RYTHM_REGULARITY,
step = GenerationConstants.DEFAULT_STEP,
@@ -35,7 +33,7 @@ class GenerationParameters:
self.pattern = pattern
self.scale = scale
-def generator1(
+def generator1(
parameters, # algorithm-specific parameters
volume, # [trackId: float(volume) ]
instrument, # [pageId][trackId: instrument]
@@ -48,7 +46,6 @@ def generator1(
makeRythm = GenerationRythm()
makePitch = GenerationPitch(parameters.pattern)
- #makeHarmonicSequence = Drunk.Drunk( 0, 7 )
def makeGainSequence( onsetList ):
gainSequence = []
@@ -63,10 +60,10 @@ def generator1(
append(rand(midMax, max))
elif ( onset % Config.TICKS_PER_BEAT) == 0:
append(rand(midMin, midMax))
- else:
+ else:
append(rand(min, midMin))
- return gainSequence
-
+ return gainSequence
+
def makeDurationSequence( onsetList, parameters, table_duration, barLength, currentInstrument ):
durationSequence = []
if Config.INSTRUMENTS[currentInstrument].soundClass == 'drum':
@@ -88,11 +85,11 @@ def generator1(
trackNotes = trackOfNotes
- if drumPitch:
+ if drumPitch:
currentInstrument = Config.INSTRUMENTS[instrument[pageId][trackId]].kit[drumPitch[0]].name
rythmSequence = makeRythm.drumRythmSequence(parameters, currentInstrument, barLength)
pitchSequence = makePitch.drumPitchSequence(len(rythmSequence), parameters, drumPitch, table_pitch )
- else:
+ else:
currentInstrument = instrument[pageId][trackId]
rythmSequence = makeRythm.celluleRythmSequence(parameters, barLength, currentInstrument)
pitchSequence = makePitch.drunkPitchSequence(len(rythmSequence),parameters, table_pitch)
@@ -120,18 +117,14 @@ def generator1(
trackDictionary[ trackId ][ pageId ] = trackNotes
-##################################################################################
- # begin generate()
-# harmonicSequence = []
-# for i in range( nbeats ):
-# harmonicSequence.append(
-# GenerationConstants.CHORDS_TABLE[ makeHarmonicSequence.getNextValue( 2, len( GenerationConstants.CHORDS_TABLE ) - 1 ) ] )
+##################################################################################
+ # begin generate()
table_duration = Utils.scale(parameters.articule, GenerationConstants.ARTICULATION_SCALE_MIN_MAPPING, GenerationConstants.ARTICULATION_SCALE_MAX_MAPPING, GenerationConstants.ARTICULATION_SCALE_STEPS)
table_pitch = GenerationConstants.SCALES[parameters.scale]
for trackId in trackIds:
- if trackId == 4: #instrument[pageId][trackId][0:4] == 'drum':
+ if trackId == 4: # drum index
if parameters.rythmRegularity > 0.75:
streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1
elif parameters.rythmRegularity > 0.5: