// Draw samples from sample_iter starting at first_x.
// Returns the lower bound and last drawn coordinates.
Draw samples from sample_iter starting at first_x.
Returns the lower bound and last drawn coordinates.
Draw samples from sample_iter starting at first_x . Returns the lower bound and last drawn coordinates .
fn draw_samples(
        &self,
        cr: &cairo::Context,
        audio_buffer: &AudioBuffer,
        lower: usize,
        upper: usize,
        first_x: f64,
    ) -> Option<(WaveformSample, WaveformSample)> {
        if self.x_step == 1 {
            cr.set_line_width(1f64);
        } else if self.x_step < 4 {
            cr.set_line_width(1.5f64);
        } else {
            cr.set_line_width(2f64);
        }
        let sample_iter = audio_buffer.iter(lower, upper, self.sample_step);
        if sample_iter.is_none() {
            warn!(
                concat!(
                    "{}_draw_samples invalid iter for ",
                    "[{}, {}] sample_step {}, buffer: [{}, {}]",
                ),
                self.id,
                lower,
                upper,
                self.sample_step,
                audio_buffer.lower,
                audio_buffer.upper
            );
            return None;
        }
        let mut sample_iter = sample_iter.unwrap();
        if sample_iter.size_hint().0 < 2 {
            debug!(
                concat!(
                    "{}_draw_samples too small to render for ",
                    "[{}, {}] sample_step {}, buffer: [{}, {}]",
                ),
                self.id,
                lower,
                upper,
                self.sample_step,
                audio_buffer.lower,
                audio_buffer.upper
            );
            return None;
        }
        #[cfg(test)]
        {
            // in test mode, draw marks at
            // the start and end of each chunk
            cr.set_source_rgb(0f64, 0f64, 1f64);
            cr.move_to(first_x, 0f64);
            cr.line_to(first_x, 0.5f64 * self.half_range);
            cr.stroke();
        }
        let mut first_values: Vec<f64> = Vec::with_capacity(audio_buffer.channels);
        let mut last_values: Vec<f64> = Vec::with_capacity(audio_buffer.channels);
        let sample = sample_iter.next();
        for channel_value in sample.unwrap() {
            let y = self.convert_sample(channel_value);
            first_values.push(y);
            last_values.push(y);
        }
        let first_added = WaveformSample {
            x: first_x,
            values: first_values,
        };
        let first_for_amp0 = match self.last.as_ref() {
            Some(prev_last) => {
                if (first_x - prev_last.x).abs() <= self.x_step_f {
                    // appending samples right after previous last sample => add a link
                    self.link_samples(cr, prev_last, &first_added);
                    prev_last.x
                } else {
                    first_x
                }
            }
            None => first_x,
        };
        let mut x = first_x;
        for sample in sample_iter {
            let prev_x = x;
            x += self.x_step_f;
            for (channel, value) in sample.iter().enumerate() {
                self.set_channel_color(cr, channel);
                cr.move_to(prev_x, last_values[channel]);
                last_values[channel] = self.convert_sample(value);
                cr.line_to(x, last_values[channel]);
                cr.stroke();
            }
        }
        let last_added = WaveformSample {
            x,
            values: last_values,
        };
        let last_for_amp0 = match self.first.as_ref() {
            Some(prev_first) => {
                if (prev_first.x - x).abs() <= self.x_step_f {
                    // appending samples right before previous first sample => add a link
                    self.link_samples(cr, &last_added, prev_first);
                    prev_first.x
                } else {
                    x
                }
            }
            None => x,
        };
        self.draw_amplitude_0(cr, first_for_amp0, last_for_amp0);
        #[cfg(test)]
        {
            // in test mode, draw marks at
            // the start and end of each chunk
            cr.set_source_rgb(1f64, 0f64, 1f64);
            cr.move_to(x, 1.5f64 * self.half_range);
            cr.line_to(x, self.full_range);
            cr.stroke();
        }
        Some((first_added, last_added))
    }
fn draw_samples ( & self , cr : & cairo :: Context , audio_buffer : & AudioBuffer , lower : usize , upper : usize , first_x : f64 , ) -> Option < ( WaveformSample , WaveformSample ) > { if self . x_step == 1 { cr . set_line_width ( 1f64 ) ; } else if self . x_step < 4 { cr . set_line_width ( 1.5f64 ) ; } else { cr . set_line_width ( 2f64 ) ; } let sample_iter = audio_buffer . iter ( lower , upper , self . sample_step ) ; if sample_iter . is_none ( ) { warn ! ( concat ( " " " " ) self id lower upper self sample_step audio_buffer lower audio_buffer upper ) ; return None ; } let mut sample_iter = sample_iter . unwrap ( ) ; if sample_iter . size_hint ( ) . 0 < 2 { debug ! ( concat ( " " " " ) self id lower upper self sample_step audio_buffer lower audio_buffer upper ) ; return None ; } # [ cfg ( test ) ] { // in test mode, draw marks at // the start and end of each chunk cr . set_source_rgb ( 0f64 , 0f64 , 1f64 ) ; cr . move_to ( first_x , 0f64 ) ; cr . line_to ( first_x , 0.5f64 * self . half_range ) ; cr . stroke ( ) ; } let mut first_values : Vec < f64 > = Vec :: with_capacity ( audio_buffer . channels ) ; let mut last_values : Vec < f64 > = Vec :: with_capacity ( audio_buffer . channels ) ; let sample = sample_iter . next ( ) ; for channel_value in sample . unwrap ( ) { let y = self . convert_sample ( channel_value ) ; first_values . push ( y ) ; last_values . push ( y ) ; } let first_added = WaveformSample { x : first_x , values : first_values , } ; let first_for_amp0 = match self . last . as_ref ( ) { Some ( prev_last ) => { if ( first_x - prev_last . x ) . abs ( ) <= self . x_step_f { // appending samples right after previous last sample => add a link self . link_samples ( cr , prev_last , & first_added ) ; prev_last . x } else { first_x } } None => first_x , } ; let mut x = first_x ; for sample in sample_iter { let prev_x = x ; x += self . x_step_f ; for ( channel , value ) in sample . iter ( ) . enumerate ( ) { self . set_channel_color ( cr , channel ) ; cr . move_to ( prev_x , last_values [ channel ] ) ; last_values [ channel ] = self . convert_sample ( value ) ; cr . line_to ( x , last_values [ channel ] ) ; cr . stroke ( ) ; } } let last_added = WaveformSample { x , values : last_values , } ; let last_for_amp0 = match self . first . as_ref ( ) { Some ( prev_first ) => { if ( prev_first . x - x ) . abs ( ) <= self . x_step_f { // appending samples right before previous first sample => add a link self . link_samples ( cr , & last_added , prev_first ) ; prev_first . x } else { x } } None => x , } ; self . draw_amplitude_0 ( cr , first_for_amp0 , last_for_amp0 ) ; # [ cfg ( test ) ] { // in test mode, draw marks at // the start and end of each chunk cr . set_source_rgb ( 1f64 , 0f64 , 1f64 ) ; cr . move_to ( x , 1.5f64 * self . half_range ) ; cr . line_to ( x , self . full_range ) ; cr . stroke ( ) ; } Some ( ( first_added , last_added ) ) }
Draw samples from sample_iter starting at first_x.
Draw samples from sample_iter starting at first_x .
&self
cr
&cairo::Context
audio_buffer
&AudioBuffer
lower
usize
upper
usize
first_x
f64