Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getTimeSignatureObject(self):
'''
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive'
... / 'test01' / '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getTimeSignatureObject()
'''
from music21 import meter
return meter.TimeSignature(self.getTimeSignatureParameters())
if entry.measure == previousMeasure:
continue
elif entry.measure != previousMeasure + 1: # Not every measure has a chord change.
for mNo in range(previousMeasure + 1, entry.measure):
m = stream.Measure(number=mNo)
m.offset = currentOffset + currentMeasureLength
p.insert(m)
currentOffset = m.offset
previousMeasure = mNo
else: # entry.measure = previousMeasure + 1
m = stream.Measure(number=entry.measure)
m.offset = entry.totbeat
p.insert(m)
if entry.timesig != currentTimeSig:
newTS = meter.TimeSignature(entry.timesig)
m.insert(entry.beat - 1, newTS)
currentTimeSig = entry.timesig
currentMeasureLength = newTS.barDuration.quarterLength
previousMeasure = entry.measure
currentOffset = entry.totbeat
s.append(p)
self.preparedStream = s
return s
def __init__(self, fiveExcelCells=None, parentPiece=None):
super().__init__()
if fiveExcelCells is None:
fiveExcelCells = []
if fiveExcelCells != []:
if len(fiveExcelCells) != 5:
raise Exception("Need five Excel Cells to make a PolyphonicSnippet object")
self.cadenceType = fiveExcelCells[3]
self.timeSig = meter.TimeSignature(fiveExcelCells[4])
self.parentPiece = parentPiece
self.cantus = fiveExcelCells[0]
self.tenor = fiveExcelCells[1]
self.contratenor = fiveExcelCells[2]
self.longestLineLength = 0
if self.contratenor == "" or self.contratenor is None:
self.contratenor = None
else:
self.contratenor.id = 'Ct'
if self.tenor == "" or self.tenor is None:
self.tenor = None
else:
self.tenor.id = 'T'
def __init__(self, inKey=None, inTime=None):
if inKey is None:
inKey = key.Key('C')
if inTime is None:
inTime = meter.TimeSignature('4/4')
self.inKey = inKey
self.inTime = inTime
self._paddingLeft = 0.0
self._overlaidParts = stream.Part()
self._fbScale = realizerScale.FiguredBassScale(inKey.pitchFromDegree(1), inKey.mode)
self._fbList = []
streamPart._insertCore(0, instrumentObj) # add instrument at zero offset
staffReferenceList = []
# offset is in quarter note length
oMeasure = 0.0
lastTimeSignature = None
for mxMeasure in mxPart:
m, staffReference = mxToMeasure(mxMeasure, spannerBundle=spannerBundle)
# there will be one for each measure
staffReferenceList.append(staffReference)
if m.timeSignature is not None:
lastTimeSignature = m.timeSignature
elif lastTimeSignature is None and m.timeSignature is None:
# if no time sigature is defined, need to get a default
ts = meter.TimeSignature()
ts.load('%s/%s' % (defaults.meterNumerator,
defaults.meterDenominatorBeatType))
lastTimeSignature = ts
# add measure to stream at current offset for this measure
streamPart._insertCore(oMeasure, m)
# note: we cannot assume that the time signature properly
# describes the offsets w/n this bar. need to look at
# offsets within measure; if the .highestTime value is greater
# use this as the next offset
if m.highestTime >= lastTimeSignature.barDuration.quarterLength:
mOffsetShift = m.highestTime
else: # use time signature
# for the first measure, this may be a pickup
# must detect this when writing, as next measures offsets will be
'''
counterpoint1 = ModalCounterpoint()
cf = cantusFirmi[0]# getRandomCF()
environLocal.printDebug(['Using: ', cf['notes']])
cantusFirmus = stream.Part(converter.parse(cf['notes'], "4/4").notes)
baseNote = Note(cf['mode'])
thisScale = scale.MinorScale(baseNote)
(middleVoice, topVoice) = counterpoint1.generateFirstSpeciesThreeVoices(
cantusFirmus, thisScale, 'random')
score = stream.Score()
score.insert(0, meter.TimeSignature('4/4'))
score.insert(0, topVoice)
score.insert(0, middleVoice)
score.insert(0, cantusFirmus)
# score.show('text')
# score.show('musicxml')
score.show('midi')
score.show('lily.png')
def testMxMeasures(self):
'''A test of the automatic partitioning of notes in a measure and the creation of ties.
'''
n = note.Note()
n.quarterLength = 3
a = Stream()
a.repeatDeepcopy(n, range(0,120,3))
#a.show() # default time signature used
a.insertAtOffset(meter.TimeSignature("5/4"), 0)
a.insertAtOffset(meter.TimeSignature("2/4"), 10)
a.insertAtOffset(meter.TimeSignature("3/16"), 3)
a.insertAtOffset(meter.TimeSignature("9/8"), 20)
a.insertAtOffset(meter.TimeSignature("10/4"), 40)
a.show()
MM = tempo.MetronomeMark(number=metronomeMark)
return MM
except ValueError:
# assuming that metronomeMark here is text now
metronomeMark = re.sub(r'^\[','', metronomeMark)
metronomeMark = re.sub(r']\s*$','', metronomeMark)
MS = tempo.MetronomeMark(text=metronomeMark)
return MS
elif tandem.startswith("*M"):
meterType = tandem[2:]
tsTemp = re.match(r'(\d+)/(\d+)', meterType)
if (tsTemp):
numerator = int(tsTemp.group(1))
denominator = tsTemp.group(2)
if (denominator not in ('0', '00', '000')):
return meter.TimeSignature(meterType)
else:
if (denominator == '0'):
numerator *= 2
denominator = 1
elif (denominator == '00'):
numerator *= 4
denominator = 1
elif (denominator == '000'):
numerator *= 8
denominator = 1
return meter.TimeSignature('%d/%d' % (numerator, denominator))
else:
raise HumdrumException('Incorrect meter: %s found', tandem)
elif tandem.startswith("*IC"):
instrumentClass = tandem[3:]
'''
counterpoint1 = ModalCounterpoint()
cf = cantusFirmi[0]# getRandomCF()
environLocal.printDebug(['Using: ', cf['notes']])
cantusFirmus = stream.Part(converter.parse(cf['notes'], "4/4").notes)
baseNote = Note(cf['mode'])
thisScale = scale.MinorScale(baseNote)
(middleVoice, topVoice) = counterpoint1.generateFirstSpeciesThreeVoices(
cantusFirmus, thisScale, 'random')
score = stream.Score()
score.insert(0, meter.TimeSignature('4/4'))
score.insert(0, topVoice)
score.insert(0, middleVoice)
score.insert(0, cantusFirmus)
# score.show('text')
# score.show('musicxml')
score.show('midi')
score.show('lily.png')