summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2015-10-24 10:50:27 +0200
committerDamiano Galassi <[email protected]>2015-10-24 10:50:27 +0200
commit7e32b94a04e073aa94b51811200b664a5001f983 (patch)
tree8b328e88162db42ee1d9237a61ea2c97f4c0183d /macosx
parent97e6ad384476b97cbc36bfb0a81ac179b1fc7d70 (diff)
MacGui: add redo/undo supports to the audio part of HBJob.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/English.lproj/Audio.xib13
-rw-r--r--macosx/HBAudio.h5
-rw-r--r--macosx/HBAudio.m57
-rw-r--r--macosx/HBAudioController.m19
-rw-r--r--macosx/HBAudioDefaults.h7
-rw-r--r--macosx/HBAudioDefaults.m16
-rw-r--r--macosx/HBAudioDefaultsController.m13
-rw-r--r--macosx/HBAudioTrack.h39
-rw-r--r--macosx/HBAudioTrack.m210
-rw-r--r--macosx/HBJob+HBJobConversion.m6
-rw-r--r--macosx/HBJob+UIAdditions.m4
-rw-r--r--macosx/HBJob.m4
-rw-r--r--macosx/HBLanguagesSelection.h14
-rw-r--r--macosx/HBLanguagesSelection.m26
-rw-r--r--macosx/HandBrake.xcodeproj/project.pbxproj4
15 files changed, 295 insertions, 142 deletions
diff --git a/macosx/English.lproj/Audio.xib b/macosx/English.lproj/Audio.xib
index c7b5b00a7..feae40baf 100644
--- a/macosx/English.lproj/Audio.xib
+++ b/macosx/English.lproj/Audio.xib
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8164.2" systemVersion="15A225f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<development version="6300" identifier="xcode"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8164.2"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9059"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="HBAudioController">
@@ -175,12 +175,12 @@
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
- <popUpButtonCell key="dataCell" type="push" title="Pop Up" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" arrowPosition="arrowAtCenter" preferredEdge="maxY" selectedItem="ScK-9X-Gvn" id="YmG-Il-WGI">
+ <popUpButtonCell key="dataCell" type="push" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" arrowPosition="arrowAtCenter" preferredEdge="maxY" id="YmG-Il-WGI">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<menu key="menu" title="OtherViews" id="cPd-Hx-eHs">
<items>
- <menuItem title="Pop Up" state="on" id="ScK-9X-Gvn"/>
+ <menuItem title="Pop Up" id="ScK-9X-Gvn"/>
</items>
</menu>
</popUpButtonCell>
@@ -284,12 +284,12 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<animations/>
- <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="1Fp-Pd-fdH">
+ <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="1Fp-Pd-fdH">
<rect key="frame" x="-100" y="-100" width="685" height="15"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
</scroller>
- <scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="5LV-7H-phB">
+ <scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="5LV-7H-phB">
<rect key="frame" x="-100" y="-100" width="15" height="206"/>
<autoresizingMask key="autoresizingMask"/>
<animations/>
@@ -368,6 +368,7 @@
</popUpButton>
</subviews>
<animations/>
+ <point key="canvasLocation" x="145" y="440"/>
</view>
<userDefaultsController representsSharedInstance="YES" id="ee3-5O-TtC"/>
<menu id="hyy-qd-qpe">
diff --git a/macosx/HBAudio.h b/macosx/HBAudio.h
index af37f4aa8..045970e6a 100644
--- a/macosx/HBAudio.h
+++ b/macosx/HBAudio.h
@@ -20,7 +20,7 @@ extern NSString *HBAudioChangedNotification;
- (instancetype)initWithTitle:(HBTitle *)title;
@property (nonatomic, readonly) NSMutableArray *tracks;
-@property (nonatomic, readonly) HBAudioDefaults *defaults;
+@property (nonatomic, readwrite) HBAudioDefaults *defaults;
- (void)addAllTracks;
- (void)removeAll;
@@ -30,7 +30,8 @@ extern NSString *HBAudioChangedNotification;
- (void)settingTrackToNone:(HBAudioTrack *)newNoneTrack;
- (void)switchingTrackFromNone:(nullable HBAudioTrack *)noLongerNoneTrack;
-- (void)containerChanged:(int)container;
+@property (nonatomic, readwrite) int container;
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
@end
diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m
index 5e66ef21b..f1b6ce854 100644
--- a/macosx/HBAudio.m
+++ b/macosx/HBAudio.m
@@ -22,8 +22,6 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
@property (nonatomic, readonly, strong) NSDictionary *noneTrack;
@property (nonatomic, readonly, strong) NSArray *masterTrackArray; // the master list of audio tracks from the title
-@property (nonatomic, readwrite) int container; // initially is the default HB_MUX_MP4
-
@end
@implementation HBAudio
@@ -92,8 +90,9 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
[newAudio setDataSource:self];
[newAudio setDelegate:self];
[self insertObject: newAudio inTracksAtIndex: [self countOfTracks]];
- [newAudio setVideoContainerTag:@(self.container)];
+ [newAudio setContainer:self.container];
[newAudio setTrackFromIndex: (int)trackIndex];
+ [newAudio setUndo:self.undo];
const char *name = hb_audio_encoder_get_name(preset.encoder);
NSString *audioEncoder = nil;
@@ -148,8 +147,8 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
{
[newAudio setBitRateFromName: [NSString stringWithFormat:@"%d", preset.bitRate]];
}
- [newAudio setDrc: @(preset.drc)];
- [newAudio setGain: @(preset.gain)];
+ [newAudio setDrc:preset.drc];
+ [newAudio setGain:preset.gain];
}
else
{
@@ -272,11 +271,10 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
HBAudioTrack *newAudio = [[HBAudioTrack alloc] init];
[newAudio setDataSource:self];
[newAudio setDelegate:self];
- [self insertObject: newAudio inTracksAtIndex: [self countOfTracks]];
- [newAudio setVideoContainerTag:@(self.container)];
+ [self insertObject:newAudio inTracksAtIndex:[self countOfTracks]];
+ [newAudio setContainer:self.container];
[newAudio setTrack: self.noneTrack];
- [newAudio setDrc: @0.0f];
- [newAudio setGain: @0.0f];
+ [newAudio setUndo:self.undo];
}
#pragma mark -
@@ -322,19 +320,41 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
}
// This gets called whenever the video container changes.
-- (void)containerChanged:(int)container
+- (void)setContainer:(int)container
{
- self.container = container;
+ _container = container;
- // Update each of the instances because this value influences possible settings.
- for (HBAudioTrack *audioObject in self.tracks)
+ if (!(self.undo.isUndoing || self.undo.isRedoing))
{
- [audioObject setVideoContainerTag:@(container)];
+ // Update each of the instances because this value influences possible settings.
+ for (HBAudioTrack *audioObject in self.tracks)
+ {
+ audioObject.container = container;
+ }
+
+ // Update the Auto Passthru Fallback Codec Popup
+ // lets get the tag of the currently selected item first so we might reset it later
+ [self.defaults validateEncoderFallbackForVideoContainer:container];
}
+}
- // Update the Auto Passthru Fallback Codec Popup
- // lets get the tag of the currently selected item first so we might reset it later
- [self.defaults validateEncoderFallbackForVideoContainer:container];
+- (void)setUndo:(NSUndoManager *)undo
+{
+ _undo = undo;
+ for (HBAudioTrack *track in self.tracks)
+ {
+ track.undo = undo;
+ }
+ self.defaults.undo = undo;
+}
+
+- (void)setDefaults:(HBAudioDefaults *)defaults
+{
+ if (defaults != _defaults)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setDefaults:_defaults];
+ }
+ _defaults = defaults;
}
- (void)mixdownChanged
@@ -441,11 +461,14 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
- (void)insertObject:(HBAudioTrack *)track inTracksAtIndex:(NSUInteger)index;
{
+ [[self.undo prepareWithInvocationTarget:self] removeObjectFromTracksAtIndex:index];
[self.tracks insertObject:track atIndex:index];
}
- (void)removeObjectFromTracksAtIndex:(NSUInteger)index
{
+ HBAudioTrack *track = self.tracks[index];
+ [[self.undo prepareWithInvocationTarget:self] insertObject:track inTracksAtIndex:index];
[self.tracks removeObjectAtIndex:index];
}
diff --git a/macosx/HBAudioController.m b/macosx/HBAudioController.m
index ca051c9da..5baf50a06 100644
--- a/macosx/HBAudioController.m
+++ b/macosx/HBAudioController.m
@@ -7,6 +7,7 @@
#import "HBAudioController.h"
#import "HBAudio.h"
+#import "HBAudioDefaults.h"
#import "HBAudioDefaultsController.h"
@interface HBAudioController ()
@@ -42,17 +43,27 @@
- (IBAction)showSettingsSheet:(id)sender
{
- self.defaultsController = [[HBAudioDefaultsController alloc] initWithSettings:self.audio.defaults];
+ HBAudioDefaults *defaults = [self.audio.defaults copy];
+ self.defaultsController = [[HBAudioDefaultsController alloc] initWithSettings:defaults];
[NSApp beginSheet:self.defaultsController.window
modalForWindow:self.view.window
modalDelegate:self
- didEndSelector:@selector(sheetDidEnd)
- contextInfo:NULL];
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:(void *)CFBridgingRetain(defaults)];
}
-- (void)sheetDidEnd
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
+ HBAudioDefaults *defaults = (HBAudioDefaults *)CFBridgingRelease(contextInfo);
+
+ // If things changed, do this ugly
+ // operation to group the changes for the undo manager.
+ if (returnCode)
+ {
+ defaults.undo = self.audio.defaults.undo;
+ self.audio.defaults = defaults;
+ }
self.defaultsController = nil;
}
diff --git a/macosx/HBAudioDefaults.h b/macosx/HBAudioDefaults.h
index fce26045d..85b60fb66 100644
--- a/macosx/HBAudioDefaults.h
+++ b/macosx/HBAudioDefaults.h
@@ -9,6 +9,8 @@
NS_ASSUME_NONNULL_BEGIN
+@class HBAudioTrackPreset;
+
typedef NS_ENUM(NSUInteger, HBAudioTrackSelectionBehavior) {
HBAudioTrackSelectionBehaviorNone,
HBAudioTrackSelectionBehaviorFirst,
@@ -22,9 +24,8 @@ typedef NS_ENUM(NSUInteger, HBAudioTrackSelectionBehavior) {
@interface HBAudioDefaults : NSObject <NSSecureCoding, NSCopying, HBPresetCoding>
@property (nonatomic, readwrite) HBAudioTrackSelectionBehavior trackSelectionBehavior;
-@property (nonatomic, readwrite, strong) NSMutableArray *trackSelectionLanguages;
-
-@property (nonatomic, readwrite, strong) NSMutableArray *tracksArray;
+@property (nonatomic, readwrite, strong) NSMutableArray<NSString *> *trackSelectionLanguages;
+@property (nonatomic, readwrite, strong) NSMutableArray<HBAudioTrackPreset *> *tracksArray;
/**
* Adds a new track preset.
diff --git a/macosx/HBAudioDefaults.m b/macosx/HBAudioDefaults.m
index 4905afa8a..dc43a0372 100644
--- a/macosx/HBAudioDefaults.m
+++ b/macosx/HBAudioDefaults.m
@@ -49,6 +49,15 @@
_trackSelectionBehavior = trackSelectionBehavior;
}
+- (void)setTrackSelectionLanguages:(NSMutableArray<NSString *> *)trackSelectionLanguages
+{
+ if (trackSelectionLanguages != _trackSelectionLanguages)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setTrackSelectionLanguages:_trackSelectionLanguages];
+ }
+ _trackSelectionLanguages = trackSelectionLanguages;
+}
+
- (void)setAllowAACPassthru:(BOOL)allowAACPassthru
{
if (allowAACPassthru != _allowAACPassthru)
@@ -276,7 +285,10 @@
self.encoderFallback = hb_audio_encoder_get_from_name([preset[@"AudioEncoderFallback"] UTF8String]);
}
- [self.tracksArray removeAllObjects];
+ while ([self countOfTracksArray])
+ {
+ [self removeObjectFromTracksArrayAtIndex:0];
+ }
for (NSDictionary *track in preset[@"AudioList"])
{
@@ -303,7 +315,7 @@
newTrack.drc = [track[@"AudioTrackDRCSlider"] doubleValue];
newTrack.gain = [track[@"AudioTrackGainSlider"] doubleValue];
- [self.tracksArray addObject:newTrack];
+ [self insertObject:newTrack inTracksArrayAtIndex:[self countOfTracksArray]];
}
}
diff --git a/macosx/HBAudioDefaultsController.m b/macosx/HBAudioDefaultsController.m
index 413fba727..b7c975016 100644
--- a/macosx/HBAudioDefaultsController.m
+++ b/macosx/HBAudioDefaultsController.m
@@ -33,6 +33,7 @@ static void *HBAudioDefaultsContex = &HBAudioDefaultsContex;
_settings = settings;
_languagesList = [[HBLanguagesSelection alloc] initWithLanguages:_settings.trackSelectionLanguages];
_settings.undo = self.window.undoManager;
+ _languagesList.undo = self.window.undoManager;
}
return self;
}
@@ -84,16 +85,16 @@ static void *HBAudioDefaultsContex = &HBAudioDefaultsContex;
- (IBAction)done:(id)sender
{
- [[self window] orderOut:nil];
- [NSApp endSheet:[self window]];
-
- [self.settings.trackSelectionLanguages removeAllObjects];
- [self.settings.trackSelectionLanguages addObjectsFromArray:self.languagesList.selectedLanguages];
+ [self.window orderOut:nil];
+ if (self.window.undoManager.canUndo)
+ {
+ self.settings.trackSelectionLanguages = [self.languagesList.selectedLanguages mutableCopy];
+ }
+ [NSApp endSheet:self.window returnCode:self.window.undoManager.canUndo];
}
- (void)dealloc
{
-
@try {
[self removeObserver:self forKeyPath:@"tableController.showSelectedOnly"];
} @catch (NSException * __unused exception) {}
diff --git a/macosx/HBAudioTrack.h b/macosx/HBAudioTrack.h
index e1333678d..7bf5c8ecc 100644
--- a/macosx/HBAudioTrack.h
+++ b/macosx/HBAudioTrack.h
@@ -6,9 +6,7 @@
#import <Foundation/Foundation.h>
-@class HBAudio;
-@protocol HBAudioTrackDataSource;
-@protocol HBAudioTrackDelegate;
+@class HBAudioTrack;
NS_ASSUME_NONNULL_BEGIN
@@ -33,6 +31,17 @@ extern NSString *keyAudioMixdown;
extern NSString *keyAudioSamplerate;
extern NSString *keyAudioBitrate;
+@protocol HBAudioTrackDataSource <NSObject>
+- (NSDictionary *)noneTrack;
+- (NSArray *)masterTrackArray;
+@end
+
+@protocol HBAudioTrackDelegate <NSObject>
+- (void)settingTrackToNone:(HBAudioTrack *)newNoneTrack;
+- (void)switchingTrackFromNone:(HBAudioTrack *)noLongerNoneTrack;
+- (void)mixdownChanged;
+@end
+
@interface HBAudioTrack : NSObject <NSSecureCoding, NSCopying>
@property (nonatomic, strong) NSDictionary *track;
@@ -40,16 +49,17 @@ extern NSString *keyAudioBitrate;
@property (nonatomic, strong) NSDictionary *mixdown;
@property (nonatomic, strong) NSDictionary *sampleRate;
@property (nonatomic, strong) NSDictionary *bitRate;
-@property (nonatomic, strong) NSNumber *drc;
-@property (nonatomic, strong) NSNumber *gain;
-@property (nonatomic, strong) NSNumber *videoContainerTag;
+@property (nonatomic) double drc;
+@property (nonatomic) double gain;
+@property (nonatomic) int container;
+
@property (nonatomic, weak, nullable) id<HBAudioTrackDataSource> dataSource;
@property (nonatomic, weak, nullable) id<HBAudioTrackDelegate> delegate;
-@property (nonatomic, strong) NSMutableArray *codecs;
-@property (nonatomic, strong) NSMutableArray *mixdowns;
+@property (nonatomic, readonly) NSArray *codecs;
+@property (nonatomic, readonly) NSArray *mixdowns;
@property (nonatomic, readonly) NSArray *sampleRates;
-@property (nonatomic, strong) NSArray *bitRates;
+@property (nonatomic, readonly) NSArray *bitRates;
@property (nonatomic, readonly) BOOL enabled;
- (void) setTrackFromIndex: (int) aValue;
@@ -58,17 +68,8 @@ extern NSString *keyAudioBitrate;
- (void) setSampleRateFromName: (NSString *) aValue;
- (void) setBitRateFromName: (NSString *) aValue;
-@end
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
-@protocol HBAudioTrackDataSource <NSObject>
-- (NSDictionary *)noneTrack;
-- (NSArray *)masterTrackArray;
-@end
-
-@protocol HBAudioTrackDelegate <NSObject>
-- (void)settingTrackToNone:(HBAudioTrack *)newNoneTrack;
-- (void)switchingTrackFromNone:(HBAudioTrack *)noLongerNoneTrack;
-- (void)mixdownChanged;
@end
NS_ASSUME_NONNULL_END
diff --git a/macosx/HBAudioTrack.m b/macosx/HBAudioTrack.m
index ed51df1af..a30f7eafb 100644
--- a/macosx/HBAudioTrack.m
+++ b/macosx/HBAudioTrack.m
@@ -41,7 +41,6 @@ static NSMutableArray *masterBitRateArray = nil;
@end
@implementation NSArray (HBAudioSupport)
- (NSDictionary *) dictionaryWithObject: (id) anObject matchingKey: (NSString *) aKey reverse: (BOOL) reverse
-
{
NSDictionary *retval = nil;
NSEnumerator *enumerator = reverse ? [self reverseObjectEnumerator] : [self objectEnumerator];
@@ -68,13 +67,20 @@ static NSMutableArray *masterBitRateArray = nil;
@end
+@interface HBAudioTrack ()
+
+@property (nonatomic, readwrite) NSArray *codecs;
+@property (nonatomic, readwrite) NSArray *mixdowns;
+@property (nonatomic, readwrite) NSArray *bitRates;
+
+@end
+
@implementation HBAudioTrack
#pragma mark -
#pragma mark Object Setup
-+ (void) initialize
-
++ (void)initialize
{
if ([HBAudioTrack class] == self)
{
@@ -123,7 +129,6 @@ static NSMutableArray *masterBitRateArray = nil;
// Ensure the list of codecs is accurate
// Update the current value of codec based on the revised list
- (void) updateCodecs
-
{
NSMutableArray *permittedCodecs = [NSMutableArray array];
NSUInteger count = [masterCodecArray count];
@@ -139,8 +144,7 @@ static NSMutableArray *masterBitRateArray = nil;
dict = masterCodecArray[i];
// First make sure only codecs permitted by the container are here
- goodToAdd = !!([dict[keyAudioSupportedMuxers] intValue] &
- [self.videoContainerTag intValue]);
+ goodToAdd = !!([dict[keyAudioSupportedMuxers] intValue] & self.container);
// Now we make sure if DTS or AC3 is not available in the track it is not put in the codec list, but in a general way
if ([dict[keyAudioMustMatchTrack] boolValue])
@@ -175,8 +179,7 @@ static NSMutableArray *masterBitRateArray = nil;
}
}
-- (void) updateMixdowns: (BOOL) shouldSetDefault
-
+- (void)updateMixdowns:(BOOL)shouldSetDefault
{
NSMutableArray *permittedMixdowns = [NSMutableArray array];
NSDictionary *dict;
@@ -235,8 +238,7 @@ static NSMutableArray *masterBitRateArray = nil;
}
}
-- (void) updateBitRates: (BOOL) shouldSetDefault
-
+- (void)updateBitRates:(BOOL)shouldSetDefault
{
NSMutableArray *permittedBitRates = [NSMutableArray array];
NSDictionary *dict;
@@ -320,7 +322,7 @@ static NSMutableArray *masterBitRateArray = nil;
#pragma mark -
#pragma mark Accessors
-- (NSArray *) sampleRates
+- (NSArray *)sampleRates
{
NSMutableArray *samplerates = [[NSMutableArray alloc] init];
@@ -350,17 +352,29 @@ static NSMutableArray *masterBitRateArray = nil;
#pragma mark -
#pragma mark Setters
-- (void)setVideoContainerTag:(NSNumber *)videoContainerTag
+- (void)setContainer:(int)container
{
- _videoContainerTag = videoContainerTag;
- [self updateCodecs];
+ if (container != _container)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setContainer:_container];
+ }
+ _container = container;
+
+ if (!(self.undo.isUndoing || self.undo.isRedoing))
+ {
+ [self updateCodecs];
+ }
}
- (void)setTrack:(NSDictionary *)track
{
+ if (track != _track)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setTrack:_track];
+ }
NSDictionary *oldValue = _track;
_track = track;
- if (nil != _track)
+ if (nil != _track && !(self.undo.isUndoing || self.undo.isRedoing))
{
[self updateCodecs];
[self updateMixdowns: YES];
@@ -381,41 +395,89 @@ static NSMutableArray *masterBitRateArray = nil;
- (void)setCodec:(NSDictionary *)codec
{
+ if (codec != _codec)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setCodec:_codec];
+ }
_codec = codec;
- [self validateSamplerate];
- [self updateMixdowns: YES];
- [self updateBitRates: YES];
+
+ if (!(self.undo.isUndoing || self.undo.isRedoing))
+ {
+ [self validateSamplerate];
+ [self updateMixdowns:YES];
+ [self updateBitRates:YES];
+ }
}
- (void)setMixdown:(NSDictionary *)mixdown
{
+ if (mixdown != _mixdown)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setMixdown:_mixdown];
+ }
_mixdown = mixdown;
- [self updateBitRates: YES];
- [self.delegate mixdownChanged];
+
+ if (!(self.undo.isUndoing || self.undo.isRedoing))
+ {
+ [self updateBitRates:YES];
+ [self.delegate mixdownChanged];
+ }
}
- (void)setSampleRate:(NSDictionary *)sampleRate
{
+ if (sampleRate != _sampleRate)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setSampleRate:_sampleRate];
+ }
_sampleRate = sampleRate;
- [self updateBitRates: NO];
+
+ if (!(self.undo.isUndoing || self.undo.isRedoing))
+ {
+ [self updateBitRates: NO];
+ }
+}
+
+- (void)setBitRate:(NSDictionary *)bitRate
+{
+ if (bitRate != _bitRate)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setBitRate:_bitRate];
+ }
+ _bitRate = bitRate;
+}
+
+- (void)setDrc:(double)drc
+{
+ if (drc != _drc)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setDrc:_drc];
+ }
+ _drc = drc;
+}
+
+- (void)setGain:(double)gain
+{
+ if (gain != _gain)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setGain:_gain];
+ }
+ _gain = gain;
}
#pragma mark -
#pragma mark Special Setters
-- (void) setTrackFromIndex: (int) aValue
-
+- (void)setTrackFromIndex:(int)aValue
{
self.track = [self.dataSource.masterTrackArray dictionaryWithObject: @(aValue)
matchingKey: keyAudioTrackIndex];
}
// This returns whether it is able to set the actual codec desired.
-- (BOOL) setCodecFromName: (NSString *) aValue
-
+- (BOOL)setCodecFromName:(NSString *)aValue
{
NSDictionary *dict = [self.codecs dictionaryWithObject: aValue matchingKey: keyAudioCodecName];
-
if (nil != dict)
{
self.codec = dict;
@@ -423,39 +485,59 @@ static NSMutableArray *masterBitRateArray = nil;
return (nil != dict);
}
-- (void) setMixdownFromName: (NSString *) aValue
-
+- (void)setMixdownFromName:(NSString *)aValue
{
NSDictionary *dict = [self.mixdowns dictionaryWithObject: aValue matchingKey: keyAudioMixdownName];
-
if (nil != dict)
{
self.mixdown = dict;
}
}
-- (void) setSampleRateFromName: (NSString *) aValue
-
+- (void)setSampleRateFromName:(NSString *)aValue
{
NSDictionary *dict = [self.sampleRates dictionaryWithObject: aValue matchingKey: keyAudioSampleRateName];
-
if (nil != dict)
{
self.sampleRate = dict;
}
}
-- (void) setBitRateFromName: (NSString *) aValue
-
+- (void)setBitRateFromName:(NSString *)aValue
{
NSDictionary *dict = [self.bitRates dictionaryWithObject: aValue matchingKey: keyAudioBitrateName];
-
if (nil != dict)
{
self.bitRate = dict;
}
}
+- (void)setCodecs:(NSArray *)codecs
+{
+ if (codecs != _codecs)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setCodecs:_codecs];
+ }
+ _codecs = codecs;
+}
+
+- (void)setMixdowns:(NSArray *)mixdowns
+{
+ if (mixdowns != _mixdowns)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setMixdowns:_mixdowns];
+ }
+ _mixdowns = mixdowns;
+}
+
+- (void)setBitRates:(NSArray *)bitRates
+{
+ if (bitRates != _bitRates)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setBitRates:_bitRates];
+ }
+ _bitRates = bitRates;
+}
#pragma mark -
#pragma mark Validation
@@ -484,14 +566,12 @@ static NSMutableArray *masterBitRateArray = nil;
#pragma mark -
#pragma mark Bindings Support
-- (BOOL) enabled
-
+- (BOOL)enabled
{
return (nil != self.track) ? (![self.track isEqual: self.dataSource.noneTrack]) : NO;
}
-- (BOOL) mixdownEnabled
-
+- (BOOL)mixdownEnabled
{
BOOL retval = self.enabled;
@@ -507,8 +587,7 @@ static NSMutableArray *masterBitRateArray = nil;
return retval;
}
-- (BOOL) bitrateEnabled
-
+- (BOOL)bitrateEnabled
{
BOOL retval = self.enabled;
@@ -524,8 +603,7 @@ static NSMutableArray *masterBitRateArray = nil;
return retval;
}
-- (BOOL) DRCEnabled
-
+- (BOOL)DRCEnabled
{
BOOL retval = self.enabled;
@@ -542,8 +620,7 @@ static NSMutableArray *masterBitRateArray = nil;
return retval;
}
-- (BOOL) PassThruDisabled
-
+- (BOOL)PassThruDisabled
{
BOOL retval = self.enabled;
@@ -558,30 +635,29 @@ static NSMutableArray *masterBitRateArray = nil;
return retval;
}
-+ (NSSet *) keyPathsForValuesAffectingValueForKey: (NSString *) key
-
++ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
{
NSSet *retval = nil;
- if ([key isEqualToString: @"enabled"])
+ if ([key isEqualToString:@"enabled"])
{
- retval = [NSSet setWithObjects: @"track", nil];
+ retval = [NSSet setWithObjects:@"track", nil];
}
- else if ([key isEqualToString: @"PassThruDisabled"])
+ else if ([key isEqualToString:@"PassThruDisabled"])
{
- retval = [NSSet setWithObjects: @"track", @"codec", nil];
+ retval = [NSSet setWithObjects:@"track", @"codec", nil];
}
- else if ([key isEqualToString: @"DRCEnabled"])
+ else if ([key isEqualToString:@"DRCEnabled"])
{
- retval = [NSSet setWithObjects: @"track", @"codec", nil];
+ retval = [NSSet setWithObjects:@"track", @"codec", nil];
}
- else if ([key isEqualToString: @"bitrateEnabled"])
+ else if ([key isEqualToString:@"bitrateEnabled"])
{
- retval = [NSSet setWithObjects: @"track", @"codec", nil];
+ retval = [NSSet setWithObjects:@"track", @"codec", nil];
}
- else if ([key isEqualToString: @"mixdownEnabled"])
+ else if ([key isEqualToString:@"mixdownEnabled"])
{
- retval = [NSSet setWithObjects: @"track", @"mixdown", nil];
+ retval = [NSSet setWithObjects:@"track", @"mixdown", nil];
}
return retval;
}
@@ -599,9 +675,9 @@ static NSMutableArray *masterBitRateArray = nil;
copy->_mixdown = [_mixdown copy];
copy->_sampleRate = [_sampleRate copy];
copy->_bitRate = [_bitRate copy];
- copy->_drc = [_drc copy];
- copy->_gain = [_gain copy];
- copy->_videoContainerTag = [_videoContainerTag copy];
+ copy->_drc = _drc;
+ copy->_gain = _gain;
+ copy->_container = _container;
copy->_codecs = [_codecs copy];
copy->_mixdowns = [_mixdowns copy];
@@ -620,16 +696,16 @@ static NSMutableArray *masterBitRateArray = nil;
- (void)encodeWithCoder:(NSCoder *)coder
{
- [coder encodeInt:1 forKey:@"HBAudioTrackVersion"];
+ [coder encodeInt:2 forKey:@"HBAudioTrackVersion"];
encodeObject(_track);
encodeObject(_codec);
encodeObject(_mixdown);
encodeObject(_sampleRate);
encodeObject(_bitRate);
- encodeObject(_drc);
- encodeObject(_gain);
- encodeObject(_videoContainerTag);
+ encodeDouble(_drc);
+ encodeDouble(_gain);
+ encodeInt(_container);
encodeObject(_codecs);
encodeObject(_mixdowns);
@@ -645,9 +721,9 @@ static NSMutableArray *masterBitRateArray = nil;
decodeObject(_mixdown, NSDictionary);
decodeObject(_sampleRate, NSDictionary);
decodeObject(_bitRate, NSDictionary);
- decodeObject(_drc, NSNumber);
- decodeObject(_gain, NSNumber);
- decodeObject(_videoContainerTag, NSNumber);
+ decodeDouble(_drc);
+ decodeDouble(_gain);
+ decodeInt(_container);
decodeObject(_codecs, NSMutableArray);
decodeObject(_mixdowns, NSMutableArray);
diff --git a/macosx/HBJob+HBJobConversion.m b/macosx/HBJob+HBJobConversion.m
index 4ed4e4390..a07ca98ff 100644
--- a/macosx/HBJob+HBJobConversion.m
+++ b/macosx/HBJob+HBJobConversion.m
@@ -226,7 +226,7 @@
{
if (subTrack.isEnabled)
{
- // Shift the source index by 2 to componsate
+ // Subtract 2 to the source indexes to compensate
// for the none and foreign audio search tracks.
int sourceIdx = ((int)subTrack.sourceTrackIdx) - 2;
@@ -380,7 +380,7 @@
// output is not passthru so apply gain
if (!([[audioTrack codec][keyAudioCodec] intValue] & HB_ACODEC_PASS_FLAG))
{
- audio->out.gain = [audioTrack.gain doubleValue];
+ audio->out.gain = audioTrack.gain;
}
else
{
@@ -392,7 +392,7 @@
[audioTrack.track[keyAudioInputCodecParam] intValue],
[audioTrack.codec[keyAudioCodec] intValue]))
{
- audio->out.dynamic_range_compression = [audioTrack.drc doubleValue];
+ audio->out.dynamic_range_compression = audioTrack.drc;
}
else
{
diff --git a/macosx/HBJob+UIAdditions.m b/macosx/HBJob+UIAdditions.m
index 0515ec99b..65ec4ced2 100644
--- a/macosx/HBJob+UIAdditions.m
+++ b/macosx/HBJob+UIAdditions.m
@@ -183,8 +183,8 @@ static NSDictionary *shortHeightAttr;
if (audioTrack.enabled)
{
audioCodecSummary = [NSString stringWithFormat: @"%@", audioTrack.codec[keyAudioCodecName]];
- NSNumber *drc = audioTrack.drc;
- NSNumber *gain = audioTrack.gain;
+ NSNumber *drc = @(audioTrack.drc);
+ NSNumber *gain = @(audioTrack.gain);
NSString *detailString = [NSString stringWithFormat: @"%@ Encoder: %@ Mixdown: %@ SampleRate: %@(khz) Bitrate: %@(kbps), DRC: %@, Gain: %@",
audioTrack.track[keyAudioTrackName],
audioTrack.codec[keyAudioCodecName],
diff --git a/macosx/HBJob.m b/macosx/HBJob.m
index 8c7b2dc63..cbdbfbe15 100644
--- a/macosx/HBJob.m
+++ b/macosx/HBJob.m
@@ -95,7 +95,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
- (void)setUndo:(NSUndoManager *)undo
{
_undo = undo;
- [@[self.video, self.range, self.filters, self.picture, /*self.audio,*/ self.subtitles] makeObjectsPerformSelector:@selector(setUndo:)
+ [@[self.video, self.range, self.filters, self.picture, self.audio, self.subtitles] makeObjectsPerformSelector:@selector(setUndo:)
withObject:_undo];
[self.chapterTitles makeObjectsPerformSelector:@selector(setUndo:) withObject:_undo];
}
@@ -127,7 +127,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
_container = container;
- [self.audio containerChanged:container];
+ [self.audio setContainer:container];
[self.subtitles setContainer:container];
[self.video containerChanged];
diff --git a/macosx/HBLanguagesSelection.h b/macosx/HBLanguagesSelection.h
index b14d7d89a..0d57fba17 100644
--- a/macosx/HBLanguagesSelection.h
+++ b/macosx/HBLanguagesSelection.h
@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
+NS_ASSUME_NONNULL_BEGIN
+
/**
* A collection of KVO enabled model and controllers class
* used to populate the languages selection table view
@@ -21,6 +23,8 @@
@property (nonatomic, readonly) NSString *language;
@property (nonatomic, readonly) NSString *iso639_2;
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
+
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithLanguage:(NSString *)value iso639_2code:(NSString *)code NS_DESIGNATED_INITIALIZER;
@@ -31,10 +35,12 @@
*/
@interface HBLanguagesSelection : NSObject
-@property (nonatomic, readonly) NSMutableArray *languagesArray;
-@property (nonatomic, readonly) NSArray *selectedLanguages;
+@property (nonatomic, readonly) NSMutableArray<HBLang *> *languagesArray;
+@property (nonatomic, readonly) NSArray<NSString *> *selectedLanguages;
-- (instancetype)initWithLanguages:(NSArray *)languages NS_DESIGNATED_INITIALIZER;
+@property (nonatomic, readwrite, weak, nullable) NSUndoManager *undo;
+
+- (instancetype)initWithLanguages:(NSArray<NSString *> *)languages NS_DESIGNATED_INITIALIZER;
@end
@@ -56,3 +62,5 @@
@property (unsafe_unretained) IBOutlet NSTableView *tableView;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/macosx/HBLanguagesSelection.m b/macosx/HBLanguagesSelection.m
index d9d5a9b1e..65b06e862 100644
--- a/macosx/HBLanguagesSelection.m
+++ b/macosx/HBLanguagesSelection.m
@@ -36,6 +36,15 @@
return lang;
}
+- (void)setIsSelected:(BOOL)isSelected
+{
+ if (_isSelected != isSelected)
+ {
+ [[self.undo prepareWithInvocationTarget:self] setIsSelected:_isSelected];
+ }
+ _isSelected = isSelected;
+}
+
- (NSString *)description
{
return self.language;
@@ -47,17 +56,17 @@
- (instancetype)init
{
- self = [self initWithLanguages:nil];
+ self = [self initWithLanguages:@[]];
return self;
}
-- (instancetype)initWithLanguages:(NSArray *)languages
+- (instancetype)initWithLanguages:(NSArray<NSString *> *)languages
{
self = [super init];
if (self)
{
- NSMutableArray *internal = [[NSMutableArray alloc] init];
- NSMutableArray *selected = [[NSMutableArray alloc] init];
+ NSMutableArray<HBLang *> *internal = [[NSMutableArray alloc] init];
+ NSMutableArray<HBLang *> *selected = [[NSMutableArray alloc] init];
const iso639_lang_t *lang = lang_get_next(NULL);
for (lang = lang_get_next(lang); lang != NULL; lang = lang_get_next(lang))
@@ -116,6 +125,15 @@
return [selected copy];
}
+- (void)setUndo:(NSUndoManager *)undo
+{
+ _undo = undo;
+ for (HBLang *lang in self.languagesArray)
+ {
+ lang.undo = undo;
+ }
+}
+
@end
diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj
index 47f7f3cf1..5a037cd34 100644
--- a/macosx/HandBrake.xcodeproj/project.pbxproj
+++ b/macosx/HandBrake.xcodeproj/project.pbxproj
@@ -1144,10 +1144,10 @@
children = (
A93FD4731A62ABE800A6AC43 /* HBAudio.h */,
A93FD4741A62ABE800A6AC43 /* HBAudio.m */,
- A932E271198834130047D13E /* HBAudioDefaults.h */,
- A932E272198834130047D13E /* HBAudioDefaults.m */,
273F209114ADBE670021BE6D /* HBAudioTrack.h */,
273F209214ADBE670021BE6D /* HBAudioTrack.m */,
+ A932E271198834130047D13E /* HBAudioDefaults.h */,
+ A932E272198834130047D13E /* HBAudioDefaults.m */,
A90A0CAD1988D57200DA65CE /* HBAudioTrackPreset.h */,
A90A0CAE1988D57200DA65CE /* HBAudioTrackPreset.m */,
);