OSDN Git Service

MacGui: Picture Preview no longer distorts in Anamorphic Mode
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.mm
index 52431ce..d5881db 100644 (file)
@@ -137,6 +137,7 @@ static int FormatSettings[3][4] =
   if (nil == UserPresets) 
   {
     UserPresets = [[NSMutableArray alloc] init];
+       [self AddFactoryPresets:NULL];
   }
   /* Show/Dont Show Presets drawer upon launch based
   on user preference DefaultPresetsDrawerShow*/
@@ -167,17 +168,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     /* Video quality */
     [fVidTargetSizeField setIntValue: 700];
        [fVidBitrateField    setIntValue: 1000];
-       /* Do we want to force the quality settings if PAR is on ?
-       if ([[NSUserDefaults standardUserDefaults] boolForKey:@"PixelRatio"])
-    {
-       [fVidBitrateField    setIntValue: 1500];
-       [fVidTwoPassCheck    setState: NSOnState];
-    }
-       else
-       {
-       [fVidBitrateField    setIntValue: 1000];
-    }
-       */
+
     [fVidQualityMatrix   selectCell: fVidBitrateCell];
     [self VideoMatrixChanged: NULL];
 
@@ -442,6 +433,9 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
             }
             // Select the longuest title
                        [fSrcTitlePopUp selectItemAtIndex: indxpri];
+            /* We set the Settings Display to "Default" here
+                       until we get default presets implemented */
+                       [fPresetSelectedDisplay setStringValue: @"Default"];
                        
             [self TitlePopUpChanged: NULL];
             [self EnableUI: YES];
@@ -511,7 +505,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
 #undef p
                        
         case HB_STATE_PAUSED:
-            [fStatusField setStringValue: _( @"Paused" )];
+                   [fStatusField setStringValue: _( @"Paused" )];
             [fPauseButton setEnabled: YES];
             [fPauseButton setTitle: _( @"Resume" )];
             [fRipButton setEnabled: YES];
@@ -585,7 +579,8 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                fPicSettingDeinterlaceDsply,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
                fPicLabelAr,fPicLabelDeinter,fPicLabelSrcX,fPicLabelOutputX,
                fPicLabelPAROutp,fPicLabelPAROutputX,fPicSettingPARWidth,fPicSettingPARHeight,
-               fPicSettingPARDsply,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete};
+               fPicSettingPARDsply,fPicLabelAnamorphic,tableView,fPresetsAdd,fPresetsDelete,
+               fCreateChapterMarkers};
 
     for( unsigned i = 0;
          i < sizeof( controls ) / sizeof( NSControl * ); i++ )
@@ -603,17 +598,16 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
         [controls[i] setEnabled: b];
 
     }
-
-       /* Temporarily disable Lang2 until crash is fixed */
-       [fAudLang2PopUp setEnabled: NO];
-       [fAudLang2Field setEnabled: NO];
        
        if (b) {
                /* if we're enabling the interface, check if we should / should't offer 6-channel AAC extraction */
                [self Check6ChannelAACExtraction: NULL];
+       
        } else {
                /* if we're disabling the interface, turn it off */
                [fAudLang1SurroundCheck setEnabled: NO];
+               [tableView setEnabled: NO];
+       
        }
 
     [self VideoMatrixChanged: NULL];
@@ -663,6 +657,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
 
     [self QualitySliderChanged: sender];
     [self CalculateBitrate:     sender];
+       [self CustomSettingUsed: sender];
 }
 
 - (IBAction) QualitySliderChanged: (id) sender
@@ -670,17 +665,18 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     [fVidConstantCell setTitle: [NSString stringWithFormat:
         _( @"Constant quality: %.0f %%" ), 100.0 *
         [fVidQualitySlider floatValue]]];
