Example #1
0
    def run(self, input_pngs, output_notesequence=False):
        """Converts input PNGs into a `Score` message.

    Args:
      input_pngs: A list of PNG filenames to process.
      output_notesequence: Whether to return a NoteSequence, as opposed to a
          Score containing Pages with Glyphs.

    Returns:
      A NoteSequence message, or a Score message holding Pages for each input
          image (with their detected Glyphs).
    """
        if isinstance(input_pngs, six.string_types):
            input_pngs = [input_pngs]
        score = musicscore_pb2.Score()
        score.page.extend(
            self._get_page(feed_dict={self.png_path: png})
            for png in input_pngs)
        score = score_processors.process(score)
        return (conversions.score_to_notesequence(score)
                if output_notesequence else score)
Example #2
0
    def testSmallScore(self):
        score = musicscore_pb2.Score(page=[
            musicscore_pb2.Page(system=[
                musicscore_pb2.StaffSystem(staff=[
                    musicscore_pb2.Staff(glyph=[
                        musicscore_pb2.Glyph(
                            type=musicscore_pb2.Glyph.NOTEHEAD_FILLED,
                            x=10,
                            y_position=0,
                            note=music_pb2.NoteSequence.Note(
                                start_time=0, end_time=1, pitch=71)),
                        musicscore_pb2.Glyph(
                            type=musicscore_pb2.Glyph.NOTEHEAD_EMPTY,
                            x=110,
                            y_position=-6,
                            note=music_pb2.NoteSequence.Note(
                                start_time=1, end_time=2.5, pitch=61)),
                    ]),
                    musicscore_pb2.Staff(glyph=[
                        musicscore_pb2.Glyph(
                            type=musicscore_pb2.Glyph.NOTEHEAD_WHOLE,
                            x=10,
                            y_position=2,
                            note=music_pb2.NoteSequence.Note(
                                start_time=0, end_time=4, pitch=50)),
                        musicscore_pb2.Glyph(
                            type=musicscore_pb2.Glyph.NOTEHEAD_FILLED,
                            beam=[
                                musicscore_pb2.LineSegment(),
                                musicscore_pb2.LineSegment()
                            ],
                            x=110,
                            y_position=-4,
                            note=music_pb2.NoteSequence.Note(
                                start_time=4, end_time=4.25, pitch=60)),
                    ]),
                ]),
            ]),
        ])
        self.assertEqual(
            b"""<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE score-partwise PUBLIC
    "-//Recordare//DTD MusicXML 3.0 Partwise//EN"
    "http://www.musicxml.org/dtds/partwise.dtd">

<score-partwise version="3.0">
  <part-list>
    <score-part id="P1">
      <part-name>Part 1</part-name>
    </score-part>
    <score-part id="P2">
      <part-name>Part 2</part-name>
    </score-part>
  </part-list>
  <part id="P1">
    <measure number="1">
      <attributes>
        <divisions>1024</divisions>
        <time symbol="common">
          <beats>4</beats>
          <beat-type>4</beat-type>
        </time>
      </attributes>
      <note>
        <voice>1</voice>
        <type>quarter</type>
        <duration>1024</duration>
        <pitch>
          <step>B</step>
          <alter>0</alter>
          <octave>4</octave>
        </pitch>
      </note>
      <note>
        <voice>1</voice>
        <type>half</type>
        <duration>1536</duration>
        <pitch>
          <step>C</step>
          <alter>1</alter>
          <octave>4</octave>
        </pitch>
      </note>
    </measure>
  </part>
  <part id="P2">
    <measure number="1">
      <attributes>
        <divisions>1024</divisions>
        <time symbol="common">
          <beats>4</beats>
          <beat-type>4</beat-type>
        </time>
      </attributes>
      <note>
        <voice>1</voice>
        <type>whole</type>
        <duration>4096</duration>
        <pitch>
          <step>D</step>
          <alter>0</alter>
          <octave>3</octave>
        </pitch>
      </note>
      <note>
        <voice>1</voice>
        <type>16th</type>
        <duration>256</duration>
        <pitch>
          <step>C</step>
          <alter>0</alter>
          <octave>4</octave>
        </pitch>
      </note>
    </measure>
  </part>
</score-partwise>
""", musicxml.score_to_musicxml(score))
Example #3
0
 def testStaffSystems(self):
     # 2 staff systems on separate pages, each with 2 staves, and no bars.
     system_1_staff_1 = musicscore_pb2.Staff(
         staffline_distance=10,
         center_line=[Point(x=0, y=50),
                      Point(x=100, y=50)],
         glyph=[
             Glyph(type=Glyph.CLEF_TREBLE,
                   x=1,
                   y_position=reader.TREBLE_CLEF_EXPECTED_Y),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=10, y_position=-6),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=50, y_position=-2),
         ])
     system_1_staff_2 = musicscore_pb2.Staff(
         staffline_distance=10,
         center_line=[Point(x=0, y=150),
                      Point(x=100, y=150)],
         glyph=[
             Glyph(type=Glyph.CLEF_BASS,
                   x=2,
                   y_position=reader.BASS_CLEF_EXPECTED_Y),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=10, y_position=0),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=40, y_position=2),
             # Played after the second note in the first staff, although it is to
             # the left of it.
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=45, y_position=4),
         ])
     system_2_staff_1 = musicscore_pb2.Staff(
         staffline_distance=10,
         center_line=[Point(x=0, y=250),
                      Point(x=100, y=250)],
         glyph=[
             Glyph(type=Glyph.CLEF_TREBLE,
                   x=1,
                   y_position=reader.TREBLE_CLEF_EXPECTED_Y),
             Glyph(type=Glyph.REST_QUARTER, x=20, y_position=0),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=50, y_position=-2),
         ])
     system_2_staff_2 = musicscore_pb2.Staff(
         staffline_distance=10,
         center_line=[Point(x=0, y=250),
                      Point(x=100, y=250)],
         glyph=[
             Glyph(type=Glyph.CLEF_BASS,
                   x=2,
                   y_position=reader.BASS_CLEF_EXPECTED_Y),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=10, y_position=0),
             Glyph(type=Glyph.NOTEHEAD_FILLED, x=40, y_position=2),
         ])
     notes = conversions.score_to_notesequence(reader.ScoreReader()(
         musicscore_pb2.Score(page=[
             musicscore_pb2.Page(system=[
                 musicscore_pb2.StaffSystem(
                     staff=[system_1_staff_1, system_1_staff_2]),
             ]),
             musicscore_pb2.Page(system=[
                 musicscore_pb2.StaffSystem(
                     staff=[system_2_staff_1, system_2_staff_2]),
             ]),
         ]), ))
     self.assertEqual(
         notes,
         music_pb2.NoteSequence(notes=[
             # System 1, staff 1.
             Note(pitch=librosa.note_to_midi('C4'),
                  start_time=0,
                  end_time=1),
             Note(pitch=librosa.note_to_midi('G4'),
                  start_time=1,
                  end_time=2),
             # System 1, staff 2.
             Note(pitch=librosa.note_to_midi('D3'),
                  start_time=0,
                  end_time=1),
             Note(pitch=librosa.note_to_midi('F3'),
                  start_time=1,
                  end_time=2),
             Note(pitch=librosa.note_to_midi('A3'),
                  start_time=2,
                  end_time=3),
             # System 2, staff 1.
             # Quarter rest.
             Note(pitch=librosa.note_to_midi('G4'),
                  start_time=4,
                  end_time=5),
             # System 2, staff 2.
             Note(pitch=librosa.note_to_midi('D3'),
                  start_time=3,
                  end_time=4),
             Note(pitch=librosa.note_to_midi('F3'),
                  start_time=4,
                  end_time=5),
         ]))
Example #4
0
def page_to_notesequence(page):
    return score_to_notesequence(musicscore_pb2.Score(page=[page]))