Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Generation/GenerationPitch.py
blob: bc38ee11c762bbf6e03445adea72bb101ebd6898 (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
import random
import Drunk

import Config
from Generation.GenerationConstants import GenerationConstants

class GenerationPitch:
    def __init__( self ):
        fakeMaximum = 4
        self.drunk = Drunk.Drunk( fakeMaximum )
        self.droneAndJump = Drunk.DroneAndJump( fakeMaximum )           
        self.repeter = Drunk.Repeter( fakeMaximum )            
        self.loopseg = Drunk.Loopseg( fakeMaximum )

        self.harmonicDrunk = Drunk.Drunk( fakeMaximum )
        self.harmonicDroneAndJump = Drunk.DroneAndJump( fakeMaximum )           
        self.harmonicRepeter = Drunk.Repeter( fakeMaximum )            
        self.harmonicLoopseg = Drunk.Loopseg( fakeMaximum )

    def chooseMethod( self, pattern ):
        if pattern == 0: return self.drunk
        elif pattern == 1: return self.droneAndJump         
        elif pattern == 2: return self.repeter           
        elif pattern == 3: return self.loopseg    

    def harmonicChooseMethod( self, pattern ):
        if pattern == 0: return self.harmonicDrunk
        elif pattern == 1: return self.harmonicDroneAndJump         
        elif pattern == 2: return self.harmonicRepeter           
        elif pattern == 3: return self.harmonicLoopseg   

    def drunkPitchSequence(self, length, parameters, table_pitch):
        pitchMethod = self.chooseMethod( parameters.pattern )
        pitchSequence = []
        numberOfPitch = int( ( 1 - parameters.pitchRegularity )  * 10 + 1 )
        for i in range(numberOfPitch):
            pitchSequence.append((table_pitch[pitchMethod.getNextValue(parameters.step, (len(table_pitch)-1))]) + GenerationConstants.DEFAULT_TONIQUE)
        for i in range( length - numberOfPitch ):
            position = i % numberOfPitch
            pitchSequence.append( pitchSequence[ position ] )
        return pitchSequence

    def drumPitchSequence(self, length, parameters, drumPitch, table_pitch=None):
        pitchSequence = []
        for i in range(length):
            pitchSequence.append(drumPitch[ random.randint( 0, ( len( drumPitch ) - 1 )  ) ] )         
        return pitchSequence  

    def harmonicPitchSequence( self, rythmSequence, parameters, table_pitch, harmonicSequence ):
        pitchSequence = []
        pitchMethod = self.harmonicChooseMethod( parameters.pattern )
        for onset in rythmSequence:
            beat = int( onset / Config.TICKS_PER_BEAT )
            pitchSequence.append( ( table_pitch[ harmonicSequence[ beat ] [ pitchMethod.getNextValue(3, ( len( harmonicSequence[ beat ]) - 1) ) ]] ) + GenerationConstants.DEFAULT_TONIQUE )
 #           pitchSequence.append( ( table_pitch[ random.choice( harmonicSequence[ beat ] ) ] ) + GenerationConstants.DEFAULT_TONIQUE )
        return pitchSequence