summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2016-11-02 20:13:37 +0100
committerDamiano Galassi <[email protected]>2016-11-02 20:13:37 +0100
commit4a6bfe854904ab2e79c4958f291d40b3eebc65ff (patch)
treed94881041c7cf3e2d7ad8602deceda35307d76b4
parent4f71778cf9a1e73a5b291c9656a71d6d6dc1f976 (diff)
MacGui: fix HBJob copy method, plus small performance optimisation in HBAudio and HBSubtitles.
-rw-r--r--macosx/HBAudio.h2
-rw-r--r--macosx/HBAudio.m53
-rw-r--r--macosx/HBJob.m2
-rw-r--r--macosx/HBSubtitles.h2
-rw-r--r--macosx/HBSubtitles.m57
5 files changed, 69 insertions, 47 deletions
diff --git a/macosx/HBAudio.h b/macosx/HBAudio.h
index aaaf076ed..899c8dc88 100644
--- a/macosx/HBAudio.h
+++ b/macosx/HBAudio.h
@@ -16,7 +16,7 @@ extern NSString *HBAudioChangedNotification;
@interface HBAudio : NSObject <NSSecureCoding, NSCopying>
-@property (nonatomic, readonly) NSMutableArray<NSDictionary *> *sourceTracks;
+@property (nonatomic, readonly) NSArray<NSDictionary *> *sourceTracks;
@property (nonatomic, readonly) NSMutableArray<HBAudioTrack *> *tracks;
@property (nonatomic, readwrite) HBAudioDefaults *defaults;
diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m
index 7d92c5942..20862938c 100644
--- a/macosx/HBAudio.m
+++ b/macosx/HBAudio.m
@@ -39,13 +39,14 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
_job = job;
_container = HB_MUX_MP4;
- _sourceTracks = [job.title.audioTracks mutableCopy];
_tracks = [[NSMutableArray alloc] init];
_defaults = [[HBAudioDefaults alloc] init];
// Add the none and foreign track to the source array
+ NSMutableArray *sourceTracks = [job.title.audioTracks mutableCopy];
NSDictionary *none = @{keyAudioTrackName: NSLocalizedString(@"None", nil)};
- [_sourceTracks insertObject:none atIndex:0];
+ [sourceTracks insertObject:none atIndex:0];
+ _sourceTracks = [sourceTracks copy];
}
return self;
}
@@ -96,10 +97,7 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
- (void)addAllTracks
{
- while (self.countOfTracks)
- {
- [self removeObjectFromTracksAtIndex:0];
- }
+ [self removeTracksAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.tracks.count)]];
// Add the remainings tracks
for (NSUInteger idx = 1; idx < self.sourceTracksArray.count; idx++) {
@@ -111,10 +109,7 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
- (void)removeAll
{
- while (self.countOfTracks)
- {
- [self removeObjectFromTracksAtIndex:0];
- }
+ [self removeTracksAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.tracks.count)]];
[self addNoneTrack];
}
@@ -185,16 +180,14 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
- (void)addDefaultTracksFromJobSettings:(NSDictionary *)settings
{
- NSArray<NSDictionary<NSString *, id> *> *tracks = settings[@"Audio"][@"AudioList"];
+ NSMutableArray<HBAudioTrack *> *tracks = [NSMutableArray array];
+ NSArray<NSDictionary<NSString *, id> *> *settingsTracks = settings[@"Audio"][@"AudioList"];
// Reinitialize the configured list of audio tracks
- while (self.countOfTracks)
- {
- [self removeObjectFromTracksAtIndex:0];
- }
+ [self removeTracksAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.tracks.count)]];
// Add the tracks
- for (NSDictionary *trackDict in tracks)
+ for (NSDictionary *trackDict in settingsTracks)
{
HBAudioTrack *track = [self trackFromSourceTrackIndex:[trackDict[@"Track"] unsignedIntegerValue] + 1];
@@ -213,26 +206,25 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
track.bitRate = [trackDict[@"Bitrate"] intValue];
track.encoder = hb_audio_encoder_get_from_name([trackDict[@"Encoder"] UTF8String]);
- [self insertObject:track inTracksAtIndex:[self countOfTracks]];
+ [tracks addObject:track];
}
+ [self insertTracks:tracks atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, tracks.count)]];
+
// Add an None item
[self addNoneTrack];
}
- (BOOL)anyCodecMatches:(int)codec
{
- BOOL retval = NO;
- NSUInteger audioArrayCount = [self countOfTracks];
- for (NSUInteger i = 0; i < audioArrayCount && !retval; i++)
+ for (HBAudioTrack *track in self.tracks)
{
- HBAudioTrack *anAudio = [self objectInTracksAtIndex: i];
- if (anAudio.isEnabled && codec == anAudio.encoder)
+ if (track.isEnabled && codec == track.encoder)
{
- retval = YES;
+ return YES;
}
}
- return retval;
+ return NO;
}
#pragma mark -
@@ -337,6 +329,12 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
[self.tracks insertObject:track atIndex:index];
}
+- (void)insertTracks:(NSArray<HBAudioTrack *> *)array atIndexes:(NSIndexSet *)indexes
+{
+ [[self.undo prepareWithInvocationTarget:self] removeTracksAtIndexes:indexes];
+ [self.tracks insertObjects:array atIndexes:indexes];
+}
+
- (void)removeObjectFromTracksAtIndex:(NSUInteger)index
{
HBAudioTrack *track = self.tracks[index];
@@ -344,4 +342,11 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
[self.tracks removeObjectAtIndex:index];
}
+- (void)removeTracksAtIndexes:(NSIndexSet *)indexes
+{
+ NSArray<HBAudioTrack *> *tracks = [self.tracks objectsAtIndexes:indexes];
+ [[self.undo prepareWithInvocationTarget:self] insertTracks:tracks atIndexes:indexes];
+ [self.tracks removeObjectsAtIndexes:indexes];
+}
+
@end
diff --git a/macosx/HBJob.m b/macosx/HBJob.m
index 483735d33..e3d608a9a 100644
--- a/macosx/HBJob.m
+++ b/macosx/HBJob.m
@@ -222,7 +222,9 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
copy->_video.job = copy;
copy->_audio = [_audio copy];
+ copy->_audio.job = copy;
copy->_subtitles = [_subtitles copy];
+ copy->_subtitles.job = copy;
copy->_chaptersEnabled = _chaptersEnabled;
copy->_chapterTitles = [[NSArray alloc] initWithArray:_chapterTitles copyItems:YES];
diff --git a/macosx/HBSubtitles.h b/macosx/HBSubtitles.h
index 0d5d87a30..562052890 100644
--- a/macosx/HBSubtitles.h
+++ b/macosx/HBSubtitles.h
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)addSrtTrackFromURL:(NSURL *)srtURL;
-@property (nonatomic, readonly) NSMutableArray<NSDictionary *> *sourceTracks;
+@property (nonatomic, readonly) NSArray<NSDictionary *> *sourceTracks;
@property (nonatomic, readonly) NSMutableArray<HBSubtitlesTrack *> *tracks;
@property (nonatomic, readwrite, strong) HBSubtitlesDefaults *defaults;
diff --git a/macosx/HBSubtitles.m b/macosx/HBSubtitles.m
index 024d30dcf..985390205 100644
--- a/macosx/HBSubtitles.m
+++ b/macosx/HBSubtitles.m
@@ -28,6 +28,8 @@ extern NSString *keySubTrackSrtFileURL;
@interface HBSubtitles () <HBTrackDataSource, HBTrackDelegate>
+@property (nonatomic, readwrite) NSArray<NSDictionary *> *sourceTracks;
+
@property (nonatomic, readwrite, weak) HBJob *job;
@property (nonatomic, readwrite) int container;
@@ -43,13 +45,14 @@ extern NSString *keySubTrackSrtFileURL;
self = [super init];
if (self)
{
- job = job;
+ _job = job;
_container = HB_MUX_MP4;
- _sourceTracks = [job.title.subtitlesTracks mutableCopy];
_tracks = [[NSMutableArray alloc] init];
_defaults = [[HBSubtitlesDefaults alloc] init];
+ NSMutableArray *sourceTracks = [job.title.subtitlesTracks mutableCopy];
+
NSMutableSet<NSString *> *forcedSourceNamesArray = [NSMutableSet set];
int foreignAudioType = VOBSUB;
for (NSDictionary *dict in _sourceTracks)
@@ -78,11 +81,13 @@ extern NSString *keySubTrackSrtFileURL;
// Add the none and foreign track to the source array
NSDictionary *none = @{ keySubTrackName: NSLocalizedString(@"None", nil)};
- [_sourceTracks insertObject:none atIndex:0];
+ [sourceTracks insertObject:none atIndex:0];
NSDictionary *foreign = @{ keySubTrackName: foreignAudioSearchTrackName,
keySubTrackType: @(foreignAudioType) };
- [_sourceTracks insertObject:foreign atIndex:1];
+ [sourceTracks insertObject:foreign atIndex:1];
+
+ _sourceTracks = [sourceTracks copy];
}
return self;
@@ -186,10 +191,7 @@ extern NSString *keySubTrackSrtFileURL;
- (void)addAllTracks
{
- while (self.countOfTracks)
- {
- [self removeObjectFromTracksAtIndex:0];
- }
+ [self removeTracksAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.tracks.count)]];
// Add the remainings tracks
for (NSUInteger idx = 1; idx < self.sourceTracksArray.count; idx++) {
@@ -202,10 +204,7 @@ extern NSString *keySubTrackSrtFileURL;
- (void)removeAll
{
- while (self.countOfTracks)
- {
- [self removeObjectFromTracksAtIndex:0];
- }
+ [self removeTracksAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.tracks.count)]];
[self addNoneTrack];
}
@@ -217,9 +216,11 @@ extern NSString *keySubTrackSrtFileURL;
- (void)addSrtTrackFromURL:(NSURL *)srtURL
{
// Create a new entry for the subtitle source array so it shows up in our subtitle source list
- [self.sourceTracks addObject:@{keySubTrackName: srtURL.lastPathComponent,
+ NSMutableArray *sourceTrack = [self.sourceTracks mutableCopy];
+ [sourceTrack addObject:@{keySubTrackName: srtURL.lastPathComponent,
keySubTrackType: @(SRTSUB),
keySubTrackSrtFileURL: srtURL}];
+ self.sourceTracks = sourceTrack;
HBSubtitlesTrack *track = [self trackFromSourceTrackIndex:self.sourceTracksArray.count - 1];
[self insertObject:track inTracksAtIndex:[self countOfTracks] - 1];
}
@@ -284,14 +285,12 @@ extern NSString *keySubTrackSrtFileURL;
- (void)addDefaultTracksFromJobSettings:(NSDictionary *)settings
{
- NSArray<NSDictionary<NSString *, id> *> *tracks = settings[@"Subtitle"][@"SubtitleList"];
+ NSMutableArray<HBSubtitlesTrack *> *tracks = [NSMutableArray array];
+ NSArray<NSDictionary<NSString *, id> *> *settingsTracks = settings[@"Subtitle"][@"SubtitleList"];
NSDictionary<NSString *, id> *search = settings[@"Subtitle"][@"Search"];
// Reinitialize the configured list of audio tracks
- while (self.countOfTracks)
- {
- [self removeObjectFromTracksAtIndex:0];
- }
+ [self removeTracksAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.tracks.count)]];
// Add the foreign audio search pass
if ([search[@"Enable"] boolValue])
@@ -301,20 +300,22 @@ extern NSString *keySubTrackSrtFileURL;
track.burnedIn = [search[@"Burn"] boolValue];
track.forcedOnly = [search[@"Forced"] boolValue];
- [self addTrack:track];
+ [tracks addObject:track];
}
// Add the tracks
- for (NSDictionary *trackDict in tracks)
+ for (NSDictionary *trackDict in settingsTracks)
{
HBSubtitlesTrack *track = [self trackFromSourceTrackIndex:[trackDict[@"Track"] unsignedIntegerValue] + 2];
track.burnedIn = [trackDict[@"Burn"] boolValue];
track.forcedOnly = [trackDict[@"Forced"] boolValue];
- [self addTrack:track];
+ [tracks addObject:track];
}
+ [self insertTracks:tracks atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, tracks.count)]];
+
// Add an None item
[self addNoneTrack];
}
@@ -488,6 +489,12 @@ extern NSString *keySubTrackSrtFileURL;
[self.tracks insertObject:track atIndex:index];
}
+- (void)insertTracks:(NSArray<HBSubtitlesTrack *> *)array atIndexes:(NSIndexSet *)indexes
+{
+ [[self.undo prepareWithInvocationTarget:self] removeTracksAtIndexes:indexes];
+ [self.tracks insertObjects:array atIndexes:indexes];
+}
+
- (void)removeObjectFromTracksAtIndex:(NSUInteger)index
{
HBSubtitlesTrack *track = self.tracks[index];
@@ -495,4 +502,12 @@ extern NSString *keySubTrackSrtFileURL;
[self.tracks removeObjectAtIndex:index];
}
+- (void)removeTracksAtIndexes:(NSIndexSet *)indexes
+{
+ NSArray<HBSubtitlesTrack *> *tracks = [self.tracks objectsAtIndexes:indexes];
+ [[self.undo prepareWithInvocationTarget:self] insertTracks:tracks atIndexes:indexes];
+ [self.tracks removeObjectsAtIndexes:indexes];
+}
+
+
@end