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
|
import random
import math
from Framework.Constants import Constants
from Framework.CSound.CSoundConstants import CSoundConstants
from Player.NoteStdAlone import NoteStdAlone
from Framework.Generation.GenerationConstants import GenerationConstants
from Player.GenRythm import GenRythm
def generator( instrument, nbeats, regularity, reverbSend, client ):
def makePitchSequence(length, drumPitch):
pitchSequence = []
for i in range(length):
pitchSequence.append(drumPitch[ random.randint( 0, ( len( drumPitch ) - 1 ) ) ] )
return pitchSequence
def makeGainSequence( onsetList ):
gainSequence = []
for onset in onsetList:
if onset == 0:
gain = random.uniform(GenerationConstants.GAIN_MID_MAX_BOUNDARY, GenerationConstants.GAIN_MAX_BOUNDARY)
elif ( onset % Constants.TICKS_PER_BEAT) == 0:
gain = random.uniform(GenerationConstants.GAIN_MID_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MAX_BOUNDARY)
else:
gain = random.uniform(GenerationConstants.GAIN_MIN_BOUNDARY, GenerationConstants.GAIN_MID_MIN_BOUNDARY)
gainSequence.append(gain*2)
return gainSequence
def makeDurationSequence( onsetList ):
durationSequence = []
fullDurationSequence = []
if len( onsetList ) > 1:
for i in range(len(onsetList)):
duration = GenerationConstants.DOUBLE_TICK_DUR / 2
durationSequence.append(duration)
fullDurationSequence.append(False)
elif len( onsetList ) == 1:
durationSequence.append( GenerationConstants.DOUBLE_TICK_DUR / 2 )
fullDurationSequence.append( False )
return durationSequence, fullDurationSequence
def pageGenerate( regularity, drumPitch ):
barLength = Constants.TICKS_PER_BEAT * nbeats
if instrument == 'drum1kit':
currentInstrument = CSoundConstants.DRUM1INSTRUMENTS[ drumPitch[ 0 ] ]
elif instrument == 'drum2kit':
currentInstrument = CSoundConstants.DRUM2INSTRUMENTS[ drumPitch[ 0 ] ]
elif instrument == 'drum3kit':
currentInstrument = CSoundConstants.DRUM3INSTRUMENTS[ drumPitch[ 0 ] ]
makeRythm = GenRythm( currentInstrument, barLength, nbeats )
rythmSequence = makeRythm.drumRythmSequence(regularity)
pitchSequence = makePitchSequence(len(rythmSequence), drumPitch )
gainSequence = makeGainSequence(rythmSequence)
durationSequence, fullDurationSequence = makeDurationSequence(rythmSequence)
trackID = 5
pan = 0.5
attack = 0.005
decay = 0.095
trackNotes = []
for i in range(len(rythmSequence)):
trackNotes.append( NoteStdAlone( client, rythmSequence[i], pitchSequence[i], gainSequence[i],
pan, durationSequence[i], trackID,
fullDurationSequence[i], instrument, attack, decay, reverbSend ) )
return trackNotes
##################################################################################
# begin generate()
if regularity > 0.75:
pitchOfStream = [ [ 24 ], [30] , [ 40 ], [ 46 ] ]
elif regularity > 0.5:
pitchOfStream = [ [ 24, 28 ], [ 30, 32 ], [ 36, 38, 40 ], [ 46, 48 ] ]
elif regularity > 0.25:
pitchOfStream = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 46, 48 ] ]
else:
pitchOfStream = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 44, 46, 48 ] ]
trackNotes = []
for drumPitch in pitchOfStream:
trackNotes.append(pageGenerate( regularity, drumPitch ))
return trackNotes
|