+               [self CustomSettingUsed: sender];
 }
 
 - (IBAction) BrowseFile: (id) sender
 {
     /* Open a panel to let the user choose and update the text field */
     NSSavePanel * panel = [NSSavePanel savePanel];
-
-    [panel beginSheetForDirectory: NULL file: NULL
-        modalForWindow: fWindow modalDelegate: self
-        didEndSelector: @selector( BrowseFileDone:returnCode:contextInfo: )
-        contextInfo: NULL];
+       /* We get the current file name and path from the destination field here */
+       [panel beginSheetForDirectory: [[fDstFile2Field stringValue] stringByDeletingLastPathComponent] file: [[fDstFile2Field stringValue] lastPathComponent]
+                                  modalForWindow: fWindow modalDelegate: self
+                                  didEndSelector: @selector( BrowseFileDone:returnCode:contextInfo: )
+                                         contextInfo: NULL];
 }
 
 - (void) BrowseFileDone: (NSSavePanel *) sheet
@@ -689,7 +685,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     if( returnCode == NSOKButton )
     {
         [fDstFile2Field setStringValue: [sheet filename]];
-               [self FormatPopUpChanged: NULL];
+               
     }
 }
 
@@ -747,7 +743,12 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     job->mux    = FormatSettings[format][codecs] & HB_MUX_MASK;
     job->vcodec = FormatSettings[format][codecs] & HB_VCODEC_MASK;
     job->acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
-
+    /* We set the chapter marker extraction here based on the format being
+       mpeg4 and the checkbox being checked */
+       if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [fCreateChapterMarkers state] == NSOnState)
+       {
+       job->chapter_markers = 1;
+       }
     if( ( job->vcodec & HB_VCODEC_FFMPEG ) &&
         [fVidEncoderPopUp indexOfSelectedItem] > 0 )
     {
@@ -761,7 +762,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                Lets Deprecate Baseline Level 1.3*/
                job->h264_level = 30;
                job->mux = HB_MUX_IPOD;
-                    /* move sanity check for iPod Encoding here */
+        /* move sanity check for iPod Encoding here */
                job->pixel_ratio = 0 ;
 
                }
@@ -775,7 +776,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                }
                
                /* Sends x264 options to the core library*/
-               job->x264opts = strdup([[[NSUserDefaults standardUserDefaults] stringForKey:@"DefAdvancedx264Flags"] cString]);
+               job->x264opts = [[[NSUserDefaults standardUserDefaults] stringForKey:@"DefAdvancedx264Flags"] UTF8String];
                
                
         job->h264_13 = [fVidEncoderPopUp indexOfSelectedItem];
@@ -828,7 +829,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     job->abitrate = hb_audio_bitrates[[fAudBitratePopUp
                         indexOfSelectedItem]].rate;
        /* have we selected that 5.1 should be extracted as AAC? */
-       if (job->acodec == HB_ACODEC_FAAC && [fAudLang1SurroundCheck isEnabled] && [fAudLang1SurroundCheck state] == NSOnState) {
+       if ((job->acodec == HB_ACODEC_FAAC || job->acodec == HB_ACODEC_VORBIS) && [fAudLang1SurroundCheck isEnabled] && [fAudLang1SurroundCheck state] == NSOnState) {
                job->surround = 1;
        } else {
                job->surround = 0;
@@ -864,14 +865,14 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                [self PrepareJob];
                
                /* Destination file */
-               job->file = strdup( [[fDstFile2Field stringValue] UTF8String] );
+               job->file = [[fDstFile2Field stringValue] UTF8String];
                
                if( [fVidTwoPassCheck state] == NSOnState )
                {
                        job->pass = 1;
                        hb_add( fHandle, job );
                        job->pass = 2;
-                       job->x264opts = strdup([[[NSUserDefaults standardUserDefaults] stringForKey:@"DefAdvancedx264Flags"] cString]);
+                       job->x264opts = [[[NSUserDefaults standardUserDefaults] stringForKey:@"DefAdvancedx264Flags"] UTF8String];
                        hb_add( fHandle, job );
                }
                else
@@ -1008,7 +1009,17 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     hb_list_t  * list  = hb_get_titles( fHandle );
     hb_title_t * title = (hb_title_t*)
         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
-
+               
+               
+    /* If Auto Naming is on. We create an output filename of dvd name - title number */
+    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0)
+       {
+               [fDstFile2Field setStringValue: [NSString stringWithFormat:
+                       @"%@/%@-%d.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
+                       [NSString stringWithUTF8String: title->name],
+                       [fSrcTitlePopUp indexOfSelectedItem] + 1,
+                       [[fDstFile2Field stringValue] pathExtension]]]; 
+       }
 
     /* Update chapter popups */
     [fSrcChapterStartPopUp removeAllItems];
@@ -1033,6 +1044,15 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                                                         @"%d", fTitle->width]];
        [fPicSrcHeight setStringValue: [NSString stringWithFormat:
                                                         @"%d", fTitle->height]];
