Changeset 466034a


Ignore:
Timestamp:
02/04/15 11:18:25 (16 months ago)
Author:
ritsuka <damiog@…>
Branches:
master
Children:
9d3c887
Parents:
d5775ea
Message:

MacGui: properly deregister the job observers, and refactor a bit the HBAudioTrack notification. Refactored HBPreviewController to take a single HBPreviewGenerator instance in input.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6869 b64f7644-9d1e-0410-96f1-a4d463321fa5

Location:
macosx
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • macosx/HBAudio.h

    rc81e2df r466034a  
    1212@class HBAudioDefaults;
    1313
    14 extern NSString *HBMixdownChangedNotification;
     14extern NSString *HBAudioChangedNotification;
    1515
    1616@interface HBAudio : NSObject <NSCoding, NSCopying, HBPresetCoding>
  • macosx/HBAudio.m

    rc81e2df r466034a  
    1616#include "hb.h"
    1717
    18 NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification";
    19 
    20 @interface HBAudio () <HBAudioTrackDataSource>
     18NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
     19
     20@interface HBAudio () <HBAudioTrackDataSource, HBAudioTrackDelegate>
    2121
    2222@property (nonatomic, readonly) NSDictionary *noneTrack;
     
    4848        _masterTrackArray = [sourceTracks copy];
    4949
    50         [self switchingTrackFromNone: nil]; // this ensures there is a None track at the end of the lis
     50        [self switchingTrackFromNone: nil]; // this ensures there is a None track at the end of the list
    5151    }
    5252    return self;
     
    108108        HBAudioTrack *newAudio = [[HBAudioTrack alloc] init];
    109109        [newAudio setDataSource:self];
     110        [newAudio setDelegate:self];
    110111        [self insertObject: newAudio inTracksAtIndex: [self countOfTracks]];
    111112        [newAudio setVideoContainerTag:@(self.container)];
     
    290291    HBAudioTrack *newAudio = [[HBAudioTrack alloc] init];
    291292    [newAudio setDataSource:self];
     293    [newAudio setDelegate:self];
    292294    [self insertObject: newAudio inTracksAtIndex: [self countOfTracks]];
    293295    [newAudio setVideoContainerTag:@(self.container)];
     
    356358}
    357359
     360- (void)mixdownChanged
     361{
     362    [[NSNotificationCenter defaultCenter] postNotificationName: HBAudioChangedNotification object: self];
     363}
     364
    358365#pragma mark - NSCopying
    359366
     
    375382                HBAudioTrack *trackCopy = [obj copy];
    376383                trackCopy.dataSource = copy;
     384                trackCopy.delegate = copy;
    377385                [copy->_tracks addObject:[trackCopy autorelease]];
    378386            }
     
    413421    {
    414422        track.dataSource = self;
     423        track.delegate = self;
    415424    }
    416425
  • macosx/HBAudioTrack.h

    rc81e2df r466034a  
    99@class HBAudio;
    1010@protocol HBAudioTrackDataSource;
     11@protocol HBAudioTrackDelegate;
    1112
    1213/**
     
    4243@property (nonatomic, retain) NSNumber *videoContainerTag;
    4344@property (nonatomic, assign) id<HBAudioTrackDataSource> dataSource;
     45@property (nonatomic, assign) id<HBAudioTrackDelegate> delegate;
    4446
    4547@property (nonatomic, retain) NSMutableArray *codecs;
     
    6062- (NSDictionary *)noneTrack;
    6163- (NSArray *)masterTrackArray;
     64@end
    6265
     66@protocol HBAudioTrackDelegate <NSObject>
    6367- (void)settingTrackToNone:(HBAudioTrack *)newNoneTrack;
    6468- (void)switchingTrackFromNone:(HBAudioTrack *)noLongerNoneTrack;
     69- (void)mixdownChanged;
    6570@end
  • macosx/HBAudioTrack.m

    rc81e2df r466034a  
    366366        if ([self.dataSource.noneTrack isEqual: oldValue])
    367367        {
    368             [self.dataSource switchingTrackFromNone: self];
     368            [self.delegate switchingTrackFromNone: self];
    369369        }
    370370        if ([self.dataSource.noneTrack isEqual: self.track])
    371371        {
    372             [self.dataSource settingTrackToNone: self];
     372            [self.delegate settingTrackToNone: self];
    373373        }
    374374    }
     
    389389    _mixdown = [mixdown retain];
    390390    [self updateBitRates: YES];
    391     [[NSNotificationCenter defaultCenter] postNotificationName: HBMixdownChangedNotification object: self.dataSource];
     391    [self.delegate mixdownChanged];
    392392}
    393393
  • macosx/HBController.m

    r0fc6cf4 r466034a  
    2222#import "HBPictureController.h"
    2323#import "HBPreviewController.h"
     24#import "HBPreviewGenerator.h"
    2425
    2526#import "HBPresetsViewController.h"
     
    7677        [fPictureController setDelegate:self];
    7778
    78         fPreviewController = [[HBPreviewController  alloc] initWithDelegate:self];
    79         [fPreviewController setCore:self.core];
     79        fPreviewController = [[HBPreviewController alloc] initWithDelegate:self];
    8080
    8181        fQueueController = queueController;
     
    453453}
    454454
     455- (void)removeJobObservers
     456{
     457    if (self.job)
     458    {
     459        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBContainerChangedNotification object:_job];
     460        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBPictureChangedNotification object:_job.picture];
     461        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBFiltersChangedNotification object:_job.filters];
     462        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBVideoChangedNotification object:_job.video];
     463        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBAudioChangedNotification object:_job.audio];
     464        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBChaptersChangedNotification object:_job];
     465        [[NSNotificationCenter defaultCenter] removeObserver:self name:HBRangeChangedNotification object:_job.range];
     466    }
     467}
     468
     469/**
     470 *  Observe the job settings changes.
     471 *  This is used to update the file name and extention
     472 *  and the custom preset string.
     473 */
     474- (void)addJobObservers
     475{
     476    if (self.job)
     477    {
     478        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(formatChanged:) name:HBContainerChangedNotification object:_job];
     479        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customSettingUsed) name:HBPictureChangedNotification object:_job.picture];
     480        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customSettingUsed) name:HBFiltersChangedNotification object:_job.filters];
     481        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customSettingUsed) name:HBVideoChangedNotification object:_job.video];
     482        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFileExtension:) name:HBAudioChangedNotification object:_job.audio];
     483        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFileExtension:) name:HBChaptersChangedNotification object:_job];
     484        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(chapterPopUpChanged:) name:HBRangeChangedNotification object:_job.range];
     485    }
     486}
     487
    455488- (void)setJob:(HBJob *)job
    456489{
     490    [self removeJobObservers];
     491
     492    // Retain the new job
     493    [_job autorelease];
     494    _job = [job retain];
     495
    457496    // Set the jobs info to the view controllers
    458497    fPictureController.picture = job.picture;
    459498    fPictureController.filters = job.filters;
    460     fPreviewController.job = job;
    461499
    462500    fVideoController.job = job;
     
    467505    if (job)
    468506    {
    469         [[NSNotificationCenter defaultCenter] removeObserver:_job];
    470         [[NSNotificationCenter defaultCenter] removeObserver:_job.picture];
    471         [[NSNotificationCenter defaultCenter] removeObserver:_job.filters];
    472         [[NSNotificationCenter defaultCenter] removeObserver:_job.video];
    473         [[NSNotificationCenter defaultCenter] removeObserver:_job.audio];
    474         [[NSNotificationCenter defaultCenter] removeObserver:_job.range];
    475 
    476         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pictureSettingsDidChange) name:HBPictureChangedNotification object:job.picture];
    477         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pictureSettingsDidChange) name:HBFiltersChangedNotification object:job.filters];
    478         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(formatChanged:) name:HBContainerChangedNotification object:job];
    479         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customSettingUsed) name:HBVideoChangedNotification object:job.video];
    480         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFileExtension:) name:HBMixdownChangedNotification object:job.audio];
    481         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFileExtension:) name:HBChaptersChangedNotification object:job];
    482         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(chapterPopUpChanged:) name:HBRangeChangedNotification object:job.range];
    483     }
    484 
    485     // Retain the new job
    486     [_job autorelease];
    487     _job = [job retain];
     507        fPreviewController.generator = [[[HBPreviewGenerator alloc] initWithCore:self.core job:job] autorelease];
     508    }
     509    else
     510    {
     511        fPreviewController.generator = nil;
     512    }
    488513
    489514    [self enableUI:(job != nil)];
     515
     516    [self addJobObservers];
    490517}
    491518
     
    12361263#pragma mark - Picture
    12371264
    1238 /**
    1239  * Registers changes made in the Picture Settings Window.
    1240  */
    1241 - (void)pictureSettingsDidChange
    1242 {
    1243     [fPreviewController reloadPreviews];
    1244     [self customSettingUsed];
    1245 }
    1246 
    12471265- (IBAction)toggleDrawer:(id)sender
    12481266{
     
    12871305        self.selectedPreset = preset;
    12881306
     1307        // Remove the job observer so we don't update the file name
     1308        // too many times while the preset is being applied
     1309        [self removeJobObservers];
     1310
    12891311        // Apply the preset to the current job
    12901312        [self.job applyPreset:preset];
     
    12931315        [self updateFileName];
    12941316
    1295         [fPreviewController reloadPreviews];
     1317        [self addJobObservers];
    12961318    }
    12971319}
  • macosx/HBCore.m

    rd8eecdc r466034a  
    284284    hb_geometry_settings_t geo;
    285285    memset(&geo, 0, sizeof(geo));
    286     geo.geometry.width = frame.width;
     286    geo.geometry.width = frame.displayWidth;
    287287    geo.geometry.height = frame.height;
    288288    // ignore the par.
  • macosx/HBJob.m

    r17d0a11 r466034a  
    1717NSString *HBContainerChangedNotification = @"HBContainerChangedNotification";
    1818NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
    19 
    20 @interface HBJob ()
    21 
    22 @property (nonatomic, readwrite, getter=areNotificationsEnabled) BOOL notificationsEnabled;
    23 
    24 @end
    2519
    2620@implementation HBJob
     
    5448
    5549        [self applyPreset:preset];
    56 
    57         _notificationsEnabled = YES;
    5850    }
    5951
     
    6355- (void)applyPreset:(HBPreset *)preset
    6456{
    65     self.notificationsEnabled = NO;
    66 
    6757    if (preset.isDefault)
    6858    {
     
    8777    [@[self.audio, self.subtitles, self.filters, self.picture, self.video] makeObjectsPerformSelector:@selector(applyPreset:)
    8878                                                                                                           withObject:content];
    89 
    90     self.notificationsEnabled = YES;
    9179}
    9280
     
    11199    [self.video containerChanged];
    112100
    113     if (self.notificationsEnabled)
    114     {
    115         // post a notification for any interested observers to indicate that our video container has changed
    116         [[NSNotificationCenter defaultCenter] postNotificationName:HBContainerChangedNotification object:self];
    117     }
     101    // post a notification for any interested observers to indicate that our video container has changed
     102    [[NSNotificationCenter defaultCenter] postNotificationName:HBContainerChangedNotification object:self];
    118103}
    119104
     
    128113{
    129114    _chaptersEnabled = chaptersEnabled;
    130     if (self.notificationsEnabled)
    131     {
    132         [[NSNotificationCenter defaultCenter] postNotificationName:HBChaptersChangedNotification object:self];
    133     }
     115    [[NSNotificationCenter defaultCenter] postNotificationName:HBChaptersChangedNotification object:self];
    134116}
    135117
     
    205187        copy->_chaptersEnabled = _chaptersEnabled;
    206188        copy->_chapterTitles = [[NSMutableArray alloc] initWithArray:_chapterTitles copyItems:YES];
    207 
    208         copy->_notificationsEnabled = _notificationsEnabled;
    209189    }
    210190
  • macosx/HBPicture.m

    r677231f r466034a  
    659659    self.validating = NO;
    660660    self.notificationsEnabled = YES;
     661
     662    [self postChangedNotification];
    661663}
    662664
  • macosx/HBPreviewController.h

    r77d3703 r466034a  
    77#import <Cocoa/Cocoa.h>
    88
    9 @class HBCore;
    10 @class HBJob;
     9@class HBPreviewGenerator;
    1110
    1211@protocol HBPreviewControllerDelegate <NSObject>
     
    2019- (id)initWithDelegate:(id <HBPreviewControllerDelegate>)delegate;
    2120
    22 @property (nonatomic, assign) HBCore *core;
    23 @property (nonatomic, assign) HBJob *job;
    24 
    25 /**
    26  *  Reloads the preview images.
    27  *  Usually called after a picture setting changes.
    28  */
    29 - (void)reloadPreviews;
     21@property (nonatomic, retain) HBPreviewGenerator *generator;
    3022
    3123@end
  • macosx/HBPreviewController.m

    rde6e8f8 r466034a  
    77#import "HBPreviewController.h"
    88#import "HBPreviewGenerator.h"
    9 #import "HBUtilities.h"
    109#import <QTKit/QTKit.h>
    11 
    12 #import "HBJob.h"
    13 #import "HBPicture+UIAdditions.h"
    1410
    1511@implementation QTMovieView (HBQTMovieViewExtensions)
     
    110106@property (nonatomic, retain) NSTimer *hudTimer;
    111107
    112 @property (nonatomic, retain) HBPreviewGenerator *generator;
    113108@property (nonatomic) NSUInteger pictureIndex;
    114109
     
    234229}
    235230
    236 - (void) setJob:(HBJob *)job
    237 {
    238     _job = job;
    239 
    240     self.generator.delegate = nil;
    241     [self.generator cancel];
    242     self.generator = nil;
    243 
    244     if (job)
    245     {
    246         /* alloc and init a generator for the current title */
    247         self.generator = [[[HBPreviewGenerator alloc] initWithCore:self.core job:self.job] autorelease];
    248 
    249         /* adjust the preview slider length */
    250         [fPictureSlider setMaxValue: self.generator.imagesCount - 1.0];
    251         [fPictureSlider setNumberOfTickMarks: self.generator.imagesCount];
     231- (void)setGenerator:(HBPreviewGenerator *)generator
     232{
     233    if (_generator)
     234    {
     235        _generator.delegate = nil;
     236        [_generator cancel];
     237        [_generator autorelease];
     238    }
     239
     240    _generator = [generator retain];
     241
     242    if (generator)
     243    {
     244        generator.delegate = self;
     245
     246        // adjust the preview slider length
     247        [fPictureSlider setMaxValue: generator.imagesCount - 1.0];
     248        [fPictureSlider setNumberOfTickMarks: generator.imagesCount];
    252249
    253250        [self switchViewToMode:ViewModePicturePreview];
     
    258255- (void) reloadPreviews
    259256{
    260     if (self.job)
     257    if (self.generator)
    261258    {
    262259        // Purge the existing picture previews so they get recreated the next time
     
    312309        // to the new situation
    313310        self.backingScaleFactor = newBackingScaleFactor;
    314         if (self.job)
     311        if (self.generator)
    315312            [self reloadPreviews];
    316313    }
     
    556553
    557554    /* Test for mouse location to show/hide hud controls */
    558     if (self.currentViewMode != ViewModeEncoding && self.job)
     555    if (self.currentViewMode != ViewModeEncoding && self.generator)
    559556    {
    560557        /* Since we are not encoding, verify which control hud to show
     
    675672- (void) displayPreview
    676673{
     674    CGImageRef fPreviewImage = NULL;
     675
    677676    if (self.window.isVisible)
    678677    {
    679         CGImageRef fPreviewImage = [self.generator imageAtIndex:self.pictureIndex shouldCache:YES];
     678        fPreviewImage = [self.generator imageAtIndex:self.pictureIndex shouldCache:YES];
    680679        [self.pictureLayer setContents:(id)fPreviewImage];
    681680    }
    682 
    683     HBPicture *pict = self.job.picture;
     681    else
     682    {
     683        return;
     684    }
    684685
    685686    /* Set the picture size display fields below the Preview Picture*/
    686     int display_width = pict.width * pict.parWidth / pict.parHeight;
    687     NSSize imageScaledSize = NSMakeSize(display_width, pict.height);
    688     NSSize displaySize = NSMakeSize(display_width, pict.height);
     687    NSSize imageScaledSize = NSMakeSize(CGImageGetWidth(fPreviewImage), CGImageGetHeight(fPreviewImage));
     688    NSSize displaySize = imageScaledSize;
    689689
    690690    if (self.backingScaleFactor != 1.0)
     
    775775    /* Set the info fields in the hud controller */
    776776    [fInfoField setStringValue: [NSString stringWithFormat:
    777                                  @"%@", self.job.picture.info]];
     777                                 @"%@", self.generator.info]];
    778778
    779779    [fscaleInfoField setStringValue: [NSString stringWithFormat:
     
    781781
    782782    /* Set the info field in the window title bar */
    783     [[self window] setTitle:[NSString stringWithFormat: @"Preview - %@ %@", self.job.picture.info, scaleString]];
     783    [[self window] setTitle:[NSString stringWithFormat: @"Preview - %@ %@", self.generator.info, scaleString]];
    784784}
    785785
     
    791791- (IBAction) pictureSliderChanged: (id) sender
    792792{
    793     if ((self.pictureIndex != [fPictureSlider intValue] || !sender) && self.job) {
     793    if ((self.pictureIndex != [fPictureSlider intValue] || !sender) && self.generator) {
    794794        self.pictureIndex = [fPictureSlider intValue];
    795795        [self displayPreview];
     
    853853                if (!movie)
    854854        {
    855             [HBUtilities writeToActivityLog: "showMoviePreview: Unable to open movie"];
    856855            [self switchViewToMode:ViewModePicturePreview];
    857856                }
     
    904903        return;
    905904
    906     self.generator.delegate = self;
    907905    if ([self.generator createMovieAsyncWithImageAtIndex:self.pictureIndex
    908906                                       duration:[[fPreviewMovieLengthPopUp titleOfSelectedItem] intValue]])
  • macosx/HBPreviewGenerator.h

    rde6e8f8 r466034a  
    1111
    1212@protocol HBPreviewGeneratorDelegate <NSObject>
     13
     14- (void) reloadPreviews;
    1315
    1416- (void) didCreateMovieAtURL: (NSURL *) fileURL;
     
    3032- (void) purgeImageCache;
    3133
     34- (NSString *)info;
     35
    3236/* Video generator */
    3337- (BOOL) createMovieAsyncWithImageAtIndex: (NSUInteger) index duration: (NSUInteger) seconds;
  • macosx/HBPreviewGenerator.m

    r6823cb8 r466034a  
    1111#import "HBCore.h"
    1212#import "HBJob.h"
     13#import "HBPicture+UIAdditions.h"
    1314
    1415@interface HBPreviewGenerator ()
     
    3435        _picturePreviews = [[NSMutableDictionary alloc] init];
    3536        _imagesCount = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
     37
     38        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imagesSettingsDidChange) name:HBPictureChangedNotification object:job.picture];
     39        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imagesSettingsDidChange) name:HBFiltersChangedNotification object:job.filters];
    3640    }
    3741    return self;
     
    8084{
    8185    [self.picturePreviews removeAllObjects];
     86}
     87
     88- (void) imagesSettingsDidChange
     89{
     90    [self.delegate reloadPreviews];
     91}
     92
     93- (NSString *)info
     94{
     95    return self.job.picture.info;
    8296}
    8397
     
    218232- (void) dealloc
    219233{
     234    [[NSNotificationCenter defaultCenter] removeObserver:self];
     235
    220236    [self.core cancelEncode];
    221237
Note: See TracChangeset for help on using the changeset viewer.