def draw_png(self, image, h_zoom, v_zoom, current_y):
        """
        Draw this waveform to PNG.

        :param image: the image to draw onto
        :param int h_zoom: the horizontal zoom
        :param int v_zoom: the vertical zoom
        :param int current_y: the current y offset, in modules
        :type  image: :class:`PIL.Image`
        """
        draw = ImageDraw.Draw(image)
        mws = self.rconf.mws
        rate = self.audio_file.audio_sample_rate
        samples = self.audio_file.audio_samples
        duration = self.audio_file.audio_length

        current_y_px = current_y * v_zoom
        half_waveform_px = (self.height // 2) * v_zoom
        zero_y_px = current_y_px + half_waveform_px

        samples_per_pixel = int(rate * mws / h_zoom)
        pixels_per_second = int(h_zoom / mws)
        windows = len(samples) // samples_per_pixel

        if self.label is not None:
            font_height_pt = 18
            font = ImageFont.truetype(self.FONT_PATH, font_height_pt)
            draw.text((0, current_y_px), self.label, PlotterColors.BLACK, font=font)

        for i in range(windows):
            x = i * samples_per_pixel
            pos = numpy.clip(samples[x:(x + samples_per_pixel)], 0.0, 1.0)
            mpos = numpy.max(pos) * half_waveform_px
            if self.fast:
                # just draw a simple version, mirroring max positive samples
                draw.line((i, zero_y_px + mpos, i, zero_y_px - mpos), fill=PlotterColors.AUDACITY_DARK_BLUE, width=1)
            else:
                # draw a better version, taking min and std of positive and negative samples
                neg = numpy.clip(samples[x:(x + samples_per_pixel)], -1.0, 0.0)
                spos = numpy.std(pos) * half_waveform_px
                sneg = numpy.std(neg) * half_waveform_px
                mneg = numpy.min(neg) * half_waveform_px
                draw.line((i, zero_y_px - mneg, i, zero_y_px - mpos), fill=PlotterColors.AUDACITY_DARK_BLUE, width=1)
                draw.line((i, zero_y_px + sneg, i, zero_y_px - spos), fill=PlotterColors.AUDACITY_LIGHT_BLUE, width=1)
def draw_png ( self , image , h_zoom , v_zoom , current_y ) : draw = ImageDraw . Draw ( image ) mws = self . rconf . mws rate = self . audio_file . audio_sample_rate samples = self . audio_file . audio_samples duration = self . audio_file . audio_length current_y_px = current_y * v_zoom half_waveform_px = ( self . height // 2 ) * v_zoom zero_y_px = current_y_px + half_waveform_px samples_per_pixel = int ( rate * mws / h_zoom ) pixels_per_second = int ( h_zoom / mws ) windows = len ( samples ) // samples_per_pixel if self . label is not None : font_height_pt = 18 font = ImageFont . truetype ( self . FONT_PATH , font_height_pt ) draw . text ( ( 0 , current_y_px ) , self . label , PlotterColors . BLACK , font = font ) for i in range ( windows ) : x = i * samples_per_pixel pos = numpy . clip ( samples [ x : ( x + samples_per_pixel ) ] , 0.0 , 1.0 ) mpos = numpy . max ( pos ) * half_waveform_px if self . fast : draw . line ( ( i , zero_y_px + mpos , i , zero_y_px - mpos ) , fill = PlotterColors . AUDACITY_DARK_BLUE , width = 1 ) else : neg = numpy . clip ( samples [ x : ( x + samples_per_pixel ) ] , - 1.0 , 0.0 ) spos = numpy . std ( pos ) * half_waveform_px sneg = numpy . std ( neg ) * half_waveform_px mneg = numpy . min ( neg ) * half_waveform_px draw . line ( ( i , zero_y_px - mneg , i , zero_y_px - mpos ) , fill = PlotterColors . AUDACITY_DARK_BLUE , width = 1 ) draw . line ( ( i , zero_y_px + sneg , i , zero_y_px - spos ) , fill = PlotterColors . AUDACITY_LIGHT_BLUE , width = 1 )
Draw this waveform to PNG.

        :param image: the image to draw onto
        :param int h_zoom: the horizontal zoom
        :param int v_zoom: the vertical zoom
        :param int current_y: the current y offset, in modules
        :type  image: :class:`PIL.Image`