+       /* We get the originial output picture width and height and put them
+       in variables for use with some presets later on */
+       PicOrigOutputWidth = job->width;
+       PicOrigOutputHeight = job->height;
+       /* we test getting the max output value for pic sizing here to be used later*/
+       [fPicSettingWidth setStringValue: [NSString stringWithFormat:
+               @"%d", PicOrigOutputWidth]];
+       [fPicSettingHeight setStringValue: [NSString stringWithFormat:
+               @"%d", PicOrigOutputHeight]];
        /* Turn Deinterlace on/off depending on the preference */
        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultDeinterlaceOn"] > 0)
        {
@@ -1055,7 +1075,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        }
        /* Run Through EncoderPopUpChanged to see if there
                needs to be any pic value modifications based on encoder settings */
-       [self EncoderPopUpChanged: NULL];
+       //[self EncoderPopUpChanged: NULL];
        /* END Get and set the initial pic size for display */ 
 
 
@@ -1083,14 +1103,9 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        int indxpri=0;
        // End of pri changes 02/12/06
     [fAudLang1PopUp removeAllItems];
-       /* Disable second audio language until crashing is resolved*/
-       [fAudLang2Field setEnabled: NO];
-       [fAudLang2PopUp setEnabled: NO];
-    [fAudLang2PopUp removeAllItems];
+       [fAudLang2PopUp removeAllItems];
     [fAudLang1PopUp addItemWithTitle: _( @"None" )];
-       /* Display Currently Unavailable until crash is fixed */
-    [fAudLang2PopUp addItemWithTitle: _( @"Currently Unavailable" )];
-       //[fAudLang2PopUp addItemWithTitle: _( @"None" )];
+       [fAudLang2PopUp addItemWithTitle: _( @"None" )];
     for( int i = 0; i < hb_list_count( title->list_audio ); i++ )
     {
         audio = (hb_audio_t *) hb_list_item( title->list_audio, i );
@@ -1109,11 +1124,11 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
         [[fAudLang1PopUp menu] addItemWithTitle:
             [NSString stringWithCString: audio->lang]
             action: NULL keyEquivalent: @""];
-       /*
+       
           [[fAudLang2PopUp menu] addItemWithTitle:
             [NSString stringWithCString: audio->lang]
             action: NULL keyEquivalent: @""];
-                       */
+               
     }
        // PRI CHANGES 02/12/06
        if (indxpri==0) { indxpri=1; }
@@ -1126,6 +1141,8 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        /* changing the title may have changed the audio channels on offer, so */
        /* check if this change means we should / should't offer 6-channel AAC extraction */
        [self Check6ChannelAACExtraction: sender];
+    
+       
 
 }
 
@@ -1176,7 +1193,13 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                 _( @"MPEG-4 Video / AAC Audio" )];
             [fDstCodecsPopUp addItemWithTitle:
                 _( @"AVC/H.264 Video / AAC Audio" )];
-            break;
+                       /* We enable the create chapters checkbox here since we are .mp4 */     
+                   [fCreateChapterMarkers setEnabled: YES];
+                       if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultChapterMarkers"] > 0)
+               {
+                   [fCreateChapterMarkers setState: NSOnState];
+               }
+                       break;
         case 1: 
             ext = "avi";
             [fDstCodecsPopUp addItemWithTitle:
@@ -1187,6 +1210,10 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                 _( @"AVC/H.264 Video / MP3 Audio" )];
             [fDstCodecsPopUp addItemWithTitle:
                 _( @"AVC/H.264 Video / AC-3 Audio" )];
