summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHouyhnhnm <hykusb@bitmai.la>2018-06-02 21:51:53 +0200
committerHouyhnhnm <hykusb@bitmai.la>2018-06-02 21:51:53 +0200
commit8f2251a175d8d52edd12d62168c7c0e795be6146 (patch)
treefaedd791aa3dac3cc7480dade27c0165ee233b91
parent69eb369f73f0a64898246677d40abd2f604bcb7c (diff)
add phonology, syntax stubs
-rw-r--r--cadence.py99
-rw-r--r--diagram.py23
-rw-r--r--main.py44
-rw-r--r--phonology.py90
4 files changed, 256 insertions, 0 deletions
diff --git a/cadence.py b/cadence.py
new file mode 100644
index 0000000..b7fbde0
--- /dev/null
+++ b/cadence.py
@@ -0,0 +1,99 @@
+from pprint import pprint
+
+'''
+Cadence
+ from Latin cadō ("I fall, I cease"), Proto-Indo-European *ḱad- ("to fall").
+ Doublet of cadenza and chance.
+
+The act or state of declining or sinking.
+ A fall in inflection of a speaker’s voice, such as at the end of a sentence.
+ A progression of at least two chords which conclude a segment of music; musical punctuation; a clausula.
+ A move which ends a phrase in dance.
+
+Rhythmic flow. ("The cadence of life at the front is about to change.")
+ The measure or beat of movement.
+ The rhythm and sequence of a series of actions.
+ The number of steps per unit time.
+
+The general inflection or modulation of the voice, or of any sound.
+
+The cadence is that which closes itself by opening - the cork which makes the bottle.
+
+'''
+
+
+class Cadence(object):
+ """a musical morpheme bundling rhythmic, gestural and harmonic features"""
+ def __init__(self, footprint=None, function=None, path=None):
+ self.footprint = footprint
+ self.function = function
+ self.path = path
+
+ # string represention of cadence - note list ?
+ def __str__(self):
+ features = {
+ 'footprint': self.footprint,
+ 'function': self.function,
+ 'path': self.path,
+ }
+ return str(features)
+
+ @property
+ def features(self):
+ features = {
+ 'footprint': self.footprint,
+ 'function': self.function,
+ 'path': self.path,
+ }
+ return features
+
+ def update(featureDict):
+ if 'footprint' in featureDict:
+ self.footprint = featureDict['footprint']
+ if 'function' in featureDict:
+ self.function.update(featureDict['function'])
+ if 'path' in featureDict:
+ self.path.update(featureDict['path'])
+
+ def print(self):
+ features = {
+ 'footprint': self.footprint,
+ 'function': self.function,
+ 'path': self.path,
+ }
+ pprint(features)
+
+'''
+# example
+cad = Cadence()
+
+cad.footprint = [{
+ 'span': 2,
+ 'gait': 'double', # Gait.double or Gait['double']...
+ 'foot': [-1/2, -1/4, 0, 1/2],
+ 'step': [0, 0, 0, 1/2],
+},{
+ 'span': 1,
+ 'gait': 'double',
+ 'foot': [None],
+ 'step': [None],
+},{
+ 'span': 1,
+ 'gait': 'double',
+ 'foot': [-1/2, 0, 1/4, 1/2],
+ 'step': [1/2, 0, 0, 0],
+}]
+
+cad.function = {
+ 'address': 'A1',
+ 'transposition': 1,
+}
+
+cad.path = {
+ 'range': 2,
+ 'figure': 'rampUp',
+ 'tilt': 'float',
+}
+
+cad.print() # = pprint(cad.features)
+''' \ No newline at end of file
diff --git a/diagram.py b/diagram.py
new file mode 100644
index 0000000..6401469
--- /dev/null
+++ b/diagram.py
@@ -0,0 +1,23 @@
+from binarytree import *
+
+class Diagram(object):
+ """represents a syntactic structure (wrapper for binary tree)
+ """
+ def __init__(self, height=3, size=None):
+ self.tree = tree(height=height)
+ if isinstance(size, int):
+ if size>height and size<((2^(height+1))-1):
+ while self.tree.size != size:
+ self.tree = tree(height=height)
+ else:
+ # raise NodeNotFoundError('no node to delete at index {}')
+ print('syntax diagram impossible for height'+height+'and size'+size)
+
+ def print(self):
+ self.tree.pprint(index=True, delimiter='\'')
+
+'''
+# example
+dee = Diagram()
+dee.print()
+''' \ No newline at end of file
diff --git a/main.py b/main.py
index e69de29..52e8e2b 100644
--- a/main.py
+++ b/main.py
@@ -0,0 +1,44 @@
+from phonology import *
+from diagram import *
+
+
+'''
+modules:
+
+cadence.py define musical morphemes
+diagram.py define binary tree structures
+phonology.py distribution of cadential features for given lexicon
+lexicon.py repository of lexemes w/ weighted dependency correlations
+passage.py cadences from lexicon mapped to tree diagram
+ spellout() sequence of unified cadences in passage (for each voice)
+score.py list of n passages rendered to music21 score object
+ export() to xml, midi, ly
+
+'''
+
+phonology = Phonology()
+
+phonology.addFootprintRule([{
+ 'span': [2],
+ 'gait': ['double','triple'],
+ 'foot': [[-1/2, 0, 1/2]],
+ 'step': [[0, 1/2], [0, 1/2], [0, 1/2]],
+}])
+
+phonology.addFunctionRule({
+ 'address': ['A1','B1'],
+ 'transposition': [-1,0,1],
+})
+
+phonology.addPathRule({
+ 'range': [2,3,4],
+ 'figure': ['rampUp', 'rampDown'],
+ 'tilt': ['float', 'dive'],
+})
+
+lex = phonology.makeCadence()
+lex.print()
+
+syntax = Diagram()
+syntax.print()
+
diff --git a/phonology.py b/phonology.py
new file mode 100644
index 0000000..2e8d978
--- /dev/null
+++ b/phonology.py
@@ -0,0 +1,90 @@
+from cadence import *
+from numpy import array
+from numpy.random import choice, seed
+
+class Phonology(object):
+ """weighted repository of rhythmic, harmonic and gestural features"""
+
+ def __init__(self, footprints=[], functions=[], paths=[]):
+ self.footprints = footprints
+ self.functions = functions
+ self.paths = paths
+
+ def addFootprintRule(self, footprintRule, weight=1):
+ self.footprints.append((footprintRule, weight))
+
+ def addFunctionRule(self, functionRule, weight=1):
+ self.functions.append((functionRule, weight))
+
+ def addPathRule(self, pathRule, weight=1):
+ self.paths.append((pathRule, weight))
+
+ def makeCadence(self): # (duration=None, harmonicFilter=None)
+ """ assemble bundle of features from phonology rules """
+ cadence = Cadence()
+ cadence.footprint = self.makeFootprint()
+ cadence.function = self.makeFunction()
+ cadence.path = self.makePath()
+ return cadence
+
+ def makeFootprint(self):
+ # select footprint rule
+ weights = array([rule[1] for rule in self.functions])
+ normalized_weights = weights.astype(float) / weights.sum()
+ footprintChoices = array(self.footprints)
+ index = choice(len(footprintChoices), p=normalized_weights)
+ footprintRule = footprintChoices[index][0]
+
+ # select feature value from range where necessary
+ footprint = []
+ for footRule in footprintRule:
+ foot = {}
+ # each foot option is composite
+ footChoices = array(footRule['foot'])
+ index = choice(len(footChoices))
+ foot['foot'] = list(footChoices[index])
+ # other feature options aren't
+ foot['span'] = choice(footRule['span'])
+ foot['gait'] = choice(footRule['gait'])
+ # timing options are per note:
+ foot['step'] = []
+ for steps in footRule['step']:
+ foot['step'].append( choice(steps) )
+ footprint.append(foot)
+
+ return footprint
+
+
+ def makeFunction(self):
+ # select function rule
+ weights = array([rule[1] for rule in self.functions])
+ normalized_weights = weights.astype(float) / weights.sum()
+ functionChoices = array(self.functions)
+ index = choice(len(functionChoices), p=normalized_weights)
+ functionRule = functionChoices[index][0]
+
+ # select value from range for each feature
+ function = {}
+ function['address'] = choice(functionRule['address'])
+ function['transposition'] = choice(functionRule['transposition'])
+
+ return function
+
+
+ def makePath(self):
+
+ # select path rule
+ weights = array([rule[1] for rule in self.paths])
+ normalized_weights = weights.astype(float) / weights.sum()
+ pathChoices = array(self.paths)
+ index = choice(len(pathChoices), p=normalized_weights)
+ pathRule = pathChoices[index][0]
+
+
+ # select value from range for each feature
+ path = {}
+ path['range'] = choice(pathRule['range'])
+ path['figure'] = choice(pathRule['figure'])
+ path['tilt'] = choice(pathRule['tilt'])
+
+ return path