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
|
import math
from pprint import pprint
from utils import *
figures = {
# sample continuous functions, apply scaling factor
'flat': lambda x: 1,
'rampUp': lambda x: x,
'rampDown': lambda x: -x,
'accUp': lambda x: math.sin(5*(x-1)/math.pi)+1,
'accDown': lambda x: -(math.sin(5*(x-1)/math.pi)+1),
'decUp': lambda x: math.sin(5*x/math.pi),
'decDown': lambda x: -math.sin(5*x/math.pi),
'triangleUp': lambda x: abs(((((x/2)+0.25)%(0.5))*4)-1),
'triangleDown': lambda x: -abs(((((x/2)+0.25)%(0.5))*4)-1),
'saddleUp': lambda x: math.sin(10*(x-0.5)/math.pi),
'saddleDown': lambda x: -math.sin(10*x/math.pi),
'spikeUp': lambda x: -(abs(math.sin(10*(x-0.5)/math.pi))-1),
'spikeDown': lambda x: abs(math.sin(10*(x-0.5)/math.pi))-1,
'zigZagDown': lambda x: (abs((((x/2)%(0.3333)+0.1667)*3)-1.0)-0.5)*2,
'zigZagUp': lambda x: -(abs((((x/2)%(0.3333)+0.1667)*3)-1.0)-0.5)*2,
'sawtooth1Up': lambda x: x%(1.0), # same as ramp except f(1.0)==0
'sawtooth1Down': lambda x: -x%(1.0),
'sawtooth2Up': lambda x: (x%(0.5))*2,
'sawtooth2Down': lambda x: -(x%(0.5))*2,
'sawtooth3Up': lambda x: (x%(0.3333))*3,
'sawtooth3Down': lambda x: -(x%(0.3333))*3,
# 'stepUp': just use if/then
# 'stepDn': just use if/then
# etc
}
def makeOutline(pathFeatures, realizationFeatures):
outline = []
print("realizationFeatures['feet']", flatten(realizationFeatures['feet']))
cardinality = len(flatten(realizationFeatures['feet']))
for i in range(cardinality):
positionRatio = i / cardinality
# calculate relative positions
pitch = figures[pathFeatures['figure']](positionRatio)
# scale by height
pitch = round(pitch * pathFeatures['range'])
# shift by direction
pitch += realizationFeatures['height']
outline.append(pitch)
return outline
# print('"feet"', feet)
# span = voice['span'][1] - voice['span'][0]
# proportional - also try sampling function evenly by # notes.
# for note in voice['notes']:
# position_ratio = (note[1] - voice['span'][0]) / span
|