+                       /* We disable the create chapters checkbox here since we are NOT .mp4 
+                       and make sure it is unchecked*/
+                       [fCreateChapterMarkers setEnabled: NO];
+                       [fCreateChapterMarkers setState: NSOffState];
             break;
         case 2:
             ext = "ogm";
@@ -1194,7 +1221,11 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                 _( @"MPEG-4 Video / Vorbis Audio" )];
             [fDstCodecsPopUp addItemWithTitle:
                 _( @"MPEG-4 Video / MP3 Audio" )];
-            break;
+            /* We disable the create chapters checkbox here since we are NOT .mp4 
+                       and make sure it is unchecked*/
+                       [fCreateChapterMarkers setEnabled: NO];
+                       [fCreateChapterMarkers setState: NSOffState];
+                       break;
     }
     [self CodecsPopUpChanged: NULL];
 
@@ -1214,7 +1245,9 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        /* changing the codecs on offer may mean that we are/aren't now offering AAC, so */
        /* check if this change means we should / should't offer 6-channel AAC extraction */
        [self Check6ChannelAACExtraction: sender];
-
+       /* We call method method to change UI to reflect whether a preset is used or not*/
+       [self CustomSettingUsed: sender];       
+       
 }
 
 - (IBAction) CodecsPopUpChanged: (id) sender
@@ -1257,7 +1290,8 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        [self Check6ChannelAACExtraction: sender];
 
     [self CalculateBitrate: sender];
-
+    /* We call method method to change UI to reflect whether a preset is used or not*/
+       [self CustomSettingUsed: sender];
 }
 
 - (IBAction) EncoderPopUpChanged: (id) sender
@@ -1272,11 +1306,11 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPicSizeAutoiPod"] > 0)
                 {
                 
-                if (fTitle->job->width > 640)
+                if (job->width > 640)
                                {
-                               fTitle->job->width = 640;
+                               job->width = 640;
                                }
-                fTitle->job->keep_ratio = 1;
+                job->keep_ratio = 1;
                 hb_fix_aspect( job, HB_KEEP_WIDTH );
                 
                 }
@@ -1286,8 +1320,9 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
 
        }
     
-       [self CalculatePictureSizing: sender];    
-  
+       [self CalculatePictureSizing: sender];
+       /* We call method method to change UI to reflect whether a preset is used or not*/    
+    [self CustomSettingUsed: sender];
 }
 
 - (IBAction) Check6ChannelAACExtraction: (id) sender
@@ -1314,8 +1349,8 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
        int acodec = FormatSettings[format][codecs] & HB_ACODEC_MASK;
 
-       /* we only offer the option to extract 5.1 to 6-channel if the selected audio codec is AAC */
-       if (acodec == HB_ACODEC_FAAC) {
+       /* we only offer the option to extract 5.1 to 6-channel if the selected audio codec is AAC or Vorbis*/
+       if (acodec == HB_ACODEC_FAAC || acodec == HB_ACODEC_VORBIS) {
 
                bool doneaudios = false;
                int thisaudio = 0;
@@ -1338,7 +1373,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                }
        }
 
-    /* If we are extracting to AAC, and any of our soundtracks were 5.1, then enable the checkbox  */
+    /* If we are extracting to AAC or Vorbis, and any of our soundtracks were 5.1, then enable the checkbox  */
        if (foundfiveoneaudio) {
                [fAudLang1SurroundCheck setEnabled: YES];
                /* Check default surround sound pref and if it is YES, lets also check the checkbox */
@@ -1350,6 +1385,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
                [fAudLang1SurroundCheck setEnabled: NO];
                /* as well as disabling the checkbox, let's uncheck it if it is checked */
                [fAudLang1SurroundCheck setState: NSOffState];
+               
        }
 
 }
@@ -1363,10 +1399,30 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        [self Check6ChannelAACExtraction: sender];
        
        /* see if the new language setting will change the bitrate we need */
-    [self CalculateBitrate:     sender];       
+    [self CalculateBitrate: sender];   
 
 }
 
