示例#1
0
 def _staffContainingMeasure(self, index):
     measuresSoFar = 0
     for staff in self.iterStaffs():
         if measuresSoFar <= index < measuresSoFar + staff.numMeasures():
             return staff, index - measuresSoFar
         measuresSoFar += staff.numMeasures()
     raise BadTimeError()
示例#2
0
 def nthVisibleLineIndex(self, staffIndex, lineIndex):
     count = -1
     staff = self.getStaff(staffIndex)
     for lineNum, drum in enumerate(self.drumKit):
         if (drum.locked or self.scoreData.emptyLinesVisible
                 or staff.lineIsVisible(lineNum)):
             count += 1
             if count == lineIndex:
                 return lineNum
     if count == -1 and lineIndex == 0:
         return 0
     raise BadTimeError(staffIndex)
示例#3
0
 def getMeasurePosition(self, index):
     staffIndex = 0
     staff = self.getStaff(0)
     while index >= staff.numMeasures():
         index -= staff.numMeasures()
         staffIndex += 1
         if staffIndex == self.numStaffs():
             break
         staff = self.getStaff(staffIndex)
     if staffIndex == self.numStaffs():
         raise BadTimeError(index)
     return NotePosition(staffIndex=staffIndex, measureIndex=index)
示例#4
0
 def iterMeasuresInSection(self, sectionIndex):
     if not (0 <= sectionIndex < self.numSections()):
         raise BadTimeError()
     thisSection = 0
     inSection = (thisSection == sectionIndex)
     for measure in self.iterMeasures():
         if inSection:
             yield measure
             if measure.isSectionEnd():
                 break
         if measure.isSectionEnd():
             thisSection += 1
             inSection = (thisSection == sectionIndex)
示例#5
0
 def nextMeasure(self, position):
     self._checkStaffIndex(position.staffIndex)
     staff = self.getStaff(position.staffIndex)
     if not (0 <= position.measureIndex < staff.numMeasures()):
         raise BadTimeError()
     position = position.makeMeasurePosition()
     position.measureIndex += 1
     if position.measureIndex == staff.numMeasures():
         position.staffIndex += 1
         if position.staffIndex == self.numStaffs():
             position.staffIndex = None
             position.measureIndex = None
         else:
             position.measureIndex = 0
     return position
示例#6
0
 def _checkValidNoteTime(self, noteTime):
     if not (0 <= noteTime < len(self)):
         raise BadTimeError(noteTime)
示例#7
0
 def _isValidPosition(self, position, afterOk=False):
     if not (0 <= position.measureIndex < self.numMeasures()):
         if not (afterOk and position.measureIndex == self.numMeasures()):
             raise BadTimeError(position)
示例#8
0
 def _checkDrumIndex(self, index):
     if not (0 <= index < len(self.drumKit)):
         raise BadTimeError()
示例#9
0
 def _checkStaffIndex(self, index):
     if not (0 <= index < self.numStaffs()):
         raise BadTimeError()
示例#10
0
 def _checkMeasureIndex(self, index, endOk=False):
     if not (0 <= index < self.numMeasures()):
         if not (endOk and index == self.numMeasures()):
             raise BadTimeError()