+19
-23
@@ -39,25 +39,21 @@ class GuitarPartTests(unittest.TestCase):
|
||||
self.assertNotIn(0, generator.guitar.chord_requirements(chord, 'electric')[0])
|
||||
candidates = generator.guitar.chord_positions(*generator.guitar.chord_requirements(chord, 'electric'), profile='electric')
|
||||
self.assertTrue(any(all(p.midi % 12 != 0 for p in c) for c in candidates))
|
||||
def test_acoustic_has_independent_voices_and_alternating_bass(self):
|
||||
def test_acoustic_combines_independent_rhythms_and_alternating_bass(self):
|
||||
result = self.practice(tests.test_parts.xml_harmony() + tests.test_musicxml.xml_note(), 'acoustic')
|
||||
measure = result['staves'][0]['measures'][0]
|
||||
upper, bass = measure['voices']
|
||||
self.assertEqual((upper['id'], bass['id']), ('upper', 'bass'))
|
||||
self.assertNotEqual(tests.test_accompaniment.timing(upper['notes']), tests.test_accompaniment.timing(bass['notes']))
|
||||
attacks = [n for n in bass['notes'] if n['pitches']]
|
||||
self.assertEqual([generator.model.pitch_number(n['pitches'][0]) % 12 for n in attacks], [0, 7])
|
||||
for voice in (upper, bass):
|
||||
self.assertEqual(sum(generator.model.fraction(n['duration']) for n in voice['notes']), 4)
|
||||
for note in voice['notes']:
|
||||
self.assertEqual(note['stem'], 'up' if voice is upper else 'down')
|
||||
strings = sorted(p['tablature']['string'] for p in note['pitches'])
|
||||
if strings:
|
||||
if voice is bass:
|
||||
self.assertEqual(len(strings), 1)
|
||||
self.assertIn(strings[0], (5, 6))
|
||||
else:
|
||||
self.assertIn(strings, ([2, 3], [3, 4], [2, 3, 4]))
|
||||
self.assertEqual(len(measure['voices']), 1)
|
||||
notes = measure['voices'][0]['notes']
|
||||
bass = [(n['onset'], p) for n in notes for p in n['pitches'] if p['tablature']['string'] >= 5 and 'tie_from' not in p]
|
||||
upper = {generator.model.fraction(n['onset']) for n in notes for p in n['pitches'] if p['tablature']['string'] <= 4 and 'tie_from' not in p}
|
||||
self.assertNotEqual({generator.model.fraction(onset) for onset, _ in bass}, upper)
|
||||
self.assertEqual([generator.model.pitch_number(p) % 12 for _, p in bass], [0, 7])
|
||||
self.assertEqual(sum(generator.model.fraction(n['duration']) for n in notes), 4)
|
||||
for note in notes:
|
||||
self.assertNotIn('stem', note)
|
||||
strings = sorted(p['tablature']['string'] for p in note['pitches'] if p['tablature']['string'] <= 4)
|
||||
if strings:
|
||||
self.assertIn(strings, ([2, 3], [3, 4], [2, 3, 4]))
|
||||
timeline = generator.playback.compile_timeline(result)['events']
|
||||
by_id = {p['id']: p for v in measure['voices'] for n in v['notes'] for p in n['pitches']}
|
||||
for event in timeline:
|
||||
@@ -72,8 +68,8 @@ class GuitarPartTests(unittest.TestCase):
|
||||
chord = generator.harmony.parse_symbol(symbol)
|
||||
source['staves'][0]['measures'][0]['harmonies'] = [{**chord, 'id': 'h1', 'onset': generator.model.rational(0)}]
|
||||
result = generator.practice.generate.practice_document(source, 'acoustic', rhythms=tests.rhythm_fixtures.library())
|
||||
bass = result['staves'][0]['measures'][0]['voices'][1]
|
||||
self.assertEqual({generator.model.pitch_number(p) % 12 for n in bass['notes'] for p in n['pitches']}, {expected})
|
||||
notes = tests.test_musicxml.notes(result)
|
||||
self.assertEqual({generator.model.pitch_number(p) % 12 for n in notes for p in n['pitches'] if p['tablature']['string'] >= 5}, {expected})
|
||||
def test_acoustic_bass_and_upper_chord_can_attack_together(self):
|
||||
source = tests.test_musicxml.parse(tests.test_musicxml.xml_score(tests.test_parts.xml_harmony() + tests.test_musicxml.xml_note()))
|
||||
prepared = generator.parts.prepare_document(source, practice=True)
|
||||
@@ -81,11 +77,11 @@ class GuitarPartTests(unittest.TestCase):
|
||||
plan = generator.accompaniment.Plan((bar,), (bar,), ())
|
||||
result = generator.practice.generate._practice_document(prepared, 'acoustic', plan)
|
||||
generator.model.validate_document(result)
|
||||
upper, bass = result['staves'][0]['measures'][0]['voices']
|
||||
self.assertEqual([generator.model.fraction(n['onset']) for n in upper['notes'] if n['pitches']], [0, 2])
|
||||
self.assertEqual([generator.model.fraction(n['onset']) for n in bass['notes'] if n['pitches']], [0, 2])
|
||||
self.assertEqual(len(result['staves'][0]['measures'][0]['voices']), 1)
|
||||
notes = tests.test_musicxml.notes(result)
|
||||
self.assertEqual([generator.model.fraction(n['onset']) for n in notes if n['pitches']], [0, 2])
|
||||
for onset in (0, 2):
|
||||
pitches = [p for voice in (upper, bass) for n in voice['notes'] if generator.model.fraction(n['onset']) == onset for p in n['pitches']]
|
||||
pitches = [p for n in notes if generator.model.fraction(n['onset']) == onset for p in n['pitches']]
|
||||
positions = [generator.guitar.TabPosition(p['tablature']['string'], p['tablature']['fret'], int(generator.model.pitch_number(p) - 12)) for p in pitches]
|
||||
self.assertIn(tuple(sorted((p.string_number for p in positions), reverse=True)), generator.guitar.ACOUSTIC_STRINGS)
|
||||
self.assertTrue(generator.guitar.within_fret_span(positions))
|
||||
|
||||
Reference in New Issue
Block a user