+/* lets set the picture size back to the max from right after title scan
+   Lets use an IBAction here as down the road we could always use a checkbox
+   in the gui to easily take the user back to max. Remember, the compiler
+   resolves IBActions down to -(void) during compile anyway */
+- (IBAction) RevertPictureSizeToMax: (id) sender
+{
+        hb_job_t * job = fTitle->job;
+       /* We use the output picture width and height
+       as calculated from libhb right after title is set
+       in TitlePopUpChanged */
+       job->width = PicOrigOutputWidth;
+       job->height = PicOrigOutputHeight;
+
+
+    
+       [self CalculatePictureSizing: sender];
+       /* We call method method to change UI to reflect whether a preset is used or not*/    
+    [self CustomSettingUsed: sender];
+}
+
 
 /* Get and Display Current Pic Settings in main window */
 - (IBAction) CalculatePictureSizing: (id) sender
@@ -1398,8 +1454,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
         @"%d", displayparwidth]];
        [fPicSettingPARHeight setStringValue: [NSString stringWithFormat:
         @"%d", displayparheight]];
-       [fPicSettingHeight setStringValue: [NSString stringWithFormat:
-               @"%d", displayparheight]];
+
        fTitle->job->keep_ratio = 0;
        }
        else
@@ -1455,34 +1510,72 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
 
     [fVidBitrateField setIntValue: hb_calc_bitrate( job,
             [fVidTargetSizeField intValue] )];
+                       
+                       
 }
 
+/* Method to determine if we should change the UI
+To reflect whether or not a Preset is being used or if
+the user is using "Custom" settings by determining the sender*/
+- (IBAction) CustomSettingUsed: (id) sender
+{
+       if ([sender stringValue] != NULL)
+       {
+               /* Deselect the currently selected Preset if there is one*/
+               [tableView deselectRow:[tableView selectedRow]];
+               /* Change UI to show "Custom" settings are being used */
+               [fPresetSelectedDisplay setStringValue: @"Custom"];
+       }
+}
+
+
 - (IBAction) ShowAddPresetPanel: (id) sender
 {
     /* Show the panel */
+       /* Temporarily disable until window hang bug is fixed */
+       
     [NSApp beginSheet: fAddPresetPanel modalForWindow: fWindow
         modalDelegate: NULL didEndSelector: NULL contextInfo: NULL];
     [NSApp runModalForWindow: fAddPresetPanel];
     [NSApp endSheet: fAddPresetPanel];
     [fAddPresetPanel orderOut: self];
+       
 }
 - (IBAction) CloseAddPresetPanel: (id) sender
 {
     [NSApp stopModal];
 }
 
-- (IBAction)addPreset:(id)sender
+- (IBAction)AddFactoryPresets:(id)sender
 {
-    [UserPresets addObject:[self CreatePreset]];
+    /* Here we create each shipped preset */
+       [UserPresets addObject:[self CreateIpodPreset]];
+       [UserPresets addObject:[self CreateAppleTVPreset]];
+    [self AddPreset];
+}
+- (IBAction)AddUserPreset:(id)sender
+{
+    /* Here we create a custom user preset */
+       [UserPresets addObject:[self CreatePreset]];
+    [self AddPreset];
+
+}
+- (void)AddPreset
+{
+
+       
+       /* We Sort the Presets By Factory or Custom */
+       NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type" 
+                                                    ascending:YES] autorelease];
        /* We Sort the Presets Alphabetically by name */
-       NSSortDescriptor * lastNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName" 
+       NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName" 
                                                     ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
-       NSArray *sortDescriptors=[NSArray arrayWithObject:lastNameDescriptor];
+       NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
        NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
        [UserPresets setArray:sortedArray];
        
        /* We stop the modal window for the new preset */
-       [fPresetNewName    setStringValue: @""];
+       [fPresetNewName setStringValue: @""];
        [NSApp stopModal];
        /* We Reload the New Table data for presets */
     [tableView reloadData];
@@ -1490,7 +1583,7 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     [self savePreset];
 }
 
