Generation

This commit is contained in:
khodowany
2026-09-30 01:38:16 -05:00
parent b1a7b44d7a
commit deaa0468a7
20 changed files with 417 additions and 198 deletions
+9 -6
View File
@@ -27,17 +27,19 @@ class GuitarPartTests(unittest.TestCase):
for profile in ('acoustic', 'electric'):
with self.subTest(symbol=symbol, profile=profile):
definition = generator.harmony.parse_symbol(symbol)
required, allowed, bass = generator.guitar.chord_requirements(definition, profile)
candidates = generator.guitar.chord_positions(required, allowed, bass, profile=profile)
requirements = generator.guitar.chord_requirements(definition, profile)
candidates = generator.guitar.chord_positions(requirements, profile=profile)
self.assertTrue(candidates)
for candidate in candidates:
strings = tuple(p.string_number for p in candidate)
self.assertIn(strings, generator.guitar.ACOUSTIC_STRINGS if profile == 'acoustic' else generator.guitar.ELECTRIC_STRINGS)
self.assertTrue(set(required) <= {p.midi % 12 for p in candidate} <= set(allowed))
self.assertTrue(requirements.covers({p.midi % 12 for p in candidate}))
self.assertTrue({p.midi % 12 for p in candidate} <= set(requirements.allowed))
self.assertTrue(generator.guitar.within_fret_span(candidate))
self.assertTrue(all(1 <= p.fret <= 20 for p in candidate))
chord = generator.harmony.parse_symbol('C7')
self.assertNotIn(0, generator.guitar.chord_requirements(chord, 'electric')[0])
candidates = generator.guitar.chord_positions(*generator.guitar.chord_requirements(chord, 'electric'), profile='electric')
self.assertNotIn(0, generator.guitar.chord_requirements(chord, 'electric').required)
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_combines_independent_rhythms_with_a_fixed_grip(self):
result = self.section(tests.test_parts.xml_harmony() + tests.test_musicxml.xml_note(), 'acoustic')
@@ -47,7 +49,8 @@ class GuitarPartTests(unittest.TestCase):
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], [7, 7])
self.assertEqual(len(bass), 2)
self.assertIn([generator.model.pitch_number(p) % 12 for _, p in bass], ([0, 0], [7, 7]))
self.assertEqual(bass[0][1]['tablature'], bass[1][1]['tablature'])
upper_shapes = {tuple((p['tablature']['string'], p['tablature']['fret']) for p in n['pitches'] if p['tablature']['string'] <= 4) for n in notes}
self.assertEqual(len(upper_shapes - {()}), 1)