Fix some undo issues
This commit is contained in:
2 files changed
+65
-50
No files matched your search
+64
-49
@@ -95,7 +95,6 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
MP42_OBJC_DIRECT_MEMBERS
|
|
||||||
@implementation MP42File
|
@implementation MP42File
|
||||||
|
|
||||||
@synthesize itracks = _tracks;
|
@synthesize itracks = _tracks;
|
||||||
@@ -451,73 +450,89 @@ MP42_OBJC_DIRECT_MEMBERS
|
|||||||
NSAssert(self.status != MP42StatusWriting, @"Unsupported operation: trying to add a track while the file is open for writing");
|
NSAssert(self.status != MP42StatusWriting, @"Unsupported operation: trying to add a track while the file is open for writing");
|
||||||
NSAssert(![self.itracks containsObject:track], @"Unsupported operation: trying to add a track that is already present.");
|
NSAssert(![self.itracks containsObject:track], @"Unsupported operation: trying to add a track that is already present.");
|
||||||
|
|
||||||
track.sourceId = track.trackId;
|
if (!(self.undo.isUndoing || self.undo.isRedoing)) {
|
||||||
track.trackId = 0;
|
track.sourceId = track.trackId;
|
||||||
track.muxed = NO;
|
track.trackId = 0;
|
||||||
track.edited = YES;
|
track.muxed = NO;
|
||||||
|
track.edited = YES;
|
||||||
|
|
||||||
track.language = track.language;
|
track.language = track.language;
|
||||||
track.name = track.name;
|
track.name = track.name;
|
||||||
if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
|
if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
|
||||||
for (id previousTrack in self.itracks)
|
for (id previousTrack in self.itracks)
|
||||||
if ([previousTrack isMemberOfClass:[MP42ChapterTrack class]]) {
|
if ([previousTrack isMemberOfClass:[MP42ChapterTrack class]]) {
|
||||||
[self.itracks removeObject:previousTrack];
|
[self.itracks removeObject:previousTrack];
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (trackNeedConversion(track.format) && ![track isMemberOfClass:[MP42ChapterTrack class]]) {
|
if (trackNeedConversion(track.format) && ![track isMemberOfClass:[MP42ChapterTrack class]]) {
|
||||||
NSAssert(track.conversionSettings, @"Missing conversion settings");
|
NSAssert(track.conversionSettings, @"Missing conversion settings");
|
||||||
}
|
|
||||||
|
|
||||||
if (track.importer && track.URL) {
|
|
||||||
if (self.importers[track.URL.path]) {
|
|
||||||
track.importer = self.importers[track.URL.path];
|
|
||||||
} else {
|
|
||||||
self.importers[track.URL.path] = track.importer;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
|
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
|
||||||
MP42AudioTrack *audioTrack = (MP42AudioTrack *)track;
|
MP42AudioTrack *audioTrack = (MP42AudioTrack *)track;
|
||||||
MP42Track *fallbackTrack = audioTrack.fallbackTrack;
|
MP42Track *fallbackTrack = audioTrack.fallbackTrack;
|
||||||
if (fallbackTrack && ![self.itracks containsObject:fallbackTrack]) {
|
if (fallbackTrack && ![self.itracks containsObject:fallbackTrack]) {
|
||||||
audioTrack.fallbackTrack = nil;
|
audioTrack.fallbackTrack = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
|
if ([track isMemberOfClass:[MP42ChapterTrack class]]) {
|
||||||
track.duration = self.duration;
|
track.duration = self.duration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
track.undo = self.undo;
|
track.undo = self.undo;
|
||||||
|
|
||||||
[[self.undo prepareWithInvocationTarget:self] removeTracks:@[track]];
|
[[self.undo prepareWithInvocationTarget:self] removeTracks:@[track]];
|
||||||
|
|
||||||
[self.itracks addObject:track];
|
[self.itracks addObject:track];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)addToBeDeleted:(MP42Track *)track
|
||||||
|
{
|
||||||
|
[[self.undo prepareWithInvocationTarget:self] removeFromToBeDeleted:track];
|
||||||
|
[_tracksToBeDeleted addObject:track];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeFromToBeDeleted:(MP42Track *)track
|
||||||
|
{
|
||||||
|
[[self.undo prepareWithInvocationTarget:self] addToBeDeleted:track];
|
||||||
|
[_tracksToBeDeleted removeObject:track];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)removeTracks:(NSArray<MP42Track *> *)tracks {
|
- (void)removeTracks:(NSArray<MP42Track *> *)tracks {
|
||||||
NSAssert(self.status != MP42StatusWriting, @"Unsupported operation: trying to remove a track while the file is open for writing");
|
NSAssert(self.status != MP42StatusWriting, @"Unsupported operation: trying to remove a track while the file is open for writing");
|
||||||
|
|
||||||
for (MP42Track *track in tracks) {
|
if (!(self.undo.isUndoing || self.undo.isRedoing)) {
|
||||||
// track is muxed, it needs to be removed from the file
|
for (MP42Track *track in tracks) {
|
||||||
if (track.muxed)
|
// track is muxed, it needs to be removed from the file
|
||||||
[_tracksToBeDeleted addObject:track];
|
if (track.muxed) {
|
||||||
|
[self addToBeDeleted:track];
|
||||||
// Remove the reference
|
|
||||||
for (MP42Track *ref in self.itracks) {
|
|
||||||
if ([ref isMemberOfClass:[MP42AudioTrack class]]) {
|
|
||||||
MP42AudioTrack *a = (MP42AudioTrack *)ref;
|
|
||||||
if (a.fallbackTrack == track)
|
|
||||||
a.fallbackTrack = nil;
|
|
||||||
if (a.followsTrack == track)
|
|
||||||
a.followsTrack = nil;
|
|
||||||
}
|
}
|
||||||
if ([ref isMemberOfClass:[MP42SubtitleTrack class]]) {
|
|
||||||
MP42SubtitleTrack *a = (MP42SubtitleTrack *)ref;
|
// Remove the reference
|
||||||
if (a.forcedTrack == track)
|
for (MP42Track *ref in self.itracks) {
|
||||||
a.forcedTrack = nil;
|
if ([ref isMemberOfClass:[MP42AudioTrack class]]) {
|
||||||
|
MP42AudioTrack *a = (MP42AudioTrack *)ref;
|
||||||
|
if (a.fallbackTrack == track)
|
||||||
|
a.fallbackTrack = nil;
|
||||||
|
if (a.followsTrack == track)
|
||||||
|
a.followsTrack = nil;
|
||||||
|
}
|
||||||
|
if ([ref isMemberOfClass:[MP42SubtitleTrack class]]) {
|
||||||
|
MP42SubtitleTrack *a = (MP42SubtitleTrack *)ref;
|
||||||
|
if (a.forcedTrack == track)
|
||||||
|
a.forcedTrack = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (track.importer && track.URL) {
|
||||||
|
if (self.importers[track.URL.path]) {
|
||||||
|
track.importer = self.importers[track.URL.path];
|
||||||
|
} else {
|
||||||
|
self.importers[track.URL.path] = track.importer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ typedef struct MP4DemuxHelper {
|
|||||||
NSUInteger tracksNumber = inputTracks.count;
|
NSUInteger tracksNumber = inputTracks.count;
|
||||||
NSUInteger tracksDone = 0;
|
NSUInteger tracksDone = 0;
|
||||||
|
|
||||||
MP4DemuxHelper * helpers[tracksNumber];
|
MP4DemuxHelper *helpers[tracksNumber];
|
||||||
|
|
||||||
for (NSUInteger index = 0; index < tracksNumber; index += 1) {
|
for (NSUInteger index = 0; index < tracksNumber; index += 1) {
|
||||||
MP42Track *track = inputTracks[index];
|
MP42Track *track = inputTracks[index];
|
||||||
|
|||||||
Reference in new issue
Block a user