def _pitchTickHelper(self, attributeCounter, attributeCompare): ''' Helper method that can apply all the showEnharmonic, etc. values consistently see the `ticks` methods below. Returns a list of two-element tuples ''' s = self.stream if s is None: # better hope that hideUnused is False, or just will get an empty list nameCount = {} else: nameCount = pitchAnalysis.pitchAttributeCount(s, attributeCounter) ticks = [] helperDict = {} for i in range(int(self.minValue), int(self.maxValue) + 1): p = pitch.Pitch() setattr(p, attributeCompare, i) weights = [] # a list of pairs of count/label for key in nameCount: if key not in helperDict: # store a dict of say, C4: 60, etc. so we don't need to make so many # pitch.Pitch objects helperDict[key] = getattr(pitch.Pitch(key), attributeCompare) if helperDict[key] == i: weights.append((nameCount[key], key)) weights.sort() label = None if not weights: # get a default if self.hideUnused: continue # don't append any ticks... if not self.blankLabelUnused: label = getattr(p, attributeCounter) else: # use an empty label to maintain spacing label = '' elif not self.showEnharmonic: # get just the first weighted label = weights[0][1] # second value is label else: sub = [] for unused_weight, name in weights: sub.append(accidentalLabelToUnicode(name)) label = '/'.join(sub) ticks.append((i, label)) ticks = self.makePitchLabelsUnicode(ticks) return ticks
def _pitchTickHelper(self, attributeCounter, attributeCompare): ''' Helper method that can apply all the showEnharmonic, etc. values consistently see the `ticks` methods below. Returns a list of two-element tuples ''' s = self.stream if s is None: # better hope that hideUnused is False, or just will get an empty list nameCount = {} else: nameCount = pitchAnalysis.pitchAttributeCount(s, attributeCounter) ticks = [] helperDict = {} octavesSeen = set() def weightedSortHelper(x): ''' ensure that higher weighed weights come first, but then alphabetical by name, except that G comes before A... since we are only comparing enharmonics... ''' weight, name = x if name.startswith('A'): name = 'H' + name[1:] return (-1 * weight, name) def unweightedSortHelper(x): weight, name = x if name.startswith('A'): name = 'H' + name[1:] return (weight, name) for i in range(int(self.minValue), int(self.maxValue) + 1): p = pitch.Pitch() setattr(p, attributeCompare, i) weights = [] # a list of pairs of count/label for key in nameCount: if key not in helperDict: # store a dict of say, C4: 60, etc. so we don't need to make so many # pitch.Pitch objects helperDict[key] = getattr(pitch.Pitch(key), attributeCompare) if helperDict[key] == i: weights.append((nameCount[key], key)) if self.showEnharmonic: weights.sort(key=unweightedSortHelper) else: weights.sort(key=weightedSortHelper) label = None if not weights: # get a default if self.hideUnused: continue # don't append any ticks... if not self.blankLabelUnused: label = getattr(p, attributeCounter) else: # use an empty label to maintain spacing label = '' elif not self.showEnharmonic: # get just the first weighted label = weights[0][1] # second value is label else: sub = [] for unused_weight, name in weights: sub.append(accidentalLabelToUnicode(name)) label = '/'.join(sub) if self.showOctaves is False: label = re.sub(r'\d', '', label) elif self.showOctaves == 'few': matchOctave = re.search(r'\d', label) if matchOctave: octaveMatch = matchOctave.group(0) if octaveMatch in octavesSeen: label = re.sub(r'\d', '', label) else: octavesSeen.add(octaveMatch) ticks.append((i, label)) ticks = self.makePitchLabelsUnicode(ticks) return ticks