Exemple #1
0
 def __init__(self, frets=12, strings=None):
     StringInstrument.__init__(
         self, frets, strings if strings else
         [Pitch('G', 4),
          Pitch('C', 4),
          Pitch('E', 4),
          Pitch('A', 4)])
    def test_scale(self):
        notes = [
            (1, 'C4'), (2, 'D4'), (3, 'Eb4'), (4, 'F4'), (5, 'G4'), (6, 'A4'), (7, 'B4'),
            (8, 'C5'), (9, 'D5'), (10, 'Eb5'), (11, 'F5'), (12, 'G5'), (13, 'A5'), (14, 'B5'), (15, 'C6'),
            (-1, 'Bb3'), (-2, 'Ab3'), (-3, 'G3'), (-4, 'F3'), (-5, 'Eb3'), (-6, 'D3'), (-7, 'C3'),
            (-8, 'Bb2'), (-9, 'Ab2'), (-10, 'G2'), (-11, 'F2'), (-12, 'Eb2'), (-13, 'D2'), (-14, 'C2'),
        ]

        s = Scale(Pitch('C'), Scale.Mode('MelodicMinor', [ 0, 2, 3, 5, 7, 9, 11 ], [ 10, 8, 7, 5, 3, 2, 0 ]))
        for i, note in notes:
            self.assertEqual(str(s.get_pitch(i)), note)

        s = Scale(Pitch('C'), Scale.Mode('MelodicMinor', [ 2, 1, 2, 2, 2, 2, 1 ], [ 2, 2, 1, 2, 2, 1, 2 ], as_intervals=True))
        for i, note in notes:
            self.assertEqual(str(s.get_pitch(i)), note)
Exemple #3
0
 def find_frets_for_note_on_string(self, note, string_num):
     if isinstance(note, str):
         note = Pitch(note)
     note_diff = note.value % 12 - self.strings[string_num -
                                                1].value % 12 + 12
     if note_diff >= 12:
         note_diff -= 12
     return list(range(note_diff, self.num_frets + 1, 12))
Exemple #4
0
def _add_line_to_lyrics(line, lyrics: List[Lyric], language: Language):
    for c in language.gen_charset_from_line(line):

        val = random.randrange(3)

        lyric = Lyric(Note(Pitch(REV_NOTE_MAP[val])), value=c)
        lyrics.append(lyric)

    return lyrics
Exemple #5
0
 def __init__(self, frets=22, strings=None):
     StringInstrument.__init__(
         self, frets, strings if strings else [
             Pitch('E', 2),
             Pitch('A', 2),
             Pitch('D', 3),
             Pitch('G', 3),
             Pitch('B', 3),
             Pitch('E', 4)
         ])
 def test_pitch_steps(self):
     notes = [
         'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'
     ]
     for note in Pitch.notes():
         p = Pitch(note, 4, 440)
         i = p.value % 12
         for step in range(-40, 60):
             self.assertEqual(
                 p.transpose(step),
                 Pitch(notes[(i + step) % 12], 4 + math.floor(
                     (i + step) / 12)))
         self.assertEqual(p.transpose(1), p.sharp())
         self.assertEqual(p.transpose(-1), p.flat())
         self.assertEqual(p.transpose(12).freq(), p.freq() * 2)
         self.assertEqual(p.transpose(12).octave, p.octave + 1)
Exemple #7
0
 def pitch(self):
     return Pitch(self.name, self.octave + 4)
Exemple #8
0
    parser.add_argument(
        '-m',
        '--mode',
        default='HarmonicMinor',
        help=
        'The target mode for the song (e.g. HarmonicMinor, Major, Mixolydian).'
    )
    parser.add_argument(
        '-t',
        '--tempo',
        default=60,
        help='The tempo for the song in beats per minute (e.g. 60).')
    args = parser.parse_args()

    if args.mode in Scale.modes:
        if args.root and Pitch.valid(args.root):
            scale = Scale(Pitch(args.root, 2), args.mode)
        else:
            print('Valid roots are', [root for root in Pitch.notes()])
            sys.exit()
    elif args.mode not in Scale.modes or len(scale.mode.ascending) != 7:
        modes = []
        for mode in Scale.modes:
            if len(Scale.modes[mode].ascending) == 7:
                modes.append(mode)
        print('Valid modes are', modes)
        sys.exit()

    staff = Staff(tempo=int(args.tempo))
    for n in [8, 6, 5, 7, 8, 9, 7, 8]:
        pitch = scale.get_pitch(n)
Exemple #9
0
    def test_string_instrument(self):
        instr = StringInstrument(
            24, [Pitch('A', 1),
                 Pitch('B', 1),
                 Pitch('C', 2),
                 Pitch('D', 2)])

        self.assertEqual(instr.pluck(2, 14), Pitch('C##', 3))
        self.assertEqual(
            instr.strum(),
            [Pitch('D', 2),
             Pitch('C', 2),
             Pitch('B', 1),
             Pitch('A', 1)])
        self.assertEqual(
            instr.strum([-1, 0, 2, 1]),
            [Pitch('C', 2), Pitch('C#', 2),
             Pitch('A#', 1)])
        self.assertEqual(instr.find_frets_for_note_on_string('A', 4),
                         [0, 12, 24])
        self.assertEqual(instr.find_frets_for_note_on_string('C', 4), [3, 15])
        self.assertEqual(instr.find_frets_for_note_on_string('A', 2), [9, 21])