MCPcopy Create free account
hub / github.com/bspaans/python-mingus / int_to_note

Function int_to_note

mingus/core/notes.py:36–61  ·  view source on GitHub ↗

Convert integers in the range of 0-11 to notes in the form of C or C# or Db. Throw a RangeError exception if the note_int is not in the range 0-11. If not specified, sharps will be used. Examples: >>> int_to_note(0) 'C' >>> int_to_note(3) 'D#' >>> int_to_note(3

(note_int, accidentals="#")

Source from the content-addressed store, hash-verified

34
35
36def int_to_note(note_int, accidentals="#"):
37 """Convert integers in the range of 0-11 to notes in the form of C or C#
38 or Db.
39
40 Throw a RangeError exception if the note_int is not in the range 0-11.
41
42 If not specified, sharps will be used.
43
44 Examples:
45 >>> int_to_note(0)
46 'C'
47 >>> int_to_note(3)
48 'D#'
49 >>> int_to_note(3, 'b')
50 'Eb'
51 """
52 if note_int not in range(12):
53 raise RangeError("int out of bounds (0-11): %d" % note_int)
54 ns = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
55 nf = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
56 if accidentals == "#":
57 return ns[note_int]
58 elif accidentals == "b":
59 return nf[note_int]
60 else:
61 raise FormatError("'%s' not valid as accidental" % accidentals)
62
63
64def is_enharmonic(note1, note2):

Callers 1

reduce_accidentalsFunction · 0.85

Calls 2

RangeErrorClass · 0.90
FormatErrorClass · 0.90

Tested by

no test coverage detected