Example #1
0
 def test_unpitched_notes(self):
   with self.assertRaises(musicxml_parser.UnpitchedNoteError):
     musicxml_parser.MusicXMLDocument(os.path.join(
         testing_lib.get_testdata_dir(), 'unpitched.xml'))
   with self.assertRaises(musicxml_reader.MusicXMLConversionError):
     musicxml_reader.musicxml_file_to_sequence_proto(os.path.join(
         testing_lib.get_testdata_dir(), 'unpitched.xml'))
Example #2
0
 def setUp(self):
     super().setUp()
     self.wav_filename = os.path.join(testing_lib.get_testdata_dir(),
                                      'example.wav')
     self.wav_filename_mono = os.path.join(testing_lib.get_testdata_dir(),
                                           'example_mono.wav')
     self.wav_data = open(self.wav_filename, 'rb').read()
     self.wav_data_mono = open(self.wav_filename_mono, 'rb').read()
Example #3
0
 def setUp(self):
     super().setUp()
     self.midi_simple_filename = os.path.join(
         testing_lib.get_testdata_dir(), 'example.mid')
     self.midi_complex_filename = os.path.join(
         testing_lib.get_testdata_dir(), 'example_complex.mid')
     self.midi_is_drum_filename = os.path.join(
         testing_lib.get_testdata_dir(), 'example_is_drum.mid')
     self.midi_event_order_filename = os.path.join(
         testing_lib.get_testdata_dir(), 'example_event_order.mid')
Example #4
0
  def testcompressedmxlunicodefilename(self):
    """Test an MXL file containing a unicode filename within its zip archive."""

    unicode_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'unicode_filename.mxl')
    sequence = musicxml_reader.musicxml_file_to_sequence_proto(unicode_filename)
    self.assertLen(sequence.notes, 8)
Example #5
0
    def compare_to_abc2midi_and_metadata(self, midi_path, expected_metadata,
                                         expected_expanded_metadata, test):
        """Compare parsing results to the abc2midi "reference" implementation."""
        # Compare section annotations and groups before expanding.
        self.compare_proto_list(expected_metadata.section_annotations,
                                test.section_annotations)
        self.compare_proto_list(expected_metadata.section_groups,
                                test.section_groups)

        expanded_test = sequences_lib.expand_section_groups(test)

        abc2midi = midi_io.midi_file_to_sequence_proto(
            os.path.join(testing_lib.get_testdata_dir(), midi_path))

        # abc2midi adds a 1-tick delay to the start of every note, but we don't.
        tick_length = ((1 / (abc2midi.tempos[0].qpm / 60)) /
                       abc2midi.ticks_per_quarter)

        for note in abc2midi.notes:
            # For now, don't compare velocities.
            note.velocity = 90
            note.start_time -= tick_length

        self.compare_proto_list(abc2midi.notes, expanded_test.notes)

        self.assertEqual(abc2midi.total_time, expanded_test.total_time)

        self.compare_proto_list(abc2midi.time_signatures,
                                expanded_test.time_signatures)

        # We've checked the notes and time signatures, now compare the rest of the
        # proto to the expected proto.
        expanded_test_copy = copy.deepcopy(expanded_test)
        del expanded_test_copy.notes[:]
        expanded_test_copy.ClearField('total_time')
        del expanded_test_copy.time_signatures[:]

        self.assertProtoEquals(expected_expanded_metadata, expanded_test_copy)
Example #6
0
  def setUp(self):
    self.maxDiff = None   # pylint:disable=invalid-name

    self.steps_per_quarter = 4

    self.flute_scale_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'flute_scale.xml')

    self.clarinet_scale_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'clarinet_scale.xml')

    self.band_score_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'el_capitan.xml')

    self.compressed_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'flute_scale.mxl')

    self.multiple_rootfile_compressed_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'flute_scale_with_png.mxl')

    self.rhythm_durations_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'rhythm_durations.xml')

    self.st_anne_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'st_anne.xml')

    self.atonal_transposition_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'atonal_transposition_change.xml')

    self.chord_symbols_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'chord_symbols.xml')

    self.time_signature_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'st_anne.xml')

    self.unmetered_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'unmetered_example.xml')

    self.alternating_meter_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'alternating_meter.xml')

    self.mid_measure_meter_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'mid_measure_time_signature.xml')

    self.whole_measure_rest_forward_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'whole_measure_rest_forward.xml')

    self.meter_test_filename = os.path.join(
        testing_lib.get_testdata_dir(), 'meter_test.xml')

    super().setUp()
