summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--harmony.py101
-rw-r--r--main.py11
-rw-r--r--passage.py2
-rw-r--r--render.py6
-rw-r--r--spec.py6
5 files changed, 89 insertions, 37 deletions
diff --git a/harmony.py b/harmony.py
index fe92e72..9247acb 100644
--- a/harmony.py
+++ b/harmony.py
@@ -57,36 +57,85 @@ bisections = {
'D1': ('C2','A1'), 'B1': ('E2','D2'), 'C2': ('C1','E1'), 'E2': ('A1','D1')}
}
-
def makeLens(harmonyFeatures, ligature):
lens = []
- logicalFeet = []
- for foot in ligature:
- logicalFeet.append(foot['foot'])
- print('logicalFeet', logicalFeet)
- # each foot gets a piece
- # calculate how many pieces to cover number of feet
- # derive magnitude at which to iterate over locus, apportion to feet
- # calculate how much further to magnify so that there are enough notes for each foot
- # for each foot
-'''
- ex. one foot divided by eight:
- anacrusis station
- -1/2 -1/4 -1/8 0 1/8 1/4 1/2
- [[[-1, 0],[0, -1]], [[0, -1], [-1, -1]]], [[[0, -1],[-1, -1]],[[-1, -1], [-1, 1]]]
-'''
-
-
- locus = expand(harmonyFeatures['address'], 5)
- print('locus',locus)
+ logicalFeet = [foot['foot'] for foot in ligature]
+
+ numberOfSubloci = len(logicalFeet)
+ footMagnificationfactor = 0
+ while numberOfSubloci > 2**footMagnificationfactor:
+ footMagnificationfactor += 1
+
+ footAddresses = expand(harmonyFeatures['address'], footMagnificationfactor, False)
+ if footMagnificationfactor == 0:
+ footAddresses = [footAddresses]
+
+ for i, foot in enumerate(logicalFeet):
+ address = footAddresses[i]
+ for note in foot:
+ if note == 0:
+ lens.append( expand(address, 1) )
+ if note == 1/2:
+ lens.append( flatten(expand(address, 3))[3] )
+ if note == -1/2:
+ lens.append( flatten(expand(address, 3))[1] )
+ if note == 1/4:
+ lens.append( flatten(expand(address, 4))[5] )
+ if note == -1/4:
+ lens.append( flatten(expand(address, 4))[3] )
+ if note == 1/8:
+ lens.append( flatten(expand(address, 5))[9] )
+ if note == -1/8:
+ lens.append( flatten(expand(address, 5))[7] )
+ if note == 1/16:
+ lens.append( flatten(expand(address, 6))[17] )
+ if note == -1/16:
+ lens.append( flatten(expand(address, 6))[15] )
+ if note == 1/32:
+ lens.append( flatten(expand(address, 7))[33] )
+ if note == -1/32:
+ lens.append( flatten(expand(address, 7))[31] )
return lens
-def expand(address, magnification):
+def expand(address, magnification, getValues=True):
magnification = magnification-1
- pattern = 'A'
- # if magnification%2 == 0: pattern = 'A'
- # if magnification%2 == 1: pattern = 'B'
+ if magnification%2 == 0: pattern = 'A'
+ if magnification%2 == 1: pattern = 'B'
if magnification > 0:
- return [expand( bisections[pattern][address][0], magnification ), expand( bisections[pattern][address][1], magnification )]
+ return [expand( bisections[pattern][address][0], magnification, getValues ), expand( bisections[pattern][address][1], magnification, getValues )]
else:
- return loc[address]
+ if getValues:
+ return loc[address]
+ else:
+ return address
+
+'''
+ each foot gets a piece
+ calculate how many pieces to cover number of feet
+ if number of feet is less than 2**x, maybe give feet with longer duration a double portion
+ derive magnitude(s) at which to iterate over locus, apportion to feet
+ calculate how much further to magnify so that there are enough notes for each foot
+
+ ex. one foot divided by eight:
+ anacrusis station
+ -1/2 -1/4 -1/8 0 1/8 1/4 1/2
+ [[[-1, 0],[0, -1]], [[0, -1], [-1, -1]]], [[[0, -1],[-1, -1]],[[-1, -1], [-1, 1]]]
+
+
+ or better yet:
+ -1/2 -1/4 -1/8 0 1/8 1/4 1/2
+ 1
+ [ -1, -1 ]
+ [[ 1, 0], [1, -1]]
+ [[[-1, -1], [0, 1]], [[-1, 1], [1, 1]]]
+ [[[[1, 0], [1, -1]], [[0, 1], [-1, 0]]], [[[1, -1], [-1, -1]], [[-1, 0], [-1, 1]]]]
+
+ 0 = exp(0) = flatten(exp(2))[2]
+
+ -1/2 = exp(flatten(exp(2))[1])
+ 1/2 = exp(flatten(exp(2))[3])
+ -1/4 = exp(flatten(exp(3))[3])
+ 1/4 = exp(flatten(exp(3))[5])
+ -1/8 = exp(flatten(exp(2))[7])
+ 1/8 = exp(flatten(exp(2))[9])
+ ''' \ No newline at end of file
diff --git a/main.py b/main.py
index c10e210..8aaafbd 100644
--- a/main.py
+++ b/main.py
@@ -28,25 +28,24 @@ render.py list of n passages rendered to music21 score object
lexicon = Lexicon()
lexicon.populate(g, 8)
+
lexicon.print()
print("\n-----------\n-----------\n")
passage = Passage(height=5, size=23)
+
passage.spellout(lexicon)
passage.print()
-
# print(passage.bars)
# print(passage.tree)
print()
-
-# next: go through spellout, create musical data, append to music21 score
-
renderer = Renderer()
renderer.render(passage)
-
-# then: add good lexemes, good pairwise dependencies to lexicon pre-population, iteratively...
+# 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...
diff --git a/passage.py b/passage.py
index 13b722b..e57f337 100644
--- a/passage.py
+++ b/passage.py
@@ -101,6 +101,8 @@ class Passage(object):
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):
diff --git a/render.py b/render.py
index 53982de..90629b3 100644
--- a/render.py
+++ b/render.py
@@ -41,6 +41,8 @@ class Renderer(object):
}
pickup['_pitches'] = lexeme.realization['outline'][:len(pickup['_offsets'])]
station['_pitches'] = lexeme.realization['outline'][len(pickup['_offsets']):]
+ pickup['_lens'] = lexeme.realization['lens'][:len(pickup['_offsets'])]
+ station['_lens'] = lexeme.realization['lens'][len(pickup['_offsets']):]
# for ligatures with multiple feet, add remaining feet, with internal offset
if len(lexeme.realization['feet']) > 1:
for index in range(1, len(lexeme.realization['feet'])):
@@ -91,7 +93,7 @@ class Renderer(object):
n = m21.note.Note()
n.quarterLength = duration
n.pitch = m21.pitch.Pitch()
- n.pitch.ps = 72.0 + increment['_pitches'][k]
+ n.pitch.ps = 72.0 + increment['_pitches'][k] + increment['_lens'][k]
noteOffset = internalOffset+increment['_offsets'][k]
# measure.append(n)
measure.insert(noteOffset, n)
@@ -106,7 +108,7 @@ class Renderer(object):
n = m21.note.Note()
n.quarterLength = duration
n.pitch = m21.pitch.Pitch()
- n.pitch.ps = 72.0 + increment['_pitches'][k]
+ n.pitch.ps = 72.0 + increment['_pitches'][k] + increment['_lens'][k]
noteOffset = internalOffset+increment['_offsets'][k]
# measure.append(n)
measure.insert(noteOffset, n)
diff --git a/spec.py b/spec.py
index 84d74fc..62335be 100644
--- a/spec.py
+++ b/spec.py
@@ -4,19 +4,19 @@ ligatureRules = [
[{
'span': [2],
'gait': ['double'],
- 'foot': [[-1/2, 0, 1/2]],
+ 'foot': [[-1/2, 0, 1/2], [-1/2, 0, 1/2]],
'sync': [[0, 1/2], [0, 1/2], [0, 1/2]],
}],
[{
'span': [1],
'gait': ['double'],
- 'foot': [[-1/2, 0, 1/2]],
+ 'foot': [[-1/2, 0, 1/2], [-1/2, 0, 1/2]],
'sync': [[0], [0], [0]],
}],
[{
'span': [2],
'gait': ['double'],
- 'foot': [[-1/2, -1/4, 0, 1/2]],
+ '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]],
}],
[{