def visualise(self, context):
        # Override BGLWidget visualise
        # it's the handle passed to the ScreenArea to draw
        sp = context.scene.speaker
        if sp is None:
            return None
        action = getAction(sp)
        # action = context.area.sound_action # NEW IDEA REFACTO
        if action is None:
            return None

        area_settings = self.area_settings(context)
        if not area_settings:
            return None

        region = context.area.regions[-1]

        self.update(context)

        y = 0
        w = self.frame_width

        x = interp(action.frame_range[0], self.region_frame_range, [0, region.width])
        h = region.height
        # print("XYWH", x,y,w,h)
        frames = action.frame_range.length
        self.draw_sound_action(context, action, x, y, w, h, frames)
Example #2
0
    def visualise(self, context):
        # Override BGLWidget visualise
        # it's the handle passed to the ScreenArea to draw
        sp = context.scene.speaker
        if sp is None:
            return None
        action = getAction(sp)
        # action = context.area.sound_action # NEW IDEA REFACTO
        if action is None:
            return None

        area_settings = self.area_settings(context)
        if not area_settings:
            return None

        region = context.area.regions[-1]

        self.update(context)

        y = 0
        w = self.frame_width

        x = interp(action.frame_range[0], self.region_frame_range, [0, region.width])
        h = region.height
        #print("XYWH", x,y,w,h)
        frames = action.frame_range.length
        self.draw_sound_action(context, action, x, y, w, h, frames)
    def draw_sound_action(self, context, action, x, y, w, h, frames, color=(1, 1, 1, 1)):
        # from bgl import  #glLineWidth, glBegin, glEnd, glColor4f, glRectf, glEnable, glDisable,glVertex2f, GL_BLEND, GL_LINES
        region = context.region
        # (minf, minh), (maxf, maxh) = region_box
        minf, maxf = self.region_frame_range
        minh, maxh = self.region_channel_range
        a = action
        range = self.action_range(a)

        channel_range = [y + c * h for c in [0.2, 0.8]]
        frame_range = [x, x + frames * w]

        fcurves = [fc for fc in action.fcurves if fc.select]
        for fcurve in fcurves:

            # Strip coords

            cf_x = context.scene.frame_current_final

            # r, g, b, a = color
            col = [c for c in fcurve.color]
            col.append(1.0)

            glColor4f(*color)

            coll = fcurve.keyframe_points if len(fcurve.keyframe_points) else fcurve.sampled_points

            pts = [p for p in coll if minf <= p.co.x <= maxf]
            # pts = fcurve.sampled_points

            points = [
                (interp(p.co.x, a.frame_range, frame_range), interp(fcurve.evaluate(p.co.x), range, channel_range))
                for p in pts
                if p.co.x < cf_x
            ]

            self.draw_points(points)

            current_frame_loc = interp(cf_x, a.frame_range, frame_range)
            current_channel_loc = interp(fcurve.evaluate(cf_x), range, channel_range)

            self.draw_circle(current_frame_loc, current_channel_loc, 12, color=self.curfc)
            self.draw_circle(current_frame_loc, current_channel_loc, 8, color=(0, 0, 0, 0))
            self.draw_circle(current_frame_loc, current_channel_loc, 3, tris=6, color=col)

            points = [
                (interp(p.co.x, a.frame_range, frame_range), interp(fcurve.evaluate(p.co.x), range, channel_range))
                for p in pts
                if p.co.x > cf_x
            ]

            self.draw_points(points, lw=1.0)

        glDisable(GL_BLEND)
Example #4
0
    def draw_sound_action(self, context, action, x, y, w, h, frames, color=(1, 1, 1, 1)):
        # from bgl import  #glLineWidth, glBegin, glEnd, glColor4f, glRectf, glEnable, glDisable,glVertex2f, GL_BLEND, GL_LINES
        region = context.region
        #(minf, minh), (maxf, maxh) = region_box
        minf, maxf = self.region_frame_range
        minh, maxh = self.region_channel_range
        a = action
        range = self.action_range(a)

        channel_range = [y + c * h for c in [0.2, 0.8]]
        frame_range = [x, x + frames * w]

        fcurves = [fc for fc in action.fcurves if fc.select]
        for fcurve in fcurves:

            # Strip coords

            cf_x = context.scene.frame_current_final

            #r, g, b, a = color
            col = [c for c in fcurve.color]
            col.append(1.0)

            glColor4f(*color)

            coll = fcurve.keyframe_points if len(fcurve.keyframe_points) else fcurve.sampled_points

            pts = [p for p in coll if minf <= p.co.x <= maxf]
            #pts = fcurve.sampled_points

            points = [(interp(p.co.x, a.frame_range, frame_range),
                        interp(fcurve.evaluate(p.co.x), range, channel_range)) for p in pts if p.co.x < cf_x]

            self.draw_points(points)

            current_frame_loc = interp(cf_x, a.frame_range, frame_range)
            current_channel_loc = interp(fcurve.evaluate(cf_x), range, channel_range)

            self.draw_circle(current_frame_loc, current_channel_loc, 12, color=self.curfc)
            self.draw_circle(current_frame_loc, current_channel_loc, 8, color=(0, 0, 0, 0))
            self.draw_circle(current_frame_loc, current_channel_loc, 3, tris=6, color=col)

            points = [(interp(p.co.x, a.frame_range, frame_range),
                        interp(fcurve.evaluate(p.co.x), range, channel_range)) for p in pts if p.co.x > cf_x]

            self.draw_points(points, lw=1.0)

        glDisable(GL_BLEND)