# Path: moonlight/engine.py
# CONFIG = tf.ConfigProto(device_count={'GPU': 0})
# class OMREngine(object):
#   def __init__(self, glyph_classifier_fn=None):
#   def run(self, input_pngs, output_notesequence=False):
#   def process_image(self, image_arr, process_structure=True):
#   def _get_page(self, feed_dict=None, process_structure=True):
# def _nested_ndarrays_to_tensors(data):
# 
# Path: moonlight/score/measures.py
# MEASURE_MAX_X = 2**31 - 1
# class Measures(object):
#   def __init__(self, staff_system):
#   def size(self):
#   def get_measure(self, glyph):
# def _get_bar_intervals(staff_system):
# 
# Path: moonlight/score/reader.py
# TREBLE_CLEF_EXPECTED_Y = -2
# BASS_CLEF_EXPECTED_Y = 2
# REST_DURATIONS_ = {
#     musicscore_pb2.Glyph.REST_QUARTER: 4 / 4,
#     musicscore_pb2.Glyph.REST_EIGHTH: 4 / 8,
#     musicscore_pb2.Glyph.REST_SIXTEENTH: 4 / 16,
# }
#   GLYPH_HANDLERS_ = {
#       musicscore_pb2.Glyph.NONE: _no_op_handler,
#       musicscore_pb2.Glyph.CLEF_TREBLE: _read_clef,
#       musicscore_pb2.Glyph.CLEF_BASS: _read_clef,
#       musicscore_pb2.Glyph.NOTEHEAD_FILLED: _read_note,
#       musicscore_pb2.Glyph.NOTEHEAD_EMPTY: _read_note,
#       musicscore_pb2.Glyph.NOTEHEAD_WHOLE: _read_note,
#       musicscore_pb2.Glyph.REST_QUARTER: _read_rest,
#       musicscore_pb2.Glyph.REST_EIGHTH: _read_rest,
#       musicscore_pb2.Glyph.REST_SIXTEENTH: _read_rest,
#       musicscore_pb2.Glyph.FLAT: _read_accidental,
#       musicscore_pb2.Glyph.NATURAL: _read_accidental,
#       musicscore_pb2.Glyph.SHARP: _read_accidental,
#       musicscore_pb2.Glyph.DOUBLE_SHARP: _read_accidental,
#   }
# class ScoreReader(object):
#   def __init__(self):
#   def __call__(self, score):
#   def read_page(self, page):
#   def read_system(self, system):
#   def _read_glyph(self, glyph, staff_state):
#   def _read_clef(self, staff_state, glyph):
#   def _read_note(self, staff_state, glyph):
#   def _read_rest(self, staff_state, glyph):
#   def _read_accidental(self, staff_state, glyph):
#   def _no_op_handler(self, glyph):


import os.path
import re
from absl.app import flags
from absl.testing import absltest
from moonlight import engine
from moonlight.protobuf import musicscore_pb2
from moonlight.score import measures
from moonlight.score import reader

  def testIMSLP00823_008_mergeStandardAndBeginRepeatBars(self):
    page = engine.OMREngine().run(_get_imslp_path('IMSLP00823-008.png')).page[0]
    self.assertEqual(len(page.system), 6)

    self.assertEqual(len(page.system[0].staff), 2)
    # TODO(ringw): Fix barline detection here.
    # self.assertEqual(len(page.system[0].bar), 6)

    self.assertEqual(len(page.system[1].staff), 2)
    # self.assertEqual(len(page.system[1].bar), 6)

    self.assertEqual(len(page.system[2].staff), 2)
    self.assertEqual(len(page.system[2].bar), 7)

    self.assertEqual(len(page.system[3].staff), 2)
    self.assertEqual(len(page.system[3].bar), 6)

    self.assertEqual(len(page.system[4].staff), 2)
    self.assertEqual(len(page.system[4].bar), 6)
    # TODO(ringw): Detect BEGIN_REPEAT_BAR here.
    self.assertEqual(page.system[4].bar[0].type,
                     musicscore_pb2.StaffSystem.Bar.END_BAR)
    self.assertEqual(page.system[4].bar[1].type,
                     musicscore_pb2.StaffSystem.Bar.STANDARD_BAR)

    self.assertEqual(len(page.system[5].staff), 2)
    self.assertEqual(len(page.system[5].bar), 7)

  def testIMSLP39661_keySignature_CSharpMinor(self):

