Exemple #1
0
 def layout_objects(self):
     # Layout measure.
     self._beginX = 0
     if 'left' in self.barlines:
         self._beginX += BarLine.GAP * 2
     self.layout_lines()
     self.layout_clef()
     self.layout_key()
     self.layout_notes()
     self.layout_beams()
     self.layout_accidentals()
     self.topY = max(self.topY, self.height)
     for note in self.notes:
         note.layout()
         self.topY = max(self.topY, note.pos[1] + note.sprite.size[1] / 2)
         self.bottomY = min(self.bottomY,
                            note.pos[1] - note.sprite.size[1] / 2)
         if hasattr(note, 'stem') and note.stem:
             self.topY = max(self.topY, note.stem.head[1],
                             note.stem.tail[1])
             self.bottomY = min(self.bottomY, note.stem.head[1],
                                note.stem.tail[1])
     self.layout_barlines()
     # Display measure number
     if self.isNewSystem:
         self.add_sprite(
             sprite.Text(
                 text=str(self.number),
                 fontSize=14,
                 color=ui.Color(0., 0., 0., 1.),
                 x=10,
                 y=-(-22),
             ))
     self.layout_ending()
Exemple #2
0
 def __init__(self, pos, number):
     super().__init__(
         fontSize=self.FONT_SIZE,
         text=str(int(number)),
         align='center',
         color=ui.Color(0., 0., 0., 1.),
         x=pos[0],
         y=-pos[1],
     )
     w, h = self.guess_size()
     self.x -= w / 2
     self.y -= h / 2
Exemple #3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._renders = {
         sprite.Line.renderType: render.LineRender(),
         sprite.Texture.renderType: render.TextureRender(),
         sprite.Beam.renderType: render.BeamRender(),
         sprite.Text.renderType: render.TextRender(),
         'indicator': render.IndicatorRender()
     }
     self.color = ui.Color(0xffffcf4)
     self._scale = 1
     self._viewPoint = (0, 0)
     self.layout = None
Exemple #4
0
 def __init__(self, xmlnode):
     justify = xmlnode.attrib.get('justify', 'center')
     super().__init__(
         fontSize=int(xmlnode.attrib.get('font-size', '10')),
         text=xmlnode.text,
         align='center',
         halign=xmlnode.attrib.get('valign', 'center'),
         color=ui.Color(0., 0., 0., 1.),
         x=float(xmlnode.attrib['default-x']),
         y=-float(xmlnode.attrib['default-y']),
         # autoResize=True,
     )
     size = self.guess_size()
     self.width, self.height = size
     if justify == 'center':
         self.x -= self.width / 2
     elif justify == 'right':
         self.x -= self.width
     self.y -= self.height / 2
Exemple #5
0
 def layout_ending(self):
     ending = self.ending
     if not ending:
         return
     add_sprite = self.add_sprite
     y1 = self.topY + Ending.HEIGHT + Ending.GAP
     y0 = y1 - Ending.HEIGHT
     add_sprite(sprite.Line((0, y0), (0, y1), Ending.THICK))
     add_sprite(
         sprite.Text(
             fontSize=Ending.FONT_SIZE,
             text='{}.'.format(ending.number),
             x=10,
             y=-(y0 + 10),
             color=ui.Color(0., 0., 0., 1.),
         ))
     add_sprite(
         sprite.Line((-Ending.THICK / 2, y1), (self.width / 1.2, y1),
                     Ending.THICK))
Exemple #6
0
class IndicatorRender(LineRender):
    MEASURE_INDICATOR_COLOR = ui.Color(.96, .92, .37, .5)

    def __init__(self):
        super().__init__()
        self.color = self.MEASURE_INDICATOR_COLOR
        self.lineBuffer = gl.DynamicVertexBuffer()
        self.widthBuffer = gl.DynamicVertexBuffer()
        self.measure = None

    def set_measure(self, measure):
        self.measure = measure
        self.update_buffer()

    def make_buffer(self, *args):
        pass

    def free_buffers(self):
        pass

    def update_buffer(self):
        measure = self.measure
        if not measure:
            return
        buffer = np.zeros((1, 5), dtype=gl.GLfloat)
        # x1, y1, x2, y2, width
        y = measure.y + (measure.bottomY + measure.topY) / 2
        buffer[0, 0:2] = measure.x, y
        buffer[0, 2:4] = measure.x + measure.width, y
        buffer[0, 4] = measure.topY - measure.bottomY
        self.lineBuffer.set_data(buffer[:, 0:4])
        self.widthBuffer.set_data(buffer[:, 4])

    def render(self):
        if not self.measure:
            return
        super().render()