Пример #1
0
    def get_Note(self, string=0, fret=0, maxfret=24):
        """Return the Note on 'string', 'fret'.

        Throw a RangeError if either the fret or string is unplayable.

        Examples:
        >>> t = StringTuning('test', 'test', ['A-3', 'A-4'])
        >>> t.get_Note(0, 0)
        'A-3'
        >>> t.get_Note(0, 1)
        'A#-3'
        >>> t.get_Note(1, 0)
        'A-4'
        """
        if 0 <= string < self.count_strings():
            if 0 <= fret <= maxfret:
                s = self.tuning[string]
                if isinstance(s, list):
                    s = s[0]
                n = Note(int(s) + fret)
                n.string = string
                n.fret = fret
                return n
            else:
                raise RangeError("Fret '%d' on string '%d' is out of range" %
                                 (string, fret))
        else:
            raise RangeError("String '%d' out of range" % string)
Пример #2
0
    def get_Note(
        self,
        string=0,
        fret=0,
        maxfret=24,
        ):
        """Returns the Note on `string`, `fret`. Throws a RangeError if either the \
fret or string is unplayable.
{{{
>>> t = tunings.StringTuning(\"test\", \"test\", ['A-3', 'A-4'])
>>> t,get_Note(0, 0)
'A-3'
>>> t.get_Note(0, 1)
'A#-3'
>>> t.get_Note(1, 0)
'A-4'
}}}"""

        if 0 <= string < self.count_strings():
            if 0 <= fret <= maxfret:
                s = self.tuning[string]
                if type(s) == list:
                    s = s[0]
                n = Note(int(s) + fret)
                n.string = string
                n.fret = fret
                return n
            else:
                raise RangeError("Fret '%d' on string '%d' is out of range"\
                     % (string, fret))
        else:
            raise RangeError("String '%d' out of range" % string)
Пример #3
0
def int_to_note(note_int, accidentals='#'):
    """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, 'b')
    'Eb'
    """
    if note_int not in range(12):
        raise RangeError('int out of bounds (0-11): %d' % note_int)
    ns = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
    nf = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B']
    if accidentals == '#':
        return ns[note_int]
    elif accidentals == 'b':
        return nf[note_int]
    else:
        raise FormatError("'%s' not valid as accidental" % accidentals)
Пример #4
0
def int_to_note(note_int, accidentals="#"):
    """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, 'b')
    'Eb'
    """
    if note_int not in range(12):
        raise RangeError("int out of bounds (0-11): %d" % note_int)
    ns = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
    nf = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"]
    if accidentals == "#":
        return ns[note_int]
    elif accidentals == "b":
        return nf[note_int]
    else:
        raise FormatError("'%s' not valid as accidental" % accidentals)
Пример #5
0
def get_key(accidentals=0):
    """Return the key corrisponding to accidentals.

    Return the tuple containing the major key corrensponding to the
    accidentals put as input, and his relative minor; negative numbers for
    flats, positive numbers for sharps.
    """
    if accidentals not in range(-7, 8):
        raise RangeError('integer not in range (-7)-(+7).')
    return keys[accidentals + 7]
Пример #6
0
def from_Note(note, width=80, tuning=None):
    """Return a string made out of ASCII tablature representing a Note object
    or note string.

    Throw a RangeError if a suitable fret can't be found.

    'tuning' should be a StringTuning object or None for the default tuning.

    To force a certain fingering you can use a 'string' and 'fret' attribute
    on the Note. If the fingering is valid, it will get used instead of the
    default one.
    """
    if tuning is None:
        tuning = default_tuning
    result = begin_track(tuning)
    min = 1000
    (s, f) = (-1, -1)

    # Do an attribute check
    if hasattr(note, "string") and hasattr(note, "fret"):
        n = tuning.get_Note(note.string, note.fret)
        if n is not None and int(n) == int(note):
            (s, f) = (note.string, note.fret)
            min = 0

    if min == 1000:
        for (string, fret) in enumerate(tuning.find_frets(note)):
            if fret is not None:
                if fret < min:
                    min = fret
                    (s, f) = (string, fret)
    l = len(result[0])
    w = max(4, (width - l) - 1)

    # Build ASCII
    if min != 1000:
        fret = str(f)
        for i in range(len(result)):
            d = len(fret)
            if i != s:
                result[i] += "-" * w + "|"
            else:
                d = w - len(fret)
                result[i] += "-" * (d // 2) + fret
                d = (w - d // 2) - len(fret)
                result[i] += "-" * d + "|"
    else:
        raise RangeError("No fret found that could play note '%s'. "
                         "Note out of range." % note)
    result.reverse()
    return os.linesep.join(result)
Пример #7
0
    def degree(self, degree_number, direction='a'):
        """Return the asked scale degree.

        The direction of the scale is 'a' for ascending (default) and 'd'
        for descending.
        """
        if degree_number < 1:
            raise RangeError("degree '%s' out of range" % degree_number)
        if direction == 'a':
            notes = self.ascending()[:-1]
            return notes[degree_number - 1]
        elif direction == 'd':
            notes = reversed(self.descending())[:-1]
            return notes[degree_number - 1]
        else:
            raise FormatError("Unrecognised direction '%s'" % direction)