Beispiel #1
0
 def getMeasureByPosition(self, position):
     if position.staffIndex is None or position.measureIndex is None:
         raise BadTimeError()
     if not (0 <= position.staffIndex < len(self._staffs)):
         raise BadTimeError()
     staff = self.getStaffByIndex(position.staffIndex)
     if not (0 <= position.measureIndex < staff.numMeasures()):
         raise BadTimeError()
     return staff[position.measureIndex]
Beispiel #2
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()
Beispiel #3
0
 def nthVisibleLineIndex(self, staffIndex, lineIndex):
     count = -1
     staff = self.getStaffByIndex(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)
Beispiel #4
0
 def measureIndexToPosition(self, index):
     staffIndex = 0
     staff = self.getStaffByIndex(0)
     while index >= staff.numMeasures():
         index -= staff.numMeasures()
         staffIndex += 1
         if staffIndex == self.numStaffs():
             break
         staff = self.getStaffByIndex(staffIndex)
     if staffIndex == self.numStaffs():
         raise BadTimeError(index)
     return NotePosition(staffIndex=staffIndex, measureIndex=index)
Beispiel #5
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)
Beispiel #6
0
 def nextMeasure(self, position):
     self._checkStaffIndex(position.staffIndex)
     staff = self.getStaffByIndex(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
Beispiel #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)
Beispiel #8
0
 def noteAt(self, noteTime, drumIndex):
     self._checkValidNoteTime(noteTime)
     if drumIndex < 0:
         raise BadTimeError()
     return self._notes.getNote(noteTime, drumIndex)
Beispiel #9
0
 def _checkValidNoteTime(self, noteTime):
     if not (0 <= noteTime < len(self)):
         raise BadTimeError(noteTime)
Beispiel #10
0
 def _checkMeasureIndex(self, index, endOk=False):
     if not (0 <= index < self.numMeasures()):
         if not (endOk and index == self.numMeasures()):
             raise BadTimeError()
Beispiel #11
0
 def _checkDrumIndex(self, index):
     if not (0 <= index < len(self.drumKit)):
         raise BadTimeError()
Beispiel #12
0
 def _checkStaffIndex(self, index):
     if not (0 <= index < self.numStaffs()):
         raise BadTimeError()