diff options
author | Oli <olpc@localhost.localdomain> | 2007-03-06 01:52:23 (GMT) |
---|---|---|
committer | Oli <olpc@localhost.localdomain> | 2007-03-06 01:52:23 (GMT) |
commit | b01119220d8d174b73f0f9d0d249e5f162ecda0e (patch) | |
tree | 259e0bceafd604fbf4ee3ddc7810a39b4082baed /Generation | |
parent | d4f2d55906b97783a79233926561fe372564eebb (diff) |
algo stuff, 3 loading presetsalgo stuff, 3 loading presetsalgo stuff, 3 loading presets
Diffstat (limited to 'Generation')
-rwxr-xr-x | Generation/Drunk.py | 33 | ||||
-rwxr-xr-x | Generation/GenerationConstants.py | 71 | ||||
-rwxr-xr-x | Generation/GenerationParametersWindow.py | 6 | ||||
-rw-r--r-- | Generation/GenerationPitch.py | 25 | ||||
-rwxr-xr-x | Generation/Generator.py | 7 |
5 files changed, 84 insertions, 58 deletions
diff --git a/Generation/Drunk.py b/Generation/Drunk.py index 5a36b11..4649aff 100755 --- a/Generation/Drunk.py +++ b/Generation/Drunk.py @@ -5,10 +5,9 @@ import random -# TODO: replace magic numbers with constants class Drunk: - def __init__( self, maxValue ): - self.lastValue = random.randint( 0, maxValue ) + def __init__( self, minValue, maxValue ): + self.lastValue = random.randint( minValue, maxValue ) def getNextValue( self, maxStepSize, maxValue ): if self.lastValue < 0 or self.lastValue > maxValue: @@ -23,6 +22,14 @@ class Drunk: minStepSize = 0 self.lastValue += direction * random.randint( minStepSize, stepSize ) + + if self.lastValue < 0: + self.lastValue = 0 + elif self.lastValue > 14: + self.lastValue = 14 + else: + self.lastValue = self.lastValue + return self.lastValue def getDirection( self, maxValue ): @@ -40,9 +47,9 @@ class Drunk: return min( maxStepSize, maxValue - self.lastValue ) class DroneAndJump( Drunk ): - def __init__( self, maxValue ): - Drunk.__init__( self, maxValue ) - self.beforeLastValue = random.randint( 0, maxValue ) + def __init__( self, minValue, maxValue ): + Drunk.__init__( self, minValue, maxValue ) + self.beforeLastValue = random.randint( minValue, maxValue ) self.lastValue = self.beforeLastValue + 1 def getNextValue( self, maxStepSize, maxValue ): @@ -55,29 +62,29 @@ class DroneAndJump( Drunk ): return self.lastValue def getStepSize( self, direction, maxStepSize, maxValue ): - if random.randint( 0, 100 ) < 25: + if random.randint( 0, 100 ) < 35: return Drunk.getStepSize( self, direction, maxStepSize, maxValue ) else: return Drunk.getStepSize( self, direction, 0, maxValue ) class Repeter( Drunk ): - def __init__( self, maxValue ): - Drunk.__init__( self, maxValue) - self.lastValue = random.randint( 0, maxValue) + def __init__( self, minValue, maxValue ): + Drunk.__init__( self, minValue, maxValue) + self.lastValue = random.randint( minValue, maxValue) def getNextValue( self, maxStepSize, maxValue ): self.lastValue = Drunk.getNextValue( self, abs(maxStepSize), maxValue ) return self.lastValue def getStepSize( self, direction, maxStepSize, maxValue ): - if random.randint( 0, 100 ) < 15: + if random.randint( 0, 100 ) < 20: return Drunk.getStepSize( self, direction, maxStepSize, maxValue ) else: return Drunk.getStepSize( self, direction, 0, maxValue ) class Loopseg( Drunk ): - def __init__( self, maxValue ): - Drunk.__init__( self, maxValue ) + def __init__( self, minValue, maxValue ): + Drunk.__init__( self, minValue, maxValue ) self.recordedValues = [] self.recordState = 2 self.recordPlayback = 0 diff --git a/Generation/GenerationConstants.py b/Generation/GenerationConstants.py index 2c1d4fd..dd34dd8 100755 --- a/Generation/GenerationConstants.py +++ b/Generation/GenerationConstants.py @@ -1,3 +1,5 @@ +import random + class GenerationConstants: TWO_ROOT_TWELVE = pow( 2, 1./12 ) @@ -5,44 +7,55 @@ class GenerationConstants: #STANDALONE_BEAT_LENGTH = 12 + TABLE_ONSET_VALUES = [ 3, 4, 6, 8, 12, 18, 24, 36, 48 ] + + # scaling constants + MAJOR = 0 + HARMONIC_MINOR = 1 + NATURAL_MINOR = 2 + PHRYGIEN = 3 + DORIEN = 4 + LYDIEN = 5 + MYXOLYDIEN = 6 + + SCALES = { MAJOR : [ -12, -10, -8, -7, -5, -3, -1, 0, 2, 4, 5, 7, 9, 11, 12 ], + HARMONIC_MINOR : [ -12, -10, -9, -7, -5, -4, -1, 0, 2, 3, 5, 7, 8, 11, 12 ], + NATURAL_MINOR : [ -12, -10, -9, -7, -5, -4, -2, 0, 2, 3, 5, 7, 8, 10, 12 ], + PHRYGIEN : [ -12, -11, -9, -7, -5, -4, -2, 0, 1, 3, 5, 7, 8, 10, 12 ], + DORIEN : [ -12, -10, -9, -7, -5, -3, -2, 0, 2, 3, 5, 7, 9, 10, 12 ], + LYDIEN : [ -12, -10, -8, -6, -5, -3, -1, 0, 2, 4, 6, 7, 9, 11, 12 ], + MYXOLYDIEN : [ -12, -10, -8, -7, -5, -3, -2, 0, 2, 4, 5, 7, 9, 10, 12 ]} + + # Default parameters for algorithmic generation - DEFAULT_DENSITY = 0.4 - DEFAULT_RYTHM_REGULARITY = .75 - DEFAULT_STEP = 0.5 - DEFAULT_PITCH_REGULARITY = 0.5 - DEFAULT_ARTICULE = 0.8 - DEFAULT_SILENCE = 0.2 + + RYTHM_DENSITY_BANK = [.4, 1., .92] + RYTHM_REGU_BANK = [.75, .8, .85] + PITCH_REGU_BANK = [.5, .8, .5] + PITCH_STEP_BANK = [.5, .7, .15] + DURATION_BANK = [.8, .8, .8] + SILENCE_BANK = [.2, .5, .4] + PATTERN_BANK = [0, 3, 1] + SCALE_BANK = [MAJOR, NATURAL_MINOR, LYDIEN] + + chooseDefault = random.randint(0,2) + + DEFAULT_DENSITY = RYTHM_DENSITY_BANK[chooseDefault] + DEFAULT_RYTHM_REGULARITY = RYTHM_REGU_BANK[chooseDefault] + DEFAULT_PITCH_REGULARITY = PITCH_REGU_BANK[chooseDefault] + DEFAULT_STEP = PITCH_STEP_BANK[chooseDefault] + DEFAULT_DURATION = DURATION_BANK[chooseDefault] + DEFAULT_SILENCE = SILENCE_BANK[chooseDefault] + DEFAULT_PATTERN = PATTERN_BANK[chooseDefault] + DEFAULT_SCALE = SCALE_BANK[chooseDefault] DEFAULT_RYTHM_METHOD = 0 DEFAULT_PITCH_METHOD = 0 DEFAULT_PAN = 0.5 - DEFAULT_PATTERN = 0 - DEFAULT_PITCH_VARIATION = 0 # 0 = 'melodic' 1 = 'harmonic' DEFAULT_RYTHM_VARIATION = 0 # 0 = 'Cellule' 1 = 'Xnoise' - TABLE_ONSET_VALUES = [ 3, 4, 6, 8, 12, 18, 24, 36, 48 ] - - # scaling constants - MAJOR_SCALE = 0 - HARMONIC_MINOR_SCALE = 1 - NATURAL_MINOR_SCALE =2 - PHRYGIEN_SCALE = 3 - DORIEN_SCALE = 4 - LYDIEN_SCALE = 5 - MYXOLYDIEN_SCALE = 6 - - SCALES = { MAJOR_SCALE : [ -12, -10, -8, -7, -5, -3, -1, 0, 2, 4, 5, 7, 9, 11, 12 ], - HARMONIC_MINOR_SCALE : [ -12, -10, -9, -7, -5, -4, -1, 0, 2, 3, 5, 7, 8, 11, 12 ], - NATURAL_MINOR_SCALE : [ -12, -10, -9, -7, -5, -4, -2, 0, 2, 3, 5, 7, 8, 10, 12 ], - PHRYGIEN_SCALE : [ -12, -11, -9, -7, -5, -4, -2, 0, 1, 3, 5, 7, 8, 10, 12 ], - DORIEN_SCALE : [ -12, -10, -9, -7, -5, -3, -2, 0, 2, 3, 5, 7, 9, 10, 12 ], - LYDIEN_SCALE : [ -12, -10, -8, -6, -5, -3, -1, 0, 2, 4, 6, 7, 9, 11, 12 ], - MYXOLYDIEN_SCALE : [ -12, -10, -8, -7, -5, -3, -2, 0, 2, 4, 5, 7, 9, 10, 12 ]} - - DEFAULT_SCALE = MAJOR_SCALE - DEFAULT_TONIQUE = 36 I = [ 0, 2, 4, 7, 9, 11, 14 ] diff --git a/Generation/GenerationParametersWindow.py b/Generation/GenerationParametersWindow.py index 6ccc6f4..d74a058 100755 --- a/Generation/GenerationParametersWindow.py +++ b/Generation/GenerationParametersWindow.py @@ -28,7 +28,7 @@ class GenerationParametersWindow( gtk.VBox ): self.rythmRegularity = GenerationConstants.DEFAULT_RYTHM_REGULARITY self.pitchRegularity = GenerationConstants.DEFAULT_PITCH_REGULARITY self.pitchStep = GenerationConstants.DEFAULT_STEP - self.duration = GenerationConstants.DEFAULT_ARTICULE + self.duration = GenerationConstants.DEFAULT_DURATION self.silence = GenerationConstants.DEFAULT_SILENCE # Generation Panel Setup @@ -196,6 +196,8 @@ class GenerationParametersWindow( gtk.VBox ): if self.firstButton == None: self.firstButton = iButton iButton.connect('clicked' , self.handleMethod , methodNames.index(meth)) + if methodNames.index(meth) == self.pattern: + iButton.set_active(True) methodBox.pack_start(iButton, False, False) metaAlgoBox.pack_start(methodBox, False, False, 5) @@ -207,6 +209,8 @@ class GenerationParametersWindow( gtk.VBox ): if self.firstButton == None: self.firstButton = iButton iButton.connect('clicked' , self.handleScale , scaleNames.index(scale)) + if scaleNames.index(scale) == self.scale: + iButton.set_active(True) scaleBox.pack_start(iButton, False, False) metaAlgoBox.pack_start(scaleBox, False, False) diff --git a/Generation/GenerationPitch.py b/Generation/GenerationPitch.py index 5949d08..1660a64 100644 --- a/Generation/GenerationPitch.py +++ b/Generation/GenerationPitch.py @@ -6,16 +6,17 @@ from Generation.GenerationConstants import GenerationConstants class GenerationPitch: def __init__( self ): - fakeMaximum = 4 - self.drunk = Drunk.Drunk( fakeMaximum ) - self.droneAndJump = Drunk.DroneAndJump( fakeMaximum ) - self.repeter = Drunk.Repeter( fakeMaximum ) - self.loopseg = Drunk.Loopseg( fakeMaximum ) - - self.harmonicDrunk = Drunk.Drunk( fakeMaximum ) - self.harmonicDroneAndJump = Drunk.DroneAndJump( fakeMaximum ) - self.harmonicRepeter = Drunk.Repeter( fakeMaximum ) - self.harmonicLoopseg = Drunk.Loopseg( fakeMaximum ) + MIN = 5 + MAX = 10 + self.drunk = Drunk.Drunk( MIN, MAX ) + self.droneAndJump = Drunk.DroneAndJump( MIN, MAX ) + self.repeter = Drunk.Repeter( MIN, MAX ) + self.loopseg = Drunk.Loopseg( MIN, MAX ) + + self.harmonicDrunk = Drunk.Drunk( MIN, MAX ) + self.harmonicDroneAndJump = Drunk.DroneAndJump( MIN, MAX ) + self.harmonicRepeter = Drunk.Repeter( MIN, MAX ) + self.harmonicLoopseg = Drunk.Loopseg( MIN, MAX ) def chooseMethod( self, pattern ): if pattern == 0: return self.drunk @@ -30,11 +31,11 @@ class GenerationPitch: elif pattern == 3: return self.harmonicLoopseg def drunkPitchSequence(self, length, parameters, table_pitch): - pitchMethod = self.chooseMethod( parameters.pattern ) + self.pitchMethod = self.chooseMethod( parameters.pattern ) pitchSequence = [] numberOfPitch = int( ( 1 - (parameters.pitchRegularity*.8) ) * 10 + 1 ) for i in range(numberOfPitch): - pitchSequence.append((table_pitch[pitchMethod.getNextValue(-(10 - (int(parameters.step * 10))), (len(table_pitch)-1))]) + GenerationConstants.DEFAULT_TONIQUE) + pitchSequence.append((table_pitch[self.pitchMethod.getNextValue(-(8 - (int(parameters.step * 8))), (len(table_pitch)-1))]) + GenerationConstants.DEFAULT_TONIQUE) for i in range( length - numberOfPitch ): position = i % numberOfPitch pitchSequence.append( pitchSequence[ position ] ) diff --git a/Generation/Generator.py b/Generation/Generator.py index d6ce88a..c2db1f0 100755 --- a/Generation/Generator.py +++ b/Generation/Generator.py @@ -18,7 +18,7 @@ class GenerationParameters: rythmRegularity = GenerationConstants.DEFAULT_RYTHM_REGULARITY, step = GenerationConstants.DEFAULT_STEP, pitchRegularity = GenerationConstants.DEFAULT_PITCH_REGULARITY, - articule = GenerationConstants.DEFAULT_ARTICULE, + articule = GenerationConstants.DEFAULT_DURATION, silence = GenerationConstants.DEFAULT_SILENCE, rythmMethod = GenerationConstants.DEFAULT_RYTHM_METHOD, pitchMethod = GenerationConstants.DEFAULT_PITCH_METHOD, @@ -52,7 +52,7 @@ def generator1( pitchShuffle = PitchShuffle() makePitch = GenerationPitch() - makeHarmonicSequence = Drunk.Drunk( 7 ) + makeHarmonicSequence = Drunk.Drunk( 0, 7 ) rythmShuffle = RythmShuffle( ) rythmReverse = RythmReverse( ) @@ -116,6 +116,7 @@ def generator1( rythmSequence = makeRythm.xnoiseRythmSequence(parameters) if parameters.pitchMethod == 0: pitchSequence = makePitch.drunkPitchSequence(len(rythmSequence), parameters, table_pitch) + makePitch.pitchMethod.__init__(5, 12) elif parameters.pitchMethod == 1: pitchSequence = makePitch.harmonicPitchSequence( rythmSequence, parameters, table_pitch, harmonicSequence ) gainSequence = makeGainSequence(rythmSequence) @@ -186,7 +187,7 @@ def variate( pitchShuffle = PitchShuffle() makePitch = GenerationPitch() - makeHarmonicSequence = Drunk.Drunk( 7 ) + makeHarmonicSequence = Drunk.Drunk(0, 7 ) rythmShuffle = RythmShuffle( ) rythmReverse = RythmReverse( ) |