Exemple #1
0
 def test_song_add(self):
     songs = [music.Song() for i in range(3)]
     songs[0].add(music.Note('E3'))
     songs[1].add(music.Chord(['E3']))
     songs[2].add('E3')
     for song in songs:
         self.assertIn('E3', str(song.notes))  # This is sloppy
Exemple #2
0
def test_Note__init__invalid_letter__raises_ValueError():
    # Arrange
    invalid_letter = 'H'

    # Act/ Assert
    with pytest.raises(ValueError):
        note = m.Note(invalid_letter, 1)
Exemple #3
0
def test_Note__init__invalid_index__raises_ValueError():
    # Arrange
    invalid_index = 9

    # Act/ Assert
    with pytest.raises(ValueError):
        note = m.Note('A', invalid_index)
Exemple #4
0
 def name_notes(self, points, key):
     ''' Converts a list of (x, y) coordinate values into named Notes
     key should contain top/bottom staffline y-values, for F5 and E4 '''
     e4 = max(key)
     f5 = min(key)
     step = (e4 - f5) / 8
     c4 = e4 + int(2 * step)
     names = []
     for point in points:
         steps = round((point[1] - c4) / step)
         if steps == 0:
             names.append(music.Note('C4'))
             continue
         # Probably want to link these to the music module
         elif steps > 0:
             scale = 'BAGFEDC'
         elif steps < 0:
             scale = 'DEFGABC'
         for i, _ in zip(it.cycle(scale), range(abs(steps))):
             name = i
         octave = str(3 - ((steps - 1) // 7))  # Octaves increment at C
         names.append(music.Note(name + octave))
     return names
Exemple #5
0
 def test_four_bars(self):
     arr = tab.Arrangement()
     root = music.Note('A3')
     major = (0, 2, 4, 5, 7, 9, 11, 12)
     arr.add_run([(root + i).get_low_fret() for i in major], 1 / 2)
     try:
         self.assertEqual(
             arr, '|--------|--------|--------|--------|\n'
             '|--------|--------|--------|--------|\n'
             '|--------|--------|--------|1---2---|\n'
             '|--------|----0---|2---4---|--------|\n'
             '|0---2---|4-------|--------|--------|\n'
             '|--------|--------|--------|--------|\n\n')
     except AssertionError as e:
         print(f'Static A major, four bars:\n{arr}')
         raise e
Exemple #6
0
 def test_E_major(self):
     song = music.Song()
     for note in ('E3', 'F#3', 'G#3', 'A3', 'B3', 'C#4', 'D#4', 'E4'):
         song.add(music.Note(note, 1 / 8))
     g = player.Guitarist(song)
     expected = ('|--------------------------------|\n'
                 '|--------------------------------|\n'
                 '|--------------------------------|\n'
                 '|------------------------1---2---|\n'
                 '|------------0---2---4-----------|\n'
                 '|0---2---4-----------------------|\n\n')
     try:
         self.assertEqual(g.arr, expected)
     except AssertionError as AE:
         print(f'E major, one bar:\n{g.arr}')
         raise AE
Exemple #7
0
 def test_D_major_scale(self):
     ''' Test add_run using list of Note names '''
     D_major = ('D4', 'E4', 'F#4', 'G4', 'A4', 'B4', 'C#5', 'D5')
     bar = tab.Bar()
     for note in D_major:
         shape = music.Note(note).get_low_fret()
         bar.add_shape(shape, 1 / 8)
     try:
         self.assertEqual(
             bar, '|--------------------------------|\n'
             '|--------------------0---2---3---|\n'
             '|------------0---2---------------|\n'
             '|0---2---4-----------------------|\n'
             '|--------------------------------|\n'
             '|--------------------------------|\n')
     except AssertionError as e:
         print(f'Static D major, one bar:\n{bar}')
         raise e
Exemple #8
0
 def test_A_major_scale(self):
     ''' Test add_run using Note addition '''
     root = music.Note('A3')
     major = (0, 2, 4, 5, 7, 9, 11, 12)
     bar = tab.Bar()
     for i in major:
         shape = (root + i).get_low_fret()
         bar.add_shape(shape, 1 / 8)
     try:
         self.assertEqual(
             bar, '|--------------------------------|\n'
             '|--------------------------------|\n'
             '|------------------------1---2---|\n'
             '|------------0---2---4-----------|\n'
             '|0---2---4-----------------------|\n'
             '|--------------------------------|\n')
     except AssertionError as e:
         print(f'Static A major, one bar:\n{bar}')
         raise e
Exemple #9
0
def test_TrebleStaff__init__E5__returns_expected():
    # Arrange
    letter = 'C'
    index = 5
    expected_note = \
        "---\n" \
        " O \n" \
        "---\n" \
        "   \n" \
        "---\n" \
        "   \n" \
        "---\n" \
        "   \n" \
        "---"
    note = m.Note(letter, index)

    # Act
    staff = m.TrebleStaff(note)

    # Assert
    assert staff.display_as == expected_note
Exemple #10
0
def parse_piano_roll(matrix, row_metas, t0):
    voices = {}
    voices_last_t = {}
    for t in xrange(matrix.shape[1]):
        for i in xrange(matrix.shape[0]):
            c = matrix[i, t]
            if c.isalpha():
                name = c.lower()
                note = mu.Note(pitch=row_metas[i]["pitch"], duration=1)
                if name not in voices:
                    voices[name] = mu.Sequence(notes=[], name=name)
                # pad with Rests to t - 1
                pad_duration = t - 1 - voices_last_t.get(name, 0)
                if pad_duration > 0:
                    voices[name].append(mu.Rest(duration=pad_duration),
                                        try_tie=True)
                    voices_last_t[name] = t - 1
                voices_last_t[name] = t
                voices[name].append(note, try_tie=c.islower())
            elif c == "." or c.isspace():
                pass
            else:
                raise ValueError()
    return voices
Exemple #11
0
 def on_new_pitch(self, pitch):
     note = music.Note(pitch=pitch)
     self.harp.show_notes(note)
     self.label.setText(note.name + " " + str(note.octave))
     print note
Exemple #12
0
 def test_note_naming(self):
     points = [(0, -110), (0, 0), (0, 20), (0, 30), (0, 70), (0, 140)]
     key = (0, 80)
     names = self.d.name_notes(points, key)
     notes = [music.Note(i) for i in ('C7', 'F5', 'D5', 'C5', 'F4', 'F3')]
     self.assertEqual(names, notes)
Exemple #13
0
 def test_tie(self):
     self.assertEqual(mu.tie(mu.Rest(duration=2), mu.Rest(duration=3)),
                      mu.Rest(duration=5))
     self.assertEqual(
         mu.tie(mu.Note(pitch=0, duration=2), mu.Note(pitch=0, duration=3)),
         mu.Note(pitch=0, duration=5))
     self.assertEqual(
         mu.tie(mu.Note(pitch=0, duration=2), mu.Note(pitch=1, duration=3)),
         mu.Tie(mu.Note(pitch=0, duration=2), mu.Note(pitch=1, duration=3)))
     self.assertEqual(
         mu.tie(
             mu.Tie(mu.Note(pitch=0, duration=2),
                    mu.Note(pitch=1, duration=3)),
             mu.Note(pitch=1, duration=2)),
         mu.Tie(mu.Note(pitch=0, duration=2), mu.Note(pitch=1, duration=5)))
     self.assertEqual(
         mu.tie(
             mu.Note(pitch=1, duration=2),
             mu.Tie(mu.Note(pitch=0, duration=2),
                    mu.Note(pitch=1, duration=3))),
         mu.Tie(mu.Note(pitch=1, duration=2), mu.Note(pitch=0, duration=2),
                mu.Note(pitch=1, duration=3)))
     with self.assertRaises(mu.InvalidTieError):
         mu.tie(mu.Rest(duration=1), mu.Note(pitch=0, duration=2))
Exemple #14
0
 def setUp(self):
     self.e1 = music.Note(-8)
     self.e2 = music.Note('E3')
Exemple #15
0
 def test_fret_limit(self):
     a6 = music.Note('A6')
     self.assertEqual(a6.shapes, [(5, 17)])
     e6 = music.Note('E6')
     self.assertEqual(e6.shapes, [(4, 17), (5, 12)])