Browse Source

better duration guessing by using fractions directly, at least from split

master
Nils 6 years ago
parent
commit
02cdbf76f7
  1. 14
      engine/items.py

14
engine/items.py

@ -367,7 +367,7 @@ class Duration(object):
return None
durList = [D1024, D512, D256, D128, D64, D32, D16, D8, D4, D2, D1, DB, DL, DM]
guessedBase = _closest(completeDuration, durList)
guessedBase = _closest(completeDuration, durList)
if guessedBase:
if completeDuration in durList: #no need for guessing
@ -378,10 +378,13 @@ class Duration(object):
elif completeDuration/1.5/1.5 in durList: #double dots
new = cls(completeDuration/1.5/1.5)
new.dots = 2
elif completeDuration *3/2 in durList: #triplets are so a common we take care of them instead of brute forcing with fractions in the else branch
new = cls(guessedBase)
new.tuplets = [(2,3)]
else: #tuplet. That means the value is below a standard "notehead" duration. We need to find how much much lower.
new = cls(guessedBase)
#ratio = completeDuration / guessedBase #0.666~ for triplet
newRatio = Fraction(completeDuration, guessedBase).limit_denominator(100000) #protects 6 or 7 decimal positions
#ratio = completeDuration / guessedBase #0.666~ for triplet
newRatio = Fraction(int(completeDuration), guessedBase).limit_denominator(100000) #protects 6 or 7 decimal positions
new.tuplets = [(newRatio.numerator, newRatio.denominator)]
else:
#the base could not be guessed. In this case we just create a non-standard note.
@ -1330,8 +1333,9 @@ class Chord(Item):
oldValues = []
for note in self.notelist:
oldValues.append(note.duration.copy()) #we don't actually need a copy since we create a new one. But better safe than sorry. This matches also the behaviour of the other duration change functions.
newTicks = note.duration.completeDuration() / newparts
note.duration = Duration.createByGuessing(newTicks)
complDur = note.duration.completeDuration()
#newTicks = complDur / newparts
note.duration = Duration.createByGuessing(Fraction(complDur, newparts))
#Now we have one note with the duration the user wants to have. Make n-1 copies-
spawnedNotes = []

Loading…
Cancel
Save