summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2018-06-11 15:47:19 +0200
committerJackson Moore <jacksonmoore@tuta.io>2018-06-11 15:47:19 +0200
commit452fec5fcebc256a4387c9a17fc450a87e2222fb (patch)
treec88d733f81e16773d238e93932ae3d20da87b752
parent766c361e83843740afeaa8320f3b1bd58506bce1 (diff)
log each rendering to text file with lexicon, tree, spellout
-rw-r--r--.gitignore2
-rw-r--r--cadence.py2
-rw-r--r--grammar.py3
-rw-r--r--lexicon.py30
-rw-r--r--passage.py27
-rw-r--r--render.py25
6 files changed, 61 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index a4ff8c4..57415e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,6 @@
__pycache__/
_notes/*
_stuff/*
+_output/*
+_log/*
*.png \ No newline at end of file
diff --git a/cadence.py b/cadence.py
index d833333..6169dc9 100644
--- a/cadence.py
+++ b/cadence.py
@@ -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,
diff --git a/grammar.py b/grammar.py
index e908730..7507b18 100644
--- a/grammar.py
+++ b/grammar.py
@@ -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"""
diff --git a/lexicon.py b/lexicon.py
index a2da32e..da7b6b1 100644
--- a/lexicon.py
+++ b/lexicon.py
@@ -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()
diff --git a/passage.py b/passage.py
index b10a1e9..7f288e6 100644
--- a/passage.py
+++ b/passage.py
@@ -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']:
diff --git a/render.py b/render.py
index 155670a..dce9b3d 100644
--- a/render.py
+++ b/render.py
@@ -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'),