summaryrefslogtreecommitdiff
path: root/grammar.py
diff options
context:
space:
mode:
authorHouyhnhnm <hykusb@bitmai.la>2018-06-07 14:16:34 +0200
committerHouyhnhnm <hykusb@bitmai.la>2018-06-07 14:16:34 +0200
commit789e7c10bc8765d498ba9f1e4c3eac35b64b41e7 (patch)
tree0872e3b8b3c26753579392743789c160d0def095 /grammar.py
parent2be56d2f3541cedd0c4e872aeb5b7da110d9b260 (diff)
render rhythms to score
Diffstat (limited to 'grammar.py')
-rw-r--r--grammar.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/grammar.py b/grammar.py
index 7afec1b..aa1d310 100644
--- a/grammar.py
+++ b/grammar.py
@@ -13,14 +13,14 @@ class Grammar(object):
class Phonology(object):
"""weighted repository of rhythmic, harmonic and gestural features"""
- def __init__(self, footprints=[], functions=[], paths=[]):
- self.footprints = footprints
+ def __init__(self, ligatures=[], functions=[], paths=[]):
+ self.ligatures = ligatures
self.functions = functions
self.paths = paths
def print(self):
features = {
- 'footprints': self.footprints,
+ 'ligatures': self.ligatures,
'functions': self.functions,
'paths': self.paths,
}
@@ -28,8 +28,8 @@ class Phonology(object):
pprint(features)
print()
- def addFootprintRule(self, footprintRule, weight=1):
- self.footprints.append((footprintRule, weight))
+ def addligatureRule(self, ligatureRule, weight=1):
+ self.ligatures.append((ligatureRule, weight))
def addFunctionRule(self, functionRule, weight=1):
self.functions.append((functionRule, weight))
@@ -40,22 +40,22 @@ class Phonology(object):
def makeCadence(self): # (duration=None, harmonicFilter=None)
""" assemble bundle of features from phonology rules """
cadence = Cadence()
- cadence.footprint = self.makeFootprint()
+ cadence.ligature = self.makeligature()
cadence.function = self.makeFunction()
cadence.path = self.makePath()
return cadence
- def makeFootprint(self):
- # select footprint rule
- weights = array([rule[1] for rule in self.footprints])
+ def makeligature(self):
+ # select ligature rule
+ weights = array([rule[1] for rule in self.ligatures])
normalized_weights = weights.astype(float) / weights.sum()
- footprintChoices = array(self.footprints)
- index = choice(len(footprintChoices), p=normalized_weights)
- footprintRule = footprintChoices[index][0]
+ ligatureChoices = array(self.ligatures)
+ index = choice(len(ligatureChoices), p=normalized_weights)
+ ligatureRule = ligatureChoices[index][0]
# select feature value from range where necessary
- footprint = []
- for footRule in footprintRule:
+ ligature = []
+ for footRule in ligatureRule:
foot = {}
# each foot option is composite
footChoices = array(footRule['foot'])
@@ -68,9 +68,9 @@ class Phonology(object):
foot['sync'] = []
for steps in footRule['sync']:
foot['sync'].append( choice(steps) )
- footprint.append(foot)
+ ligature.append(foot)
- return footprint
+ return ligature
def makeFunction(self):