How to use the birdears.scale.ChromaticScale function in birdears

To help you get started, we’ve selected a few birdears examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iacchus / birdears / tests / test_basic.py View on Github external
def test_chromaticscale_gettriad():

    a = ChromaticScale(tonic='C')
    b = a.get_triad(mode='major', degree=7)
    assert(b)
github iacchus / birdears / birdears / questionbase.py View on Github external
tonic = tonic.replace(' ', '')
            tonic = choice(tonic.split(','))
        elif isinstance(tonic, str) and ('R' in tonic or 'r' in tonic):
            tonic = choice(KEYS)

        self.tonic_pitch = Pitch(note=tonic, octave=self.octave)
        self.tonic_str = str(self.tonic_pitch.note)
        self.tonic_pitch_str = str(self.tonic_pitch)

        if not chromatic:
            self.scale = DiatonicScale(tonic=self.tonic_str, mode=mode,
                                       octave=self.octave,
                                       descending=descending,
                                       n_octaves=n_octaves)
        else:
            self.scale = ChromaticScale(tonic=self.tonic_str,
                                        octave=self.octave,
                                        descending=descending,
                                        n_octaves=n_octaves)

        self.diatonic_scale = DiatonicScale(tonic=self.tonic_str, mode=mode,
                                            octave=self.octave,
                                            descending=descending,
                                            n_octaves=n_octaves)

        self.chromatic_scale = ChromaticScale(tonic=self.tonic_str,
                                              octave=self.octave,
                                              descending=descending,
                                              n_octaves=n_octaves)

        self.tonic_accident = ('flat' if (('b' in self.tonic_str)
                               or (self.tonic_str == 'F'))
github iacchus / birdears / birdears / interfaces / urwid.py View on Github external
def draw_question(self):

        if self.exercise != 'notename':
            scale = \
                ChromaticScale(tonic=self.question.lowest_tonic_pitch.note,
                               octave=self.question.lowest_tonic_pitch.octave,
                               descending=False,
                               n_octaves=self.question.n_octaves)
        else:
            scale = \
                ChromaticScale(tonic='C',
                               octave=self.question.lowest_tonic_pitch.octave)
                               #descending=False,
                               #n_octaves=self.question.n_octaves)

        self.keyboard = \
            Keyboard(scale=scale,
                     question_tonic_pitch=self.question.tonic_pitch,
                     main_loop=self.loop,
                     keyboard_index=self.question.keyboard_index)
github iacchus / birdears / birdears / scale.py View on Github external
def __init__(self, tonic='C', octave=4, n_octaves=1, descending=False,
                 dont_repeat_tonic=False):
        """Returns a chromatic scale from tonic.

        Args:
            tonic (str): The note which the scale will be built upon.
            octave (int): The scientific octave the scale will be built upon.
            n_octaves (int): The number of octaves the scale will contain.
            descending (bool): Whether the scale is descending.
            dont_repeat_tonic (bool): Whether to skip appending the last
                note (octave) to the scale.
        """

        super(ChromaticScale, self).__init__()

        # global CHROMATIC_SHARP, CHROMATIC_FLAT

        self.tonic = Pitch(tonic, octave)
        self.direction = "Ascending" if not descending else "Descending"
        self.is_descending = descending
        self.n_octaves = n_octaves

        direction = +1 if not descending else -1

        tonic_pitch_num = int(self.tonic)
        repeat_tonic = not dont_repeat_tonic  # 1 or 0

        accident = 'flat' if (('b' in tonic) or (tonic == 'F')) else 'sharp'

        scale = [get_pitch_by_number(numeric=tonic_pitch_num + (i*direction),
github iacchus / birdears / birdears / interfaces / urwid.py View on Github external
def draw_question(self):

        if self.exercise != 'notename':
            scale = \
                ChromaticScale(tonic=self.question.lowest_tonic_pitch.note,
                               octave=self.question.lowest_tonic_pitch.octave,
                               descending=False,
                               n_octaves=self.question.n_octaves)
        else:
            scale = \
                ChromaticScale(tonic='C',
                               octave=self.question.lowest_tonic_pitch.octave)
                               #descending=False,
                               #n_octaves=self.question.n_octaves)

        self.keyboard = \
            Keyboard(scale=scale,
                     question_tonic_pitch=self.question.tonic_pitch,
                     main_loop=self.loop,
                     keyboard_index=self.question.keyboard_index)

        top_variables = {
            'tonic': self.question.tonic_str,
            'mode': self.question.mode.capitalize(),
            'random': ('(random) ' if ('tonic' in self.arguments and
                                       any(el in self.arguments['tonic']
                                       for el in ('r', 'R'))) else ''),
github iacchus / birdears / birdears / questionbase.py View on Github external
self.scale = DiatonicScale(tonic=self.tonic_str, mode=mode,
                                       octave=self.octave,
                                       descending=descending,
                                       n_octaves=n_octaves)
        else:
            self.scale = ChromaticScale(tonic=self.tonic_str,
                                        octave=self.octave,
                                        descending=descending,
                                        n_octaves=n_octaves)

        self.diatonic_scale = DiatonicScale(tonic=self.tonic_str, mode=mode,
                                            octave=self.octave,
                                            descending=descending,
                                            n_octaves=n_octaves)

        self.chromatic_scale = ChromaticScale(tonic=self.tonic_str,
                                              octave=self.octave,
                                              descending=descending,
                                              n_octaves=n_octaves)

        self.tonic_accident = ('flat' if (('b' in self.tonic_str)
                               or (self.tonic_str == 'F'))
                               else 'sharp')

        if self.is_descending:
            self.lowest_tonic_pitch = \
                get_pitch_by_number(int(self.tonic_pitch)
                                    - (self.n_octaves * 12),
                                    accident=self.tonic_accident)
        else:
            self.lowest_tonic_pitch = self.tonic_pitch