Ejemplo n.º 1
0
    def _predict_single(self, pcgts_file: PcGts) -> PredictionResult:
        mls_cols = pcgts_file.page.all_music_lines_in_columns()
        for mls in mls_cols:
            mls.sort(key=lambda ml: ml.center_y())
            ids_aabbs = [(ml.id, ml.staff_lines.aabb()) for ml in mls]
            music_coords = [aabb.to_coords() for _, aabb in ids_aabbs]
            ids_aabbs.sort(key=lambda id_aabb: id_aabb[1].bottom())
            lyrics_aabbs = []
            if len(ids_aabbs) > 0:
                for i in range(len(ids_aabbs) - 1):
                    _, top = ids_aabbs[i]
                    _, bot = ids_aabbs[i + 1]
                    lyrics_aabbs.append(
                        Rect(Point(top.left(), top.bottom()),
                             Size(top.size.w,
                                  bot.top() - top.bottom())))

                if len(lyrics_aabbs) > 0:
                    avg_h = np.mean([a.size.h for a in lyrics_aabbs])
                else:
                    avg_h = np.mean([a.size.h for _, a in ids_aabbs])

                _, last = ids_aabbs[-1]
                lyrics_aabbs.append(
                    Rect(Point(last.left(), last.bottom()),
                         Size(last.size.w, avg_h)))

        return PredictionResult(blocks={
            BlockType.LYRICS: [aabb.to_coords() for aabb in lyrics_aabbs],
            BlockType.MUSIC:
            music_coords
        }, )
Ejemplo n.º 2
0
 def from_json(json):
     if json is None:
         return None
     return Accidental(
         AccidentalType(json.get('type', AccidentalType.NATURAL)),
         Point.from_json(json.get('coord', Point().to_json())),
         json.get('fixedSorting', False),
         json.get('positionInStaff', MusicSymbolPositionInStaff.UNDEFINED),
         json.get('id', None),
     )
Ejemplo n.º 3
0
 def extract_symbols(self, dataset, p, m: RegionLineMaskData) -> List[MusicSymbol]:
     sentence = [(pos.chars[0].char,
                  m.operation.page.image_to_page_scale(
                      dataset.local_to_global_pos(Point((pos.global_start + pos.global_end) / 2, 40), m.operation.params).x,
                      m.operation.scale_reference
                  ))
                 for pos in p.positions]
     return CalamariSequence.to_symbols(dataset.params.calamari_codec, sentence, m.operation.music_line.staff_lines)
Ejemplo n.º 4
0
 def from_json(json: dict):
     return Clef(
         ClefType(json.get("type", ClefType.CLEF_F)),
         Point.from_json(json.get("coord", "0,0")),
         MusicSymbolPositionInStaff(
             json.get('positionInStaff',
                      MusicSymbolPositionInStaff.UNDEFINED)),
         json.get('fixedSorting', False), json.get('id', None))
Ejemplo n.º 5
0
 def __init__(self,
              accidental=AccidentalType.NATURAL,
              coord=Point(),
              fixed_sorting: bool = False,
              position_in_staff=MusicSymbolPositionInStaff.UNDEFINED,
              s_id: str = None):
     super().__init__(s_id, SymbolType.ACCID, fixed_sorting, coord,
                      position_in_staff)
     self.accidental = accidental
Ejemplo n.º 6
0
 def __init__(self,
              clef_type=ClefType.CLEF_F,
              coord=Point(),
              position_in_staff=MusicSymbolPositionInStaff.UNDEFINED,
              fixed_sorting: bool = False,
              s_id: str = None):
     super().__init__(s_id, SymbolType.CLEF, fixed_sorting, coord,
                      position_in_staff)
     self.clef_type = clef_type
Ejemplo n.º 7
0
 def __init__(self,
              s_id: Optional[str],
              symbol_type: SymbolType,
              fixed_sorting: bool = False,
              coord: Point = None,
              position_in_staff: MusicSymbolPositionInStaff = MusicSymbolPositionInStaff.UNDEFINED,
              ):
     self.id = s_id if s_id else str(uuid4())
     self.coord = coord if coord else Point()
     self.symbol_type = symbol_type
     self.fixed_sorting = fixed_sorting
     self.position_in_staff = position_in_staff
     self.octave = 0
     self.note_name = NoteName.UNDEFINED
Ejemplo n.º 8
0
 def from_json(json: dict):
     try:
         return NoteComponent(
             NoteName(json.get('pname', NoteName.UNDEFINED)),
             json.get('oct', -1),
             NoteType(json.get('type', NoteType.NORMAL)),
             Point.from_json(json.get('coord', [])),
             MusicSymbolPositionInStaff(json.get('positionInStaff', MusicSymbolPositionInStaff.UNDEFINED)),
             GraphicalConnectionType(json.get('graphicalConnection', GraphicalConnectionType.GAPED)),
             json.get('fixedSorting', False),
             json.get('id', None),
         )
     except Exception as e:
         logger.exception(e)
         logger.error("Got faulty dict {}".format(json))
         return None