def keyboardPartsToBraille(music21PartStaffUpper, music21PartStaffLower, **keywords): """ Translates two :class:`~music21.stream.Part` instances to braille, an upper part and a lower part. Assumes that the two parts are aligned and well constructed. Bar over bar format is used. """ (inPlace, debug) = _translateArgs(**keywords) upperPartToTranscribe = music21PartStaffUpper if not inPlace: upperPartToTranscribe = music21PartStaffUpper.makeNotation( cautionaryNotImmediateRepeat=False) lowerPartToTranscribe = music21PartStaffLower if not inPlace: lowerPartToTranscribe = music21PartStaffLower.makeNotation( cautionaryNotImmediateRepeat=False) rhSegments = segment.findSegments(upperPartToTranscribe, **keywords) lhSegments = segment.findSegments(lowerPartToTranscribe, **keywords) allBrailleText = [] for (rhSegment, lhSegment) in zip(rhSegments, lhSegments): bg = segment.BrailleGrandSegment(rhSegment, lhSegment) if not debug: allBrailleText.append(bg.transcription) else: allBrailleText.append(str(bg)) return u"\n".join([unicode(bt) for bt in allBrailleText])
def keyboardPartsToBraille(keyboardScore, **keywords): """ Translates a Score object containing two :class:`~music21.stream.Part` instances to braille, an upper part and a lower part. Assumes that the two parts are aligned and well constructed. Bar over bar format is used. """ parts = keyboardScore.getElementsByClass(['Part', 'PartStaff']) if len(parts) != 2: raise BrailleTranslateException( "Can only translate two keyboard parts at a time") (inPlace, debug) = _translateArgs(**keywords) staffUpper = parts[0] staffLower = parts[1] upperPartToTranscribe = staffUpper if not inPlace: upperPartToTranscribe = staffUpper.makeNotation( cautionaryNotImmediateRepeat=False) lowerPartToTranscribe = staffLower if not inPlace: lowerPartToTranscribe = staffLower.makeNotation( cautionaryNotImmediateRepeat=False) rhSegments = segment.findSegments(upperPartToTranscribe, setHand='right', **keywords) lhSegments = segment.findSegments(lowerPartToTranscribe, setHand='left', **keywords) allBrailleText = [] for (rhSegment, lhSegment) in zip(rhSegments, lhSegments): bg = segment.BrailleGrandSegment() for rhGroupingKey in rhSegment: bg[rhGroupingKey] = rhSegment[rhGroupingKey] for lhGroupingKey in lhSegment: bg[lhGroupingKey] = lhSegment[lhGroupingKey] bg.transcribe() if not debug: allBrailleText.append(bg.brailleText) else: if six.PY2: bsStr = str(bg) bsUni = bsStr.decode('utf-8') allBrailleText.append(bsUni) else: allBrailleText.append(str(bg)) if six.PY2 and debug: return u"\n".join(allBrailleText) else: return u"\n".join([unicode(bt) for bt in allBrailleText])
def keyboardPartsToBraille(keyboardScore, *, inPlace=False, debug=False, cancelOutgoingKeySig=True, descendingChords=None, dummyRestLength=None, maxLineLength=40, segmentBreaks=None, showClefSigns=False, showFirstMeasureNumber=True, showHand=None, showHeading=True, showLongSlursAndTiesTogether: t.Optional[bool] = None, showShortSlursAndTiesTogether=False, slurLongPhraseWithBrackets=True, suppressOctaveMarks=False, upperFirstInNoteFingering=True, ): ''' Translates a Score object containing two :class:`~music21.stream.Part` instances to braille, an upper part and a lower part. Assumes that the two parts are aligned and well constructed. Bar over bar format is used. ''' parts = keyboardScore.getElementsByClass(['Part', 'PartStaff']) if len(parts) != 2: raise BrailleTranslateException('Can only translate two keyboard parts at a time') staffUpper = parts[0] staffLower = parts[1] upperPartToTranscribe = staffUpper if not inPlace: upperPartToTranscribe = staffUpper.makeNotation(cautionaryNotImmediateRepeat=False) lowerPartToTranscribe = staffLower if not inPlace: lowerPartToTranscribe = staffLower.makeNotation(cautionaryNotImmediateRepeat=False) rhSegments = segment.findSegments(upperPartToTranscribe, setHand='right', cancelOutgoingKeySig=cancelOutgoingKeySig, descendingChords=descendingChords, dummyRestLength=dummyRestLength, maxLineLength=maxLineLength, segmentBreaks=segmentBreaks, showClefSigns=showClefSigns, showFirstMeasureNumber=showFirstMeasureNumber, showHand=showHand, showHeading=showHeading, showLongSlursAndTiesTogether=showLongSlursAndTiesTogether, showShortSlursAndTiesTogether=showShortSlursAndTiesTogether, slurLongPhraseWithBrackets=slurLongPhraseWithBrackets, suppressOctaveMarks=suppressOctaveMarks, upperFirstInNoteFingering=upperFirstInNoteFingering, ) lhSegments = segment.findSegments(lowerPartToTranscribe, setHand='left', cancelOutgoingKeySig=cancelOutgoingKeySig, descendingChords=descendingChords, dummyRestLength=dummyRestLength, maxLineLength=maxLineLength, segmentBreaks=segmentBreaks, showClefSigns=showClefSigns, showFirstMeasureNumber=showFirstMeasureNumber, showHand=showHand, showHeading=showHeading, showLongSlursAndTiesTogether=showLongSlursAndTiesTogether, showShortSlursAndTiesTogether=showShortSlursAndTiesTogether, slurLongPhraseWithBrackets=slurLongPhraseWithBrackets, suppressOctaveMarks=suppressOctaveMarks, upperFirstInNoteFingering=upperFirstInNoteFingering, ) allBrailleText = [] for (rhSegment, lhSegment) in zip(rhSegments, lhSegments): bg = segment.BrailleGrandSegment(lineLength=maxLineLength) for rhGroupingKey in rhSegment: # print(type(rhSegment), type(rhSegment[rhGroupingKey])) # breakpoint() bg[rhGroupingKey] = rhSegment[rhGroupingKey] for lhGroupingKey in lhSegment: bg[lhGroupingKey] = lhSegment[lhGroupingKey] bg.transcribe() if not debug: allBrailleText.append(bg.brailleText) else: allBrailleText.append(str(bg)) return '\n'.join([str(bt) for bt in allBrailleText])