summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cadence.py16
-rw-r--r--grammar.py32
-rw-r--r--lexicon.py40
-rw-r--r--main.py24
-rw-r--r--passage.py102
-rw-r--r--render.py172
-rw-r--r--rhythm.py26
-rw-r--r--spec.py22
-rw-r--r--utils.py35
9 files changed, 325 insertions, 144 deletions
diff --git a/cadence.py b/cadence.py
index b84c6c0..8b7b585 100644
--- a/cadence.py
+++ b/cadence.py
@@ -20,15 +20,15 @@ Cadence
class Cadence(object):
"""a musical morpheme bundling rhythmic, gestural and harmonic features"""
- def __init__(self, footprint=None, function=None, path=None):
- self.footprint = footprint
+ def __init__(self, ligature=None, function=None, path=None):
+ self.ligature = ligature
self.function = function
self.path = path
# string represention of cadence - note list ?
def __str__(self):
features = {
- 'footprint': self.footprint,
+ 'ligature': self.ligature,
'function': self.function,
'path': self.path,
}
@@ -37,15 +37,15 @@ class Cadence(object):
@property
def features(self):
features = {
- 'footprint': self.footprint,
+ 'ligature': self.ligature,
'function': self.function,
'path': self.path,
}
return features
def update(featureDict):
- if 'footprint' in featureDict:
- self.footprint = featureDict['footprint']
+ if 'ligature' in featureDict:
+ self.ligature = featureDict['ligature']
if 'function' in featureDict:
self.function.update(featureDict['function'])
if 'path' in featureDict:
@@ -53,7 +53,7 @@ class Cadence(object):
def print(self):
features = {
- 'footprint': self.footprint,
+ 'ligature': self.ligature,
'function': self.function,
'path': self.path,
}
@@ -63,7 +63,7 @@ class Cadence(object):
# example
cad = Cadence()
-cad.footprint = [{
+cad.ligature = [{
'span': 2,
'gait': 'double', # Gait.double or Gait['double']...
'foot': [-1/2, -1/4, 0, 1/2],
diff --git a/grammar.py b/grammar.py
index 7afec1b..aa1d310 100644
--- a/grammar.py
+++ b/grammar.py
@@ -13,14 +13,14 @@ class Grammar(object):
class Phonology(object):
"""weighted repository of rhythmic, harmonic and gestural features"""
- def __init__(self, footprints=[], functions=[], paths=[]):
- self.footprints = footprints
+ def __init__(self, ligatures=[], functions=[], paths=[]):
+ self.ligatures = ligatures
self.functions = functions
self.paths = paths
def print(self):
features = {
- 'footprints': self.footprints,
+ 'ligatures': self.ligatures,
'functions': self.functions,
'paths': self.paths,
}
@@ -28,8 +28,8 @@ class Phonology(object):
pprint(features)
print()
- def addFootprintRule(self, footprintRule, weight=1):
- self.footprints.append((footprintRule, weight))
+ def addligatureRule(self, ligatureRule, weight=1):
+ self.ligatures.append((ligatureRule, weight))
def addFunctionRule(self, functionRule, weight=1):
self.functions.append((functionRule, weight))
@@ -40,22 +40,22 @@ class Phonology(object):
def makeCadence(self): # (duration=None, harmonicFilter=None)
""" assemble bundle of features from phonology rules """
cadence = Cadence()
- cadence.footprint = self.makeFootprint()
+ cadence.ligature = self.makeligature()
cadence.function = self.makeFunction()
cadence.path = self.makePath()
return cadence
- def makeFootprint(self):
- # select footprint rule
- weights = array([rule[1] for rule in self.footprints])
+ def makeligature(self):
+ # select ligature rule
+ weights = array([rule[1] for rule in self.ligatures])
normalized_weights = weights.astype(float) / weights.sum()
- footprintChoices = array(self.footprints)
- index = choice(len(footprintChoices), p=normalized_weights)
- footprintRule = footprintChoices[index][0]
+ ligatureChoices = array(self.ligatures)
+ index = choice(len(ligatureChoices), p=normalized_weights)
+ ligatureRule = ligatureChoices[index][0]
# select feature value from range where necessary
- footprint = []
- for footRule in footprintRule:
+ ligature = []
+ for footRule in ligatureRule:
foot = {}
# each foot option is composite
footChoices = array(footRule['foot'])
@@ -68,9 +68,9 @@ class Phonology(object):
foot['sync'] = []
for steps in footRule['sync']:
foot['sync'].append( choice(steps) )
- footprint.append(foot)
+ ligature.append(foot)
- return footprint
+ return ligature
def makeFunction(self):
diff --git a/lexicon.py b/lexicon.py
index c90cb78..26488f2 100644
--- a/lexicon.py
+++ b/lexicon.py
@@ -39,9 +39,8 @@ class Lexicon(object):
return nextLabel
def print(self):
+ print('Lexicon')
for i, lex in enumerate(self.categories):
- print('Lexeme', str(i))
- print('--------')
lex.print()
print()
@@ -51,24 +50,22 @@ class Lexeme(object):
def __init__(self, cadence, anticipation=None, prolongation=None):
self.cadence = cadence
- # projections
- self.anticipation = anticipation
- self.prolongation = prolongation
-
- # dependents
- self.antecedents = []
- self.consequents = []
+ self.government = {
+ # projected features
+ 'anticipation': anticipation,
+ 'prolongation': prolongation,
+ # dependents
+ 'antecedents': [],
+ 'consequents': [],
+ }
+ self.realization = {}
self.label = 'unlabeled'
-
def print(self):
- print("\n"+str(self.label))
+ print("\nlexeme "+str(self.label))
self.cadence.print()
- print("anticipation:", self.anticipation)
- print("prolongation:", self.prolongation)
- print("antecedents:", self.antecedents)
- print("consequents:", self.consequents)
+ pprint(self.government)
def addAntecedent(self, category):
self.antecedents.append(category)
@@ -79,11 +76,11 @@ class Lexeme(object):
return self
def addAnticipation(self, projection):
- self.anticipations.append(projection)
+ self.government['anticipation'].append(projection)
return self
def addProlongation(self, projection):
- self.prolongations.append(projection)
+ self.government['prolongation'].append(projection)
return self
@@ -101,14 +98,13 @@ class Lexeme(object):
def selectAnticipation(self):
anticipation = None
- if len(self.anticipations>0):
- anticipation = choice(self.anticipations)
+ if len(self.government['anticipation']>0):
+ anticipation = choice(self.government['anticipation'])
return anticipation
def selectProlongation(self):
prolongation = None
- if len(self.prolongations>0):
- prolongation = choice(self.prolongations)
+ if len(self.government['prolongation']>0):
+ prolongation = choice(self.government['prolongation'])
return prolongation
-
diff --git a/main.py b/main.py
index 4a285ac..c10e210 100644
--- a/main.py
+++ b/main.py
@@ -27,24 +27,26 @@ render.py list of n passages rendered to music21 score object
# g.morphology.print()
lexicon = Lexicon()
-lexicon.populate(g, 4)
+lexicon.populate(g, 8)
lexicon.print()
+print("\n-----------\n-----------\n")
passage = Passage(height=5, size=23)
+passage.spellout(lexicon)
+passage.print()
-realization = passage.spellout(lexicon)
-# passage.printSyntax()
-
-# for lex in realization:
-# lex.print()
-
-passage.setMeter()
-print(passage.tree)
-print(passage.bars)
+# print(passage.bars)
+# print(passage.tree)
print()
# next: go through spellout, create musical data, append to music21 score
-# then: add good lexemes, dependency of good lexeme pairs to lexicon pre-population, iteratively...
+
+renderer = Renderer()
+renderer.render(passage)
+
+
+
+# then: add good lexemes, good pairwise dependencies to lexicon pre-population, iteratively...
diff --git a/passage.py b/passage.py
index a87a089..9bf7356 100644
--- a/passage.py
+++ b/passage.py
@@ -3,10 +3,11 @@ from binarytree import *
from utils import *
from math import ceil, floor
from copy import copy, deepcopy
+from pprint import pprint
class Passage(object):
- """represents a syntactic structure (wrapper for binary tree)
- """
+ """represents a syntactic structure (wrapper for binary tree)"""
+
def __init__(self, height=3, size=None):
self.tree = tree(height=height)
if isinstance(size, int):
@@ -19,15 +20,36 @@ class Passage(object):
for i, node in enumerate(self.tree.levelorder):
node.value = i
node.unify = {}
- self.unified = []
+
+ # sequence of lexeme objects constituting passage
+ self.spelling = []
+
+ # duration of each individual foot in each ligature (including any pickup)
self.durations = []
+
+ # duration of the pre-barline portion of each lexeme
self.anacruses = []
- self.landings = []
+
+ # duration of the post-barline portion of each lexeme
+ self.stations = []
+
self.bars = []
def printSyntax(self):
print(self.tree)
+ def print(self):
+ lexemes = []
+ for lex in self.spelling:
+ lexemes.append({
+ '_label': lex.label,
+ 'ligature': lex.cadence.ligature,
+ 'function': lex.cadence.function,
+ 'path': lex.cadence.path,
+ 'realization': lex.realization,
+ })
+ pprint(lexemes)
+
def spellout(self, lexicon):
# prolonged features trickle down to leaves
for node in self.tree.levelorder:
@@ -36,10 +58,10 @@ class Passage(object):
if node.left:
node.left.unify = copy(node.unify)
- for feat in node.lexeme.anticipation:
- # if feat == 'footprint': <- take off first condition for 'agree' prolongation
- if feat not in node.left.unify.keys() and feat == 'footprint':
- node.left.unify['footprint'] = node.lexeme.cadence.footprint
+ for feat in node.lexeme.government['anticipation']:
+ # if feat == 'ligature': <- take off first condition for 'agree' prolongation
+ if feat not in node.left.unify.keys() and feat == 'ligature':
+ node.left.unify['ligature'] = node.lexeme.cadence.ligature
if feat not in node.left.unify.keys() and feat in node.lexeme.cadence.function:
node.left.unify[feat] = node.lexeme.cadence.function[feat]
if feat not in node.left.unify.keys() and feat in node.lexeme.cadence.path:
@@ -47,9 +69,9 @@ class Passage(object):
if node.right:
node.right.unify = copy(node.unify)
- for feat in node.lexeme.prolongation:
- if feat not in node.right.unify.keys() and feat == 'footprint':
- node.right.unify['footprint'] = node.lexeme.cadence.footprint
+ for feat in node.lexeme.government['prolongation']:
+ if feat not in node.right.unify.keys() and feat == 'ligature':
+ node.right.unify['ligature'] = node.lexeme.cadence.ligature
if feat not in node.right.unify.keys() and feat in node.lexeme.cadence.function:
node.right.unify[feat] = node.lexeme.cadence.function[feat]
if feat not in node.right.unify.keys() and feat in node.lexeme.cadence.path:
@@ -60,29 +82,27 @@ class Passage(object):
for node in self.tree.inorder:
next_lexeme = deepcopy(node.lexeme)
for feat in node.unify.keys():
- if feat == 'footprint':
- next_lexeme.cadence.footprint = node.unify[feat]
+ if feat == 'ligature':
+ next_lexeme.cadence.ligature = node.unify[feat]
if feat in ['address', 'transposition']:
next_lexeme.cadence.function[feat] = node.unify[feat]
if feat in ['range','figure','tilt']:
next_lexeme.cadence.path[feat] = node.unify[feat]
spellout.append(next_lexeme)
- self.unified = spellout
+ self.spelling = spellout
+ self.setMeter()
return spellout
def setMeter(self):
- durations = self.getDurations(self.unified)
+ durations = self.getDurations(self.spelling)
pickupBar = max([fl(ceil(-self.anacruses[0])),2.0])
bars = []
- for i in range(len(self.durations)-1):
- bars.append(self.landings[i]-self.anacruses[i+1])
- bars.append(self.landings[-1])
+ for i in range(len(self.stations)-1):
+ bars.append(self.stations[i]-self.anacruses[i+1])
+ bars.append(self.stations[-1])
# partitionedBars = self.partition(bars, self.tree)
- # depthScores = (flatten(depth(partitionedBars,0)))
- # depthTransitions = [abs(depthScores[i]-depthScores[i+1]) for i in range(len(depthScores)-1) ]
- # print('depthScores',depthScores)
removedIndices = []
prolongedIndices = []
while isOversliced(bars):
@@ -97,7 +117,6 @@ class Passage(object):
self.bars = bars
return bars
-
def desliceBars(self, bars, removedIndices, prolongedIndices):
# targets = [bar < 2.5 for bar in bars]
# i = targets.index(True)
@@ -191,37 +210,20 @@ class Passage(object):
return newBars
- def incrementalSetMeter(self, durations, anacruses, landings):
- firstChunk = -anacruses[0]
- firstBar = ceil(firstChunk)
- bars = [firstBar]
- load = 0
- partitions = []
- nextPartition = []
- for i, duration in enumerate(durations):
- nextChunk = landings[i]
- if (i+1) < len(landings):
- nextChunk -= anacruses[i+1]
- load += nextChunk
- nextPartition.append(duration)
- if load >= 3:
- bars.append(load)
- partitions.append(nextPartition)
- load = 0
- nextPartition = []
- return bars, partitions
-
- def getDurations(self, unified):
+ def getDurations(self, realization):
durations = []
anacruses = []
- for lexeme in unified:
+ for lexeme in realization:
# special extra bit before barline
anacrusis = 0.0
boundaryEvents = []
metricBoundaries = []
subdurations = []
- for i, foot in enumerate(lexeme.cadence.footprint):
+ lexeme.realization['feet'] = []
+ for i, foot in enumerate(lexeme.cadence.ligature):
offsets = rhythm.getOffsets(foot)
+ lexeme.realization['feet'].append(offsets)
+
firstAttack = offsets[0]
lastAttack = offsets[-1]
boundaryEvents.append( (firstAttack, offsets[-1]) )
@@ -254,17 +256,11 @@ class Passage(object):
if i == 0:
anacruses.append(leadingBoundary)
- durations.append(sum(subdurations))
-
- # print('boundaryEvents', boundaryEvents)
- # print('metricBoundaries', metricBoundaries)
- # print('subdurations', subdurations)
+ durations.append(subdurations)
- # print('durations', durations)
- # print('anacruses', anacruses)
self.durations = durations
self.anacruses = anacruses
- self.landings = [self.durations[i] + self.anacruses[i] for i in range(len(durations))]
+ self.stations = [sum(self.durations[i]) + self.anacruses[i] for i in range(len(durations))]
return durations
diff --git a/render.py b/render.py
index a283b87..8636696 100644
--- a/render.py
+++ b/render.py
@@ -1,15 +1,169 @@
-from rhythm import *
+import music21 as m21
+from utils import *
+from pprint import pprint
+from copy import copy, deepcopy
+class Renderer(object):
+ """ turns feature spellout into score object, with processing """
-'''
-[{,
+ def render(self, passage):
+ part = m21.stream.Part()
+ # cl = instrument.Clarinet()
+ # p.insert(0, cl)
-calculate notes from:
+ for barDuration in passage.bars:
+ m = m21.stream.Measure()
+ m.timeSignature = deepcopy(timeSignatures[barDuration])
+ part.append(m)
+ measures = part.getElementsByClass('Measure')
-'foot': [-0.5, 0.0, 0.5],
-'gait': 'double',
-'span': 2,
-'sync': [0.0, 0.0, 0.5]
+ incrementPairs = [[passage.anacruses[i], passage.stations[i]] for i in range(len(passage.stations)) ]
+ increments = []
+ for pair in incrementPairs:
+ increments.extend(pair)
-'''
+ # print('increments =', increments)
+ # print("\nincrementPairs =", incrementPairs)
+ # print('passage.bars', passage.bars)
+ # print('passage.durations', passage.durations)
+ # print('passage.stations', passage.stations)
+ # split each lexeme in anacrusis and station, put them in a flat list
+ splitLexemes = []
+ for i, lexeme in enumerate(passage.spelling):
+ pickup = {
+ '_label': lexeme.label,
+ '_offsets': [offset for offset in lexeme.realization['feet'][0] if offset < 0],
+ '_nextOffset': firstNonNegative(lexeme.realization['feet'][0]), # 0
+ '_duration': incrementPairs[i][0],
+ 'parent': lexeme,
+ }
+ station = {
+ '_label': lexeme.label,
+ '_offsets': [offset for offset in lexeme.realization['feet'][0] if offset >= 0],
+ '_priorOffset': 0, # lastNonPositive(lexeme.realization['feet'][0]),
+ '_duration': incrementPairs[i][1],
+ 'parent': lexeme,
+ }
+ # 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'])):
+ internalOffset = sum(passage.durations[i][0:index])
+ station['_offsets'].extend([ offset+internalOffset for offset in lexeme.realization['feet'][index] ])
+ splitLexemes.append(pickup)
+ splitLexemes.append(station)
+
+ # now go through and group lexeme increments by measure
+ measureGroups = [ [splitLexemes[0]] ] # pickup to first measure will be padded to correct length of pickup measure
+ measureDurations = [measure.barDuration.quarterLength for measure in measures[1:]]
+
+ counter = 0.0
+ bundle = []
+ measureDuration = measureDurations.pop(0)
+ for i in range(1, len(splitLexemes)):
+ bundle.append(splitLexemes[i])
+ counter += abs(splitLexemes[i]['_duration'])
+ if counter == measureDuration:
+ measureGroups.append(bundle)
+ counter = 0.0
+ bundle = []
+ if i < len(splitLexemes)-1:
+ measureDuration = measureDurations.pop(0)
+ print("\nmeasureGroups")
+ pprint(measureGroups)
+
+ # for each measure bundle
+ # recalculate all offsets relative to barline, find durations
+ # insert into m21 measure object for rendering
+ for i, measureGroup in enumerate(measureGroups):
+ measure = measures[i]
+ measureOffsets = []
+ internalOffset = 0.0
+ for j, increment in enumerate(measureGroup):
+ # if duration is negative, is pickup
+ if increment['_duration'] < 0:
+ noteEndpoints = copy(increment['_offsets'])
+ # calculate duration of last note accurately
+ noteEndpoints.append(increment['_nextOffset'])
+ durations = [ fl(x-y) for y, x in zip(noteEndpoints[:-1], noteEndpoints[1:]) ]
+ # subtract from end of increment to find offsets
+ internalOffset += abs(increment['_duration'])
+ # special case for pickup bar - use duration including hidden leading rest
+ if i==0 and j==0:
+ internalOffset = measure.barDuration.quarterLength
+ for k, duration in enumerate(durations):
+ n = m21.note.Note()
+ n.quarterLength = duration
+ n.pitch = m21.pitch.Pitch('C4')
+ noteOffset = internalOffset+increment['_offsets'][k]
+ print(i,j,k, noteOffset)
+ # measure.append(n)
+ measure.insert(noteOffset, n)
+ # if duration is positive, is station
+ if increment['_duration'] > 0:
+ noteEndpoints = copy(increment['_offsets'])
+ # calculate duration of last note accurately
+ noteEndpoints.append(abs(increment['_duration']))
+ durations = [ fl(x-y) for y, x in zip(noteEndpoints[:-1], noteEndpoints[1:]) ]
+ # add to beginning of increment to find offsets
+ for k, duration in enumerate(durations):
+ n = m21.note.Note()
+ n.quarterLength = duration
+ n.pitch = m21.pitch.Pitch('C4')
+ noteOffset = internalOffset+increment['_offsets'][k]
+ print(str(i)+" "+str(j)+" "+str(k)+" "+str(noteOffset))
+ # measure.append(n)
+ measure.insert(noteOffset, n)
+ internalOffset += abs(increment['_duration'])
+ if i == 0:
+ # doesn't work in MuseScore at least...
+ measure.padAsAnacrusis()
+ measure.makeRests(fillGaps=False, timeRangeFromBarDuration=True)
+ measures.show()
+
+
+timeSignatures = {
+ 1.5: m21.meter.TimeSignature('3/8'),
+ 2.0: m21.meter.TimeSignature('2/4'),
+ 2.5: m21.meter.TimeSignature('5/8'),
+ 3.0: m21.meter.TimeSignature('3/4'),
+ 3.5: m21.meter.TimeSignature('7/8'),
+ 4.0: m21.meter.TimeSignature('4/4'),
+ 4.5: m21.meter.TimeSignature('9/8'),
+ 5.0: m21.meter.TimeSignature('5/4'),
+ 5.5: m21.meter.TimeSignature('11/8'),
+ 6.0: m21.meter.TimeSignature('6/4'),
+ 6.5: m21.meter.TimeSignature('13/8'),
+ 7.0: m21.meter.TimeSignature('7/4'),
+ 7.5: m21.meter.TimeSignature('15/8'),
+ 8.0: m21.meter.TimeSignature('8/4'),
+ 8.5: m21.meter.TimeSignature('17/8'),
+ 9.0: m21.meter.TimeSignature('9/4'),
+ 9.5: m21.meter.TimeSignature('19/8'),
+ 10.0: m21.meter.TimeSignature('10/4'),
+ 10.5: m21.meter.TimeSignature('21/8'),
+ 11.0: m21.meter.TimeSignature('11/4'),
+ 11.5: m21.meter.TimeSignature('23/8'),
+ 12.0: m21.meter.TimeSignature('12/4'),
+}
+
+timeSignatures[2.5].beamSequence.partition(['3/8', '2/8'])
+# timeSignatures[2.5].beamSequence.partition(['2/8', '3/8'])
+
+# timeSignatures[8.0].beamSequence.partition(['1/4', '1/4', '1/4', '1/4', '1/4', '1/4', '1/4', '1/4'])
+# for i in range(len(timeSignatures[8.0].beamSequence)):
+# timeSignatures[8.0].beamSequence[i] = timeSignatures[8.0].beamSequence[i].subdivide(['1/8', '1/8'])
+
+timeSignatures[8.0].beamSequence.partition(['2/4', '2/4', '2/4', '2/4'])
+for i in range(len(timeSignatures[8.0].beamSequence)):
+ timeSignatures[8.0].beamSequence[i] = timeSignatures[8.0].beamSequence[i].subdivide(['1/4', '1/4'])
+ for j in range(len(timeSignatures[8.0].beamSequence[i])):
+ timeSignatures[8.0].beamSequence[i][j] = timeSignatures[8.0].beamSequence[i][j].subdivide(2)
+
+timeSignatures[5.0].beamSequence.partition(['3/4', '2/4'])
+timeSignatures[5.0].beamSequence[0] = timeSignatures[5.0].beamSequence[0].subdivide(['1/4', '1/4', '1/4'])
+timeSignatures[5.0].beamSequence[1] = timeSignatures[5.0].beamSequence[1].subdivide(['1/4', '1/4'])
+
+# timeSignatures[5.0].beamSequence.partition(['2/4', '3/4'])
+# timeSignatures[5.0].beamSequence[0] = timeSignatures[5.0].beamSequence[1].subdivide(['1/4', '1/4'])
+# timeSignatures[5.0].beamSequence[1] = timeSignatures[5.0].beamSequence[0].subdivide(['1/4', '1/4', '1/4'])
diff --git a/rhythm.py b/rhythm.py
index 0ada3fa..960f247 100644
--- a/rhythm.py
+++ b/rhythm.py
@@ -1,4 +1,5 @@
from utils import *
+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)],
@@ -45,11 +46,12 @@ def getOffsets(foot):
finalOffsets.append(finalOffset)
return finalOffsets
+
def syncOffsets(foot):
""" syncopate logical offsets, desyncopate axis if crowded """
syncedOffsets = []
for i, offset in enumerate(foot['foot']):
- j = i%(len(foot['sync'])) # sync index
+ j = i%(len(foot['sync'])) # sync index wraps around
if offset == 0:
syncBasis = 1.0
else:
@@ -66,6 +68,26 @@ def syncOffsets(foot):
for offset in afterAxis:
if offset <= syncedOffsets[axisIndex]:
syncedOffsets[axisIndex] = 0.0
+ syncedOffsets = resolveCollisions(syncedOffsets)
+ return syncedOffsets
+
+
+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
@@ -83,5 +105,5 @@ def getFinalOffset(offset, refraction, scale):
return fl((final[0]*scale)/(final[1]), 6)
+# [0.0, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625]
-# [0.0, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625] \ No newline at end of file
diff --git a/spec.py b/spec.py
index e95b387..3be91f2 100644
--- a/spec.py
+++ b/spec.py
@@ -1,6 +1,6 @@
from grammar import *
-footprintRules = [
+ligatureRules = [
[{
'span': [2],
'gait': ['double'],
@@ -9,7 +9,7 @@ footprintRules = [
}],
[{
'span': [1],
- 'gait': ['trp_ls'],
+ 'gait': ['double'],
'foot': [[-1/2, 0, 1/2]],
'sync': [[0], [0], [0]],
}],
@@ -17,11 +17,11 @@ footprintRules = [
'span': [2],
'gait': ['double'],
'foot': [[-1/2, -1/4, 0, 1/2]],
- 'sync': [[0, 1/4], [0, 1/4], [0, 1/4], [0, 1/4]],
+ 'sync': [[0, 1/2], [0, 1/2], [0, 1/2], [0, 1/2]],
}],
[{
'span': [1],
- 'gait': ['trp_sl'],
+ 'gait': ['double'],
'foot': [[-1/2, -1/4, 0, 1/4]],
'sync': [[0], [0], [0], [0]],
}],
@@ -33,9 +33,9 @@ footprintRules = [
}],
[{
'span': [2],
- 'gait': ['trp_ll'],
+ 'gait': ['double'],
'foot': [[-1/2, -1/4, 0, 1/4]],
- 'sync': [[0, 1/4], [0, 1/4], [0, 1/4], [0, 1/4]],
+ 'sync': [[0, 1/2], [0, 1/2], [0, 1/2], [0, 1/2]],
}],
]
@@ -72,9 +72,9 @@ pathRules = [
]
anticipationRules = [
- # ['footprint'],
- # ['footprint','tilt'],
- # ['footprint','figure'],
+ # ['ligature'],
+ # ['ligature','tilt'],
+ # ['ligature','figure'],
[],
['tilt'],
['figure'],
@@ -92,8 +92,8 @@ prolongationRules = [
# assemble grammar object
phonology = Phonology()
-for rule in footprintRules:
- phonology.addFootprintRule(rule)
+for rule in ligatureRules:
+ phonology.addligatureRule(rule)
for rule in functionRules:
phonology.addFunctionRule(rule)
for rule in pathRules:
diff --git a/utils.py b/utils.py
index fa37568..23995ae 100644
--- a/utils.py
+++ b/utils.py
@@ -8,23 +8,34 @@ def depth(myList, counter):
counter += 1
depthList = []
for item in myList:
- if isinstance(item, list):
- depthList.append(depth(item, counter))
- else:
- depthList.append(counter)
+ if isinstance(item, list):
+ depthList.append(depth(item, counter))
+ else:
+ depthList.append(counter)
return depthList
def flatten(pool):
- res = []
- for v in pool:
- if isinstance(v, list):
- res += flatten(v)
- else:
- if isinstance(v, int) or isinstance(v, str):
- res.append(v)
- return res
+ res = []
+ for v in pool:
+ if isinstance(v, list):
+ res += flatten(v)
+ else:
+ if isinstance(v, int) or isinstance(v, str):
+ res.append(v)
+ return res
def isOversliced(bars):
targets = [bar > 0 and bar < 2.5 for bar in bars]
return (True in targets)
+def firstNonNegative(lst):
+ for x in lst:
+ if x >= 0:
+ return x
+ return 0
+
+def lastNonPositive(lst):
+ for x in list(reversed(lst)):
+ if x <= 0:
+ return x
+ return 0 \ No newline at end of file