def test_remove_redundant_accidentals(self): known = {'C##b': 'C#', 'Eb##b': 'E'} for k in known.keys(): self.assertEqual( known[k], notes.remove_redundant_accidentals(k), 'The simplified note of %s is not %s, expecting %s' % (k, notes.remove_redundant_accidentals(k), known[k]))
def test_remove_redundant_accidentals(self): known = {"C##b": "C#", "Eb##b": "E"} for k in known: self.assertEqual( known[k], notes.remove_redundant_accidentals(k), "The simplified note of %s is not %s, expecting %s" % (k, notes.remove_redundant_accidentals(k), known[k]), )
def test_remove_redundant_accidentals(self): known = { 'C##b': 'C#', 'Eb##b': 'E' } for k in known.keys(): self.assertEqual(known[k], notes.remove_redundant_accidentals(k), 'The simplified note of %s is not %s, expecting %s' % (k, notes.remove_redundant_accidentals(k), known[k]))
def generate_blues_scale(key="C"): """Returns an ordered list of the notes of the blues scale in this key. \ For example: if the key is set to 'C', this function will return \ `['C', 'D#', 'F', 'F#', 'G', 'A#']`. \ This function will raise an !NoteFormatError if the key isn't recognised""" if not (notes.is_valid_note(key)): raise NoteFormatError, "Unrecognised format for key '%s'" % key result = [] fifth_index = notes.fifths.index(key[0]) result.append(intervals.unison(key)) result.append(notes.diminish(intervals.third(key, key))) result.append(intervals.third(key, key)) result.append(intervals.fourth(key, key)) result.append(notes.diminish(intervals.fifth(key, key))) result.append(intervals.fifth(key, key)) result.append(notes.diminish(intervals.seventh(key, key))) # Remove redundant #'s and b's from the result result = map(notes.remove_redundant_accidentals, result) tonic = result.index(notes.remove_redundant_accidentals(key)) result = result[tonic:] + result[:tonic] return result
def note_validity_chk_redundancy_remover(self, note): ''' Objective: Check if note is valid or not; if so remove any redundancy from the note ''' if M_notes.is_valid_note(note): note1 = M_notes.reduce_accidentals( M_notes.remove_redundant_accidentals(note)) if self.__original_notation_intact(note) not in note1: return (note, True) else: return (note1, True) return (note, False)
def __parse_note(self, note): step = etree.ETXPath("./pitch/step")(note) alter = etree.ETXPath("./pitch/alter")(note) n = "" if step: n = step[0].text n += self.__calc_alteration(alter) if n: return notes.remove_redundant_accidentals(n)
def checkNote(n): """ Displays a prompt, followed by a new line and python prompt (>>> ) Checks to see if user wants to quit. If so, returns True and main() will end. Otherwise, checks whether note is valid and removes accidentals """ cond = False while cond == False: try: n0 = n[0].upper() n = n0 + n[1:] if notes.is_valid_note(n): cond = True else: n = raw_input("Please Try Again.\n>>> ") except IndexError: pass return str(notes.remove_redundant_accidentals(n))
def checkNote(n): """ Checks whether note is valid and removes redundant accidentals. """ cond = False while cond == False: if type(n) != str or len(n) < 1: n = raw_input("Please Try Again.\n>>> ") pass try: n0 = n[0].upper() n = n0 + n[1:] if notes.is_valid_note(n): return str(notes.remove_redundant_accidentals(n)) else: n = raw_input("Please Try Again.\n>>> ") except IndexError: pass
def remove_redundant_accidentals(self): """Call notes.remove_redundant_accidentals on this note's name.""" self.name = notes.remove_redundant_accidentals(self.name)
def scratch(): import mingus.core.notes as notes print notes.reduce_accidentals('B#') ## output is 'C' print notes.remove_redundant_accidentals('C###############') print notes.diminish('C##############')