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 /miniTamTam | |
parent | b9f2160bfd40c28ee2ee7e14d3b4802cbc84f06b (diff) |
algo optimizations
Diffstat (limited to 'miniTamTam')
-rw-r--r-- | miniTamTam/GenRythm.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/miniTamTam/GenRythm.py b/miniTamTam/GenRythm.py index 97bd2c0..5e4a873 100644 --- a/miniTamTam/GenRythm.py +++ b/miniTamTam/GenRythm.py @@ -17,30 +17,30 @@ class GenRythm: if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 - downBeats = GenerationConstants.DRUM_PUNCH_PROB[ nbeats ] + downBeats = [x for x in GenerationConstants.DRUM_PUNCH_ACCENTS[ nbeats ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.LOW: registerDensity =1 downBeatRecurence = 4 - downBeats = GenerationConstants.DRUM_LOW_PROB[ nbeats ] + downBeats = [x for x in GenerationConstants.DRUM_LOW_ACCENTS[ nbeats ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 2 , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.MID: registerDensity = .75 downBeatRecurence = 1 - downBeats = GenerationConstants.DRUM_MID_PROB[ nbeats ] + downBeats = [x for x in GenerationConstants.DRUM_MID_ACCENTS[ nbeats ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 - downBeats = GenerationConstants.DRUM_HIGH_PROB[ nbeats ] + downBeats = [x for x in GenerationConstants.DRUM_HIGH_ACCENTS[ nbeats ]] for downBeat in downBeats: - upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) + upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) realDensity = density * registerDensity if realDensity > 1.: @@ -58,15 +58,23 @@ class GenRythm: countDown = binSelection.count( 1 ) + length = len(downBeats) - 1 for i in range( countDown ): - while onsetTime in rythmSequence or onsetTime == None: - onsetTime = 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 = 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 |