Training Model
This commit is contained in:
+11
-15
@@ -19,8 +19,6 @@ import generator.parts
|
||||
import generator.pitch
|
||||
import generator.playback
|
||||
import tests.arrangement_fixtures
|
||||
import tests.rhythm_fixtures
|
||||
import tests.scale_fixtures
|
||||
import tests.solo_fixtures
|
||||
import tests.test_musicxml
|
||||
|
||||
@@ -135,8 +133,8 @@ class GuitarTests(unittest.TestCase):
|
||||
def test_melody_placement_preserves_notes_timing_and_sound(self):
|
||||
source = tests.test_musicxml.parse(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note('E', 2, 'half', octave=4) + tests.test_musicxml.xml_note('F', 2, 'half', octave=4)))
|
||||
before = copy.deepcopy(source)
|
||||
electric = tests.arrangement_fixtures.section_document(source, 'electric', rhythms=tests.rhythm_fixtures.library())
|
||||
vocal = tests.arrangement_fixtures.section_document(source, 'vocal', rhythms=tests.rhythm_fixtures.library())
|
||||
electric = tests.arrangement_fixtures.section_document(source, 'electric')
|
||||
vocal = tests.arrangement_fixtures.section_document(source, 'vocal')
|
||||
generator.model.validate_document(electric)
|
||||
self.assertEqual(source, before)
|
||||
self.assertEqual([(e['onset'], e['duration'], generator.model.fraction(e['pitch']) - 12) for e in generator.playback.compile_timeline(electric)['events']], [(e['onset'], e['duration'], generator.model.fraction(e['pitch'])) for e in generator.playback.compile_timeline(vocal)['events']])
|
||||
@@ -148,12 +146,12 @@ class GuitarTests(unittest.TestCase):
|
||||
for attributes, expected in (('', 48), ('<transpose><chromatic>-12</chromatic><diatonic>-7</diatonic></transpose>', 48), ('<transpose><chromatic>0</chromatic></transpose>', 60), ('<clef><sign>G</sign><line>2</line><clef-octave-change>-1</clef-octave-change></clef>', 60), ('<clef><sign>F</sign><line>4</line></clef>', 48)):
|
||||
source = tests.test_musicxml.parse(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note(), attributes))
|
||||
for part in ('electric', 'vocal'):
|
||||
document = tests.arrangement_fixtures.section_document(source, part, rhythms=tests.rhythm_fixtures.library())
|
||||
document = tests.arrangement_fixtures.section_document(source, part)
|
||||
self.assertEqual(generator.model.fraction(generator.playback.compile_timeline(document)['events'][0]['pitch']), expected + (12 if part == 'electric' else 0))
|
||||
def test_written_middle_c_and_c_sharp_six_have_matching_tab_and_audio(self):
|
||||
for octave, alter, expected, tab in ((4, 0, 48, {'string': 5, 'fret': 3}), (6, 1, 73, {'string': 1, 'fret': 9})):
|
||||
source = tests.test_musicxml.parse(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note(octave=octave - 1, alter=alter)))
|
||||
document = tests.arrangement_fixtures.section_document(source, 'electric', rhythms=tests.rhythm_fixtures.library())
|
||||
document = tests.arrangement_fixtures.section_document(source, 'electric')
|
||||
tone = tests.test_musicxml.notes(document)[0]['pitches'][0]
|
||||
self.assertEqual(generator.model.pitch_number(tone), 12 * (octave + 1) + alter)
|
||||
self.assertEqual(tone['tablature'], tab)
|
||||
@@ -166,7 +164,7 @@ class GuitarTests(unittest.TestCase):
|
||||
concert = generator.pitch.concert_document(source, octave_transposing=True)
|
||||
self.assertEqual(generator.pitch.concert_document(concert, octave_transposing=True), concert)
|
||||
self.assertEqual(source, before)
|
||||
document = tests.arrangement_fixtures.section_document(source, 'electric', rhythms=tests.rhythm_fixtures.library())
|
||||
document = tests.arrangement_fixtures.section_document(source, 'electric')
|
||||
self.assertEqual([generator.model.fraction(e['pitch']) for e in generator.playback.compile_timeline(document)['events']], [60, 72])
|
||||
def test_all_parts_share_written_octave_convention(self):
|
||||
chord = '<harmony><root><root-step>C</root-step></root><kind>major</kind></harmony>'
|
||||
@@ -174,7 +172,7 @@ class GuitarTests(unittest.TestCase):
|
||||
for generate in (tests.arrangement_fixtures.section_document, generator.arrange.generate.arrange_document):
|
||||
for part in generator.parts.PART_TYPES:
|
||||
with self.subTest(generator=generate.__name__, part=part):
|
||||
document = generate(source, part, rhythms=tests.rhythm_fixtures.library())
|
||||
document = generate(source, part)
|
||||
generator.model.validate_document(document)
|
||||
written = {p['id']: generator.model.pitch_number(p) for m in document['staves'][0]['measures'] for v in m['voices'] for n in v['notes'] for p in n['pitches']}
|
||||
events = generator.playback.compile_timeline(document)['events']
|
||||
@@ -244,7 +242,7 @@ class GuitarTests(unittest.TestCase):
|
||||
(tests.test_musicxml.xml_note(), '<staff-details><capo>1</capo></staff-details>', 'capo')]
|
||||
for content, attributes, error in cases:
|
||||
with self.subTest(error=error), self.assertRaisesRegex(ValueError, error):
|
||||
tests.arrangement_fixtures.section_document(tests.test_musicxml.parse(tests.test_musicxml.xml_score(content, attributes)), 'electric', rhythms=tests.rhythm_fixtures.library())
|
||||
tests.arrangement_fixtures.section_document(tests.test_musicxml.parse(tests.test_musicxml.xml_score(content, attributes)), 'electric')
|
||||
for content, attributes in [(tests.test_musicxml.xml_note(), '<clef><sign>TAB</sign></clef>'), (tests.test_musicxml.xml_note(extra='<notations><technical><fingering>1</fingering></technical></notations>'), '')]:
|
||||
with self.assertRaisesRegex(ValueError, 'authored TAB'):
|
||||
tests.test_musicxml.parse(tests.test_musicxml.xml_score(content, attributes))
|
||||
@@ -253,13 +251,11 @@ class GuitarTests(unittest.TestCase):
|
||||
source, output = pathlib.Path(temporary) / 'source', pathlib.Path(temporary) / 'output'
|
||||
source.mkdir()
|
||||
(source / '0000.xml').write_text(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note('E', alter=-1), '<key><fifths>-3</fifths></key>'))
|
||||
self.assertEqual(generator.arrange.generate.generate_performance_scores(source, output, rhythms=tests.rhythm_fixtures.library(), scales=tests.scale_fixtures.library(), sequences=tests.solo_fixtures.library()), 3)
|
||||
self.assertEqual(generator.arrange.generate.generate_performance_scores(source, output), 3)
|
||||
first = {p.name: p.read_bytes() for p in output.rglob('*.json')}
|
||||
generator.arrange.generate.generate_performance_scores(source, output, rhythms=tests.rhythm_fixtures.library(), scales=tests.scale_fixtures.library(), sequences=tests.solo_fixtures.library())
|
||||
generator.arrange.generate.generate_performance_scores(source, output)
|
||||
self.assertEqual(first, {p.name: p.read_bytes() for p in output.rglob('*.json')})
|
||||
def test_unplayable_generation_preserves_previous_assets(self):
|
||||
self.enterContext(unittest.mock.patch('generator.solo.sequences.load_library', return_value=tests.solo_fixtures.library()))
|
||||
self.enterContext(unittest.mock.patch('generator.scales.library.load_library', return_value=tests.scale_fixtures.library()))
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = pathlib.Path(temporary)
|
||||
(root / 'data/songs').mkdir(parents=True)
|
||||
@@ -268,11 +264,11 @@ class GuitarTests(unittest.TestCase):
|
||||
output.mkdir()
|
||||
(output / 'last-good').write_text('preserved')
|
||||
args = argparse.Namespace(data_dir=root / 'data', output_dir=output, static_assets_dir=pathlib.Path('package/assets'), check=False)
|
||||
with unittest.mock.patch('generator.rhythm.load_library', return_value=tests.rhythm_fixtures.library()), self.assertRaisesRegex(ValueError, '0001.xml/electric_melody:.*1-20'):
|
||||
with self.assertRaisesRegex(ValueError, '0001.xml/electric_melody:.*1-20'):
|
||||
generator.__main__.generate_assets(args)
|
||||
self.assertEqual([p.name for p in output.iterdir()], ['last-good'])
|
||||
self.assertEqual((output / 'last-good').read_text(), 'preserved')
|
||||
with unittest.mock.patch('generator.comping.voicings', side_effect=ValueError('no legal sparse voicing')), unittest.mock.patch('generator.rhythm.load_library', return_value=tests.rhythm_fixtures.library()):
|
||||
with unittest.mock.patch('generator.comping.voicings', side_effect=ValueError('no legal sparse voicing')):
|
||||
(root / 'data/songs/0001.xml').write_text(tests.test_musicxml.xml_score('<harmony><root><root-step>C</root-step></root><kind>dominant</kind></harmony>'+tests.test_musicxml.xml_note()))
|
||||
with self.assertRaisesRegex(ValueError, 'no legal sparse voicing'):
|
||||
generator.__main__.generate_assets(args)
|
||||
|
||||
Reference in New Issue
Block a user