Example #7
0
 def setUp(self):
     super().setUp()
     # This example archive contains a single file consisting of just a major
     # chord.
     self.musicnet_example_filename = os.path.join(
         testing_lib.get_testdata_dir(), 'musicnet_example.npz')
Example #8
0
 def testMidiFileToMelody(self):
     filename = os.path.join(testing_lib.get_testdata_dir(), 'melody.mid')
     melody = melodies_lib.midi_file_to_melody(filename)
     expected = melodies_lib.Melody(
         [60, 62, 64, 66, 68, 70, 72, 70, 68, 66, 64, 62])
     self.assertEqual(expected, melody)
Example #9
0
 def testMultiVoice(self):
     tunes, exceptions = abc_parser.parse_abc_tunebook_file(
         os.path.join(testing_lib.get_testdata_dir(), 'zocharti_loch.abc'))
     self.assertEmpty(tunes)
     self.assertLen(exceptions, 1)
     self.assertIsInstance(exceptions[0], abc_parser.MultiVoiceError)
Example #10
0
    def testParseEnglishAbc(self):
        tunes, exceptions = abc_parser.parse_abc_tunebook_file(
            os.path.join(testing_lib.get_testdata_dir(), 'english.abc'))
        self.assertLen(tunes, 1)
        self.assertLen(exceptions, 2)
        self.assertIsInstance(exceptions[0], abc_parser.VariantEndingError)
        self.assertIsInstance(exceptions[1], abc_parser.PartError)

        expected_metadata1 = testing_lib.parse_test_proto(
            music_pb2.NoteSequence, """
        ticks_per_quarter: 220
        source_info: {
          source_type: SCORE_BASED
          encoding_type: ABC
          parser: MAGENTA_ABC
        }
        reference_number: 1
        sequence_metadata {
          title: "Dusty Miller, The; Binny's Jig"
          artist: "Trad."
          composers: "Trad."
        }
        key_signatures {
          key: G
        }
        section_annotations {
          time: 0.0
          section_id: 0
        }
        section_annotations {
          time: 6.0
          section_id: 1
        }
        section_annotations {
          time: 12.0
          section_id: 2
        }
        section_groups {
          sections {
            section_id: 0
          }
          num_times: 2
        }
        section_groups {
          sections {
            section_id: 1
          }
          num_times: 2
        }
        section_groups {
          sections {
            section_id: 2
          }
          num_times: 2
        }
        """)
        expected_expanded_metadata1 = testing_lib.parse_test_proto(
            music_pb2.NoteSequence, """
        ticks_per_quarter: 220
        source_info: {
          source_type: SCORE_BASED
          encoding_type: ABC
          parser: MAGENTA_ABC
        }
        reference_number: 1
        sequence_metadata {
          title: "Dusty Miller, The; Binny's Jig"
          artist: "Trad."
          composers: "Trad."
        }
        key_signatures {
          key: G
        }
        section_annotations {
          time: 0.0
          section_id: 0
        }
        section_annotations {
          time: 6.0
          section_id: 0
        }
        section_annotations {
          time: 12.0
          section_id: 1
        }
        section_annotations {
          time: 18.0
          section_id: 1
        }
        section_annotations {
          time: 24.0
          section_id: 2
        }
        section_annotations {
          time: 30.0
          section_id: 2
        }
        """)
        self.compare_to_abc2midi_and_metadata('english1.mid',
                                              expected_metadata1,
                                              expected_expanded_metadata1,
                                              tunes[1])