diff options
author | Oli2 <olivier.belanger@umontreal.ca> | 2007-03-12 22:36:44 (GMT) |
---|---|---|
committer | Oli2 <olivier.belanger@umontreal.ca> | 2007-03-12 22:36:44 (GMT) |
commit | 24ccae384fe86b4062476fa43ecb119e744253a7 (patch) | |
tree | 4c4b32c121d8d2abbcf18f44b04087700a661663 /Generation | |
parent | b9f2160bfd40c28ee2ee7e14d3b4802cbc84f06b (diff) |
algo optimizations
Diffstat (limited to 'Generation')
-rwxr-xr-x | Generation/GenerationConstants.py | 58 | ||||
-rw-r--r-- | Generation/GenerationPitch.py | 35 | ||||
-rw-r--r-- | Generation/GenerationRythm.py | 40 | ||||
-rwxr-xr-x | Generation/Generator.py | 34 | ||||
-rwxr-xr-x | Generation/Utils.py | 45 | ||||
-rw-r--r-- | Generation/bList.py | 32 |
6 files changed, 120 insertions, 124 deletions
diff --git a/Generation/GenerationConstants.py b/Generation/GenerationConstants.py index b4be958..1972181 100755 --- a/Generation/GenerationConstants.py +++ b/Generation/GenerationConstants.py @@ -80,7 +80,7 @@ class GenerationConstants: DENSITY_SCALE_STEPS = 38 ARTICULATION_SCALE_MIN_MAPPING = .6 ARTICULATION_SCALE_MAX_MAPPING = 1 - ARTICULATION_SCALE_STEPS = 30 + ARTICULATION_SCALE_STEPS = 10 # Rythmic durations, in ticks, and how many to complete figure (celluleRythmSequence) DOUBLE_TICK_DUR = 3 @@ -158,58 +158,10 @@ class GenerationConstants: [ 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)]] + DRUM_PUNCH_ACCENTS = [[], [0], [0, 12], [0, 24, 12], [0, 24, 36, 12], [0, 36, 24, 48, 12], [0, 36, 24, 60, 12, 48], [0, 24, 48, 72, 60, 36, 12], [0, 48, 24, 72, 36, 84, 60, 12], [0, 48, 72, 24, 96, 60, 36, 84, 12], [0, 72, 48, 96, 24, 60, 84, 36, 108, 12], [0, 48, 72, 120, 96, 24, 60, 84, 108, 36, 12], [0, 72, 48, 24, 96, 120, 84, 60, 36, 108, 132, 12]] + DRUM_LOW_ACCENTS = [[], [0], [0, 12], [0, 24, 12], [0, 24, 36, 12], [0, 36, 24, 48, 12], [0, 36, 24, 60, 12, 48], [0, 24, 48, 72, 60, 36, 12], [0, 48, 24, 72, 36, 84, 60, 12], [0, 48, 72, 24, 96, 60, 36, 84, 12], [0, 72, 48, 96, 24, 60, 84, 36, 108, 12], [0, 48, 72, 120, 96, 24, 60, 84, 108, 36, 12], [0, 72, 48, 24, 96, 120, 84, 60, 36, 108, 132, 12]] + DRUM_MID_ACCENTS = [[], [0, 6], [0, 12, 18, 6], [0, 12, 24, 18, 6, 30], [0, 24, 36, 12, 42, 6, 18, 30], [0, 36, 24, 48, 12, 6, 30, 18, 54, 42], [0, 36, 66, 30, 18, 54, 60, 12, 48, 42, 6, 24], [0, 24, 48, 72, 60, 78, 66, 54, 18, 12, 36, 30, 42, 6], [0, 48, 24, 72, 36, 84, 12, 60, 42, 90, 6, 54, 18, 66, 30, 78], [0, 48, 96, 24, 72, 84, 36, 12, 60, 42, 90, 6, 54, 18, 102, 66, 30, 78], [0, 60, 48, 24, 96, 72, 36, 84, 108, 12, 42, 54, 90, 18, 6, 114, 30, 66, 78, 102], [0, 48, 60, 96, 24, 120, 36, 72, 108, 84, 12, 54, 42, 18, 90, 126, 114, 6, 30, 66, 102, 78], [0, 60, 48, 24, 96, 36, 120, 132, 108, 72, 12, 84, 42, 54, 90, 18, 114, 6, 126, 30, 138, 102, 66, 78]] + DRUM_HIGH_ACCENTS = [[], [6, 0], [6, 18, 12, 0], [30, 6, 18, 24, 12, 0], [30, 18, 6, 42, 12, 36, 24, 0], [42, 54, 18, 30, 6, 12, 48, 24, 36, 0], [24, 6, 42, 30, 18, 54, 60, 12, 48, 66, 36, 0], [6, 42, 48, 30, 60, 78, 66, 54, 18, 12, 36, 72, 24, 0], [78, 30, 66, 18, 54, 6, 90, 60, 42, 12, 84, 36, 72, 24, 48, 0], [78, 30, 66, 102, 18, 54, 6, 90, 42, 60, 12, 36, 84, 72, 24, 96, 48, 0], [102, 78, 66, 30, 114, 6, 18, 90, 54, 42, 12, 108, 84, 36, 72, 96, 24, 48, 60, 0], [78, 102, 66, 30, 6, 114, 126, 90, 18, 42, 54, 12, 84, 108, 72, 36, 120, 24, 96, 60, 48, 0], [78, 66, 102, 138, 30, 126, 6, 114, 18, 90, 54, 42, 84, 12, 72, 108, 132, 120, 36, 96, 24, 48, 60, 0]] # Gain boundaries GAIN_MAX_BOUNDARY = 1. diff --git a/Generation/GenerationPitch.py b/Generation/GenerationPitch.py index a0f7435..7bfe2ff 100644 --- a/Generation/GenerationPitch.py +++ b/Generation/GenerationPitch.py @@ -5,25 +5,23 @@ import Config from Generation.GenerationConstants import GenerationConstants class GenerationPitch: - def __init__( self ): + def __init__( self, pattern ): 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 ) + if pattern == 0: + self.pitchMethod = Drunk.Drunk( MIN, MAX ) + elif pattern == 1: + self.pitchMethod = Drunk.DroneAndJump( MIN, MAX ) + elif pattern == 2: + self.pitchMethod = Drunk.Repeter( MIN, MAX ) + elif pattern == 3: + self.pitchMethod = 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 - elif pattern == 1: return self.droneAndJump - 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 @@ -31,20 +29,25 @@ class GenerationPitch: # elif pattern == 3: return self.harmonicLoopseg def drunkPitchSequence(self, length, parameters, table_pitch): - self.pitchMethod = self.chooseMethod( parameters.pattern ) pitchSequence = [] + append = pitchSequence.append numberOfPitch = int( ( 1 - (parameters.pitchRegularity*.8) ) * 10 + 1 ) + step = -(8 - (int(parameters.step * 8))) + max = len(table_pitch)-1 for i in range(numberOfPitch): - 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 ): + append((table_pitch[self.pitchMethod.getNextValue(step, max)]) + GenerationConstants.DEFAULT_TONIQUE) + restOfNotes = range( length - numberOfPitch ) + for i in restOfNotes: position = i % numberOfPitch - pitchSequence.append( pitchSequence[ position ] ) + append( pitchSequence[ position ] ) return pitchSequence def drumPitchSequence(self, length, parameters, drumPitch, table_pitch=None): pitchSequence = [] + append = pitchSequence.append + max = len(drumPitch) - 1 for i in range(length): - pitchSequence.append(drumPitch[ random.randint( 0, ( len( drumPitch ) - 1 ) ) ] ) + append(drumPitch[ random.randint( 0, max ) ] ) return pitchSequence # def harmonicPitchSequence( self, rythmSequence, parameters, table_pitch, harmonicSequence ): diff --git a/Generation/GenerationRythm.py b/Generation/GenerationRythm.py index bf96253..c211602 100644 --- a/Generation/GenerationRythm.py +++ b/Generation/GenerationRythm.py @@ -99,30 +99,34 @@ class GenerationRythm: if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 - downBeats = GenerationConstants.DRUM_PUNCH_PROB[ beatsPerPage ] + downBeats = [x for x in GenerationConstants.DRUM_PUNCH_ACCENTS[ beatsPerPage ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) + #upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT , downBeat[ 1 ] ) ) if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.LOW: registerDensity =1.5 downBeatRecurence = 4 - downBeats = GenerationConstants.DRUM_LOW_PROB[ beatsPerPage ] + downBeats = [x for x in GenerationConstants.DRUM_LOW_ACCENTS[ beatsPerPage ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 2 , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) + #upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 2 , downBeat[ 1 ] ) ) if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.MID: registerDensity = 1 downBeatRecurence = 1 - downBeats = GenerationConstants.DRUM_MID_PROB[ beatsPerPage ] + downBeats = [x for x in GenerationConstants.DRUM_MID_ACCENTS[ beatsPerPage ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) + #upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) if Config.INSTRUMENTS[ trackInstrument ].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 - downBeats = GenerationConstants.DRUM_HIGH_PROB[ beatsPerPage ] + downBeats = [x for x in GenerationConstants.DRUM_HIGH_ACCENTS[ beatsPerPage ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) + #upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) for i in range( int( density * registerDensity * len( downBeats ) ) ): if random.random() < ( parameters.rythmRegularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): @@ -135,15 +139,27 @@ class GenerationRythm: countDown = binSelection.count( 1 ) + length = len(downBeats) - 1 for i in range( countDown ): - while onsetTime in rythmSequence or onsetTime == None: - onsetTime = Utils.prob2( downBeats ) +# while onsetTime in rythmSequence or onsetTime == None: +# onsetTime = Utils.prob2( downBeats ) + ran1 = random.randint(0, length) + ran2 = random.randint(0, length) + randMin = min(ran1, ran2) + onsetTime = downBeats.pop(randMin) rythmSequence.append( onsetTime ) + length -= 1 + length = len(upBeats) - 1 for i in range( len( binSelection ) - countDown ): - while onsetTime in rythmSequence or onsetTime == None: - onsetTime = Utils.prob2( upBeats ) +# while onsetTime in rythmSequence or onsetTime == None: +# onsetTime = Utils.prob2( upBeats ) + ran1 = random.randint(0, length) + ran2 = random.randint(0, length) + randMin = min(ran1, ran2) + onsetTime = upBeats.pop(randMin) rythmSequence.append( onsetTime ) + length -= 1 rythmSequence.sort() return rythmSequence diff --git a/Generation/Generator.py b/Generation/Generator.py index e5cf6b9..c5be1b7 100755 --- a/Generation/Generator.py +++ b/Generation/Generator.py @@ -47,7 +47,7 @@ def generator1( ): makeRythm = GenerationRythm() - makePitch = GenerationPitch() + makePitch = GenerationPitch(parameters.pattern) #makeHarmonicSequence = Drunk.Drunk( 0, 7 ) def makeGainSequence( onsetList ): @@ -75,37 +75,29 @@ def generator1( durationSequence.append(duration) durationSequence.append(( barLength - onsetList[-1]) * Utils.prob2( table_duration )) elif len( onsetList ) == 1: - 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, trackOfNotes, drumPitch = None ): trackNotes = trackOfNotes - if drumPitch: - currentInstrument = Config.INSTRUMENTS[instrument[ trackId ]].kit[drumPitch[0]].name - else: - #drumPitch = [ 36 ] - currentInstrument = instrument[ trackId ] - - if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': + if drumPitch: + currentInstrument = Config.INSTRUMENTS[instrument[ trackId ]].kit[drumPitch[0]].name 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, barLength, currentInstrument) - elif parameters.rythmMethod == 1: - rythmSequence = makeRythm.xnoiseRythmSequence(parameters, barLength) - 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 ) + else: + currentInstrument = instrument[ trackId ] + rythmSequence = makeRythm.celluleRythmSequence(parameters, barLength, currentInstrument) + pitchSequence = makePitch.drunkPitchSequence(len(rythmSequence),parameters, table_pitch) + makePitch.pitchMethod.__init__(5, 12) + gainSequence = makeGainSequence(rythmSequence) durationSequence = makeDurationSequence(rythmSequence, parameters, table_duration, barLength, currentInstrument) - for i in range(len(rythmSequence)): - if Config.INSTRUMENTS[ currentInstrument ].soundClass == 'drum': + numOfNotes = range(len(rythmSequence)) + for i in numOfNotes: + if drumPitch: if ( random.random() * fillDrum ) > ( parameters.silence * .7 ): if fillDrum != 1: if rythmSequence[i] not in trackOnsets or pitchSequence[i] not in trackPitchs: diff --git a/Generation/Utils.py b/Generation/Utils.py index 7f00525..f025188 100755 --- a/Generation/Utils.py +++ b/Generation/Utils.py @@ -40,32 +40,35 @@ def prob2(x): break def scale(val, mini=0., maxi=1., length=100): - slope = [] + slope = [] - if (1.- val) <= 0.5: - low_val = (pow(1.-((1.- val)*2.),4.)*(-50.5)+0.5) - else: - low_val = 1.- val + up = 1.-val + if up <= 0.5: + low_val = (pow(1.-(up*2.),4.)*(-50.5)+0.5) + else: + low_val = up - if val <= 0.5: - high_val = (pow(1.-(val * 2.),4.)*(-50.5)+0.5) - else: - high_val = val + if val <= 0.5: + high_val = (pow(1.-(val * 2.),4.)*(-50.5)+0.5) + else: + high_val = val - step = (maxi - mini) * (1. / length) - - for i in range(length + 1): - temp = i * (1. / length) * (high_val - low_val) + low_val - if temp < 0: - temp = 0 - elif temp > 1: - temp = 1 - else: - temp = temp + step = (maxi - mini) * (1. / length) + + calc = (1. / length) * (high_val - low_val) + append = slope.append + for i in range(length + 1): + temp = i * calc + low_val + if temp < 0: + temp = 0 + elif temp > 1: + temp = 1 + else: + temp = temp - slope.append(((step * i) + mini, int(temp * 100))) + append(((step * i) + mini, int(temp * 100))) - return slope + return slope def midtotrans(x): return pow(1.059463, x - 36) diff --git a/Generation/bList.py b/Generation/bList.py index ceb3d1f..5657ac9 100644 --- a/Generation/bList.py +++ b/Generation/bList.py @@ -8,9 +8,15 @@ def gen(): high_list = [[], ] f = open('/home/olpc/tamtam/Generation/drumTablesList', 'w') + g = open('/home/olpc/tamtam/Generation/drumStraightTables', 'w') # gen punch list + beatsList = [[], ] for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + accents = [] + for j in GenerationConstants.PUNCH_ACCENTS[beatsPerPage]: + accents.append(j * Config.TICKS_PER_BEAT) + beatsList.append(accents) beats = [] downBeats = [] for beat in range( beatsPerPage ): @@ -21,9 +27,16 @@ def gen(): string = ' DRUM_PUNCH_PROB = ' + str(punch_list) + '\n' f.write(string) + string = ' DRUM_PUNCH_ACCENT = ' + str(beatsList) + '\n' + g.write(string) # gen low list + beatsList = [[], ] for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + accents = [] + for j in GenerationConstants.LOW_ACCENTS[beatsPerPage]: + accents.append(j * Config.TICKS_PER_BEAT) + beatsList.append(accents) beats = [] downBeats = [] for beat in range( beatsPerPage ): @@ -34,9 +47,16 @@ def gen(): string = ' DRUM_LOW_PROB = ' + str(low_list) + '\n' f.write(string) + string = ' DRUM_LOW_ACCENT = ' + str(beatsList) + '\n' + g.write(string) # gen mid list + beatsList = [[], ] for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + accents = [] + for j in GenerationConstants.MID_ACCENTS[beatsPerPage]: + accents.append(j * Config.TICKS_PER_BEAT / 2) + beatsList.append(accents) beats = [] downBeats = [] for beat in range( beatsPerPage ): @@ -45,12 +65,19 @@ def gen(): 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) + string = ' DRUM_MID_ACCENT = ' + str(beatsList) + '\n' + g.write(string) # gen high list + beatsList = [[], ] for beatsPerPage in [1,2,3,4,5,6,7,8,9,10,11,12]: + accents = [] + for j in GenerationConstants.HIGH_ACCENTS[beatsPerPage]: + accents.append(j * Config.TICKS_PER_BEAT / 2) + beatsList.append(accents) beats = [] downBeats = [] for beat in range( beatsPerPage ): @@ -62,6 +89,9 @@ def gen(): string = ' DRUM_HIGH_PROB = ' + str(high_list) + '\n' f.write(string) + string = ' DRUM_HIGH_ACCENT = ' + str(beatsList) + '\n' + g.write(string) f.close() + g.close() |