From 02ba1128f2c7b4acee6f23f133c18fa81bf75d6f Mon Sep 17 00:00:00 2001 From: Zoltan Meszaros Date: Mon, 20 Feb 2017 17:47:50 +0100 Subject: [PATCH] Added progressTimeRange to only visualize progress only in part of the waveform; bugfix compilation --- Sources/SCWaveformView.h | 8 ++++++++ Sources/SCWaveformView.m | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Sources/SCWaveformView.h b/Sources/SCWaveformView.h index ee35c42..1b0ad2c 100644 --- a/Sources/SCWaveformView.h +++ b/Sources/SCWaveformView.h @@ -67,6 +67,14 @@ */ @property (assign, nonatomic) CMTimeRange timeRange; +/** + The progressTimeRange defines an interval between which + the progressColor can be applied to the waveform. + + Default is kCMTimeZero, kCMTimePositiveInfinity + */ +@property (assign, nonatomic) CMTimeRange progressTimeRange; + /** The first audio channel index to render. Default is 0 diff --git a/Sources/SCWaveformView.m b/Sources/SCWaveformView.m index 9c686b4..11ea358 100644 --- a/Sources/SCWaveformView.m +++ b/Sources/SCWaveformView.m @@ -19,21 +19,16 @@ @protocol SCLayerDelegate @end #endif -@interface SCWaveformLayerDelegate : NSObject - -@end +@interface SCWaveformLayer : CALayer @property (assign, nonatomic) CMTime waveformTime; @end @implementation SCWaveformLayer - - @end -@interface SCWaveformLayerDelegate : NSObject - +@interface SCWaveformLayerDelegate : NSObject @end @implementation SCWaveformLayerDelegate @@ -83,6 +78,7 @@ - (void)commonInit { _waveformLayersDelegate = [SCWaveformLayerDelegate new]; _timeRange = CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity); + _progressTimeRange = _timeRange; _progressTime = kCMTimeZero; _cache = [SCWaveformCache new]; @@ -229,7 +225,9 @@ - (void)layoutSubviews { CGColorRef destColor = nil; - if (CMTIME_COMPARE_INLINE(time, >=, _progressTime)) { + if (CMTIME_COMPARE_INLINE(time, >=, _progressTime) + || CMTIME_COMPARE_INLINE(time, < , _progressTimeRange.start) + || CMTIME_COMPARE_INLINE(time, > , CMTimeAdd(_progressTimeRange.start, _progressTimeRange.duration))) { destColor = normalColor; } else { destColor = progressColor; @@ -295,7 +293,9 @@ - (void)_updateLayersColor:(BOOL)updateColor lineWidth:(BOOL)lineWidth { for (SCWaveformLayer *layer in layers) { if (updateColor) { CGColorRef destColor = progressColor; - if (CMTIME_COMPARE_INLINE(layer.waveformTime, >, _progressTime)) { + if (CMTIME_COMPARE_INLINE(layer.waveformTime, >, _progressTime) + || CMTIME_COMPARE_INLINE(layer.waveformTime, <, _progressTimeRange.start) + || CMTIME_COMPARE_INLINE(layer.waveformTime, >, CMTimeAdd(_progressTimeRange.start, _progressTimeRange.duration))) { destColor = normalColor; } @@ -364,6 +364,16 @@ - (void)setTimeRange:(CMTimeRange)timeRange { [self didChangeValueForKey:@"timeRange"]; } +- (void)setProgressTimeRange:(CMTimeRange)progressTimeRange { + [self willChangeValueForKey:@"progressTimeRange"]; + + _progressTimeRange = progressTimeRange; + + [self setNeedsLayout]; + + [self didChangeValueForKey:@"progressTimeRange"]; +} + - (void)setPrecision:(CGFloat)precision { _precision = precision;