diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2018-06-09 15:17:03 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2018-06-09 15:17:03 +0200 |
| commit | 2a6446bd77f0e330784d14a291d6db7b9bee91df (patch) | |
| tree | 2dda4c7cfec184663e3c7c0536adf951324b4191 | |
| parent | 63ce35f3f7ced2200464613654968690328e3973 (diff) | |
reprojected features don't inherit value
| -rw-r--r-- | grammar.py | 59 | ||||
| -rw-r--r-- | harmony.py | 3 | ||||
| -rw-r--r-- | main.py | 21 | ||||
| -rw-r--r-- | passage.py | 16 | ||||
| -rw-r--r-- | render.py | 4 | ||||
| -rw-r--r-- | rhythm.py | 66 | ||||
| -rw-r--r-- | spec.py | 148 |
7 files changed, 201 insertions, 116 deletions
@@ -10,8 +10,37 @@ class Grammar(object): self.syntax = syntax + +class Morphology(object): + + def __init__(self): + self.anticipationRules = [] + self.prolongationRules = [] + + def addAnticipationRule(self, projectedFeatures): + self.anticipationRules.append(projectedFeatures) + + def addProlongationRule(self, projectedFeatures): + self.prolongationRules.append(projectedFeatures) + + def selectAnticipation(self): + return choice(self.anticipationRules) + + def selectProlongation(self): + return choice(self.prolongationRules) + + def print(self): + features = { + 'anticipations': self.anticipationRules, + 'prolongations': self.prolongationRules, + } + print("\nMorphology") + pprint(features) + print() + + class Phonology(object): - """weighted repository of rhythmic, harmonic and gestural features""" + """weighted repository of rhythmic, harmonic and gestural features, and feature dependencies""" def __init__(self, ligatures=[], functions=[], paths=[]): self.ligatures = ligatures @@ -108,31 +137,3 @@ class Phonology(object): return path -class Morphology(object): - - def __init__(self): - self.anticipationRules = [] - self.prolongationRules = [] - - def addAnticipationRule(self, projectedFeatures): - self.anticipationRules.append(projectedFeatures) - - def addProlongationRule(self, projectedFeatures): - self.prolongationRules.append(projectedFeatures) - - def selectAnticipation(self): - return choice(self.anticipationRules) - - def selectProlongation(self): - return choice(self.prolongationRules) - - def print(self): - features = { - 'anticipations': self.anticipationRules, - 'prolongations': self.prolongationRules, - } - print("\nMorphology") - pprint(features) - print() - - @@ -95,6 +95,9 @@ def makeLens(harmonyFeatures, ligature): lens.append( flatten(expand(address, 7))[33] ) if note == -1/32: lens.append( flatten(expand(address, 7))[31] ) + for shift in lens: + shift = (shift+harmonyFeatures['transposition']) + if abs(shift) == 2: shift = int(shift * -1/2) return lens def expand(address, magnification, getValues=True): @@ -27,25 +27,32 @@ render.py list of n passages rendered to music21 score object # g.morphology.print() lexicon = Lexicon() -lexicon.populate(g, 8) +lexicon.populate(g, 13) lexicon.print() print("\n-----------\n-----------\n") -passage = Passage(height=5, size=23) +passage = Passage(height=6) passage.spellout(lexicon) passage.print() # print(passage.bars) -# print(passage.tree) +print(passage.tree) print() renderer = Renderer() renderer.render(passage) -# todo: working with multiple voices at once -# todo: convincing m21 to break durations into tied notes over the tactus -# todo: add discovered lexemes, pairwise dependencies to lexicon pre-population, iteratively... - +# todo +# working with multiple voices at once +# label events on score +# record phonology/agreement, spellout to log, label it and score with unix time +# rests after constituents, corresponding to depth +# lexemes with opacity to certain features - or: local agreement... +# pruning algorithm for shorter sentences over taller trees - remove random/weighted leaves from larger tree +# fit to instrument range - octave break optimization (score *constituent* boundaries using 2017 codebase metric?) +# convince m21 to break durations into tied notes on the beat +# add discovered lexemes, pairwise dependencies to lexicon pre-population, iteratively +# spec bundles which can be selected and unified (merge-mask) until a full lexeme is obtained (allowing all feature correlations) @@ -80,9 +80,16 @@ class Passage(object): node.right.unify[feat] = node.lexeme.cadence.path[feat] spellout = [] - # now read out nodes into list, with prolonged features replacing lexical features + # read out nodes into list for node in self.tree.inorder: next_lexeme = node.lexeme # deepcopy(node.lexeme) + # prolonged features replace lexical features, unless lexeme projects that feature itself + reprojectedFeatures = [] + for feat in node.unify.keys(): + if feat in next_lexeme.government['prolongation'] or next_lexeme.government['anticipation']: + reprojectedFeatures.append(feat) + for feat in reprojectedFeatures: + del node.unify[feat] for feat in node.unify.keys(): if feat == 'ligature': next_lexeme.cadence.ligature = node.unify[feat] @@ -98,11 +105,8 @@ class Passage(object): return spellout def setHarmony(self): - print("\nsetHarmony\n----------") for i, node in enumerate(self.tree.levelorder): node.lexeme.realization['lens'] = harmony.makeLens(node.lexeme.cadence.function, node.lexeme.cadence.ligature) - print('lens', node.lexeme.realization['lens']) - def setFigure(self): for i, node in enumerate(self.tree.levelorder): @@ -165,9 +169,9 @@ class Passage(object): elif i == len(bars)-1 or next > len(bars)-1: right = False else: - if bars[i]+bars[next] < 5.5 and bars[i]+bars[prev] > 5.5: + if bars[i]+bars[next] <= 5.0 and bars[i]+bars[prev] > 5.0: right = True - elif bars[i]+bars[next] > 5.5 and bars[i]+bars[prev] < 5.5: + elif bars[i]+bars[next] > 5.0 and bars[i]+bars[prev] <= 5.0: right = False else: if (scores[i] > scores[prev]) and (next not in prolongedIndices): @@ -115,8 +115,10 @@ class Renderer(object): internalOffset += abs(increment['_duration']) if i == 0: measure.padAsAnacrusis() - measure.makeRests(fillGaps=False, timeRangeFromBarDuration=True) + measure.makeRests(fillGaps=True, timeRangeFromBarDuration=True) + measure.timeSignature = measure.bestTimeSignature() measures.show() + # measures.show('lily') timeSignatures = { 1.5: m21.meter.TimeSignature('3/8'), @@ -3,14 +3,14 @@ from math import ceil, floor refractions = { # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 'double': [(0,1),(1,16),(1,8), (3,16),(1,4), (5,16),(3,8), (7,16), (1,2), (9,16), (5,8), (11,16),(3,4), (13,16),(7,8), (15,16),(1,1)], - 'trp_ls': [(0,1),(1,12),(1,6), (1,4), (1,3), (5,12),(1,2), (7,12), (2,3), (17,24),(3,4), (19,24),(5,6), (7,8), (11,12),(23,24),(1,1)], - 'qnt_ls': [(0,1),(1,10),(2,10),(3,10),(4,10),(9,20),(1,2), (11,20),(3,5),(13,20),(7,10), (3,4), (4,5), (17,20),(9,10), (19,20),(1,1)], - 'trp_ll': [(0,1),(1,12),(1,6), (1,4), (1,3), (5,12),(1,2), (7,12), (2,3), (3,4), (5,6), (11,12),(1,1), (13,12),(7,6), (5,4), (4,3)], - 'qnt_ll': [(0,1),(1,10),(2,10),(3,10),(4,10),(1,2), (3,5), (7,10), (4,5), (9,10), (1,1), (11,10),(6,5), (13,10),(7,5), (15,10),(8,5)], - 'trp_sl': [(0,1),(1,24),(1,12),(1,8), (1,6), (5,24),(1,4), (7,24), (1,3), (5,12), (1,2), (7,12), (2,3), (3,4), (5,6), (11,12),(1,1)], - 'qnt_sl': [(0,1),(1,20),(1,10),(3,20),(2,10),(1,4), (3,10),(7,20), (4,10),(9,20), (1,2), (11,20),(3,5), (7,10), (4,5), (9,10), (1,1)], - 'trp_ss': [(0,1),(1,24),(1,12),(1,8), (1,6), (5,24),(1,4), (7,24), (1,3), (3,8), (5,12),(11,24),(1,2), (13,24),(7,12), (5,8), (2,3)], - 'qnt_ss': [(0,1),(1,20),(1,10),(3,20),(2,10),(1,4), (3,10),(7,20), (4,10),(9,20), (1,2), (11,20),(3,5), (13,20),(7,10), (3,4), (4,5)], + 'trip_ls': [(0,1),(1,12),(1,6), (1,4), (1,3), (5,12),(1,2), (7,12), (2,3), (17,24),(3,4), (19,24),(5,6), (7,8), (11,12),(23,24),(1,1)], + 'quint_ls': [(0,1),(1,10),(2,10),(3,10),(4,10),(9,20),(1,2), (11,20),(3,5),(13,20),(7,10), (3,4), (4,5), (17,20),(9,10), (19,20),(1,1)], + 'trip_ll': [(0,1),(1,12),(1,6), (1,4), (1,3), (5,12),(1,2), (7,12), (2,3), (3,4), (5,6), (11,12),(1,1), (13,12),(7,6), (5,4), (4,3)], + 'quint_ll': [(0,1),(1,10),(2,10),(3,10),(4,10),(1,2), (3,5), (7,10), (4,5), (9,10), (1,1), (11,10),(6,5), (13,10),(7,5), (15,10),(8,5)], + 'trip_sl': [(0,1),(1,24),(1,12),(1,8), (1,6), (5,24),(1,4), (7,24), (1,3), (5,12), (1,2), (7,12), (2,3), (3,4), (5,6), (11,12),(1,1)], + 'quint_sl': [(0,1),(1,20),(1,10),(3,20),(2,10),(1,4), (3,10),(7,20), (4,10),(9,20), (1,2), (11,20),(3,5), (7,10), (4,5), (9,10), (1,1)], + 'trip_ss': [(0,1),(1,24),(1,12),(1,8), (1,6), (5,24),(1,4), (7,24), (1,3), (3,8), (5,12),(11,24),(1,2), (13,24),(7,12), (5,8), (2,3)], + 'quint_ss': [(0,1),(1,20),(1,10),(3,20),(2,10),(1,4), (3,10),(7,20), (4,10),(9,20), (1,2), (11,20),(3,5), (13,20),(7,10), (3,4), (4,5)], 'qt2_ls': [(0,1),(1,10),(2,10),(1,4), (3,10),(7,20),(4,10),(9,20), (1,2), (3,5), (7,10),(3,4), (4,5), (17,20),(9,10), (19,20),(1,1)], 'qt2_sl': [(0,1),(1,20),(1,10),(3,20),(2,10),(1,4), (3,10),(4,10), (1,2), (11,20),(3,5), (13,20),(7,10),(3,4), (4,5), (9,10), (1,1)], 'tp2_ls': [(0,1),(1,12),(1,6), (1,4), (1,3), (3,8), (5,12),(11,24),(1,2), (7,12), (2,3), (3,4), (5,6), (7,8), (11,12),(23,24),(1,1)], @@ -22,14 +22,14 @@ points = [0.0, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625] metric_distances = { 'double': [(0,1), (1,2), (1,4), (1,8), (1,16)], - 'trp_ls': [(0,1), (2,3), (1,3), (1,6), (1,12)], - 'qnt_ls': [(0,1), (3,5), (4,10), (2,10), (1,10)], - 'trp_ll': [(0,1), (2,3), (1,3), (1,6), (1,12)], - 'qnt_ll': [(0,1), (4,5), (4,10), (2,10), (1,10)], - 'trp_sl': [(0,1), (1,3), (1,6), (1,12), (1,24)], - 'qnt_sl': [(0,1), (4,10), (2,10), (1,10), (1,20)], - 'trp_ss': [(0,1), (1,3), (1,6), (1,12), (1,24)], - 'qnt_ss': [(0,1), (4,10), (2,10), (1,10), (1,20)], + 'trip_ls': [(0,1), (2,3), (1,3), (1,6), (1,12)], + 'quint_ls': [(0,1), (3,5), (4,10), (2,10), (1,10)], + 'trip_ll': [(0,1), (2,3), (1,3), (1,6), (1,12)], + 'quint_ll': [(0,1), (4,5), (4,10), (2,10), (1,10)], + 'trip_sl': [(0,1), (1,3), (1,6), (1,12), (1,24)], + 'quint_sl': [(0,1), (4,10), (2,10), (1,10), (1,20)], + 'trip_ss': [(0,1), (1,3), (1,6), (1,12), (1,24)], + 'quint_ss': [(0,1), (4,10), (2,10), (1,10), (1,20)], 'qt2_ls': [(0,1), (1,2), (3,10), (2,10), (1,10)], 'qt2_sl': [(0,1), (1,2), (2,10), (1,10), (1,20)], 'tp2_ls': [(0,1), (1,2), (1,3), (1,6), (1,12)], @@ -74,21 +74,25 @@ def syncOffsets(foot): def resolveCollisions(syncedOffsets): # for now remove one - note lexeme object will reflect incorrect number of notes - while len(syncedOffsets) != len(set(syncedOffsets)): - neighborPairs = [ (x,y) for x, y in zip(syncedOffsets[:-1], syncedOffsets[1:]) ] - for i, pair in enumerate(neighborPairs): - if pair[0] == pair[1]: - if pair[0] > 0: - if syncedOffsets[i+1] == ceil((syncedOffsets[i+1]*2)) / 2: - syncedOffsets[i+1] += 0.5 - else: - syncedOffsets[i+1] = fl(ceil((syncedOffsets[i+1]*2)) / 2) - if pair[0] < 0: - if syncedOffsets[i] == floor((syncedOffsets[i]*2)) / 2: - syncedOffsets[i] -= 0.5 - else: - syncedOffsets[i] = fl(floor((syncedOffsets[i]*2)) / 2) - return syncedOffsets + return sorted(list(set(syncedOffsets))) + + # because this breaks it + # while len(syncedOffsets) != len(set(syncedOffsets)): + # neighborPairs = [ (x,y) for x, y in zip(syncedOffsets[:-1], syncedOffsets[1:]) ] + # removeIndices = [] + # for i, pair in enumerate(neighborPairs): + # if pair[0] == pair[1]: + # if pair[0] > 0: + # if syncedOffsets[i+1] == ceil((syncedOffsets[i+1]*2)) / 2: + # syncedOffsets[i+1] += 0.5 + # else: + # syncedOffsets[i+1] = fl(ceil((syncedOffsets[i+1]*2)) / 2) + # if pair[0] < 0: + # if syncedOffsets[i] == floor((syncedOffsets[i]*2)) / 2: + # syncedOffsets[i] -= 0.5 + # else: + # syncedOffsets[i] = fl(floor((syncedOffsets[i]*2)) / 2) + # return syncedOffsets def getFinalOffset(offset, refraction, scale): @@ -2,99 +2,163 @@ from grammar import * ligatureRules = [ [{ - 'span': [2], + 'span': [1], 'gait': ['double'], 'foot': [[-1/2, 0, 1/2], [-1/2, 0, 1/2]], - 'sync': [[0, 1/2], [0, 1/2], [0, 1/2]], + 'sync': [[0], [0], [-1/2], [0], [0], [-1/2]], }], [{ 'span': [1], 'gait': ['double'], - 'foot': [[-1/2, 0, 1/2], [-1/2, 0, 1/2]], - 'sync': [[0], [0], [0]], + 'foot': [[-1/2, 0, 1/2], [-1/2, 0], [-1/2, 0]], + 'sync': [[0], [0], [0], [0], [0, 1/2], [0], [0, 1/2]], # }], [{ 'span': [2], - 'gait': ['double'], - 'foot': [[-1/2, -1/4, 0, 1/2], [-1/2, 0, 1/2]], - 'sync': [[0, 1/2], [0, 1/2], [0, 1/2], [0, 1/2]], + 'gait': ['quint_ss', 'trip_ss'], + 'foot': [[1/2, 0, 1/2], [-1/2, 0, 1/2]], + 'sync': [[0], [0], [0], [0], [0], [0]], }], [{ 'span': [1], 'gait': ['double'], - 'foot': [[-1/2, -1/4, 0, 1/4]], - 'sync': [[0], [0], [0], [0]], + 'foot': [[-1/2, 0], [-1/2, 0, 1/2]], + 'sync': [[0, 1/2], [0], [0], [0], [0]], }], [{ 'span': [1], - 'gait': ['double'], + 'gait': ['trip_ss'], + 'foot': [[-1/2, 0, 1/2], [-1/2, 0, 1/2]], + 'sync': [[0], [0], [0], [0], [0], [0]], + }], + [{ + 'span': [1], + 'gait': ['trip_ss'], + 'foot': [[-1/2, 0, 1/2], [-1/2, 0, 1/2]], + 'sync': [[0], [0], [0], [0], [0], [0]], + }], + [{ + 'span': [1], + 'gait': ['quint_ss','trip_ss', 'double'], + 'foot': [[0, 1/2], [0], [0, 1/2]], + 'sync': [[0], [0], [0], [0], [0]], + }], + [{ + 'span': [1], + 'gait': ['quint_ss','trip_ss', 'double'], + 'foot': [[-1/2, 0], [0], [1/2, 0]], + 'sync': [[0], [0], [0], [0], [0]], + }], + [{ + 'span': [2,4], + 'gait': ['trip_ss','quint_ss','double'], + 'foot': [[-1/2, 0],[-1/2, 0],[-1/2, 0],[0]], + 'sync': [[0], [0], [0], [0], [0], [0], [-1/2]], + }], + [{ + 'span': [2,4], + 'gait': ['trip_ss','quint_ss'], 'foot': [[-1/2, -1/4, 0, 1/2]], 'sync': [[0], [0], [0], [0]], }], [{ - 'span': [2], + 'span': [1,4], 'gait': ['double'], 'foot': [[-1/2, -1/4, 0, 1/4]], - 'sync': [[0, 1/2], [0, 1/2], [0, 1/2], [0, 1/2]], + 'sync': [[0, 1/2], [0], [0], [0]], }], ] functionRules = [ { 'address': ['A1','B1'], - 'transposition': [-1,0], + 'transposition': [-1,0,1], }, { 'address': ['C1','D1'], - 'transposition': [0,1], + 'transposition': [-1,0,1], + }, + { + 'address': ['D2','C2'], + 'transposition': [-1,0,1], + }, + { + 'address': ['E1','E2'], + 'transposition': [-1,0,1], }, - # { - # 'address': ['D2','C2'], - # 'transposition': [0,1], - # }, - # { - # 'address': ['E1','E2'], - # 'transposition': [0,1], - # }, ] +# +# ['flat'] +# ['rampDown','accDown','decDown','sawtooth1Down','sawtooth2Down','sawtooth3Down'] +# ['rampUp','accUp','decUp','sawtooth1Up','sawtooth2Up','sawtooth3Up'] +# ['triangleUp','saddleUp','spikeUp','zigZagUp'] +# ['triangleDown','saddleDown','spikeDown','zigZagDown'] +# + pathRules = [ { - 'range': [2,3,4], - 'figure': ['zigZagUp', 'zigZagDown'], - 'direction': [-1, 0, 1], + 'range': [9,10,11], + 'figure': ['saddleUp','spikeUp'], + 'direction': [1], }, { - 'range': [5,6,7], - 'figure': ['rampUp'], - 'direction': [-4,-5,-6], + 'range': [6,7,8], + 'figure': ['saddleDown','spikeDown'], + 'direction': [-1], }, + # { + # 'range': [2,3,4], + # 'figure': ['rampUp','accUp','decUp'], + # 'direction': [1], + # }, + # { + # 'range': [5,6,7], + # 'figure': ['rampDown','accDown','decDown'], + # 'direction': [-1], + # }, { - 'range': [5,6,7], - 'figure': ['rampDown'], - 'direction': [4,5,6], + 'range': [2,3,4,10,11,12], + 'figure': ['sawtooth2Up','sawtooth2Down','sawtooth3Up','sawtooth3Down','zigZagUp','zigZagDown'], + 'direction': [0], }, ] anticipationRules = [ - # ['ligature'], - # ['ligature','direction'], - # ['ligature','figure'], - [], + ['transposition','askldfjds'], + ['address'], ['direction'], - ['figure'], + [], ] prolongationRules = [ - ['address','figure','range'], - ['address','figure'], - ['address','range'], + ['transposition','sdfsdf'], ['address'], - ['figure','range'], - ['figure'], - ['range'], + ['direction'], + [], ] +# as patient - (yield, check, ask) # ([default] adopt given features, refuse given features, request features +# as agent - (let, put, drive) # ([default] feature not shared, feature shared with immediately below, feature shared with all below +# probe - goal + +''' +# need something like +projectionRules = { + + + # produces less uniformity + 'check': [], + # produces local uniformity (inflection) + 'anticipate': [], + 'prolong': [], + # produces global uniformity + 'project': [], + 'inject': [], + +} +''' + # assemble grammar object phonology = Phonology() for rule in ligatureRules: |