# Path: moonlight/engine.py
# CONFIG = tf.ConfigProto(device_count={'GPU': 0})
# class OMREngine(object):
#   def __init__(self, glyph_classifier_fn=None):
#   def run(self, input_pngs, output_notesequence=False):
#   def process_image(self, image_arr, process_structure=True):
#   def _get_page(self, feed_dict=None, process_structure=True):
# def _nested_ndarrays_to_tensors(data):
# 
# Path: moonlight/score/measures.py
# MEASURE_MAX_X = 2**31 - 1
# class Measures(object):
#   def __init__(self, staff_system):
#   def size(self):
#   def get_measure(self, glyph):
# def _get_bar_intervals(staff_system):
# 
# Path: moonlight/score/reader.py
# TREBLE_CLEF_EXPECTED_Y = -2
# BASS_CLEF_EXPECTED_Y = 2
# REST_DURATIONS_ = {
#     musicscore_pb2.Glyph.REST_QUARTER: 4 / 4,
#     musicscore_pb2.Glyph.REST_EIGHTH: 4 / 8,
#     musicscore_pb2.Glyph.REST_SIXTEENTH: 4 / 16,
# }
#   GLYPH_HANDLERS_ = {
#       musicscore_pb2.Glyph.NONE: _no_op_handler,
#       musicscore_pb2.Glyph.CLEF_TREBLE: _read_clef,
#       musicscore_pb2.Glyph.CLEF_BASS: _read_clef,
#       musicscore_pb2.Glyph.NOTEHEAD_FILLED: _read_note,
#       musicscore_pb2.Glyph.NOTEHEAD_EMPTY: _read_note,
#       musicscore_pb2.Glyph.NOTEHEAD_WHOLE: _read_note,
#       musicscore_pb2.Glyph.REST_QUARTER: _read_rest,
#       musicscore_pb2.Glyph.REST_EIGHTH: _read_rest,
#       musicscore_pb2.Glyph.REST_SIXTEENTH: _read_rest,
#       musicscore_pb2.Glyph.FLAT: _read_accidental,
#       musicscore_pb2.Glyph.NATURAL: _read_accidental,
#       musicscore_pb2.Glyph.SHARP: _read_accidental,
#       musicscore_pb2.Glyph.DOUBLE_SHARP: _read_accidental,
#   }
# class ScoreReader(object):
#   def __init__(self):
#   def __call__(self, score):
#   def read_page(self, page):
#   def read_system(self, system):
#   def _read_glyph(self, glyph, staff_state):
#   def _read_clef(self, staff_state, glyph):
#   def _read_note(self, staff_state, glyph):
#   def _read_rest(self, staff_state, glyph):
#   def _read_accidental(self, staff_state, glyph):
#   def _no_op_handler(self, glyph):


# Path: moonlight/omr_regression_test.py
import os.path
import re
from absl.app import flags
from absl.testing import absltest
from moonlight import engine
from moonlight.protobuf import musicscore_pb2
from moonlight.score import measures
from moonlight.score import reader


  def testIMSLP00823_008_mergeStandardAndBeginRepeatBars(self):
    page = engine.OMREngine().run(_get_imslp_path('IMSLP00823-008.png')).page[0]
    self.assertEqual(len(page.system), 6)

    self.assertEqual(len(page.system[0].staff), 2)
    # TODO(ringw): Fix barline detection here.
    # self.assertEqual(len(page.system[0].bar), 6)

    self.assertEqual(len(page.system[1].staff), 2)
    # self.assertEqual(len(page.system[1].bar), 6)

    self.assertEqual(len(page.system[2].staff), 2)
    self.assertEqual(len(page.system[2].bar), 7)

    self.assertEqual(len(page.system[3].staff), 2)
    self.assertEqual(len(page.system[3].bar), 6)

    self.assertEqual(len(page.system[4].staff), 2)
    self.assertEqual(len(page.system[4].bar), 6)
    # TODO(ringw): Detect BEGIN_REPEAT_BAR here.
    self.assertEqual(page.system[4].bar[0].type,
                     musicscore_pb2.StaffSystem.Bar.END_BAR)
    self.assertEqual(page.system[4].bar[1].type,
                     musicscore_pb2.StaffSystem.Bar.STANDARD_BAR)

    self.assertEqual(len(page.system[5].staff), 2)
    self.assertEqual(len(page.system[5].bar), 7)

  def testIMSLP39661_keySignature_CSharpMinor(self):

    page = engine.OMREngine().run(_get_imslp_path('IMSLP39661-000.png')).page[0]