-- (IBAction)insertPreset:(id)sender
+- (IBAction)InsertPreset:(id)sender
 {
     int index = [tableView selectedRow];
     [UserPresets insertObject:[self CreatePreset] atIndex:index];
@@ -1503,10 +1596,16 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
     NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
        /* Get the New Preset Name from the field in the AddPresetPanel */
     [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"];
+       /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"Type"];
+       /*Set whether or not this is default, at creation set to 0*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
        /*Get the whether or not to apply pic settings in the AddPresetPanel*/
        [preset setObject:[NSNumber numberWithInt:[fPresetNewPicSettingsApply state]] forKey:@"UsesPictureSettings"];
        /* File Format */
     [preset setObject:[fDstFormatPopUp titleOfSelectedItem] forKey:@"FileFormat"];
+       /* Chapter Markers fCreateChapterMarkers*/
+       [preset setObject:[NSNumber numberWithInt:[fCreateChapterMarkers state]] forKey:@"ChapterMarkers"];
        /* Codecs */
        [preset setObject:[fDstCodecsPopUp titleOfSelectedItem] forKey:@"FileCodecs"];
        /* Video encoder */
@@ -1527,6 +1626,8 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
        /*Picture Settings*/
        hb_job_t * job = fTitle->job;
        /* Basic Picture Settings */
+       /* Use Max Picture settings for whatever the dvd is.*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
        [preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
        [preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
        [preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
@@ -1557,7 +1658,147 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
 
 }
 
-- (IBAction)deletePreset:(id)sender
+- (NSDictionary *)CreateIpodPreset
+{
+    NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
+       /* Get the New Preset Name from the field in the AddPresetPanel */
+    [preset setObject:@"HB-iPod" forKey:@"PresetName"];
+       /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
+       /*Set whether or not this is default, at creation set to 0*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
+       /*Get the whether or not to apply pic settings in the AddPresetPanel*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesPictureSettings"];
+       /* File Format */
+    [preset setObject:@"MP4 file" forKey:@"FileFormat"];
+       /* Chapter Markers*/
+        [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
+    /* Codecs */
+       [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
+       /* Video encoder */
+       [preset setObject:@"x264 (h.264 iPod)" forKey:@"VideoEncoder"];
+       /* Video quality */
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
+       [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
+       [preset setObject:@"1400" forKey:@"VideoAvgBitrate"];
+       [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
+       
+       /* Video framerate */
+       [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
+       /* GrayScale */
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
+       /* 2 Pass Encoding */
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
+       
+       /*Picture Settings*/
+       //hb_job_t * job = fTitle->job;
+       /* Basic Picture Settings */
+       /* Use Max Picture settings for whatever the dvd is.*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
+       //[preset setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PictureWidth"];
+       //[preset setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
+       //[preset setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
+       //[preset setObject:[NSNumber numberWithInt:fTitle->job->deinterlace] forKey:@"PictureDeinterlace"];
+       //[preset setObject:[NSNumber numberWithInt:fTitle->job->pixel_ratio] forKey:@"PicturePAR"];
+       /* Set crop settings here */
+       /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
+       //[preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
+    //[preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
+       //[preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
+       //[preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
+       
+       /*Audio*/
+       /* Audio Language One*/
+       [preset setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"AudioLang1"];
+       /* Audio Language One Surround Sound Checkbox*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"AudioLang1Surround"];
+       /* Audio Sample Rate*/
+       [preset setObject:@"44.1" forKey:@"AudioSampleRate"];
+       /* Audio Bitrate Rate*/
+       [preset setObject:@"128" forKey:@"AudioBitRate"];
+       /* Subtitles*/
+       [preset setObject:@"None" forKey:@"Subtitles"];
+       
+
+    [preset autorelease];
+    return preset;
+
+}
+
+- (NSDictionary *)CreateAppleTVPreset
+{
+    NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
+       /* Get the New Preset Name from the field in the AddPresetPanel */
+    [preset setObject:@"HB-AppleTV" forKey:@"PresetName"];
+       /*Set whether or not this is a user preset or factory 0 is factory, 1 is user*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
+       /*Set whether or not this is default, at creation set to 0*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
+       /*Get the whether or not to apply pic settings in the AddPresetPanel*/
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
+       /* File Format */
+    [preset setObject:@"MP4 file" forKey:@"FileFormat"];
+       /* Chapter Markers*/
+        [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
+       /* Codecs */
+       [preset setObject:@"AVC/H.264 Video / AAC Audio" forKey:@"FileCodecs"];
+       /* Video encoder */
+       [preset setObject:@"x264 (h.264 Main)" forKey:@"VideoEncoder"];
+       /* Video quality */
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
+       [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
+       [preset setObject:@"3000" forKey:@"VideoAvgBitrate"];
+       [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
+       
+       /* Video framerate */
+       [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
+       /* GrayScale */
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
+       /* 2 Pass Encoding */
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
+       
+       /*Picture Settings*/
+       /* For AppleTV we only want to retain UsesMaxPictureSettings
+       which depend on the source dvd picture settings, so we don't
+       record the current dvd's picture info since it will vary from
+       source to source*/
+       //hb_job_t * job = fTitle->job;
+       //hb_job_t * job = title->job;
+       /* Basic Picture Settings */
+       /* Use Max Picture settings for whatever the dvd is.*/
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesMaxPictureSettings"];
+       //[preset setObject:[NSNumber numberWithInt:PicOrigOutputWidth] forKey:@"PictureWidth"];
+       //[preset setObject:[NSNumber numberWithInt:PicOrigOutputHeight] forKey:@"PictureHeight"];
+       //[preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureKeepRatio"];
+       //[preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"PicturePAR"];
+       /* Set crop settings here */
+       /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
+       //[preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
+    //[preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
+       //[preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
+       //[preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
+       
+       /*Audio*/
+       /* Audio Language One*/
+       [preset setObject:[fAudLang1PopUp titleOfSelectedItem] forKey:@"AudioLang1"];
+       /* Audio Language One Surround Sound Checkbox*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"AudioLang1Surround"];
+       /* Audio Sample Rate*/
+       [preset setObject:@"44.1" forKey:@"AudioSampleRate"];
+       /* Audio Bitrate Rate*/
+       [preset setObject:@"320" forKey:@"AudioBitRate"];
+       /* Subtitles*/
+       [preset setObject:@"None" forKey:@"Subtitles"];
+       
+
+    [preset autorelease];
+    return preset;
+
+}
+
+
+- (IBAction)DeletePreset:(id)sender
 {
     int status;
     NSEnumerator *enumerator;
@@ -1588,80 +1829,106 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultPresetsDrawerShow
 }
 - (IBAction)tableViewSelected:(id)sender
 {
-
-    /* we get the chosen preset from the UserPresets array */
-       chosenPreset = [UserPresets objectAtIndex:[sender selectedRow]];
-       /* we set the preset display field in main window here */
-       //[fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@", [chosenPreset valueForKey:@"PresetName"]]];
-       /* File Format */
-       [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
-       [self FormatPopUpChanged: NULL];
-    /* Codecs */
-       [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
-       [self CodecsPopUpChanged: NULL];
-       /* Video encoder */
-       [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
-       /* Lets run through the following functions to get variables set there */
-       [self EncoderPopUpChanged: sender];
-       [self Check6ChannelAACExtraction: sender];
-       [self CalculateBitrate: sender];
-       
-       /* Video quality */
-       [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
-       
-       [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
-       [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
-       
-       [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
-       [self VideoMatrixChanged: sender];
-       
-       /* Video framerate */
-       [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
-       
-       /* GrayScale */
-       [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
-
-       /* 2 Pass Encoding */
-       [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
-    
-       
-       /*Audio*/
-       /* Audio Language One*/
-       [fAudLang1PopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioLang1"]]];
-       /* Audio Language One Surround Sound Checkbox*/
-       [fAudLang1SurroundCheck setState:[[chosenPreset objectForKey:@"AudioLang1Surround"] intValue]];
-       [self Check6ChannelAACExtraction: sender];
-       /* Audio Sample Rate*/
-       [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
-       /* Audio Bitrate Rate*/
-       [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
-       /*Subtitles*/
-       [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
-       
-       /* Picture Settings */
-       /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
-       if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] == 1)
+    /* Since we cannot disable the presets tableView in terms of clickability
+          we will use the enabled state of the add presets button to determine whether
+          or not clicking on a preset will do anything */
+       if ([fPresetsAdd isEnabled])
        {
-               hb_job_t * job = fTitle->job;
-               job->width = [[chosenPreset objectForKey:@"PictureWidth"]  intValue];
-               job->height = [[chosenPreset objectForKey:@"PictureHeight"]  intValue];
-               job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
-               if (job->keep_ratio == 1)
+               
+               /* we get the chosen preset from the UserPresets array */
+               chosenPreset = [UserPresets objectAtIndex:[sender selectedRow]];
+               /* we set the preset display field in main window here */
+               [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@", [chosenPreset valueForKey:@"PresetName"]]];
+               /* File Format */
+               [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
+               [self FormatPopUpChanged: NULL];
+               /* Chapter Markers*/
+               [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
+           /* Codecs */
+               [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
+               [self CodecsPopUpChanged: NULL];
+               /* Video encoder */
+               [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
+               /* Lets run through the following functions to get variables set there */
+               [self EncoderPopUpChanged: NULL];
+               [self Check6ChannelAACExtraction: NULL];
+               [self CalculateBitrate: NULL];
+               
+               /* Video quality */
+               [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
+               
+               [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
+               [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
+               
+               [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
+               [self VideoMatrixChanged: NULL];
+               
+               /* Video framerate */
+               [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
+               
+               /* GrayScale */
+               [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
+               
+               /* 2 Pass Encoding */
+               [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
+               
+               
+               /*Audio*/
+               /* Audio Language One*/
+               [fAudLang1PopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioLang1"]]];
+               /* Audio Language One Surround Sound Checkbox*/
+               [fAudLang1SurroundCheck setState:[[chosenPreset objectForKey:@"AudioLang1Surround"] intValue]];
+               [self Check6ChannelAACExtraction: NULL];
+               /* Audio Sample Rate*/
+               [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
+               /* Audio Bitrate Rate*/
+               [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
+               /*Subtitles*/
+               [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
+               
+               /* Picture Settings */
+               /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
+               if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] == 1)
                {
-                       hb_fix_aspect( job, HB_KEEP_WIDTH );
+                       hb_job_t * job = fTitle->job;
+                       /* Check to see if we should use the max picture setting for the current title*/
+                       if ([[chosenPreset objectForKey:@"UsesMaxPictureSettings"]  intValue] == 1)
+                       {
+                               /* Use Max Picture settings for whatever the dvd is.*/
+                               [self RevertPictureSizeToMax: NULL];
+                               job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
+                               if (job->keep_ratio == 1)
+                               {
+                                       hb_fix_aspect( job, HB_KEEP_WIDTH );
+                               }
+                               job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
+                       }
+                       else
+                       {
+                               job->width = [[chosenPreset objectForKey:@"PictureWidth"]  intValue];
+                               job->height = [[chosenPreset objectForKey:@"PictureHeight"]  intValue];
+                               job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"]  intValue];
+                               if (job->keep_ratio == 1)
+                               {
+                                       hb_fix_aspect( job, HB_KEEP_WIDTH );
+                               }
+                               job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
+                               job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"]  intValue];
+                               job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"]  intValue];
+                               job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"]  intValue];
+                               job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"]  intValue];
+                       }
+                       [self CalculatePictureSizing: NULL]; 
                }
-               job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"]  intValue];
-               job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"]  intValue];
-               job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"]  intValue];
-               job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"]  intValue];
-               job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"]  intValue];
-               [self CalculatePictureSizing: sender]; 
-       }
-       
-       // Deselect the currently selected table //
-       //[tableView deselectRow:[tableView selectedRow]];
+               
+
+
+
+}
 }
 
+
+
 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
 {
     return [UserPresets count];