1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
import random
from Framework.Generation.GenerationConstants import GenerationConstants
from Framework.CSound.CSoundConstants import CSoundConstants
from Framework.Constants import Constants
from Framework.Generation.Utils import *
class GenRythm:
def __init__( self, instrument, barLength, nbeats ):
self.instrument = instrument
self.barLength = barLength
self.nbeats = nbeats
#############################################################################
def drumRythmSequence(self, regularity ):
rythmSequence = []
binSelection = []
downBeats = []
upBeats = []
beats = []
density = 0.8
countDown = 0
onsetTime = None
beatsPerPage = int( self.barLength / Constants.TICKS_PER_BEAT )
if CSoundConstants.INSTRUMENTS[ self.instrument ].instrumentRegister == CSoundConstants.PUNCH:
registerDensity = 0.5
downBeatRecurence = 4
for beat in range( beatsPerPage ):
beats.append( beat * Constants.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.) )
for downBeat in downBeats:
upBeats.append( ( downBeat[ 0 ] + Constants.TICKS_PER_BEAT , downBeat[ 1 ] ) )
if CSoundConstants.INSTRUMENTS[ self.instrument ].instrumentRegister == CSoundConstants.LOW:
registerDensity =1.5
downBeatRecurence = 4
for beat in range( beatsPerPage ):
beats.append( beat * Constants.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.) )
for downBeat in downBeats:
upBeats.append( ( downBeat[ 0 ] + Constants.TICKS_PER_BEAT / 2 , downBeat[ 1 ] ) )
if CSoundConstants.INSTRUMENTS[ self.instrument ].instrumentRegister == CSoundConstants.MID:
registerDensity = .75
downBeatRecurence = 1
for beat in range( beatsPerPage ):
beats.append( beat * Constants.TICKS_PER_BEAT )
beats.append( beat * Constants.TICKS_PER_BEAT + ( Constants.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.) )
for downBeat in downBeats:
upBeats.append( ( downBeat[ 0 ] + Constants.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) )
if CSoundConstants.INSTRUMENTS[ self.instrument ].instrumentRegister == CSoundConstants.HIGH:
registerDensity = 1.5
downBeatRecurence = 1
for beat in range( beatsPerPage ):
beats.append( beat * Constants.TICKS_PER_BEAT )
beats.append( beat * Constants.TICKS_PER_BEAT + ( Constants.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.) )
for downBeat in downBeats:
upBeats.append( ( downBeat[ 0 ] + Constants.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) )
for i in range( int( density * registerDensity * len( downBeats ) ) ):
if random.randint( 0, 100 ) < ( regularity * 100 * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ):
binSelection.append( 1 )
else:
if binSelection.count( 0 ) < len( downBeats ):
binSelection.append( 0 )
else:
binSelection.append( 1 )
countDown = binSelection.count( 1 )
for i in range( countDown ):
while onsetTime in rythmSequence or onsetTime == None:
onsetTime = prob2( downBeats )
rythmSequence.append( onsetTime )
for i in range( len( binSelection ) - countDown ):
while onsetTime in rythmSequence or onsetTime == None:
onsetTime = prob2( upBeats )
rythmSequence.append( onsetTime )
rythmSequence.sort()
return rythmSequence
|