Exemplo n.º 1
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()
Exemplo n.º 2
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')
 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)
  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)
Exemplo n.º 5
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')
Exemplo n.º 6
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)
  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])