diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | cadence.py | 2 | ||||
| -rw-r--r-- | grammar.py | 3 | ||||
| -rw-r--r-- | lexicon.py | 30 | ||||
| -rw-r--r-- | passage.py | 27 | ||||
| -rw-r--r-- | render.py | 25 |
6 files changed, 61 insertions, 28 deletions
@@ -2,4 +2,6 @@ __pycache__/ _notes/* _stuff/* +_output/* +_log/* *.png
\ No newline at end of file @@ -25,7 +25,7 @@ class Cadence(object): self.function = function self.path = path - # string represention of cadence - note list ? + # string represention of cadence def __str__(self): features = { 'ligature': self.ligature, @@ -9,8 +9,6 @@ class Grammar(object): self.morphology = morphology self.syntax = syntax - - class Morphology(object): def __init__(self): @@ -38,7 +36,6 @@ class Morphology(object): pprint(features) print() - class Phonology(object): """weighted repository of rhythmic, harmonic and gestural features, and feature dependencies""" @@ -4,8 +4,21 @@ from copy import deepcopy class Lexicon(object): - def __init__(self): + def __init__(self, minimumMetricUnit=0.5): self.categories = [] + self.minimumMetricUnit = minimumMetricUnit + + def __str__(self): + lexicon = [] + for i, lex in enumerate(self.categories): + lexicon.append(str(lex)) + return "\n".join(lexicon) + + def print(self): + print('Lexicon') + for i, lex in enumerate(self.categories): + lex.print() + print() def populate(self, grammar, number_categories=0): for x in range(number_categories): @@ -39,12 +52,6 @@ class Lexicon(object): nextLabel = self.categories[-1].label + 1 return nextLabel - def print(self): - print('Lexicon') - for i, lex in enumerate(self.categories): - lex.print() - print() - class Lexeme(object): """the specification of an dependant and its agreement""" @@ -63,6 +70,15 @@ class Lexeme(object): self.realization = {} self.label = 'unlabeled' + def __str__(self): + rep = str(self.label) + "\t" + str(self.cadence.ligature)+"\n" + rep += "\t" + str(self.cadence.function)+"\n" + rep += "\t" + str(self.cadence.path)+"\n" + if len(self.realization) > 0: + rep += "\t" + str(self.realization)+"\n" + return rep + + def print(self): print("\nlexeme "+str(self.label)) self.cadence.print() @@ -37,6 +37,12 @@ class Passage(object): self.bars = [] + def __str__(self): + passage = [] + for i, lex in enumerate(self.spelling): + passage.append(str(i)+": "+str(lex)), + return "\n".join(passage) + def printSyntax(self): print(self.tree) @@ -53,6 +59,7 @@ class Passage(object): pprint(lexemes) def spellout(self, lexicon): + self.lexicon=lexicon # prolonged features trickle down to leaves for node in self.tree.levelorder: node.lexeme = lexicon.selectLexeme() @@ -99,7 +106,7 @@ class Passage(object): next_lexeme.cadence.path[feat] = node.unify[feat] spellout.append(next_lexeme) self.spelling = spellout - self.setMeter() + self.setMeter(lexicon.minimumMetricUnit) self.setFigure() self.setHarmony() return spellout @@ -120,8 +127,8 @@ class Passage(object): node.right.lexeme.realization['height'] = node.lexeme.realization['height'] + trailingDirection node.lexeme.realization['outline'] = path.makeOutline(node.lexeme.cadence.path, node.lexeme.realization) - def setMeter(self): - durations = self.getDurations(self.spelling) + def setMeter(self, minimumMetricUnit): + durations = self.getDurations(self.spelling, minimumMetricUnit) pickupBar = max([fl(ceil(-self.anacruses[0])),2.0]) bars = [] for i in range(len(self.stations)-1): @@ -241,9 +248,10 @@ class Passage(object): return newBars - def getDurations(self, spelling): + def getDurations(self, spelling, minimumMetricUnit=0.5): durations = [] anacruses = [] + denominator = 1/minimumMetricUnit for lexeme in spelling: # special extra bit before barline anacrusis = 0.0 @@ -261,20 +269,15 @@ class Passage(object): leadingBoundary = 0 if firstAttack < 0: - leadingBoundary = floor((firstAttack*4)) / 4 - # leadingBoundary = floor(firstAttack) # use this version for whole-beat measures (1 of 3) + leadingBoundary = floor((firstAttack*denominator)) / denominator trailingBoundary = 0 if lastAttack > 0: - trailingBoundary = ceil((lastAttack*4)) / 4 - # trailingBoundary = ceil(lastAttack) # use this version for whole-beat measures (2 of 3) + trailingBoundary = ceil((lastAttack*denominator)) / denominator # give last note some time to sustain if lastAttack - floor(lastAttack) == 0: - trailingBoundary += 0.25 - # comment below out in case of whole-beat measures (3 of 3) - if lastAttack - floor(lastAttack) == 0.25: - trailingBoundary += 0.25 + trailingBoundary += minimumMetricUnit # pad out to minimum duration if trailingBoundary < foot['span']: @@ -133,10 +133,16 @@ class Renderer(object): measure.makeRests(fillGaps=True, timeRangeFromBarDuration=True) measure.timeSignature = measure.bestTimeSignature() + heading = self.makeHeading() + + # write log file + self.writeLog(passage, heading) + + # render score part.insert(0, m21.metadata.Metadata()) - part.metadata.title = heading[0] - part.metadata.composer = heading[1] + part.metadata.title = heading[1] + part.metadata.composer = heading[0] part.show() # measures.show('lily') @@ -160,9 +166,18 @@ class Renderer(object): word_site = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain" response = requests.get(word_site) words = response.content.splitlines() - word = choice(words).decode("utf-8").capitalize() - title = word+" ยท "+str(timestamp) - return (title, date) + title = choice(words).decode("utf-8").capitalize() + return (timestamp, title, date) + + def writeLog(self,passage,heading): + """ write log file """ + f = open("/Users/home/Documents/top/shelf/composition/framework/_log/"+heading[0]+"-"+heading[1]+".txt", 'w') + f.write(str(passage.lexicon)) + f.write("\n\n") + f.write(str(passage.tree)) + f.write("\n\n") + f.write(str(passage)) + timeSignatures = { 1.25: m21.meter.TimeSignature('5/16'), |