Skip to content

Commit bdee9f0

Browse files
committed
MIDI Visualization: Fix track change handling
Signed-off-by: Christopher Snowhill <[email protected]>
1 parent 863576b commit bdee9f0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Audio/Visualization/MIDIVisualizationController.m

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,18 @@ - (void)cleanup:(id)sender {
8585
++i;
8686
}
8787
if(i < count)
88-
files[idx].events = [[events subarrayWithRange:NSMakeRange(i, count - i)] mutableCopy];
88+
file.events = [[events subarrayWithRange:NSMakeRange(i, count - i)] mutableCopy];
8989
else if(idx > 0)
90-
files[idx].events = [NSMutableArray new];
90+
file.events = [NSMutableArray new];
9191
else {
9292
[files removeObjectAtIndex:0];
9393
--fileCount;
94+
if(currentTrack && [currentTrack isEqualTo:file.url]) {
95+
if(fileCount)
96+
currentTrack = files[0].url;
97+
else
98+
currentTrack = nil;
99+
}
94100
continue;
95101
}
96102
}
@@ -140,18 +146,21 @@ - (void)removeObservers {
140146
}
141147

142148
- (void)playbackDidBegin:(NSNotification *)notification {
149+
NSURL *url = _getPlaylistEntryURL(notification.object);
143150
@synchronized (self) {
144-
if(currentTrack) {
145-
[self removeTrack:currentTrack];
146-
NSURL *url = _getPlaylistEntryURL(notification.object);
147-
if([files count]) {
148-
MIDIFileEventContainer *file = files[0];
149-
if([file.url isEqualTo:url])
150-
currentTrack = files[0].url;
151-
else
152-
currentTrack = nil;
151+
while([files count]) {
152+
MIDIFileEventContainer *file = files[0];
153+
if(currentTrack && [file.url isEqualTo:currentTrack]) {
154+
currentTrack = nil;
155+
[self removeTrack:file.url];
156+
continue;
157+
} else if([file.url isEqualTo:url]) {
158+
currentTrack = file.url;
159+
break;
153160
} else {
161+
// track(s) buffered, but current track doesn't match them
154162
currentTrack = nil;
163+
break;
155164
}
156165
}
157166
}

0 commit comments

Comments
 (0)