Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TamTamMini.activity/Mini/NoteStdAlone.py
blob: d007da91b307b99d4c88cb0d31fd9193334cd08e (plain)
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
import common.Config as Config
from common.Util.CSoundClient import CSoundClient
from common.Generation.GenerationConstants import GenerationConstants

class NoteStdAlone:
    def __init__( self, client,
                        onset,
                        pitch,
                        amplitude,
                        pan,
                        duration,
                        trackId,
                        fullDuration = False,
                        instrument = Config.FLUTE,
                        attack = 0.005,
                        decay = 0.095,
                        reverbSend = 0.1,
                        filterType = 0,
                        filterCutoff = 1000,
                        tied = False,
                        overlap = False,
                        instrumentFlag = Config.FLUTE  ):
        self.csnd = client
        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 play( self ):
        self.csnd.sendText( self.getText(120) )

    def getText( self, tempo ):
        if self.instrument[ 0: 4 ] == 'drum':
            if GenerationConstants.DRUMPITCH.has_key( self.pitch ):
                self.pitch = GenerationConstants.DRUMPITCH[ self.pitch ]

            if self.instrument == 'drum1kit':
                self.instrumentFlag = Config.DRUM1INSTRUMENTS[ self.pitch ]
            if self.instrument == 'drum2kit':
                self.instrumentFlag = Config.DRUM2INSTRUMENTS[ self.pitch ]
            if self.instrument == 'drum3kit':
                self.instrumentFlag = Config.DRUM3INSTRUMENTS[ self.pitch ]
            newPitch = 1
        else:
            self.instrumentFlag = self.instrument
            newPitch = pow( GenerationConstants.TWO_ROOT_TWELVE, self.pitch - 36 )

        oneTickDuration = (Config.MS_PER_MINUTE / 1000)  / tempo / Config.TICKS_PER_BEAT

        newDuration = oneTickDuration * self.duration

        # condition for tied notes
        if self.instrumentDB.instNamed[ self.instrumentFlag ].csoundInstrumentId  == 101  and self.tied and self.fullDuration:
            newDuration = -1
        # condition for overlaped notes
        if self.instrumentDB.instNamed[ 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

        loopStart = self.instrumentDB.instNamed[ self.instrumentFlag ].loopStart
        loopEnd = self.instrumentDB.instNamed[ self.instrumentFlag ].loopEnd
        crossDur = self.instrumentDB.instNamed[ self.instrumentFlag ].crossDur
        return Config.PLAY_NOTE_COMMAND % ( self.instrumentDB.instNamed[ self.instrumentFlag ].csoundInstrumentId,
                                                     self.trackId,
                                                     0,
                                                     newDuration,
                                                     newPitch,
                                                     self.reverbSend,
                                                     newAmplitude,
                                                     self.pan,
                                                     Config.INSTRUMENT_TABLE_OFFSET + self.instrumentDB.instNamed[ self.instrumentFlag ].instrumentId,
                                                     newAttack,
                                                     newDecay,
                                                     self.filterType,
                                                     self.filterCutoff,
                                                     loopStart,
                                                     loopEnd,
                                                     crossDur )