# Path: note_seq/musicnet_io.py
# MUSICNET_SAMPLE_RATE = 44100
# MUSICNET_NOTE_VELOCITY = 100
# def note_interval_tree_to_sequence_proto(note_interval_tree, sample_rate):
# def musicnet_iterator(musicnet_file):
# 
# Path: note_seq/testing_lib.py
# BEAT = music_pb2.NoteSequence.TextAnnotation.BEAT
# CHORD_SYMBOL = music_pb2.NoteSequence.TextAnnotation.CHORD_SYMBOL
# def add_track_to_sequence(note_sequence,
#                           instrument,
#                           notes,
#                           is_drum=False,
#                           program=0):
# def add_chords_to_sequence(note_sequence, chords):
# def add_key_signatures_to_sequence(note_sequence, keys):
# def add_beats_to_sequence(note_sequence, beats, beats_per_bar=None):
# def add_control_changes_to_sequence(note_sequence, instrument, control_changes):
# def add_pitch_bends_to_sequence(
#     note_sequence, instrument, program, pitch_bends):
# def add_quantized_steps_to_sequence(sequence, quantized_steps):
# def add_quantized_chord_steps_to_sequence(sequence, quantized_steps):
# def add_quantized_control_steps_to_sequence(sequence, quantized_steps):
#   def __init__(self, num_classes, num_steps=None):
#   def num_classes(self):
#   def default_event(self):
#   def encode_event(self, event):
#   def decode_event(self, index):
#   def event_to_num_steps(self, event):
# def parse_test_proto(proto_type, proto_string):
# def get_testdata_dir():
#   def setUp(self):
#   def _AssertProtoEquals(self, a, b, msg=None):  # pylint:disable=invalid-name
#   def assertProtoEquals(self, expected_message_maybe_ascii, message, msg=None):
# class TrivialOneHotEncoding(encoder_decoder.OneHotEncoding):
# class ProtoTestCase(absltest.TestCase):


import os
import numpy as np
from absl.testing import absltest
from note_seq import musicnet_io
from note_seq import testing_lib

"""Tests for MusicNet data parsing."""




class MusicNetIoTest(absltest.TestCase):

  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')

  def testNoteIntervalTreeToSequenceProto(self):
    # allow_pickle is required because the npz files contain intervaltrees.
    example = np.load(
        self.musicnet_example_filename, encoding='latin1', allow_pickle=True)
    note_interval_tree = example['test'][1]
    sequence = musicnet_io.note_interval_tree_to_sequence_proto(
        note_interval_tree, 44100)
    self.assertLen(sequence.notes, 3)
    self.assertEqual(72, min(note.pitch for note in sequence.notes))
    self.assertEqual(79, max(note.pitch for note in sequence.notes))
    self.assertTrue(all(note.instrument == 0 for note in sequence.notes))
    self.assertTrue(all(note.program == 41 for note in sequence.notes))
    self.assertEqual(0.5, sequence.total_time)

  def testMusicNetIterator(self):

# Path: note_seq/musicnet_io.py
# MUSICNET_SAMPLE_RATE = 44100
# MUSICNET_NOTE_VELOCITY = 100
# def note_interval_tree_to_sequence_proto(note_interval_tree, sample_rate):
# def musicnet_iterator(musicnet_file):
# 
# Path: note_seq/testing_lib.py
# BEAT = music_pb2.NoteSequence.TextAnnotation.BEAT
# CHORD_SYMBOL = music_pb2.NoteSequence.TextAnnotation.CHORD_SYMBOL
# def add_track_to_sequence(note_sequence,
#                           instrument,
#                           notes,
#                           is_drum=False,
#                           program=0):
# def add_chords_to_sequence(note_sequence, chords):
# def add_key_signatures_to_sequence(note_sequence, keys):
# def add_beats_to_sequence(note_sequence, beats, beats_per_bar=None):
# def add_control_changes_to_sequence(note_sequence, instrument, control_changes):
# def add_pitch_bends_to_sequence(
#     note_sequence, instrument, program, pitch_bends):
# def add_quantized_steps_to_sequence(sequence, quantized_steps):
# def add_quantized_chord_steps_to_sequence(sequence, quantized_steps):
# def add_quantized_control_steps_to_sequence(sequence, quantized_steps):
#   def __init__(self, num_classes, num_steps=None):
#   def num_classes(self):
#   def default_event(self):
#   def encode_event(self, event):
#   def decode_event(self, index):
#   def event_to_num_steps(self, event):
# def parse_test_proto(proto_type, proto_string):
# def get_testdata_dir():
#   def setUp(self):
#   def _AssertProtoEquals(self, a, b, msg=None):  # pylint:disable=invalid-name
#   def assertProtoEquals(self, expected_message_maybe_ascii, message, msg=None):
# class TrivialOneHotEncoding(encoder_decoder.OneHotEncoding):
# class ProtoTestCase(absltest.TestCase):


# Path: note_seq/musicnet_io_test.py
import os
import numpy as np
from absl.testing import absltest
from note_seq import musicnet_io
from note_seq import testing_lib


"""Tests for MusicNet data parsing."""




class MusicNetIoTest(absltest.TestCase):

  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')

  def testNoteIntervalTreeToSequenceProto(self):
    # allow_pickle is required because the npz files contain intervaltrees.
    example = np.load(
        self.musicnet_example_filename, encoding='latin1', allow_pickle=True)
    note_interval_tree = example['test'][1]
    sequence = musicnet_io.note_interval_tree_to_sequence_proto(
        note_interval_tree, 44100)
    self.assertLen(sequence.notes, 3)
    self.assertEqual(72, min(note.pitch for note in sequence.notes))
    self.assertEqual(79, max(note.pitch for note in sequence.notes))
    self.assertTrue(all(note.instrument == 0 for note in sequence.notes))
    self.assertTrue(all(note.program == 41 for note in sequence.notes))
    self.assertEqual(0.5, sequence.total_time)

  def testMusicNetIterator(self):

    iterator = musicnet_io.musicnet_iterator(self.musicnet_example_filename)