diff options
author | Oli2 <olivier.belanger@umontreal.ca> | 2007-03-10 09:07:50 (GMT) |
---|---|---|
committer | Oli2 <olivier.belanger@umontreal.ca> | 2007-03-10 09:07:50 (GMT) |
commit | 6c80aaf9f7fd203dfac220361773ab4de4ec27ce (patch) | |
tree | ef76800beea5ef6550c45a851ec1291cc96e4eb6 /Generation | |
parent | 5e7caf23a63d8f98555d01d2b5df274552b7a392 (diff) |
algo clean-up, cool stuff on drums...
Diffstat (limited to 'Generation')
-rwxr-xr-x | Generation/GenerationConstants.py | 109 | ||||
-rw-r--r-- | Generation/GenerationPitch.py | 33 | ||||
-rw-r--r-- | Generation/GenerationRythm.py | 53 | ||||
-rwxr-xr-x | Generation/Generator.py | 94 | ||||
-rw-r--r-- | Generation/bList.py | 67 |
5 files changed, 210 insertions, 146 deletions
diff --git a/Generation/GenerationConstants.py b/Generation/GenerationConstants.py index 3dbddca..8be5de2 100755 --- a/Generation/GenerationConstants.py +++ b/Generation/GenerationConstants.py @@ -5,7 +5,8 @@ class GenerationConstants: TWO_ROOT_TWELVE = pow( 2, 1./12 ) MAX_NOTES_PER_BAR = 12 - #STANDALONE_BEAT_LENGTH = 12 + PHRASE_LENGTH = 4 + PHRASE_COMPLEXITY = .5 TABLE_ONSET_VALUES = [ 3, 4, 6, 8, 12, 18, 24, 36, 48 ] @@ -101,61 +102,66 @@ class GenerationConstants: # Onsets probability tables (drumRythmSequence) PUNCH_ACCENTS = [ [], - [ 0 ], - [ 0, 1 ], - [ 0, 2, 1 ], - [ 0, 2, 3, 1 ], - [ 0, 3, 2, 4, 1], - [ 0, 3, 2, 5, 1, 4 ], - [ 0, 2, 4, 6, 5, 3, 1 ], - [ 0, 4, 2, 6, 3, 7, 5, 1 ], - [ 0, 4, 6, 2, 8, 5, 3, 7, 1], - [ 0, 6, 4, 8, 2, 5, 7, 3, 9, 1], - [ 0, 4, 6, 10, 8, 2, 5, 7, 9, 3, 1], - [0, 6, 4, 2, 8, 10, 7, 5, 3, 9, 11, 1] ] + [ 0 ], + [ 0, 1 ], + [ 0, 2, 1 ], + [ 0, 2, 3, 1 ], + [ 0, 3, 2, 4, 1], + [ 0, 3, 2, 5, 1, 4 ], + [ 0, 2, 4, 6, 5, 3, 1 ], + [ 0, 4, 2, 6, 3, 7, 5, 1 ], + [ 0, 4, 6, 2, 8, 5, 3, 7, 1], + [ 0, 6, 4, 8, 2, 5, 7, 3, 9, 1], + [ 0, 4, 6, 10, 8, 2, 5, 7, 9, 3, 1], + [0, 6, 4, 2, 8, 10, 7, 5, 3, 9, 11, 1] ] LOW_ACCENTS = [ [], - [ 0 ], - [ 0, 1 ], - [ 0, 2, 1 ], - [ 0, 2, 3, 1 ], - [ 0, 3, 2, 4, 1 ], - [ 0, 3, 2, 5, 1, 4 ], - [ 0, 2, 4, 6, 5, 3, 1 ], - [ 0, 4, 2, 6, 3, 7, 5, 1 ], - [ 0, 4, 6, 2, 8, 5, 3, 7, 1 ], - [ 0, 6, 4, 8, 2, 5, 7, 3, 9, 1 ], - [ 0, 4, 6, 10, 8, 2, 5, 7, 9, 3, 1 ], - [0, 6, 4, 2, 8, 10, 7, 5, 3, 9, 11, 1 ] ] + [ 0 ], + [ 0, 1 ], + [ 0, 2, 1 ], + [ 0, 2, 3, 1 ], + [ 0, 3, 2, 4, 1 ], + [ 0, 3, 2, 5, 1, 4 ], + [ 0, 2, 4, 6, 5, 3, 1 ], + [ 0, 4, 2, 6, 3, 7, 5, 1 ], + [ 0, 4, 6, 2, 8, 5, 3, 7, 1 ], + [ 0, 6, 4, 8, 2, 5, 7, 3, 9, 1 ], + [ 0, 4, 6, 10, 8, 2, 5, 7, 9, 3, 1 ], + [0, 6, 4, 2, 8, 10, 7, 5, 3, 9, 11, 1 ] ] MID_ACCENTS = [ [], - [ 0, 1 ], - [ 0, 2, 3, 1 ], - [ 0, 2, 4, 3, 1, 5 ], - [ 0, 4, 6, 2, 7, 1, 3, 5 ], - [ 0, 6, 4, 8, 2, 1, 5, 3, 9, 7 ], - [ 0, 6, 11, 5, 3, 9, 10, 2, 8, 7, 1, 4 ], - [ 0, 4, 8, 12, 10, 13, 11, 9, 3, 2, 6, 5, 7, 1 ], - [ 0, 8, 4, 12, 6, 14, 2, 10, 7, 15, 1, 9, 3, 11, 5, 13 ], - [ 0, 8, 16, 4, 12, 14, 6, 2, 10, 7, 15, 1, 9, 3, 17, 11, 5, 13], - [ 0, 10, 8, 4, 16, 12, 6, 14, 18, 2, 7, 9, 15, 3, 1, 19, 5, 11, 13, 17], - [ 0, 8, 10, 16, 4, 20, 6, 12, 18, 14, 2, 9, 7, 3, 15, 21, 19, 1, 5, 11, 17, 13], - [ 0, 10, 8, 4, 16, 6, 20, 22, 18, 12, 2, 14, 7, 9, 15, 3, 19, 1, 21, 5, 23, 17, 11, 13] ] + [ 0, 1 ], + [ 0, 2, 3, 1 ], + [ 0, 2, 4, 3, 1, 5 ], + [ 0, 4, 6, 2, 7, 1, 3, 5 ], + [ 0, 6, 4, 8, 2, 1, 5, 3, 9, 7 ], + [ 0, 6, 11, 5, 3, 9, 10, 2, 8, 7, 1, 4 ], + [ 0, 4, 8, 12, 10, 13, 11, 9, 3, 2, 6, 5, 7, 1 ], + [ 0, 8, 4, 12, 6, 14, 2, 10, 7, 15, 1, 9, 3, 11, 5, 13 ], + [ 0, 8, 16, 4, 12, 14, 6, 2, 10, 7, 15, 1, 9, 3, 17, 11, 5, 13], + [ 0, 10, 8, 4, 16, 12, 6, 14, 18, 2, 7, 9, 15, 3, 1, 19, 5, 11, 13, 17], + [ 0, 8, 10, 16, 4, 20, 6, 12, 18, 14, 2, 9, 7, 3, 15, 21, 19, 1, 5, 11, 17, 13], + [ 0, 10, 8, 4, 16, 6, 20, 22, 18, 12, 2, 14, 7, 9, 15, 3, 19, 1, 21, 5, 23, 17, 11, 13] ] HIGH_ACCENTS = [ [], - [ 1, 0 ], - [ 1, 3, 2, 0 ], - [ 5, 1, 3, 4, 2, 0 ], - [ 5, 3, 1, 7, 2, 6, 4, 0 ], - [ 7, 9, 3, 5, 1, 2, 8, 4, 6, 0 ], - [ 4, 1, 7, 5, 3, 9, 10, 2, 8, 11, 6, 0 ], - [ 1, 7, 8, 5, 10, 13, 11, 9, 3, 2, 6, 12, 4, 0 ], - [ 13, 5, 11, 3, 9, 1, 15, 10, 7, 2, 14, 6, 12, 4, 8, 0 ], - [ 13, 5, 11, 17, 3, 9, 1, 15, 7, 10, 2, 6, 14, 12, 4, 16, 8, 0 ], - [ 17, 13, 11, 5, 19, 1, 3, 15, 9, 7, 2, 18, 14, 6, 12, 16, 4, 8, 10, 0 ], - [ 13, 17, 11, 5, 1, 19, 21, 15, 3, 7, 9, 2, 14, 18, 12, 6, 20, 4, 16, 10, 8, 0 ], - [ 13, 11, 17, 23, 5, 21, 1, 19, 3, 15, 9, 7, 14, 2, 12, 18, 22, 20, 6, 16, 4, 8, 10, 0 ] ] + [ 1, 0 ], + [ 1, 3, 2, 0 ], + [ 5, 1, 3, 4, 2, 0 ], + [ 5, 3, 1, 7, 2, 6, 4, 0 ], + [ 7, 9, 3, 5, 1, 2, 8, 4, 6, 0 ], + [ 4, 1, 7, 5, 3, 9, 10, 2, 8, 11, 6, 0 ], + [ 1, 7, 8, 5, 10, 13, 11, 9, 3, 2, 6, 12, 4, 0 ], + [ 13, 5, 11, 3, 9, 1, 15, 10, 7, 2, 14, 6, 12, 4, 8, 0 ], + [ 13, 5, 11, 17, 3, 9, 1, 15, 7, 10, 2, 6, 14, 12, 4, 16, 8, 0 ], + [ 17, 13, 11, 5, 19, 1, 3, 15, 9, 7, 2, 18, 14, 6, 12, 16, 4, 8, 10, 0 ], + [ 13, 17, 11, 5, 1, 19, 21, 15, 3, 7, 9, 2, 14, 18, 12, 6, 20, 4, 16, 10, 8, 0 ], + [ 13, 11, 17, 23, 5, 21, 1, 19, 3, 15, 9, 7, 14, 2, 12, 18, 22, 20, 6, 16, 4, 8, 10, 0 ] ] + + DRUM_PUNCH_PROB = [[], [(0, 100)], [(0, 100), (12, 35)], [(0, 100), (24, 54), (12, 19)], [(0, 100), (24, 64), (36, 35), (12, 12)], [(0, 100), (36, 71), (24, 46), (48, 25), (12, 8)], [(0, 100), (36, 76), (24, 54), (60, 35), (12, 19), (48, 6)], [(0, 100), (24, 79), (48, 60), (72, 43), (60, 28), (36, 15), (12, 5)], [(0, 100), (48, 81), (24, 64), (72, 49), (36, 35), (84, 22), (60, 12), (12, 4)], [(0, 100), (48, 83), (72, 68), (24, 54), (96, 41), (60, 29), (36, 19), (84, 10), (12, 3)], [(0, 100), (72, 85), (48, 71), (96, 58), (24, 46), (60, 35), (84, 25), (36, 16), (108, 8), (12, 3)], [(0, 100), (48, 86), (72, 74), (120, 62), (96, 50), (24, 40), (60, 30), (84, 21), (108, 14), (36, 7), (12, 2)], [(0, 100), (72, 87), (48, 76), (24, 64), (96, 54), (120, 44), (84, 35), (60, 26), (36, 19), (108, 12), (132, 6), (12, 2)]] + DRUM_LOW_PROB = [[], [(0, 100)], [(0, 100), (12, 35)], [(0, 100), (24, 54), (12, 19)], [(0, 100), (24, 64), (36, 35), (12, 12)], [(0, 100), (36, 71), (24, 46), (48, 25), (12, 8)], [(0, 100), (36, 76), (24, 54), (60, 35), (12, 19), (48, 6)], [(0, 100), (24, 79), (48, 60), (72, 43), (60, 28), (36, 15), (12, 5)], [(0, 100), (48, 81), (24, 64), (72, 49), (36, 35), (84, 22), (60, 12), (12, 4)], [(0, 100), (48, 83), (72, 68), (24, 54), (96, 41), (60, 29), (36, 19), (84, 10), (12, 3)], [(0, 100), (72, 85), (48, 71), (96, 58), (24, 46), (60, 35), (84, 25), (36, 16), (108, 8), (12, 3)], [(0, 100), (48, 86), (72, 74), (120, 62), (96, 50), (24, 40), (60, 30), (84, 21), (108, 14), (36, 7), (12, 2)], [(0, 100), (72, 87), (48, 76), (24, 64), (96, 54), (120, 44), (84, 35), (60, 26), (36, 19), (108, 12), (132, 6), (12, 2)]] + DRUM_MID_PROB = [[], [(0, 100), (6, 35)], [(0, 100), (12, 64), (18, 35), (6, 12)], [(0, 100), (12, 76), (24, 54), (18, 35), (6, 19), (30, 6)], [(0, 100), (24, 81), (36, 64), (12, 49), (42, 35), (6, 22), (18, 12), (30, 4)], [(0, 100), (36, 85), (24, 71), (48, 58), (12, 46), (6, 35), (30, 25), (18, 16), (54, 8), (42, 3)], [(0, 100), (36, 87), (66, 76), (30, 64), (18, 54), (54, 44), (60, 35), (12, 26), (48, 19), (42, 12), (6, 6), (24, 2)], [(0, 100), (24, 89), (48, 79), (72, 69), (60, 60), (78, 51), (66, 43), (54, 35), (18, 28), (12, 21), (36, 15), (30, 9), (42, 5), (6, 1)], [(0, 100), (48, 90), (24, 81), (72, 73), (36, 64), (84, 57), (12, 49), (60, 42), (42, 35), (90, 28), (6, 22), (54, 17), (18, 12), (66, 8), (30, 4), (78, 1)], [(0, 100), (48, 91), (96, 83), (24, 76), (72, 68), (84, 61), (36, 54), (12, 47), (60, 41), (42, 35), (90, 29), (6, 24), (54, 19), (18, 14), (102, 10), (66, 6), (30, 3), (78, 1)], [(0, 100), (60, 92), (48, 85), (24, 78), (96, 71), (72, 64), (36, 58), (84, 52), (108, 46), (12, 40), (42, 35), (54, 30), (90, 25), (18, 20), (6, 16), (114, 12), (30, 8), (66, 5), (78, 3), (102, 1)], [(0, 100), (48, 93), (60, 86), (96, 80), (24, 74), (120, 67), (36, 62), (72, 56), (108, 50), (84, 45), (12, 40), (54, 35), (42, 30), (18, 26), (90, 21), (126, 17), (114, 14), (6, 10), (30, 7), (66, 5), (102, 2), (78, 0)], [(0, 100), (60, 93), (48, 87), (24, 81), (96, 76), (36, 70), (120, 64), (132, 59), (108, 54), (72, 49), (12, 44), (84, 39), (42, 35), (54, 31), (90, 26), (18, 22), (114, 19), (6, 15), (126, 12), (30, 9), (138, 6), (102, 4), (66, 2), (78, 0)]] + DRUM_HIGH_PROB = [[], [(6, 100), (0, 35)], [(6, 100), (18, 64), (12, 35), (0, 12)], [(30, 100), (6, 76), (18, 54), (24, 35), (12, 19), (0, 6)], [(30, 100), (18, 81), (6, 64), (42, 49), (12, 35), (36, 22), (24, 12), (0, 4)], [(42, 100), (54, 85), (18, 71), (30, 58), (6, 46), (12, 35), (48, 25), (24, 16), (36, 8), (0, 3)], [(24, 100), (6, 87), (42, 76), (30, 64), (18, 54), (54, 44), (60, 35), (12, 26), (48, 19), (66, 12), (36, 6), (0, 2)], [(6, 100), (42, 89), (48, 79), (30, 69), (60, 60), (78, 51), (66, 43), (54, 35), (18, 28), (12, 21), (36, 15), (72, 9), (24, 5), (0, 1)], [(78, 100), (30, 90), (66, 81), (18, 73), (54, 64), (6, 57), (90, 49), (60, 42), (42, 35), (12, 28), (84, 22), (36, 17), (72, 12), (24, 8), (48, 4), (0, 1)], [(78, 100), (30, 91), (66, 83), (102, 76), (18, 68), (54, 61), (6, 54), (90, 47), (42, 41), (60, 35), (12, 29), (36, 24), (84, 19), (72, 14), (24, 10), (96, 6), (48, 3), (0, 1)], [(102, 100), (78, 92), (66, 85), (30, 78), (114, 71), (6, 64), (18, 58), (90, 52), (54, 46), (42, 40), (12, 35), (108, 30), (84, 25), (36, 20), (72, 16), (96, 12), (24, 8), (48, 5), (60, 3), (0, 1)], [(78, 100), (102, 93), (66, 86), (30, 80), (6, 74), (114, 67), (126, 62), (90, 56), (18, 50), (42, 45), (54, 40), (12, 35), (84, 30), (108, 26), (72, 21), (36, 17), (120, 14), (24, 10), (96, 7), (60, 5), (48, 2), (0, 0)], [(78, 100), (66, 93), (102, 87), (138, 81), (30, 76), (126, 70), (6, 64), (114, 59), (18, 54), (90, 49), (54, 44), (42, 39), (84, 35), (12, 31), (72, 26), (108, 22), (132, 19), (120, 15), (36, 12), (96, 9), (24, 6), (48, 4), (60, 2), (0, 0)]] # Gain boundaries GAIN_MAX_BOUNDARY = 1. @@ -166,6 +172,11 @@ class GenerationConstants: # pitch mapping for drum kit DRUMPITCH = {25: 24, 27: 26, 29: 28, 31: 30, 33: 32, 35: 34, 37: 36, 39: 38, 41: 40, 43: 42, 45: 44, 47: 46 } + DRUM_COMPLEXITY1 = [ [ 24 ], [30] , [ 40 ], [ 46 ] ] + DRUM_COMPLEXITY2 = [ [ 24, 28 ], [ 30, 32 ], [ 36, 38, 40 ], [ 46, 48 ] ] + DRUM_COMPLEXITY3 = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 46, 48 ] ] + DRUM_COMPLEXITY4 = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 44, 46, 48 ] ] + TRANSPOSE = [0.5, 0.52973154717964765, 0.56123102415468651, 0.59460355750136051, 0.6299605249474366, 0.66741992708501718, 0.70710678118654757, 0.74915353843834076, 0.79370052598409979, 0.8408964152537145, 0.89089871814033927, 0.94387431268169353, 1.0, 1.0594630943592953, 1.122462048309373, 1.189207115002721, 1.2599210498948732, 1.3348398541700344, 1.4142135623730951, 1.4983070768766815, 1.5874010519681994, 1.681792830507429, 1.7817974362806785, 1.8877486253633868, 2.0] CELLULES_MARKERS = [ 8, 16, 21, 24 ] diff --git a/Generation/GenerationPitch.py b/Generation/GenerationPitch.py index 1660a64..a0f7435 100644 --- a/Generation/GenerationPitch.py +++ b/Generation/GenerationPitch.py @@ -13,10 +13,10 @@ class GenerationPitch: 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 ) +# 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 @@ -24,11 +24,11 @@ class GenerationPitch: elif pattern == 2: return self.repeter elif pattern == 3: return self.loopseg - def harmonicChooseMethod( self, pattern ): - if pattern == 0: return self.harmonicDrunk - elif pattern == 1: return self.harmonicDroneAndJump - elif pattern == 2: return self.harmonicRepeter - elif pattern == 3: return self.harmonicLoopseg +# def harmonicChooseMethod( self, pattern ): +# if pattern == 0: return self.harmonicDrunk +# elif pattern == 1: return self.harmonicDroneAndJump +# elif pattern == 2: return self.harmonicRepeter +# elif pattern == 3: return self.harmonicLoopseg def drunkPitchSequence(self, length, parameters, table_pitch): self.pitchMethod = self.chooseMethod( parameters.pattern ) @@ -47,13 +47,12 @@ class GenerationPitch: pitchSequence.append(drumPitch[ random.randint( 0, ( len( drumPitch ) - 1 ) ) ] ) return pitchSequence - def harmonicPitchSequence( self, rythmSequence, parameters, table_pitch, harmonicSequence ): - pitchSequence = [] - pitchMethod = self.harmonicChooseMethod( parameters.pattern ) - for onset in rythmSequence: - beat = int( onset / Config.TICKS_PER_BEAT ) - pitchSequence.append( ( table_pitch[ harmonicSequence[ beat ] [ pitchMethod.getNextValue(3, ( len( harmonicSequence[ beat ]) - 1) ) ]] ) + GenerationConstants.DEFAULT_TONIQUE ) - # pitchSequence.append( ( table_pitch[ random.choice( harmonicSequence[ beat ] ) ] ) + GenerationConstants.DEFAULT_TONIQUE ) - return pitchSequence +# def harmonicPitchSequence( self, rythmSequence, parameters, table_pitch, harmonicSequence ): +# pitchSequence = [] +# pitchMethod = self.harmonicChooseMethod( parameters.pattern ) +# for onset in rythmSequence: +# beat = int( onset / Config.TICKS_PER_BEAT ) +# pitchSequence.append( ( table_pitch[ harmonicSequence[ beat ] [ pitchMethod.getNextValue(3, ( len( harmonicSequence[ beat ]) - 1) ) ]] ) + GenerationConstants.DEFAULT_TONIQUE ) +# return pitchSequence diff --git a/Generation/GenerationRythm.py b/Generation/GenerationRythm.py index 5709977..d0827ef 100644 --- a/Generation/GenerationRythm.py +++ b/Generation/GenerationRythm.py @@ -5,11 +5,8 @@ import Config from Generation.GenerationConstants import GenerationConstants class GenerationRythm: - def __init__( self, trackInstrument, barLength ): - self.trackInstrument = trackInstrument - self.barLength = barLength - def celluleRythmSequence(self, parameters ): + def celluleRythmSequence(self, parameters, barLength ): rythmSequence = [0, ] self.count = 0 lastOnsetTime = 0 @@ -26,7 +23,7 @@ class GenerationRythm: onsetDelta = GenerationConstants.TABLE_ONSET_VALUES[ currentOnsetValue ] - for i in range( int( self.barLength / Config.TICKS_PER_BEAT * 8 ) ): + for i in range( int( barLength / Config.TICKS_PER_BEAT * 8 ) ): if self.count == 0: currentOnsetValue = onsetValue + ( random.randint( 0, onsetDeviation ) - ( onsetDeviation / 2 ) ) if currentOnsetValue < 0: @@ -44,13 +41,13 @@ class GenerationRythm: onsetTime = onsetDelta + lastOnsetTime lastOnsetTime = onsetTime - if onsetTime < self.barLength: + if onsetTime < barLength: rythmSequence.append(onsetTime) else: break return rythmSequence - def xnoiseRythmSequence(self, parameters ): + def xnoiseRythmSequence(self, parameters, barLength ): rythmSequence = [] onsetTime = None randomParamScaler = parameters.rythmRegularity * 2 + 0.5 @@ -74,12 +71,12 @@ class GenerationRythm: onsetTime = random.weibullvariate(GenerationConstants.RANDOM_WEIBULL_PARAM1, GenerationConstants.RANDOM_WEIBULL_PARAM2 * randomParamScaler) - onsetTime = int(onsetTime * (int(( self.barLength - 1) / GenerationConstants.DOUBLE_TICK_DUR))) * GenerationConstants.DOUBLE_TICK_DUR + onsetTime = int(onsetTime * (int(( barLength - 1) / GenerationConstants.DOUBLE_TICK_DUR))) * GenerationConstants.DOUBLE_TICK_DUR if onsetTime < 0: onsetTime = 0 - elif onsetTime > ( self.barLength - GenerationConstants.DOUBLE_TICK_DUR): - onsetTime = ( self.barLength - GenerationConstants.DOUBLE_TICK_DUR) + elif onsetTime > ( barLength - GenerationConstants.DOUBLE_TICK_DUR): + onsetTime = ( barLength - GenerationConstants.DOUBLE_TICK_DUR) else: onsetTime = onsetTime @@ -88,7 +85,7 @@ class GenerationRythm: rythmSequence.sort() return rythmSequence - def drumRythmSequence(self, parameters ): + def drumRythmSequence(self, parameters, trackInstrument, barLength ): density = sqrt(parameters.density) rythmSequence = [] binSelection = [] @@ -97,52 +94,38 @@ class GenerationRythm: beats = [] countDown = 0 onsetTime = None - beatsPerPage = int( self.barLength / Config.TICKS_PER_BEAT ) + beatsPerPage = int( barLength / Config.TICKS_PER_BEAT ) - if Config.INSTRUMENTS[ self.trackInstrument ].instrumentRegister == Config.PUNCH: + if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.PUNCH_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_PUNCH_PROB[ beatsPerPage ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT , downBeat[ 1 ] ) ) - if Config.INSTRUMENTS[ self.trackInstrument ].instrumentRegister == Config.LOW: + if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.LOW: registerDensity =1.5 downBeatRecurence = 4 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.LOW_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_LOW_PROB[ beatsPerPage ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 2 , downBeat[ 1 ] ) ) - if Config.INSTRUMENTS[ self.trackInstrument ].instrumentRegister == Config.MID: + if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.MID: registerDensity = 1 downBeatRecurence = 1 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - beats.append( beat * Config.TICKS_PER_BEAT + ( Config.TICKS_PER_BEAT / 2 ) ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.MID_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_MID_PROB[ beatsPerPage ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) - if Config.INSTRUMENTS[ self.trackInstrument ].instrumentRegister == Config.HIGH: + if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - beats.append( beat * Config.TICKS_PER_BEAT + ( Config.TICKS_PER_BEAT / 2 ) ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.HIGH_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_HIGH_PROB[ beatsPerPage ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) for i in range( int( density * registerDensity * len( downBeats ) ) ): - if random.randint( 0, 100 ) < ( parameters.rythmRegularity * 100 * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): + if random.random() < ( parameters.rythmRegularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): binSelection.append( 1 ) else: if binSelection.count( 0 ) < len( downBeats ): diff --git a/Generation/Generator.py b/Generation/Generator.py index c2db1f0..11a1071 100755 --- a/Generation/Generator.py +++ b/Generation/Generator.py @@ -46,16 +46,9 @@ def generator1( trackDictionary # map [ trackId : [ pageId : events ] ] ): - pitchMarkov = PitchMarkov() - pitchReverse = PitchReverse() - pitchSort = PitchSort() - pitchShuffle = PitchShuffle() - + makeRythm = GenerationRythm() makePitch = GenerationPitch() - makeHarmonicSequence = Drunk.Drunk( 0, 7 ) - - rythmShuffle = RythmShuffle( ) - rythmReverse = RythmReverse( ) + #makeHarmonicSequence = Drunk.Drunk( 0, 7 ) def makeGainSequence( onsetList ): gainSequence = [] @@ -71,49 +64,38 @@ def generator1( def makeDurationSequence( onsetList, parameters, table_duration, barLength, currentInstrument ): durationSequence = [] + if Config.INSTRUMENTS[currentInstrument].soundClass == 'drum': + duration = GenerationConstants.DOUBLE_TICK_DUR / 2 + durationSequence = [duration] * len(onsetList) + return durationSequence + if len( onsetList ) > 1: for i in range(len(onsetList) - 1): duration = (onsetList[i+1] - onsetList[i]) * Utils.prob2( table_duration ) - if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': - duration = GenerationConstants.DOUBLE_TICK_DUR / 2 - durationSequence.append(duration) - - if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': - durationSequence.append( GenerationConstants.DOUBLE_TICK_DUR / 2) - else: - durationSequence.append(( barLength - onsetList[-1]) * Utils.prob2( table_duration )) + durationSequence.append(( barLength - onsetList[-1]) * Utils.prob2( table_duration )) elif len( onsetList ) == 1: - if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': - durationSequence.append( GenerationConstants.DOUBLE_TICK_DUR / 2 ) - else: - durationSequence.append( ( barLength - onsetList[ 0 ] ) * Utils.prob2( table_duration )) + durationSequence.append( ( barLength - onsetList[ 0 ] ) * Utils.prob2( table_duration )) return durationSequence - def pageGenerate( parameters, trackId, pageId, selectedPageCount, lastPageId, trackOfNotes, drumPitch = None ): + def pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch = None ): + trackNotes = trackOfNotes - barLength = Config.TICKS_PER_BEAT * nbeats[ pageId ] if drumPitch: currentInstrument = Config.INSTRUMENTS[instrument[ trackId ]].kit[drumPitch[0]].name else: - drumPitch = [ 36 ] + #drumPitch = [ 36 ] currentInstrument = instrument[ trackId ] - makeRythm = GenerationRythm( currentInstrument, barLength ) - - 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] if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': - rythmSequence = makeRythm.drumRythmSequence(parameters) + rythmSequence = makeRythm.drumRythmSequence(parameters, currentInstrument, barLength) pitchSequence = makePitch.drumPitchSequence(len(rythmSequence), parameters, drumPitch, table_pitch ) elif Config.INSTRUMENTS[ currentInstrument ].soundClass == 'melo': if parameters.rythmMethod == 0: - rythmSequence = makeRythm.celluleRythmSequence(parameters) + rythmSequence = makeRythm.celluleRythmSequence(parameters, barLength) elif parameters.rythmMethod == 1: - rythmSequence = makeRythm.xnoiseRythmSequence(parameters) + rythmSequence = makeRythm.xnoiseRythmSequence(parameters, barLength) if parameters.pitchMethod == 0: pitchSequence = makePitch.drunkPitchSequence(len(rythmSequence), parameters, table_pitch) makePitch.pitchMethod.__init__(5, 12) @@ -124,12 +106,16 @@ def generator1( for i in range(len(rythmSequence)): if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': - if random.random() > ( parameters.silence * .7 ): - 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' ) ) + if ( random.random() * fillDrum ) > ( parameters.silence * .7 ): + 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' ) ) + 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' ) ) 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.098, 0.1, 0, 1000, False, 'edit' ) ) -# del trackDictionary[ trackId ][ pageId ] + trackDictionary[ trackId ][ pageId ] = trackNotes ################################################################################## @@ -138,27 +124,45 @@ def generator1( # for i in range( nbeats ): # harmonicSequence.append( # GenerationConstants.CHORDS_TABLE[ makeHarmonicSequence.getNextValue( 2, len( GenerationConstants.CHORDS_TABLE ) - 1 ) ] ) - + + 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 instrument[ trackId ][0:4] == 'drum': if parameters.rythmRegularity > 0.75: - pitchOfStream = [ [ 24 ], [30] , [ 40 ], [ 46 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1 elif parameters.rythmRegularity > 0.5: - pitchOfStream = [ [ 24, 28 ], [ 30, 32 ], [ 36, 38, 40 ], [ 46, 48 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY2 elif parameters.rythmRegularity > 0.25: - pitchOfStream = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 46, 48 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY3 else: - pitchOfStream = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 44, 46, 48 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY4 selectedPageCount = 0 lastPageId = 0 for pageId in pageIds: + barLength = Config.TICKS_PER_BEAT * nbeats[ pageId ] trackOfNotes = [] -# del trackDictionary[ trackId ][ pageId ] if instrument[ trackId ][0:4] == 'drum': - for drumPitch in pitchOfStream: - pageGenerate( parameters, trackId, pageId, selectedPageCount, lastPageId, trackOfNotes, drumPitch ) + if ( selectedPageCount % 4 ) in [1,2]: + trackDictionary[ trackId ][ pageId ] = [ n for n in trackDictionary[ trackId ][ lastPageId ] ] + elif ( selectedPageCount % 4 ) == 3: + trackOfNotes = [ n for n in trackDictionary[ trackId ][ lastPageId ] ] + trackOnsets = [n.onset for n in trackOfNotes] + trackPitchs = [n.pitch for n in trackOfNotes] + fillDrum = .5 + rythmRegTemp = parameters.rythmRegularity + parameters.rythmRegularity = 0. + for drumPitch in GenerationConstants.DRUM_COMPLEXITY4: + pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch ) + parameters.rythmRegularity = rythmRegTemp + elif ( selectedPageCount % 4 ) == 0: + fillDrum = 1 + for drumPitch in streamOfPitch: + pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch ) + else: - pageGenerate( parameters, trackId, pageId, selectedPageCount, lastPageId, trackOfNotes, drumPitch = None ) + pageGenerate( parameters, trackId, pageId, trackOfNotes, drumPitch = None ) selectedPageCount += 1 lastPageId = pageId diff --git a/Generation/bList.py b/Generation/bList.py new file mode 100644 index 0000000..ceb3d1f --- /dev/null +++ b/Generation/bList.py @@ -0,0 +1,67 @@ +import Config +from Generation.GenerationConstants import GenerationConstants + +def gen(): + punch_list = [[], ] + low_list = [[], ] + mid_list = [[], ] + high_list = [[], ] + + f = open('/home/olpc/tamtam/Generation/drumTablesList', 'w') + + # gen punch list + for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + beats = [] + downBeats = [] + for beat in range( beatsPerPage ): + beats.append( beat * Config.TICKS_PER_BEAT ) + for i in range( len( beats ) ): + downBeats.append( ( beats[ GenerationConstants.PUNCH_ACCENTS[ beatsPerPage ][ i ] ], int( pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) ) + punch_list.append(downBeats) + + string = ' DRUM_PUNCH_PROB = ' + str(punch_list) + '\n' + f.write(string) + + # gen low list + for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + beats = [] + downBeats = [] + for beat in range( beatsPerPage ): + beats.append( beat * Config.TICKS_PER_BEAT ) + for i in range( len( beats ) ): + downBeats.append( ( beats[ GenerationConstants.LOW_ACCENTS[ beatsPerPage ][ i ] ], int( pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) ) + low_list.append(downBeats) + + string = ' DRUM_LOW_PROB = ' + str(low_list) + '\n' + f.write(string) + + # gen mid list + for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + beats = [] + downBeats = [] + for beat in range( beatsPerPage ): + beats.append( beat * Config.TICKS_PER_BEAT ) + beats.append( beat * Config.TICKS_PER_BEAT + ( Config.TICKS_PER_BEAT / 2 ) ) + for i in range( len( beats ) ): + downBeats.append( ( beats[ GenerationConstants.MID_ACCENTS[ beatsPerPage ][ i ] ], int( pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) ) + mid_list.append(downBeats) + + string = ' DRUM_MID_PROB = ' + str(mid_list) + '\n' + f.write(string) + + # gen high list + for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + beats = [] + downBeats = [] + for beat in range( beatsPerPage ): + beats.append( beat * Config.TICKS_PER_BEAT ) + beats.append( beat * Config.TICKS_PER_BEAT + ( Config.TICKS_PER_BEAT / 2 ) ) + for i in range( len( beats ) ): + downBeats.append( ( beats[ GenerationConstants.HIGH_ACCENTS[ beatsPerPage ][ i ] ], int( pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) ) + high_list.append(downBeats) + + string = ' DRUM_HIGH_PROB = ' + str(high_list) + '\n' + f.write(string) + + f.close() + |