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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
import Config
from Util.CSoundClient import CSoundClient
from Generation.GenerationConstants import GenerationConstants
class CSoundNote :
#-----------------------------------
# initialization
#-----------------------------------
def __init__( self,
onset,
pitch,
amplitude,
pan,
duration,
trackId,
fullDuration = False,
instrument = Config.FLUTE,
attack = 0.002,
decay = 0.098,
reverbSend = 0.1,
filterType = 0,
filterCutoff = 1000,
tied = False,
overlap = False,
instrumentFlag = Config.FLUTE ):
self.onset = onset
self.pitch = pitch
self.amplitude = amplitude
self.pan = pan
self.duration = duration
self.trackId = trackId
self.instrument = instrument
self.fullDuration = fullDuration
self.attack = attack
self.decay = decay
self.reverbSend = reverbSend
self.filterType = filterType
self.filterCutoff = filterCutoff
self.tied = tied
self.overlap = overlap
if self.instrument == 'drum1kit':
self.instrumentFlag = Config.DRUM1INSTRUMENTS[ self.pitch ]
else:
self.instrumentFlag = self.instrument
def __getstate__(self):
return {'onset': self.onset,
'pitch': self.pitch,
'amplitude': self.amplitude,
'pan': self.pan,
'duration': self.duration,
'trackId': self.trackId,
'instrument': self.instrument,
'fullDuration': self.fullDuration,
'attack': self.attack,
'decay': self.decay,
'reverbSend': self.reverbSend,
'filterType': self.filterType,
'filterCutoff': self.filterCutoff,
'tied': self.tied,
'overlap': self.overlap,
'instrumentFlag': self.instrumentFlag }
def __setstate__(self,dict):
self.onset = dict['onset']
self.pitch = dict['pitch']
self.amplitude = dict['amplitude']
self.pan = dict['pan']
self.duration = dict['duration']
self.trackId = dict['trackId']
self.instrument = dict['instrument']
self.fullDuration = dict['fullDuration']
self.attack = dict['attack']
self.decay = dict['decay']
self.reverbSend = dict['reverbSend']
self.filterType = dict['filterType']
self.filterCutoff = dict['filterCutoff']
self.tied = dict['tied']
self.overlap = dict['overlap']
self.instrumentFlag = dict['instrumentFlag']
def clone( self ):
return CSoundNote( self.onset, self.pitch, self.amplitude, self.pan,
self.duration, self.trackId, self.fullDuration, self.instrument,
self.attack, self.decay, self.reverbSend, self.filterType, self.filterCutoff, self.tied, self.overlap, self.instrumentFlag )
def getText( self, secs_per_tick, delay ):
if secs_per_tick > 1 : raise 'invalid secs_per_tick'
if self.instrument == 'drum1kit':
if GenerationConstants.DRUMPITCH.has_key( self.pitch ):
self.pitch = GenerationConstants.DRUMPITCH[ self.pitch ]
self.instrumentFlag = Config.DRUM1INSTRUMENTS[ self.pitch ]
newPitch = 1
else:
self.instrumentFlag = self.instrument
newPitch = pow( GenerationConstants.TWO_ROOT_TWELVE, self.pitch - 36 )
newDuration = secs_per_tick * self.duration
# condition for tied notes
if Config.INSTRUMENTS[ self.instrumentFlag ].csoundInstrumentId == 101 and self.tied and self.fullDuration:
newDuration = -1
# condition for overlaped notes
if Config.INSTRUMENTS[ self.instrumentFlag ].csoundInstrumentId == 102 and self.overlap:
newDuration = oneTickDuration * self.duration + 1.
if True: newAmplitude = self.amplitude * 0.8
else : newAmplitude = self.amplitude * music_volume_get( self.trackId )
newAttack = newDuration * self.attack
if newAttack <= 0.002:
newAttack = 0.002
newDecay = newDuration * self.decay
if newDecay <= 0.002:
newDecay = 0.002
return Config.PLAY_NOTE_COMMAND % ( \
Config.INSTRUMENTS[ self.instrumentFlag ].csoundInstrumentId,
self.trackId,
delay,
newDuration,
newPitch,
self.reverbSend,
newAmplitude,
self.pan,
Config.INSTRUMENT_TABLE_OFFSET+Config.INSTRUMENTS[self.instrumentFlag].instrumentId,
newAttack,
newDecay,
self.filterType,
self.filterCutoff,
Config.INSTRUMENTS[ self.instrumentFlag ].loopStart,
Config.INSTRUMENTS[ self.instrumentFlag ].loopEnd,
Config.INSTRUMENTS[ self.instrumentFlag ].crossDur )
|