@@ -698,7 +698,7 @@ def translateStreamToString(inputStreamOrIterator, returnMeasures=False):
698698 b += translateNoteWithDurationToBytes (n )
699699 if returnMeasures :
700700 measures .append (n .measureNumber )
701- if returnMeasures is False :
701+ if not returnMeasures :
702702 return b
703703 else :
704704 return (b , measures )
@@ -750,7 +750,7 @@ def translateDiatonicStreamToString(inputStreamOrIterator, returnMeasures=False)
750750 mNum = n .measureNumber
751751
752752 if n .isRest :
753- if previousRest is True :
753+ if previousRest :
754754 continue
755755 else :
756756 previousRest = True
@@ -759,7 +759,7 @@ def translateDiatonicStreamToString(inputStreamOrIterator, returnMeasures=False)
759759 continue
760760 else :
761761 previousRest = False
762- if previousTie is True :
762+ if previousTie :
763763 if n .tie is None or n .tie .type == 'stop' :
764764 previousTie = False
765765 continue
@@ -778,7 +778,7 @@ def translateDiatonicStreamToString(inputStreamOrIterator, returnMeasures=False)
778778 b .append (newName )
779779
780780 joined = '' .join (b )
781- if returnMeasures is False :
781+ if not returnMeasures :
782782 return joined
783783 else :
784784 return (joined , measures )
@@ -822,21 +822,20 @@ def translateIntervalsAndSpeed(inputStream, returnMeasures=False):
822822 b = []
823823 measures = []
824824
825- previousRest = False
826- previousTie = False
825+ previousRest = False # was the previous a Rest
826+ previousTie = False # was the previous a Tie?
827827 previousQL = None
828828 previousMidi = 60
829- for n in inputStream :
830- if n .isNote :
831- previousMidi = n .pitches [0 ].midi
832- break
829+ for n in inputStream .getElementsByClass (note .Note ):
830+ previousMidi = n .pitches [0 ].midi
831+ break
833832
834833 for n in inputStream :
835834 mNum = None
836835 if returnMeasures :
837836 mNum = n .measureNumber
838837 if n .isRest :
839- if previousRest is True :
838+ if previousRest :
840839 continue
841840 else :
842841 previousRest = True
@@ -845,7 +844,7 @@ def translateIntervalsAndSpeed(inputStream, returnMeasures=False):
845844 continue
846845 else :
847846 previousRest = False
848- if previousTie is True :
847+ if previousTie :
849848 if n .tie is None or n .tie .type == 'stop' :
850849 previousTie = False
851850 continue
@@ -870,7 +869,7 @@ def translateIntervalsAndSpeed(inputStream, returnMeasures=False):
870869 b .append (newName )
871870
872871 joined = '' .join (b )
873- if returnMeasures is False :
872+ if not returnMeasures :
874873 return joined
875874 else :
876875 return (joined , measures )
@@ -928,10 +927,10 @@ def translateStreamToStringOnlyRhythm(inputStream, returnMeasures=False):
928927 return b
929928
930929
931- def translateNoteToByte (n : note .GeneralNote ):
930+ def translateNoteToByte (n : note .GeneralNote ) -> str :
932931 # noinspection PyShadowingNames
933932 '''
934- takes a note.Note object and translates it to a single byte representation.
933+ takes a note.Note object and translates it to a single byte representation in a string .
935934
936935 currently returns the chr() for the note's midi number. or chr(127) for rests
937936 and unpitched.
@@ -957,10 +956,10 @@ def translateNoteToByte(n: note.GeneralNote):
957956 else :
958957 return chr (127 )
959958
960- def translateNoteWithDurationToBytes (n : note .GeneralNote , includeTieByte = True ):
959+ def translateNoteWithDurationToBytes (n : note .GeneralNote , includeTieByte : bool = True ) -> str :
961960 # noinspection PyShadowingNames
962961 '''
963- takes a note.Note object and translates it to a three-byte representation.
962+ takes a note.Note object and translates it to a three-byte representation as a string .
964963
965964 currently returns the chr() for the note's midi number. or chr(127) for rests
966965 followed by the log of the quarter length (fitted to 1-127, see
@@ -987,7 +986,7 @@ def translateNoteWithDurationToBytes(n: note.GeneralNote, includeTieByte=True):
987986 firstByte = translateNoteToByte (n )
988987 secondByte = translateDurationToBytes (n )
989988 thirdByte = translateNoteTieToByte (n )
990- if includeTieByte is True :
989+ if includeTieByte :
991990 return firstByte + secondByte + thirdByte
992991 else :
993992 return firstByte + secondByte
@@ -1098,7 +1097,6 @@ def mostCommonMeasureRhythms(streamIn, transposeDiatonic=False):
10981097 * Changed in v7: bars are ordered first by number, then by part.
10991098 '''
11001099 returnDicts = []
1101- distanceToTranspose = 0
11021100
11031101 for thisMeasure in streamIn [Measure ]:
11041102 rhythmString = translateStreamToStringOnlyRhythm (thisMeasure .notesAndRests )
@@ -1109,7 +1107,7 @@ def mostCommonMeasureRhythms(streamIn, transposeDiatonic=False):
11091107 entry ['number' ] += 1
11101108 entry ['measures' ].append (thisMeasure )
11111109 break
1112- if rhythmFound is False :
1110+ if not rhythmFound :
11131111 newDict = {
11141112 'number' : 1 ,
11151113 'rhythmString' : rhythmString ,
0 commit comments