 
     override open func layoutSubviews() {
         super.layoutSubviews()
-        guard self.assetTrack != nil && !self.renderingInProgress && self.zoomEndSamples > 0 else {
+        guard assetTrack != nil && !renderingInProgress && zoomEndSamples > 0 else {
             return
         }
 

    }

    func handlePinchGesture(_ recognizer: UIPinchGestureRecognizer) {
        if !self.doesAllowStretch {
            return
        }
        if recognizer.scale == 1 {
            return
        }
        let middleSamples = CGFloat((zoomStartSamples + zoomEndSamples) / 2)
        let rangeSamples = CGFloat(self.zoomEndSamples - self.zoomStartSamples)
        if middleSamples - 1.0 / recognizer.scale * CGFloat(rangeSamples) >= 0 {
            self.zoomStartSamples = Int(CGFloat(middleSamples) - 1.0 / recognizer.scale * CGFloat(rangeSamples) / 2)
        }
        else {
            self.zoomStartSamples = 0
        }
        if middleSamples + 1 / recognizer.scale * CGFloat(rangeSamples) / 2 <= CGFloat(totalSamples) {
            self.zoomEndSamples = Int(middleSamples + 1.0 / recognizer.scale * rangeSamples / 2)
        }
        else {
            self.zoomEndSamples = self.totalSamples
        }
        self.setNeedsDisplay()
        self.setNeedsLayout()
        recognizer.scale = 1
    }

    func handlePanGesture(_ recognizer: UIPanGestureRecognizer) {
        let point = recognizer.translation(in: self)
        if self.doesAllowScroll {
            if recognizer.state == .began {
                delegate?.waveformDidEndPanning?(self)
            }
            var translationSamples = Int(CGFloat(self.zoomEndSamples - self.zoomStartSamples) * point.x / self.bounds.size.width)
            recognizer.setTranslation(CGPoint.zero, in: self)
            if self.zoomStartSamples - translationSamples < 0 {
                translationSamples = self.zoomStartSamples
            }
            if self.zoomEndSamples - translationSamples > self.totalSamples {
                translationSamples = self.zoomEndSamples - self.totalSamples
            }
            self.zoomStartSamples -= translationSamples
            self.zoomEndSamples -= translationSamples
            if recognizer.state == .ended {
                delegate?.waveformDidEndPanning?(self)
                self.setNeedsDisplay()
                self.setNeedsLayout()
            }
            else if self.doesAllowScrubbing {
                let rangeSamples = CGFloat(zoomEndSamples - zoomStartSamples)
                progressSamples = Int(CGFloat(zoomStartSamples) + rangeSamples * recognizer.location(in: self).x / self.bounds.size.width)
            }
        }
    }

    func handleTapGesture(_ recognizer: UITapGestureRecognizer) {
        if self.doesAllowScrubbing {
            let rangeSamples = CGFloat(zoomEndSamples - zoomStartSamples)
            progressSamples = Int(CGFloat(zoomStartSamples) + rangeSamples * recognizer.location(in: self).x / self.bounds.size.width)
        }
    }
}

        addSubview(clipping)
        clipsToBounds = true

        setupGestureRecognizers()
        addGestureRecognizer(tapRecognizer)
    }

    fileprivate func setupGestureRecognizers() {
        //TODO: try to do this in the lazy initializer above
        pinchRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(handlePinchGesture))
        pinchRecognizer.delegate = self
        addGestureRecognizer(pinchRecognizer)
        panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture))
        panRecognizer.delegate = self
        addGestureRecognizer(panRecognizer)
        tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture))
    }

    required public init?(coder aCoder: NSCoder) {
        super.init(coder: aCoder)
        setup()
    }

    override init(frame rect: CGRect) {
        super.init(frame: rect)
        setup()
    }

    /// If the cached image is insufficient for the current frame
