Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/SCWaveformView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions Sources/SCWaveformView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ @protocol SCLayerDelegate<CALayerDelegate>
@end
#endif

@interface SCWaveformLayerDelegate : NSObject<SCLayerDelegate>

@end
@interface SCWaveformLayer : CALayer

@property (assign, nonatomic) CMTime waveformTime;

@end

@implementation SCWaveformLayer


@end

@interface SCWaveformLayerDelegate : NSObject

@interface SCWaveformLayerDelegate : NSObject<SCLayerDelegate>
@end

@implementation SCWaveformLayerDelegate
Expand Down Expand Up @@ -83,6 +78,7 @@ - (void)commonInit {

_waveformLayersDelegate = [SCWaveformLayerDelegate new];
_timeRange = CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity);
_progressTimeRange = _timeRange;
_progressTime = kCMTimeZero;

_cache = [SCWaveformCache new];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down