OSDN Git Service

MacGui: Allow up to 320 kbps bitrate for stereo and 768 kbps for 6 channel discrete...
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.m
index d364c0d..71cc5a6 100644 (file)
@@ -202,8 +202,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                                       NSLocalizedString(@" Do you want to reload them ?", nil));
         }
         
-        // call didDimissReloadQueue: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
-        // right below to either clear the old queue or keep it loaded up.
     }
     else
     {
@@ -228,8 +226,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     int hbInstances = 0;
     for (aDictionary in runningAppDictionaries)
        {
-        //     NSLog(@"Open App: %@", [aDictionary valueForKey:@"NSApplicationName"]);
-        
         if ([[aDictionary valueForKey:@"NSApplicationName"] isEqualToString:@"HandBrake"])
                {
             hbInstances++;
@@ -266,15 +262,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 
 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
 {
-    /* if we are in preview full screen mode, we need to go to
-     * windowed mode and release the display before we terminate.
-     * We do it here (instead of applicationWillTerminate) so we 
-     * release the displays and can then see the alerts below.
-     */
-    if ([fPictureController previewFullScreenMode] == YES)
-    {
-        [fPictureController previewGoWindowed:nil];
-    }
+
     
     hb_state_t s;
     hb_get_state( fQueueEncodeLibhb, &s );
@@ -321,15 +309,18 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     [fPictureController release];
     [fApplicationIcon release];
 
-       hb_close(&fHandle);
+    hb_close(&fHandle);
     hb_close(&fQueueEncodeLibhb);
+    hb_global_close();
+
 }
 
 
 - (void) awakeFromNib
 {
     [fWindow center];
-    [fWindow setExcludedFromWindowsMenu:YES];
+    [fWindow setExcludedFromWindowsMenu:NO];
+    
     [fAdvancedOptions setView:fAdvancedView];
     
     /* lets setup our presets drawer for drag and drop here */
@@ -382,6 +373,18 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     [fSrcAngleLabel setHidden:YES];
     [fSrcAnglePopUp setHidden:YES];
     
+    /* Setup the start / stop popup */
+    [fEncodeStartStopPopUp removeAllItems];
+    [fEncodeStartStopPopUp addItemWithTitle: @"Chapters"];
+    [fEncodeStartStopPopUp addItemWithTitle: @"Seconds"];
+    [fEncodeStartStopPopUp addItemWithTitle: @"Frames"];
+    /* Align the start / stop widgets with the chapter popups */
+    [fSrcTimeStartEncodingField setFrameOrigin:[fSrcChapterStartPopUp frame].origin];
+    [fSrcTimeEndEncodingField setFrameOrigin:[fSrcChapterEndPopUp frame].origin];
+    
+    [fSrcFrameStartEncodingField setFrameOrigin:[fSrcChapterStartPopUp frame].origin];
+    [fSrcFrameEndEncodingField setFrameOrigin:[fSrcChapterEndPopUp frame].origin];
+    
     /* Destination box*/
     NSMenuItem *menuItem;
     [fDstFormatPopUp removeAllItems];
@@ -414,7 +417,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     [fVidEncoderPopUp addItemWithTitle: @"FFmpeg"];
     
     
-    
     /* Video quality */
     [fVidTargetSizeField setIntValue: 700];
        [fVidBitrateField    setIntValue: 1000];
@@ -511,7 +513,8 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         fAudTrack2DrcField, fAudTrack3DrcSlider, fAudTrack3DrcField, fAudTrack4DrcSlider,fAudTrack4DrcField,
         fQueueStatus,fPresetsAdd,fPresetsDelete,fSrcAngleLabel,fSrcAnglePopUp,
                fCreateChapterMarkers,fVidTurboPassCheck,fDstMp4LargeFileCheck,fSubForcedCheck,fPresetsOutlineView,
-    fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel};
+        fAudDrcLabel,fDstMp4HttpOptFileCheck,fDstMp4iPodFileCheck,fVidQualityRFField,fVidQualityRFLabel,
+        fEncodeStartStopPopUp,fSrcTimeStartEncodingField,fSrcTimeEndEncodingField,fSrcFrameStartEncodingField,fSrcFrameEndEncodingField};
     
     for( unsigned i = 0;
         i < sizeof( controls ) / sizeof( NSControl * ); i++ )
@@ -753,8 +756,57 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                        break;
         }
 #undef p
+
             
 #define p s.param.working
+        
+        case HB_STATE_SEARCHING:
+               {
+            NSMutableString * string;
+            NSString * pass_desc;
+            
+            /* Update text field */
+            pass_desc = @"";
+            //string = [NSMutableString stringWithFormat: NSLocalizedString( @"Searching for start point: pass %d %@ of %d, %.2f %%", @"" ), p.job_cur, pass_desc, p.job_count, 100.0 * p.progress];
+            /* For now, do not announce "pass x of x for the search phase ... */
+            string = [NSMutableString stringWithFormat: NSLocalizedString( @"Searching for start point ... :  %.2f %%", @"" ), 100.0 * p.progress];
+            
+                       if( p.seconds > -1 )
+            {
+                [string appendFormat:
+                 NSLocalizedString( @" (ETA %02dh%02dm%02ds)", @"" ), p.hours, p.minutes, p.seconds];
+            }
+            
+            [fStatusField setStringValue: string];
+            /* Set the status string in fQueueController as well */
+            [fQueueController setQueueStatusString: string];
+            /* Update slider */
+            CGFloat progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
+            [fRipIndicator setIndeterminate: NO];
+            [fRipIndicator setDoubleValue:100.0 * progress_total];
+            
+            // If progress bar hasn't been revealed at the bottom of the window, do
+            // that now. This code used to be in doRip. I moved it to here to handle
+            // the case where hb_start is called by HBQueueController and not from
+            // HBController.
+            if( !fRipIndicatorShown )
+            {
+                NSRect frame = [fWindow frame];
+                if( frame.size.width <= 591 )
+                    frame.size.width = 591;
+                frame.size.height += 36;
+                frame.origin.y -= 36;
+                [fWindow setFrame:frame display:YES animate:YES];
+                fRipIndicatorShown = YES;
+                
+            }
+            
+            /* Update dock icon */
+            /* Note not done yet */
+            break;  
+        }
+            
+
         case HB_STATE_WORKING:
         {
             NSMutableString * string;
@@ -1100,12 +1152,36 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         hb_state_t s;
         
         hb_get_state( fHandle, &s );
-        if (s.state == HB_STATE_SCANNING && ([ident isEqualToString: StartEncodingIdentifier] || [ident isEqualToString: AddToQueueIdentifier]))
-            return NO;
-        
+        if (s.state == HB_STATE_SCANNING)
+        {
+            
+            if ([ident isEqualToString: ChooseSourceIdentifier])
+            {
+                [toolbarItem setImage: [NSImage imageNamed: @"Stop"]];
+                [toolbarItem setLabel: @"Cancel Scan"];
+                [toolbarItem setPaletteLabel: @"Cancel Scanning"];
+                [toolbarItem setToolTip: @"Cancel Scanning Source"];
+                return YES;
+            }
+            
+            if ([ident isEqualToString: StartEncodingIdentifier] || [ident isEqualToString: AddToQueueIdentifier])
+                return NO;
+        }
+        else
+        {
+            if ([ident isEqualToString: ChooseSourceIdentifier])
+            {
+                [toolbarItem setImage: [NSImage imageNamed: @"Source"]];
+                [toolbarItem setLabel: @"Source"];
+                [toolbarItem setPaletteLabel: @"Source"];
+                [toolbarItem setToolTip: @"Choose Video Source"];
+                return YES;
+            }
+        }
+
         hb_get_state2( fQueueEncodeLibhb, &s );
         
-        if (s.state == HB_STATE_WORKING || s.state == HB_STATE_MUXING)
+        if (s.state == HB_STATE_WORKING || s.state == HB_STATE_SEARCHING || s.state == HB_STATE_MUXING)
         {
             if ([ident isEqualToString: StartEncodingIdentifier])
             {
@@ -1296,9 +1372,15 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     /* This end of encode action is called as each encode rolls off of the queue */
     if([[NSUserDefaults standardUserDefaults] boolForKey: @"sendToMetaX"] == YES)
     {
-        NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"MetaX\" to open (POSIX file \"", filePath, @"\")"]];
-        [myScript executeAndReturnError: nil];
-        [myScript release];
+        NSString *sendToApp = [[NSUserDefaults standardUserDefaults] objectForKey: @"SendCompletedEncodeToApp"];
+        if (![sendToApp isEqualToString:@"None"])
+        {
+            [self writeToActivityLog: "trying to send encode to: %s", [sendToApp UTF8String]];
+            NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@%@%@", @"tell application \"",sendToApp,@"\" to open (POSIX file \"", filePath, @"\")"]];
+            [myScript executeAndReturnError: nil];
+            [myScript release];
+        }
+        
     }
 }
 #pragma mark -
@@ -1307,6 +1389,16 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 /*Opens the source browse window, called from Open Source widgets */
 - (IBAction) browseSources: (id) sender
 {
+    
+    hb_state_t s;
+    hb_get_state( fHandle, &s );
+    if (s.state == HB_STATE_SCANNING)
+    {
+        [self cancelScanning:nil];
+        return;
+    }
+    
+    
     NSOpenPanel * panel;
        
     panel = [NSOpenPanel openPanel];
@@ -1354,7 +1446,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
          */
         [sheet orderOut: self];
         
-        if (sender == fOpenSourceTitleMMenu)
+        if (sender == fOpenSourceTitleMMenu || [[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
         {
             /* We put the chosen source path in the source display text field for the
              * source title selection sheet in which the user specifies the specific title to be
@@ -1368,7 +1460,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             if ([[scanPath lastPathComponent] isEqualToString: @"VIDEO_TS"])
             {
                 /* If VIDEO_TS Folder is chosen, choose its parent folder for the source display name
-                 we have to use the title->dvd value so we get the proper name of the volume if a physical dvd is the source*/
+                 we have to use the title->path value so we get the proper name of the volume if a physical dvd is the source*/
                 displayTitlescanSourceName = [[scanPath stringByDeletingLastPathComponent] lastPathComponent];
             }
             else
@@ -1450,6 +1542,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                     /* make sure we remove any path extension as this can also be an '.mpg' file */
                     browsedSourceDisplayName = [[path lastPathComponent] retain];
                 }
+                applyQueueToScan = NO;
                 [self performScan:path scanTitleNum:0];
             }
 
@@ -1482,7 +1575,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 {
     [NSApp endSheet: fScanSrcTitlePanel];
     [fScanSrcTitlePanel orderOut: self];
-
+    
     if(sender == fScanSrcTitleOpenButton)
     {
         /* We setup the scan status in the main window to indicate a source title scan */
@@ -1492,8 +1585,9 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         [fScanIndicator startAnimation: nil];
                
         /* We use the performScan method to actually perform the specified scan passing the path and the title
-            * to be scanned
-            */
+         * to be scanned
+         */
+        applyQueueToScan = NO;
         [self performScan:[fScanSrcTitlePathField stringValue] scanTitleNum:[fScanSrcTitleNumField intValue]];
     }
 }
@@ -1501,10 +1595,10 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 /* Here we actually tell hb_scan to perform the source scan, using the path to source and title number*/
 - (void) performScan:(NSString *) scanPath scanTitleNum: (int) scanTitleNum
 {
-    /* set the bool applyQueueToScan so that we dont apply a queue setting to the final scan */
-    applyQueueToScan = NO;
+    
     /* use a bool to determine whether or not we can decrypt using vlc */
     BOOL cancelScanDecrypt = 0;
+    BOOL vlcFound = 0;
     NSString *path = scanPath;
     HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
     
@@ -1569,6 +1663,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         {
             /* VLC was found in /Applications so all is well, we can carry on using vlc's libdvdcss.dylib for decrypting if needed */
             [self writeToActivityLog: "VLC app found for decrypting physical dvd"];
+            vlcFound = 1;
         }
         /* test for architecture of the vlc app */
         NSArray *vlc_architecturesArray = [[NSBundle bundleWithPath:@"/Applications/VLC.app"] executableArchitectures];
@@ -1612,7 +1707,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         
         
         
-        if (hb_arch == 64 && !vlcIntel64bit && cancelScanDecrypt != 1)
+        if (vlcFound && hb_arch == 64 && !vlcIntel64bit && cancelScanDecrypt != 1)
         {
             
             /* we are 64 bit */
@@ -1632,7 +1727,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 [self writeToActivityLog: "cannot open physical dvd VLC found but not 64 bit, scan cancelled"];
                 cancelScanDecrypt = 1;
             }
-            else if (status == NSAlertDefaultReturn)
+            else if (status == NSAlertAlternateReturn)
             {
                 [self writeToActivityLog: "user overrode 64-bit warning trying to open physical dvd without proper decryption"];
                 cancelScanDecrypt = 0;
@@ -1644,7 +1739,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             }
             
         }    
-        else if (hb_arch == 32 && !vlcIntel32bit && cancelScanDecrypt != 1)
+        else if (vlcFound && hb_arch == 32 && !vlcIntel32bit && cancelScanDecrypt != 1)
         {
             /* we are 32 bit */
             /* Appropriate VLC not found, so cancel */
@@ -1662,7 +1757,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 [self writeToActivityLog: "cannot open physical dvd VLC found but not 32 bit, scan cancelled"];
                 cancelScanDecrypt = 1;
             }
-            else if (status == NSAlertDefaultReturn)
+            else if (status == NSAlertAlternateReturn)
             {
                 [self writeToActivityLog: "user overrode 32-bit warning trying to open physical dvd without proper decryption"];
                 cancelScanDecrypt = 0;
@@ -1693,12 +1788,17 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         /* We use our advance pref to determine how many previews to scan */
         int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
         /* set title to NULL */
-        //fTitle = NULL;
+        fTitle = NULL;
         hb_scan( fHandle, [path UTF8String], scanTitleNum, hb_num_previews, 1 );
         [fSrcDVD2Field setStringValue:@"Scanning new source ..."];
     }
 }
 
+- (IBAction) cancelScanning:(id)sender
+{
+    hb_scan_stop(fHandle);
+}
+
 - (IBAction) showNewScan:(id)sender
 {
     hb_list_t  * list;
@@ -1725,11 +1825,25 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
         }
         else
         {
-            /* We increment the successful scancount here by one,
+            if (applyQueueToScan == YES)
+            {
+                /* we are a rescan of an existing queue item and need to apply the queued settings to the scan */
+                [self writeToActivityLog: "showNewScan: This is a queued item rescan"];
+                
+            }
+            else if (applyQueueToScan == NO)
+            {
+                [self writeToActivityLog: "showNewScan: This is a new source item scan"];
+            }
+            else
+            {
+                [self writeToActivityLog: "showNewScan: cannot grok scan status"];
+            }
+            
+              /* We increment the successful scancount here by one,
              which we use at the end of this function to tell the gui
              if this is the first successful scan since launch and whether
              or not we should set all settings to the defaults */
-            
             currentSuccessfulScanCount++;
             
             [[fWindow toolbar] validateVisibleItems];
@@ -1741,12 +1855,20 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 
                 currentSource = [NSString stringWithUTF8String: title->name];
                 /*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
+                if (!browsedSourceDisplayName)
+                {
+                    browsedSourceDisplayName = @"NoNameDetected";
+                }
                 [fSrcDVD2Field setStringValue:browsedSourceDisplayName];
                 
-                /* Use the dvd name in the default output field here
-                 May want to add code to remove blank spaces for some dvd names*/
+                /* If its a queue rescan for edit, get the queue item output path */
+                /* if not, its a new source scan. */
                 /* Check to see if the last destination has been set,use if so, if not, use Desktop */
-                if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
+                if (applyQueueToScan == YES)
+                {
+                    [fDstFile2Field setStringValue: [NSString stringWithFormat:@"%@", [[QueueFileArray objectAtIndex:fqueueEditRescanItemNum] objectForKey:@"DestinationPath"]]];
+                }
+                else if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"])
                 {
                     [fDstFile2Field setStringValue: [NSString stringWithFormat:
                                                      @"%@/%@.mp4", [[NSUserDefaults standardUserDefaults] stringForKey:@"LastDestinationDirectory"],[browsedSourceDisplayName stringByDeletingPathExtension]]];
@@ -1765,13 +1887,21 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 }
                 
                 [fSrcTitlePopUp addItemWithTitle: [NSString
-                                                   stringWithFormat: @"%d - %02dh%02dm%02ds",
-                                                   title->index, title->hours, title->minutes,
+                                                   stringWithFormat: @"%s %d - %02dh%02dm%02ds",
+                                                   title->name,title->index, title->hours, title->minutes,
                                                    title->seconds]];
             }
             
-            // Select the longuest title
-            [fSrcTitlePopUp selectItemAtIndex: indxpri];
+            /* if we are a stream, select the first title */
+            if (title->type == HB_STREAM_TYPE)
+            {
+                [fSrcTitlePopUp selectItemAtIndex: 0];
+            }
+            else
+            {
+                /* if not then select the longest title (dvd) */
+                [fSrcTitlePopUp selectItemAtIndex: indxpri];
+            }
             [self titlePopUpChanged:nil];
             
             SuccessfulScan = YES;
@@ -1780,6 +1910,8 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             /* if its the initial successful scan after awakeFromNib */
             if (currentSuccessfulScanCount == 1)
             {
+                [self encodeStartStopPopUpChanged:nil];
+                
                 [self selectDefaultPreset:nil];
                 
                 // Open preview window now if it was visible when HB was closed
@@ -1791,6 +1923,13 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                     [self showPicturePanel:nil];
                 
             }
+            if (applyQueueToScan == YES)
+            {
+                /* we are a rescan of an existing queue item and need to apply the queued settings to the scan */
+                [self writeToActivityLog: "showNewScan: calling applyQueueSettingsToMainWindow"];
+                [self applyQueueSettingsToMainWindow:nil];
+                
+            }
 
             
         }
@@ -1908,7 +2047,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
      * by one to keep in sync with the queue array
      */
     currentQueueEncodeIndex--;
-    [self writeToActivityLog: "removeQueueFileItem: Removing a cancelled/finished encode, decrement currentQueueEncodeIndex to %d", currentQueueEncodeIndex];
+
     }
     [QueueFileArray removeObjectAtIndex:queueItemToRemove];
     [self saveQueueFileItem];
@@ -2075,13 +2214,38 @@ fWorkingCount = 0;
     [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"Status"];
     /* Source and Destination Information */
     
-    [queueFileJob setObject:[NSString stringWithUTF8String: title->dvd] forKey:@"SourcePath"];
+    [queueFileJob setObject:[NSString stringWithUTF8String: title->path] forKey:@"SourcePath"];
     [queueFileJob setObject:[fSrcDVD2Field stringValue] forKey:@"SourceName"];
     [queueFileJob setObject:[NSNumber numberWithInt:title->index] forKey:@"TitleNumber"];
     [queueFileJob setObject:[NSNumber numberWithInt:[fSrcAnglePopUp indexOfSelectedItem] + 1] forKey:@"TitleAngle"];
-    [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
     
+    /* Determine and set a variable to tell hb what start and stop times to use ... chapters vs seconds */
+    if( [fEncodeStartStopPopUp indexOfSelectedItem] == 0 )
+    {
+        [queueFileJob setObject:[NSNumber numberWithInt:0] forKey:@"fEncodeStartStop"];    
+    }
+    else if ([fEncodeStartStopPopUp indexOfSelectedItem] == 1)
+    {
+        [queueFileJob setObject:[NSNumber numberWithInt:1] forKey:@"fEncodeStartStop"];   
+    }
+    else if ([fEncodeStartStopPopUp indexOfSelectedItem] == 2)
+    {
+        [queueFileJob setObject:[NSNumber numberWithInt:2] forKey:@"fEncodeStartStop"];
+    }
+    /* Chapter encode info */
+    [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterStartPopUp indexOfSelectedItem] + 1] forKey:@"ChapterStart"];
     [queueFileJob setObject:[NSNumber numberWithInt:[fSrcChapterEndPopUp indexOfSelectedItem] + 1] forKey:@"ChapterEnd"];
+    /* Time (pts) encode info */
+    [queueFileJob setObject:[NSNumber numberWithInt:[fSrcTimeStartEncodingField intValue]] forKey:@"StartSeconds"];
+    [queueFileJob setObject:[NSNumber numberWithInt:[fSrcTimeEndEncodingField intValue] - [fSrcTimeStartEncodingField intValue]] forKey:@"StopSeconds"];
+    /* Frame number encode info */
+    [queueFileJob setObject:[NSNumber numberWithInt:[fSrcFrameStartEncodingField intValue]] forKey:@"StartFrame"];
+    [queueFileJob setObject:[NSNumber numberWithInt:[fSrcFrameEndEncodingField intValue] - [fSrcFrameStartEncodingField intValue]] forKey:@"StopFrame"];
+    
+    
+    /* The number of seek points equals the number of seconds announced in the title as that is our current granularity */
+    int title_duration_seconds = (title->hours * 3600) + (title->minutes * 60) + (title->seconds);
+    [queueFileJob setObject:[NSNumber numberWithInt:title_duration_seconds] forKey:@"SourceTotalSeconds"];
     
     [queueFileJob setObject:[fDstFile2Field stringValue] forKey:@"DestinationPath"];
     
@@ -2151,10 +2315,11 @@ fWorkingCount = 0;
        [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PictureHeight"];
        [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->keep_ratio] forKey:@"PictureKeepRatio"];
        [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.mode] forKey:@"PicturePAR"];
+    [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->modulus] forKey:@"PictureModulus"];
     /* if we are custom anamorphic, store the exact storage, par and display dims */
     if (fTitle->job->anamorphic.mode == 3)
     {
-        [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->anamorphic.modulus] forKey:@"PicturePARModulus"];
+        [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->modulus] forKey:@"PicturePARModulus"];
         
         [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->width] forKey:@"PicturePARStorageWidth"];
         [queueFileJob setObject:[NSNumber numberWithInt:fTitle->job->height] forKey:@"PicturePARStorageHeight"];
@@ -2237,8 +2402,8 @@ fWorkingCount = 0;
     }
     
        /* Subtitles*/
-    NSMutableArray *subtitlesArray = [[NSMutableArray alloc] init];
-    [queueFileJob setObject:[NSArray arrayWithArray: [fSubtitlesDelegate getSubtitleArray: subtitlesArray]] forKey:@"SubtitleList"];
+    NSMutableArray *subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray] copyItems:YES];
+    [queueFileJob setObject:[NSArray arrayWithArray: subtitlesArray] forKey:@"SubtitleList"];
     [subtitlesArray autorelease];
 
     /* Now we go ahead and set the "job->values in the plist for passing right to fQueueEncodeLibhb */
@@ -2278,7 +2443,6 @@ fWorkingCount = 0;
     /*Audio*/
     if ([fAudLang1PopUp indexOfSelectedItem] > 0)
     {
-        //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio1Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1CodecPopUp selectedItem] tag]] forKey:@"JobAudio1Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1MixPopUp selectedItem] tag]] forKey:@"JobAudio1Mixdown"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack1RatePopUp selectedItem] tag]] forKey:@"JobAudio1Samplerate"];
@@ -2286,7 +2450,6 @@ fWorkingCount = 0;
      }
     if ([fAudLang2PopUp indexOfSelectedItem] > 0)
     {
-        //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio2Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2CodecPopUp selectedItem] tag]] forKey:@"JobAudio2Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2MixPopUp selectedItem] tag]] forKey:@"JobAudio2Mixdown"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack2RatePopUp selectedItem] tag]] forKey:@"JobAudio2Samplerate"];
@@ -2294,7 +2457,6 @@ fWorkingCount = 0;
     }
     if ([fAudLang3PopUp indexOfSelectedItem] > 0)
     {
-        //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio3Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3CodecPopUp selectedItem] tag]] forKey:@"JobAudio3Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3MixPopUp selectedItem] tag]] forKey:@"JobAudio3Mixdown"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack3RatePopUp selectedItem] tag]] forKey:@"JobAudio3Samplerate"];
@@ -2302,14 +2464,12 @@ fWorkingCount = 0;
     }
     if ([fAudLang4PopUp indexOfSelectedItem] > 0)
     {
-        //[queueFileJob setObject:[fAudTrack1CodecPopUp indexOfSelectedItem] forKey:@"JobAudio4Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4CodecPopUp selectedItem] tag]] forKey:@"JobAudio4Encoder"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4MixPopUp selectedItem] tag]] forKey:@"JobAudio4Mixdown"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4RatePopUp selectedItem] tag]] forKey:@"JobAudio4Samplerate"];
         [queueFileJob setObject:[NSNumber numberWithInt:[[fAudTrack4BitratePopUp selectedItem] tag]] forKey:@"JobAudio4Bitrate"];
     }
 
     /* we need to auto relase the queueFileJob and return it */
     [queueFileJob autorelease];
     return queueFileJob;
@@ -2360,21 +2520,17 @@ fWorkingCount = 0;
        
     /* We save all of the Queue data here */
     [self saveQueueFileItem];
-       /* We Reload the New Table data for presets */
-    //[fPresetsOutlineView reloadData];
 
     /* Since we have now marked a queue item as done
      * we can go ahead and increment currentQueueEncodeIndex 
      * so that if there is anything left in the queue we can
      * go ahead and move to the next item if we want to */
     currentQueueEncodeIndex++ ;
-    [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
     int queueItems = [QueueFileArray count];
     /* If we still have more items in our queue, lets go to the next one */
     if (currentQueueEncodeIndex < queueItems)
     {
-    [self writeToActivityLog: "incrementQueueItemDone currentQueueEncodeIndex is incremented to: %d", currentQueueEncodeIndex];
-    [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
+        [self performNewQueueScan:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"SourcePath"] scanTitleNum:[[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"TitleNumber"]intValue]];
     }
     else
     {
@@ -2388,21 +2544,14 @@ fWorkingCount = 0;
    /* Tell HB to output a new activity log file for this encode */
     [outputPanel startEncodeLog:[[QueueFileArray objectAtIndex:currentQueueEncodeIndex] objectForKey:@"DestinationPath"]];
     
-    
-     /* use a bool to determine whether or not we can decrypt using vlc */
+    /* use a bool to determine whether or not we can decrypt using vlc */
     BOOL cancelScanDecrypt = 0;
     /* set the bool so that showNewScan knows to apply the appropriate queue
-    * settings as this is a queue rescan
-    */
-    applyQueueToScan = YES;
+     * settings as this is a queue rescan
+     */
     NSString *path = scanPath;
     HBDVDDetector *detector = [HBDVDDetector detectorForPath:path];
-
-        /*On Screen Notification*/
-        //int status;
-        //status = NSRunAlertPanel(@"HandBrake is now loading up a new queue item...",@"Would You Like to wait until you add another encode?", @"Cancel", @"Okay", nil);
-        //[NSApp requestUserAttention:NSCriticalRequest];
-
+    
     if( [detector isVideoDVD] )
     {
         // The chosen path was actually on a DVD, so use the raw block
@@ -2462,28 +2611,139 @@ fWorkingCount = 0;
             [self writeToActivityLog: "scanning specifically for title: %d", scanTitleNum];
         }
         
-        [self writeToActivityLog: "performNewQueueScan currentQueueEncodeIndex is: %d", currentQueueEncodeIndex];
-        /* We use our advance pref to determine how many previews to scan */
+         /* We use our advance pref to determine how many previews to scan */
         int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
         hb_scan( fQueueEncodeLibhb, [path UTF8String], scanTitleNum, hb_num_previews, 0 );
     }
 }
 
-/* This method was originally used to load up a new queue item in the gui and
- * then start processing it. However we now have modified -prepareJob and use a second
- * instance of libhb to do our actual encoding, therefor right now it is not required. 
- * Nonetheless I want to leave this in here
- * because basically its everything we need to be able to actually modify a pending queue
- * item in the gui and resave it. At least for now - dynaflash
- */
-
-- (IBAction)applyQueueSettings:(id)sender
+/* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
+- (void) processNewQueueEncode
 {
+    hb_list_t  * list  = hb_get_titles( fQueueEncodeLibhb );
+    hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
+    hb_job_t * job = title->job;
+    
+    if( !hb_list_count( list ) )
+    {
+        [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
+    }
+    
     NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
-    hb_job_t * job = fTitle->job;
+    [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
+    [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
+    job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
+    [self prepareJob];
     
+    /*
+     * If scanning we need to do some extra setup of the job.
+     */
+    if( job->indepth_scan == 1 )
+    {
+        char *x264opts_tmp;
+        
+        /*
+         * When subtitle scan is enabled do a fast pre-scan job
+         * which will determine which subtitles to enable, if any.
+         */
+        job->pass = -1;
+        x264opts_tmp = job->x264opts;
+        
+        job->x264opts = NULL;
+        
+        job->indepth_scan = 1;  
+
+        
+        /*
+         * Add the pre-scan job
+         */
+        hb_add( fQueueEncodeLibhb, job );
+        job->x264opts = x264opts_tmp;
+    }
+
+    
+    if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
+    {
+        job->indepth_scan = 0;
+        
+
+        
+        job->pass = 1;
+        
+        hb_add( fQueueEncodeLibhb, job );
+        
+        job->pass = 2;
+        
+        job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */  
+        strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
+        
+        hb_add( fQueueEncodeLibhb, job );
+        
+    }
+    else
+    {
+        job->indepth_scan = 0;
+        job->pass = 0;
+        
+        hb_add( fQueueEncodeLibhb, job );
+    }
+       
+    NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
+       [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
+       /* Lets mark our new encode as 1 or "Encoding" */
+    [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
+    [self saveQueueFileItem];
+    
+    /* we need to clean up the subtitle tracks after the job(s) have been set  */
+    int num_subtitle_tracks = hb_list_count(job->list_subtitle);
+    int ii;
+    for(ii = 0; ii < num_subtitle_tracks; ii++)
+    {
+        hb_subtitle_t * subtitle;
+        subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
+        
+
+        hb_list_rem(job->list_subtitle, subtitle);
+        free(subtitle);
+    }
+    
+    /* We should be all setup so let 'er rip */   
+    [self doRip];
+}
+
+
+
+#pragma mark -
+#pragma mark Queue Item Editing
+
+/* Rescans the chosen queue item back into the main window */
+- (void)rescanQueueItemToMainWindow:(NSString *) scanPath scanTitleNum: (int) scanTitleNum selectedQueueItem: (int) selectedQueueItem
+{
+    fqueueEditRescanItemNum = selectedQueueItem;
+    [self writeToActivityLog: "rescanQueueItemToMainWindow: Re-scanning queue item at index:%d",fqueueEditRescanItemNum];
+    applyQueueToScan = YES;
+    /* Set the browsedSourceDisplayName for showNewScan */
+    browsedSourceDisplayName = [[QueueFileArray objectAtIndex:fqueueEditRescanItemNum] objectForKey:@"SourceName"];
+    [self performScan:scanPath scanTitleNum:scanTitleNum];
+}
+
+
+/* We use this method after a queue item rescan for edit.
+ * it largely mirrors -selectPreset in terms of structure.
+ * Assumes that a queue item has been reloaded into the main window.
+ */
+- (IBAction)applyQueueSettingsToMainWindow:(id)sender
+{
+    NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:fqueueEditRescanItemNum];
+    hb_job_t * job = fTitle->job;
+    if (queueToApply)
+    {
+        [self writeToActivityLog: "applyQueueSettingsToMainWindow: queue item found"];
+    }
     /* Set title number and chapters */
-    /* since the queue only scans a single title, we really don't need to pick a title */
+    /* since the queue only scans a single title, its already been selected in showNewScan
+       so do not try to reset it here. However if we do decide to do full source scans on
+       a queue edit rescan, we would need it. So leaving in for now but commenting out. */
     //[fSrcTitlePopUp selectItemAtIndex: [[queueToApply objectForKey:@"TitleNumber"] intValue] - 1];
     
     [fSrcChapterStartPopUp selectItemAtIndex: [[queueToApply objectForKey:@"ChapterStart"] intValue] - 1];
@@ -2516,10 +2776,34 @@ fWorkingCount = 0;
     
     [fVidTargetSizeField setStringValue:[queueToApply objectForKey:@"VideoTargetSize"]];
     [fVidBitrateField setStringValue:[queueToApply objectForKey:@"VideoAvgBitrate"]];
-    [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
+    /* Since we are now using RF Values for the slider, we detect if the preset uses an old quality float.
+     * So, check to see if the quality value is less than 1.0 which should indicate the old ".062" type
+     * quality preset. Caveat: in the case of x264, where the RF scale starts at 0, it would misinterpret
+     * a preset that uses 0.0 - 0.99 for RF as an old style preset. Not sure how to get around that one yet,
+     * though it should be a corner case since it would pretty much be a preset for lossless encoding. */
+    if ([[queueToApply objectForKey:@"VideoQualitySlider"] floatValue] < 1.0)
+    {
+        /* For the quality slider we need to convert the old percent's to the new rf scales */
+        float rf =  (([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]);
+        [fVidQualitySlider setFloatValue:rf];
+        
+    }
+    else
+    {
+        /* Since theora's qp value goes up from left to right, we can just set the slider float value */
+        if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
+        {
+            [fVidQualitySlider setFloatValue:[[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
+        }
+        else
+        {
+            /* since ffmpeg and x264 use an "inverted" slider (lower qp/rf values indicate a higher quality) we invert the value on the slider */
+            [fVidQualitySlider setFloatValue:([fVidQualitySlider maxValue] + [fVidQualitySlider minValue]) - [[queueToApply objectForKey:@"VideoQualitySlider"] floatValue]];
+        }
+    }
     
     [self videoMatrixChanged:nil];
-    
+        
     /* Video framerate */
     /* For video preset video framerate, we want to make sure that Same as source does not conflict with the
      detected framerate in the fVidRatePopUp so we use index 0*/
@@ -2539,120 +2823,129 @@ fWorkingCount = 0;
     [fVidTurboPassCheck setState:[[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue]];
     
     /*Audio*/
-    if ([queueToApply objectForKey:@"Audio1Track"] > 0)
+    
+    
+    /* Now lets add our new tracks to the audio list here */
+    if ([[queueToApply objectForKey:@"Audio1Track"] intValue] > 0)
     {
-        if ([fAudLang1PopUp indexOfSelectedItem] == 0)
-        {
-            [fAudLang1PopUp selectItemAtIndex: 1];
-        }
+        [fAudLang1PopUp selectItemAtIndex: [[queueToApply objectForKey:@"Audio1Track"] intValue]];
         [self audioTrackPopUpChanged: fAudLang1PopUp];
         [fAudTrack1CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Encoder"]];
         [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
+        
         [fAudTrack1MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Mixdown"]];
-        /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
-         * mixdown*/
-        if  ([fAudTrack1MixPopUp selectedItem] == nil)
-        {
-            [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
-        }
-        [fAudTrack1RatePopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Samplerate"]];
-        /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
-        if (![[queueToApply objectForKey:@"Audio1Encoder"] isEqualToString:@"AC3 Passthru"])
-        {
-            [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
-        }
+        
+        [fAudTrack1RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Samplerate"]];
+        [fAudTrack1BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio1Bitrate"]];
+        
         [fAudTrack1DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio1TrackDRCSlider"] floatValue]];
         [self audioDRCSliderChanged: fAudTrack1DrcSlider];
     }
-    if ([queueToApply objectForKey:@"Audio2Track"] > 0)
+    else
     {
-        if ([fAudLang2PopUp indexOfSelectedItem] == 0)
-        {
-            [fAudLang2PopUp selectItemAtIndex: 1];
-        }
+        [fAudLang1PopUp selectItemAtIndex: 0];
+        [self audioTrackPopUpChanged: fAudLang1PopUp];
+    }
+    if ([[queueToApply objectForKey:@"Audio2Track"] intValue] > 0)
+    {
+        [fAudLang2PopUp selectItemAtIndex: [[queueToApply objectForKey:@"Audio2Track"] intValue]];
         [self audioTrackPopUpChanged: fAudLang2PopUp];
         [fAudTrack2CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Encoder"]];
         [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
+        
         [fAudTrack2MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Mixdown"]];
-        /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
-         * mixdown*/
-        if  ([fAudTrack2MixPopUp selectedItem] == nil)
-        {
-            [self audioTrackPopUpChanged: fAudTrack2CodecPopUp];
-        }
+        
         [fAudTrack2RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Samplerate"]];
-        /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
-        if (![[queueToApply objectForKey:@"Audio2Encoder"] isEqualToString:@"AC3 Passthru"])
-        {
-            [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
-        }
+        [fAudTrack2BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio2Bitrate"]];
+        
         [fAudTrack2DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio2TrackDRCSlider"] floatValue]];
         [self audioDRCSliderChanged: fAudTrack2DrcSlider];
     }
-    if ([queueToApply objectForKey:@"Audio3Track"] > 0)
+    else
     {
-        if ([fAudLang3PopUp indexOfSelectedItem] == 0)
-        {
-            [fAudLang3PopUp selectItemAtIndex: 1];
-        }
+        [fAudLang2PopUp selectItemAtIndex: 0];
+        [self audioTrackPopUpChanged: fAudLang2PopUp];
+    }
+    if ([[queueToApply objectForKey:@"Audio3Track"] intValue] > 0)
+    {
+        [fAudLang3PopUp selectItemAtIndex: [[queueToApply objectForKey:@"Audio3Track"] intValue]];
         [self audioTrackPopUpChanged: fAudLang3PopUp];
         [fAudTrack3CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Encoder"]];
         [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
+        
         [fAudTrack3MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Mixdown"]];
-        /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
-         * mixdown*/
-        if  ([fAudTrack3MixPopUp selectedItem] == nil)
-        {
-            [self audioTrackPopUpChanged: fAudTrack3CodecPopUp];
-        }
+        
         [fAudTrack3RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Samplerate"]];
-        /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
-        if (![[queueToApply objectForKey:@"Audio3Encoder"] isEqualToString: @"AC3 Passthru"])
-        {
-            [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
-        }
+        [fAudTrack3BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio3Bitrate"]];
+        
         [fAudTrack3DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio3TrackDRCSlider"] floatValue]];
         [self audioDRCSliderChanged: fAudTrack3DrcSlider];
     }
-    if ([queueToApply objectForKey:@"Audio4Track"] > 0)
+    else
     {
-        if ([fAudLang4PopUp indexOfSelectedItem] == 0)
-        {
-            [fAudLang4PopUp selectItemAtIndex: 1];
-        }
+        [fAudLang3PopUp selectItemAtIndex: 0];
+        [self audioTrackPopUpChanged: fAudLang3PopUp];
+    }
+    if ([[queueToApply objectForKey:@"Audio4Track"] intValue] > 0)
+    {
+        [fAudLang4PopUp selectItemAtIndex: [[queueToApply objectForKey:@"Audio4Track"] intValue]];
         [self audioTrackPopUpChanged: fAudLang4PopUp];
         [fAudTrack4CodecPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Encoder"]];
         [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
+        
         [fAudTrack4MixPopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Mixdown"]];
-        /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
-         * mixdown*/
-        if  ([fAudTrack4MixPopUp selectedItem] == nil)
-        {
-            [self audioTrackPopUpChanged: fAudTrack4CodecPopUp];
-        }
+        
         [fAudTrack4RatePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Samplerate"]];
-        /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
-        if (![[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString:@"AC3 Passthru"])
-        {
-            [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
-        }
+        [fAudTrack4BitratePopUp selectItemWithTitle:[queueToApply objectForKey:@"Audio4Bitrate"]];
+        
         [fAudTrack4DrcSlider setFloatValue:[[queueToApply objectForKey:@"Audio4TrackDRCSlider"] floatValue]];
         [self audioDRCSliderChanged: fAudTrack4DrcSlider];
     }
-    
+    else
+    {
+        [fAudLang4PopUp selectItemAtIndex: 0];
+        [self audioTrackPopUpChanged: fAudLang4PopUp];
+    }
     
     /*Subtitles*/
-    [fSubPopUp selectItemWithTitle:[queueToApply objectForKey:@"Subtitles"]];
-    /* Forced Subtitles */
-    [fSubForcedCheck setState:[[queueToApply objectForKey:@"SubtitlesForced"] intValue]];
-    
+    /* Crashy crashy right now, working on it */
+    [fSubtitlesDelegate setNewSubtitles:[queueToApply objectForKey:@"SubtitleList"]];
+    [fSubtitlesTable reloadData];  
     /* Picture Settings */
+    
+    /* If Cropping is set to custom, then recall all four crop values from
+     when the preset was created and apply them */
+    if ([[queueToApply objectForKey:@"PictureAutoCrop"]  intValue] == 0)
+    {
+        [fPictureController setAutoCrop:NO];
+        
+        /* Here we use the custom crop values saved at the time the preset was saved */
+        job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"]  intValue];
+        job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"]  intValue];
+        job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"]  intValue];
+        job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"]  intValue];
+        
+    }
+    else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
+    {
+        [fPictureController setAutoCrop:YES];
+        /* Here we use the auto crop values determined right after scan */
+        job->crop[0] = AutoCropTop;
+        job->crop[1] = AutoCropBottom;
+        job->crop[2] = AutoCropLeft;
+        job->crop[3] = AutoCropRight;
+        
+    }
+    
+    job->modulus = [[queueToApply objectForKey:@"PictureModulus"]  intValue];
+    
     /* we check to make sure the presets width/height does not exceed the sources width/height */
     if (fTitle->width < [[queueToApply objectForKey:@"PictureWidth"]  intValue] || fTitle->height < [[queueToApply objectForKey:@"PictureHeight"]  intValue])
     {
         /* if so, then we use the sources height and width to avoid scaling up */
-        job->width = fTitle->width;
-        job->height = fTitle->height;
+        //job->width = fTitle->width;
+        //job->height = fTitle->height;
+        [self revertPictureSizeToMax:nil];
     }
     else // source width/height is >= the preset height/width
     {
@@ -2671,180 +2964,140 @@ fWorkingCount = 0;
         }
     }
     job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"]  intValue];
+    job->modulus = [[queueToApply objectForKey:@"PictureModulus"]  intValue];
     
+    /* Filters */
     
-    /* If Cropping is set to custom, then recall all four crop values from
-     when the preset was created and apply them */
-    if ([[queueToApply objectForKey:@"PictureAutoCrop"]  intValue] == 0)
+    /* We only allow *either* Decomb or Deinterlace. So check for the PictureDecombDeinterlace key.
+     * also, older presets may not have this key, in which case we also check to see if that preset had  PictureDecomb
+     * specified, in which case we use decomb and ignore any possible Deinterlace settings as using both was less than
+     * sane.
+     */
+    [fPictureController setUseDecomb:1];
+    [fPictureController setDecomb:0];
+    [fPictureController setDeinterlace:0];
+    if ([[queueToApply objectForKey:@"PictureDecombDeinterlace"] intValue] == 1 || [[queueToApply objectForKey:@"PictureDecomb"] intValue] > 0)
     {
-        [fPictureController setAutoCrop:NO];
-        
-        /* Here we use the custom crop values saved at the time the preset was saved */
-        job->crop[0] = [[queueToApply objectForKey:@"PictureTopCrop"]  intValue];
-        job->crop[1] = [[queueToApply objectForKey:@"PictureBottomCrop"]  intValue];
-        job->crop[2] = [[queueToApply objectForKey:@"PictureLeftCrop"]  intValue];
-        job->crop[3] = [[queueToApply objectForKey:@"PictureRightCrop"]  intValue];
-        
+        /* we are using decomb */
+        /* Decomb */
+        if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] > 0)
+        {
+            [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
+            
+            /* if we are using "Custom" in the decomb setting, also set the custom string*/
+            if ([[queueToApply objectForKey:@"PictureDecomb"] intValue] == 1)
+            {
+                [fPictureController setDecombCustomString:[queueToApply objectForKey:@"PictureDecombCustom"]];    
+            }
+        }
     }
-    else /* if auto crop has been saved in preset, set to auto and use post scan auto crop */
+    else
     {
-        [fPictureController setAutoCrop:YES];
-        /* Here we use the auto crop values determined right after scan */
-        job->crop[0] = AutoCropTop;
-        job->crop[1] = AutoCropBottom;
-        job->crop[2] = AutoCropLeft;
-        job->crop[3] = AutoCropRight;
-        
+        /* We are using Deinterlace */
+        /* Deinterlace */
+        if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] > 0)
+        {
+            [fPictureController setUseDecomb:0];
+            [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
+            /* if we are using "Custom" in the deinterlace setting, also set the custom string*/
+            if ([[queueToApply objectForKey:@"PictureDeinterlace"] intValue] == 1)
+            {
+                [fPictureController setDeinterlaceCustomString:[queueToApply objectForKey:@"PictureDeinterlaceCustom"]];    
+            }
+        }
     }
     
-    /* Filters */
-    /* Deinterlace */
-    [fPictureController setDeinterlace:[[queueToApply objectForKey:@"PictureDeinterlace"] intValue]];
     
     /* Detelecine */
-    [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
-    /* Denoise */
-    [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
-    /* Deblock */
-    [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
-    /* Decomb */
-    [fPictureController setDecomb:[[queueToApply objectForKey:@"PictureDecomb"] intValue]];
-    /* Grayscale */
-    [fPictureController setGrayscale:[[queueToApply objectForKey:@"VideoGrayScale"] intValue]];
-    
-    [self calculatePictureSizing:nil];
-    
-    
-    /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
-    //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
-    //    [queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
-    if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
-       {
-               /* Deselect the currently selected Preset if there is one*/
-        //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
-        //[self selectPreset:nil];
-               
-        //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
-               /* Change UI to show "Custom" settings are being used */
-               //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
-        
-               curUserPresetChosenNum = nil;
-       }
+    if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] > 0)
+    {
+        [fPictureController setDetelecine:[[queueToApply objectForKey:@"PictureDetelecine"] intValue]];
+        /* if we are using "Custom" in the detelecine setting, also set the custom string*/
+        if ([[queueToApply objectForKey:@"PictureDetelecine"] intValue] == 1)
+        {
+            [fPictureController setDetelecineCustomString:[queueToApply objectForKey:@"PictureDetelecineCustom"]];    
+        }
+    }
     else
     {
-        /* Deselect the currently selected Preset if there is one*/
-               [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
-               /* Change UI to show "Custom" settings are being used */
-               [fPresetSelectedDisplay setStringValue: @"Custom"];
-        
-               //curUserPresetChosenNum = nil;
+        [fPictureController setDetelecine:0];
     }
     
-    /* We need to set this bool back to NO, in case the user wants to do a scan */
-    //applyQueueToScan = NO;
-    
-    /* so now we go ahead and process the new settings */
-    [self processNewQueueEncode];
-}
-
-
-
-/* This assumes that we have re-scanned and loaded up a new queue item to send to libhb as fQueueEncodeLibhb */
-- (void) processNewQueueEncode
-{
-    hb_list_t  * list  = hb_get_titles( fQueueEncodeLibhb );
-    hb_title_t * title = (hb_title_t *) hb_list_item( list,0 ); // is always zero since now its a single title scan
-    hb_job_t * job = title->job;
-    
-    if( !hb_list_count( list ) )
+    /* Denoise */
+    if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] > 0)
     {
-        [self writeToActivityLog: "processNewQueueEncode WARNING nothing found in the title list"];
+        [fPictureController setDenoise:[[queueToApply objectForKey:@"PictureDenoise"] intValue]];
+        /* if we are using "Custom" in the denoise setting, also set the custom string*/
+        if ([[queueToApply objectForKey:@"PictureDenoise"] intValue] == 1)
+        {
+            [fPictureController setDenoiseCustomString:[queueToApply objectForKey:@"PictureDenoiseCustom"]];    
+        }
     }
+    else
+    {
+        [fPictureController setDenoise:0];
+    }   
     
-    NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
-    [self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
-    [self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
-    job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
-    //[self writeToActivityLog: "processNewQueueEncode sending to prepareJob"];
-    [self prepareJob];
-    
-    /*
-     * If scanning we need to do some extra setup of the job.
-     */
-    if( job->indepth_scan == 1 )
+    /* Deblock */
+    if ([[queueToApply objectForKey:@"PictureDeblock"] intValue] == 1)
     {
-        char *x264opts_tmp;
-        
-        /*
-         * When subtitle scan is enabled do a fast pre-scan job
-         * which will determine which subtitles to enable, if any.
-         */
-        job->pass = -1;
-        x264opts_tmp = job->x264opts;
-        
-        job->x264opts = NULL;
-        
-        job->indepth_scan = 1;  
-
-        
-        /*
-         * Add the pre-scan job
-         */
-        hb_add( fQueueEncodeLibhb, job );
-        job->x264opts = x264opts_tmp;
+        /* if its a one, then its the old on/off deblock, set on to 5*/
+        [fPictureController setDeblock:5];
+    }
+    else
+    {
+        /* use the settings intValue */
+        [fPictureController setDeblock:[[queueToApply objectForKey:@"PictureDeblock"] intValue]];
     }
-
     
-    if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
+    if ([[queueToApply objectForKey:@"VideoGrayScale"] intValue] == 1)
     {
-        job->indepth_scan = 0;
-        
-
-        
-        job->pass = 1;
-        
-        hb_add( fQueueEncodeLibhb, job );
-        
-        job->pass = 2;
-        
-        job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */  
-        strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
-        
-        hb_add( fQueueEncodeLibhb, job );
-        
+        [fPictureController setGrayscale:1];
     }
     else
     {
-        job->indepth_scan = 0;
-        job->pass = 0;
-        
-        hb_add( fQueueEncodeLibhb, job );
+        [fPictureController setGrayscale:0];
     }
-       
-    NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
-       [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
-       /* Lets mark our new encode as 1 or "Encoding" */
-    [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
-    [self saveQueueFileItem];
     
-    /* we need to clean up the subtitle tracks after the job(s) have been set  */
-    int num_subtitle_tracks = hb_list_count(job->list_subtitle);
-    int ii;
-    for(ii = 0; ii < num_subtitle_tracks; ii++)
+    /* we call SetTitle: in fPictureController so we get an instant update in the Picture Settings window */
+    [fPictureController SetTitle:fTitle];
+    [self calculatePictureSizing:nil];
+    
+    /* somehow we need to figure out a way to tie the queue item to a preset if it used one */
+    //[queueFileJob setObject:[fPresetSelectedDisplay stringValue] forKey:@"PresetName"];
+    //[queueFileJob setObject:[NSNumber numberWithInt:[fPresetsOutlineView selectedRow]] forKey:@"PresetIndexNum"];
+    if ([queueToApply objectForKey:@"PresetIndexNum"]) // This item used a preset so insert that info
+       {
+               /* Deselect the currently selected Preset if there is one*/
+        //[fPresetsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]] byExtendingSelection:NO];
+        //[self selectPreset:nil];
+               
+        //[fPresetsOutlineView selectRow:[[queueToApply objectForKey:@"PresetIndexNum"] intValue]];
+               /* Change UI to show "Custom" settings are being used */
+               //[fPresetSelectedDisplay setStringValue: [[queueToApply objectForKey:@"PresetName"] stringValue]];
+        
+               curUserPresetChosenNum = nil;
+       }
+    else
     {
-        hb_subtitle_t * subtitle;
-        subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
+        /* Deselect the currently selected Preset if there is one*/
+               [fPresetsOutlineView deselectRow:[fPresetsOutlineView selectedRow]];
+               /* Change UI to show "Custom" settings are being used */
+               [fPresetSelectedDisplay setStringValue: @"Custom"];
         
-
-        hb_list_rem(job->list_subtitle, subtitle);
-        free(subtitle);
+               //curUserPresetChosenNum = nil;
     }
     
+    /* We need to set this bool back to NO, in case the user wants to do a scan */
+    //applyQueueToScan = NO;
     
-    /* We should be all setup so let 'er rip */   
-    [self doRip];
+    /* Not that source is loaded and settings applied, delete the queue item from the queue */
+    [self writeToActivityLog: "applyQueueSettingsToMainWindow: deleting queue item:%d",fqueueEditRescanItemNum];
+    [self removeQueueFileItem:fqueueEditRescanItemNum];
 }
 
+
+
 #pragma mark -
 #pragma mark Live Preview
 /* Note,this is much like prepareJob, but directly sets the job vars so Picture Preview
@@ -2931,12 +3184,10 @@ fWorkingCount = 0;
     }
 
     /* Subtitle settings */
-    NSMutableArray *subtitlesArray = nil;
-    subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray: subtitlesArray]];
+    NSMutableArray *subtitlesArray = [[NSMutableArray alloc] initWithArray:[fSubtitlesDelegate getSubtitleArray] copyItems:YES];
     
     
-    
- int subtitle = nil;
+int subtitle = nil;
 int force;
 int burned;
 int def;
@@ -3035,8 +3286,6 @@ bool one_burned = FALSE;
                 
                 if (subt != NULL)
                 {
-                    [self writeToActivityLog: "Setting Subtitle: %s", subt];
-
                     hb_subtitle_config_t sub_config = subt->config;
                     
                     if (!burned && job->mux == HB_MUX_MKV && 
@@ -3291,10 +3540,46 @@ bool one_burned = FALSE;
     hb_audio_config_t * audio;
     /* Title Angle for dvdnav */
     job->angle = [[queueToApply objectForKey:@"TitleAngle"] intValue];
-    /* Chapter selection */
-    job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
-    job->chapter_end   = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
+    
+    if([[queueToApply objectForKey:@"fEncodeStartStop"] intValue] == 0)
+    {
+        /* Chapter selection */
+        [self writeToActivityLog: "Start / Stop set to chapters"];
+        job->chapter_start = [[queueToApply objectForKey:@"JobChapterStart"] intValue];
+        job->chapter_end   = [[queueToApply objectForKey:@"JobChapterEnd"] intValue];
+    }
+    else if ([[queueToApply objectForKey:@"fEncodeStartStop"] intValue] == 1)
+    {
+        /* we are pts based start / stop */
+        [self writeToActivityLog: "Start / Stop set to seconds ..."];
+        
+        /* Point A to Point B. Time to time in seconds.*/
+        /* get the start seconds from the start seconds field */
+        int start_seconds = [[queueToApply objectForKey:@"StartSeconds"] intValue];
+        job->pts_to_start = start_seconds * 90000LL;
+        /* Stop seconds is actually the duration of encode, so subtract the end seconds from the start seconds */
+        int stop_seconds = [[queueToApply objectForKey:@"StopSeconds"] intValue];
+        job->pts_to_stop = stop_seconds * 90000LL;
+        
+    }
+    else if ([[queueToApply objectForKey:@"fEncodeStartStop"] intValue] == 2)
+    {
+        /* we are frame based start / stop */
+        [self writeToActivityLog: "Start / Stop set to frames ..."];
+        
+        /* Point A to Point B. Frame to frame */
+        /* get the start frame from the start frame field */
+        int start_frame = [[queueToApply objectForKey:@"StartFrame"] intValue];
+        job->frame_to_start = start_frame;
+        /* get the frame to stop on from the end frame field */
+        int stop_frame = [[queueToApply objectForKey:@"StopFrame"] intValue];
+        job->frame_to_stop = stop_frame;
+        
+    }
+
        
+        
+    
     /* Format (Muxer) and Video Encoder */
     job->mux = [[queueToApply objectForKey:@"JobFileFormatMux"] intValue];
     job->vcodec = [[queueToApply objectForKey:@"JobVideoEncoderVcodec"] intValue];
@@ -3373,7 +3658,7 @@ bool one_burned = FALSE;
                if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 && [[queueToApply objectForKey:@"VideoTurboTwoPass"] intValue] == 1 )
                {
                        /* pass the "Turbo" string to be appended to the existing x264 opts string into a variable for the first pass */
-                       NSString *firstPassOptStringTurbo = @":ref=1:subme=1:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
+                       NSString *firstPassOptStringTurbo = @":ref=1:subme=2:me=dia:analyse=none:trellis=0:no-fast-pskip=0:8x8dct=0:weightb=0";
                        /* append the "Turbo" string variable to the existing opts string.
              Note: the "Turbo" string must be appended, not prepended to work properly*/
                        NSString *firstPassOptStringCombined = [[queueToApply objectForKey:@"x264Option"] stringByAppendingString:firstPassOptStringTurbo];
@@ -3393,13 +3678,14 @@ bool one_burned = FALSE;
     
     job->keep_ratio = [[queueToApply objectForKey:@"PictureKeepRatio"]  intValue];
     job->anamorphic.mode = [[queueToApply objectForKey:@"PicturePAR"]  intValue];
+    job->modulus = [[queueToApply objectForKey:@"PictureModulus"] intValue];
     if ([[queueToApply objectForKey:@"PicturePAR"]  intValue] == 3)
     {
         /* insert our custom values here for capuj */
         job->width = [[queueToApply objectForKey:@"PicturePARStorageWidth"]  intValue];
         job->height = [[queueToApply objectForKey:@"PicturePARStorageHeight"]  intValue];
         
-        job->anamorphic.modulus = [[queueToApply objectForKey:@"PicturePARModulus"] intValue];
+        job->modulus = [[queueToApply objectForKey:@"PicturePARModulus"] intValue];
         
         job->anamorphic.par_width = [[queueToApply objectForKey:@"PicturePARPixelWidth"]  intValue];
         job->anamorphic.par_height = [[queueToApply objectForKey:@"PicturePARPixelHeight"]  intValue];
@@ -3560,9 +3846,7 @@ bool one_burned = FALSE;
                     sub_config.offset = [[tempObject objectForKey:@"subtitleTrackSrtOffset"] intValue];
                     
                     /* we need to srncpy file name and codeset */
-                    //sub_config.src_filename = [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String];
                     strncpy(sub_config.src_filename, [[tempObject objectForKey:@"subtitleSourceSrtFilePath"] UTF8String], 128);
-                    //sub_config.src_codeset = [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String];
                     strncpy(sub_config.src_codeset, [[tempObject objectForKey:@"subtitleTrackSrtCharCode"] UTF8String], 40);
                     
                     sub_config.force = 0;
@@ -3575,8 +3859,6 @@ bool one_burned = FALSE;
                 
                 if (subt != NULL)
                 {
-                    [self writeToActivityLog: "Setting Subtitle: %s", subt];
-
                     hb_subtitle_config_t sub_config = subt->config;
                     
                     if (!burned && job->mux == HB_MUX_MKV && 
@@ -4136,6 +4418,28 @@ bool one_burned = FALSE;
     hb_title_t * title = (hb_title_t*)
         hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
 
+    /* If we are a stream type and a batch scan, grok the output file name from title->name upon title change */
+    if (title->type == HB_STREAM_TYPE && hb_list_count( list ) > 1 )
+    {
+        /* we set the default name according to the new title->name */
+        [fDstFile2Field setStringValue: [NSString stringWithFormat:
+                                         @"%@/%@.%@", [[fDstFile2Field stringValue] stringByDeletingLastPathComponent],
+                                         [NSString stringWithUTF8String: title->name],
+                                         [[fDstFile2Field stringValue] pathExtension]]];
+        
+        /* Change the source to read out the parent folder also */
+        [fSrcDVD2Field setStringValue:[NSString stringWithFormat:@"%@/%@", browsedSourceDisplayName,[NSString stringWithUTF8String: title->name]]];
+    }
+    
+    /* For point a to point b pts encoding, set the start and end fields to 0 and the title duration in seconds respectively */
+    int duration = (title->hours * 3600) + (title->minutes * 60) + (title->seconds);
+    [fSrcTimeStartEncodingField setStringValue: [NSString stringWithFormat: @"%d", 0]];
+    [fSrcTimeEndEncodingField setStringValue: [NSString stringWithFormat: @"%d", duration]];
+    /* For point a to point b frame encoding, set the start and end fields to 0 and the title duration * announced fps in seconds respectively */
+    [fSrcFrameStartEncodingField setStringValue: [NSString stringWithFormat: @"%d", 1]];
+    //[fSrcFrameEndEncodingField setStringValue: [NSString stringWithFormat: @"%d", ((title->hours * 3600) + (title->minutes * 60) + (title->seconds)) * 24]];
+    [fSrcFrameEndEncodingField setStringValue: [NSString stringWithFormat: @"%d", duration * (title->rate / title->rate_base)]];    
+    
     /* If Auto Naming is on. We create an output filename of dvd name - title number */
     if( [[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"] > 0 && ( hb_list_count( list ) > 1 ) )
        {
@@ -4145,7 +4449,10 @@ bool one_burned = FALSE;
             title->index,
                        [[fDstFile2Field stringValue] pathExtension]]]; 
        }
-
+    /* Update encode start / stop variables */
+     
+    
+    
     /* Update chapter popups */
     [fSrcChapterStartPopUp removeAllItems];
     [fSrcChapterEndPopUp   removeAllItems];
@@ -4246,6 +4553,55 @@ bool one_burned = FALSE;
     [self selectPreset:nil];
 }
 
+- (IBAction) encodeStartStopPopUpChanged: (id) sender;
+{
+    if( [fEncodeStartStopPopUp isEnabled] )
+    {
+        /* We are chapters */
+        if( [fEncodeStartStopPopUp indexOfSelectedItem] == 0 )
+        {
+            [fSrcChapterStartPopUp  setHidden: NO];
+            [fSrcChapterEndPopUp  setHidden: NO];
+            
+            [fSrcTimeStartEncodingField  setHidden: YES];
+            [fSrcTimeEndEncodingField  setHidden: YES];
+            
+            [fSrcFrameStartEncodingField  setHidden: YES];
+            [fSrcFrameEndEncodingField  setHidden: YES];
+            
+               [self chapterPopUpChanged:nil];   
+        }
+        /* We are time based (seconds) */
+        else if ([fEncodeStartStopPopUp indexOfSelectedItem] == 1)
+        {
+            [fSrcChapterStartPopUp  setHidden: YES];
+            [fSrcChapterEndPopUp  setHidden: YES];
+            
+            [fSrcTimeStartEncodingField  setHidden: NO];
+            [fSrcTimeEndEncodingField  setHidden: NO];
+            
+            [fSrcFrameStartEncodingField  setHidden: YES];
+            [fSrcFrameEndEncodingField  setHidden: YES];
+            
+            [self startEndSecValueChanged:nil];
+        }
+        /* We are frame based */
+        else if ([fEncodeStartStopPopUp indexOfSelectedItem] == 2)
+        {
+            [fSrcChapterStartPopUp  setHidden: YES];
+            [fSrcChapterEndPopUp  setHidden: YES];
+            
+            [fSrcTimeStartEncodingField  setHidden: YES];
+            [fSrcTimeEndEncodingField  setHidden: YES];
+            
+            [fSrcFrameStartEncodingField  setHidden: NO];
+            [fSrcFrameEndEncodingField  setHidden: NO];
+            
+            [self startEndFrameValueChanged:nil];
+        }
+    }
+}
+
 - (IBAction) chapterPopUpChanged: (id) sender
 {
 
@@ -4274,7 +4630,7 @@ bool one_burned = FALSE;
     [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
         @"%02lld:%02lld:%02lld", duration / 3600, ( duration / 60 ) % 60,
         duration % 60]];
-
+    
     [self calculateBitrate: sender];
     
     if ( [fSrcChapterStartPopUp indexOfSelectedItem] ==  [fSrcChapterEndPopUp indexOfSelectedItem] )
@@ -4289,6 +4645,33 @@ bool one_burned = FALSE;
     }
 }
 
+- (IBAction) startEndSecValueChanged: (id) sender
+{
+
+       int duration = [fSrcTimeEndEncodingField intValue] - [fSrcTimeStartEncodingField intValue];
+    [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
+        @"%02d:%02d:%02d", duration / 3600, ( duration / 60 ) % 60,
+        duration % 60]];
+    
+    //[self calculateBitrate: sender];
+    
+}
+
+- (IBAction) startEndFrameValueChanged: (id) sender
+{
+    hb_list_t  * list  = hb_get_titles( fHandle );
+    hb_title_t * title = (hb_title_t*)
+    hb_list_item( list, [fSrcTitlePopUp indexOfSelectedItem] );
+    
+    int duration = ([fSrcFrameEndEncodingField intValue] - [fSrcFrameStartEncodingField intValue]) / (title->rate / title->rate_base);
+    [fSrcDuration2Field setStringValue: [NSString stringWithFormat:
+                                         @"%02d:%02d:%02d", duration / 3600, ( duration / 60 ) % 60,
+                                         duration % 60]];
+    
+    //[self calculateBitrate: sender];
+}
+
+
 - (IBAction) formatPopUpChanged: (id) sender
 {
     NSString * string = [fDstFile2Field stringValue];
@@ -4451,18 +4834,9 @@ the user is using "Custom" settings by determining the sender*/
         [fAdvancedOptions setHidden:NO];
         [self autoSetM4vExtension: sender];
     }
-    
-    /* We need to set loose anamorphic as available depending on whether or not the ffmpeg encoder
-    is being used as it borks up loose anamorphic .
-    For convenience lets use the titleOfSelected index. Probably should revisit whether or not we want
-    to use the index itself but this is easier */
+
     if (videoEncoder == HB_VCODEC_FFMPEG)
     {
-        if (job->anamorphic.mode == 2)
-        {
-            job->anamorphic.mode = 0;
-        }
-        [fPictureController setAllowLooseAnamorphic:NO];
         /* We set the iPod atom checkbox to disabled and uncheck it as its only for x264 in the mp4
          container. Format is taken care of in formatPopUpChanged method by hiding and unchecking
          anything other than MP4.
@@ -4472,7 +4846,6 @@ the user is using "Custom" settings by determining the sender*/
     }
     else
     {
-        [fPictureController setAllowLooseAnamorphic:YES];
         [fDstMp4iPodFileCheck setEnabled: YES];
     }
     [self setupQualitySlider];
@@ -4567,7 +4940,7 @@ the user is using "Custom" settings by determining the sender*/
      * so that we can choose a new similar value on the new slider scale */
     float previousMaxValue = [fVidQualitySlider maxValue];
     float previousPercentOfSliderScale = [fVidQualitySlider floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue] + 1);
-    NSString * qpRFLabelString = @"RF:";
+    NSString * qpRFLabelString = @"QP:";
     /* x264 0-51 */
     if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_X264)
     {
@@ -4576,6 +4949,7 @@ the user is using "Custom" settings by determining the sender*/
         /* As x264 allows for qp/rf values that are fractional, we get the value from the preferences */
         int fractionalGranularity = 1 / [[NSUserDefaults standardUserDefaults] floatForKey:@"x264CqSliderFractional"];
         [fVidQualitySlider setNumberOfTickMarks:(([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]) * fractionalGranularity) + 1];
+        qpRFLabelString = @"RF:";
     }
     /* ffmpeg  1-31 */
     if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_FFMPEG )
@@ -4621,20 +4995,15 @@ the user is using "Custom" settings by determining the sender*/
     
     float sliderRfInverse = ([fVidQualitySlider maxValue] - [fVidQualitySlider floatValue]) + [fVidQualitySlider minValue];
     /* If the encoder is theora, use the float, otherwise use the inverse float*/
-    float sliderRfToPercent;
+    //float sliderRfToPercent;
     if ([[fVidEncoderPopUp selectedItem] tag] == HB_VCODEC_THEORA)
     {
-        [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]];
-        sliderRfToPercent = [fVidQualityRFField floatValue] / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);   
+        [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", [fVidQualitySlider floatValue]]];   
     }
     else
     {
         [fVidQualityRFField setStringValue: [NSString stringWithFormat: @"%.2f", sliderRfInverse]];
-        sliderRfToPercent = ( ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue])  - ([fVidQualityRFField floatValue] - [fVidQualitySlider minValue])) / ([fVidQualitySlider maxValue] - [fVidQualitySlider minValue]);
     }
-    [fVidConstantCell setTitle: [NSString stringWithFormat:
-                                 NSLocalizedString( @"Constant quality: %.2f %%", @"" ), 100 * sliderRfToPercent]];
-    
     [self customSettingUsed: sender];
 }
 
@@ -4784,8 +5153,14 @@ the user is using "Custom" settings by determining the sender*/
         fTitle->job->keep_ratio = 0;
        }
     
-    [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@", [fPictureController getPictureSizeInfoString]]];
-    
+    if (fTitle->job->anamorphic.mode != 1) // we are not strict so show the modulus
+       {
+        [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@, Modulus: %d", [fPictureController getPictureSizeInfoString], fTitle->job->modulus]];
+    }
+    else
+    {
+        [fPictureSizeField setStringValue: [NSString stringWithFormat:@"Picture Size: %@", [fPictureController getPictureSizeInfoString]]];
+    }
     NSString *picCropping;
     /* Set the display field for crop as per boolean */
        if (![fPictureController autoCrop])
@@ -4945,6 +5320,13 @@ the user is using "Custom" settings by determining the sender*/
     /* We will first verify that a lower track number has been selected before enabling each track
      * for example, make sure a track is selected for track 1 before enabling track 2, etc.
      */
+    
+    /* If the source has no audio then disable audio track 1 */
+    if (hb_list_count( fTitle->list_audio ) == 0)
+    {
+        [fAudLang1PopUp selectItemAtIndex:0];
+    }
+     
     if ([fAudLang1PopUp indexOfSelectedItem] == 0)
     {
         [fAudLang2PopUp setEnabled: NO];
@@ -4986,7 +5368,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack1MixPopUp removeAllItems];
         [fAudTrack1RatePopUp removeAllItems];
         [fAudTrack1BitratePopUp removeAllItems];
-        [fAudTrack1DrcSlider setFloatValue: 1.00];
+        [fAudTrack1DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack1DrcSlider];
     }
     else if ([[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack1MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5010,7 +5392,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack2MixPopUp removeAllItems];
         [fAudTrack2RatePopUp removeAllItems];
         [fAudTrack2BitratePopUp removeAllItems];
-        [fAudTrack2DrcSlider setFloatValue: 1.00];
+        [fAudTrack2DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack2DrcSlider];
     }
     else if ([[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack2MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5034,7 +5416,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack3MixPopUp removeAllItems];
         [fAudTrack3RatePopUp removeAllItems];
         [fAudTrack3BitratePopUp removeAllItems];
-        [fAudTrack3DrcSlider setFloatValue: 1.00];
+        [fAudTrack3DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack3DrcSlider];
     }
     else if ([[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack3MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5058,7 +5440,7 @@ the user is using "Custom" settings by determining the sender*/
         [fAudTrack4MixPopUp removeAllItems];
         [fAudTrack4RatePopUp removeAllItems];
         [fAudTrack4BitratePopUp removeAllItems];
-        [fAudTrack4DrcSlider setFloatValue: 1.00];
+        [fAudTrack4DrcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: fAudTrack4DrcSlider];
     }
     else if ([[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_AC3 || [[fAudTrack4MixPopUp selectedItem] tag] == HB_ACODEC_DCA)
@@ -5100,28 +5482,34 @@ the user is using "Custom" settings by determining the sender*/
     /* e.g. to find the first French track, pass in an NSString * of "Francais" */
     /* e.g. to find the first English 5.1 AC3 track, pass in an NSString * of "English (AC3) (5.1 ch)" */
     /* if no matching track is found, then selectIndexIfNotFound is used to choose which track to select instead */
-
-       if (searchPrefixString)
-       {
-
-        for( int i = 0; i < [sender numberOfItems]; i++ )
+    if (hb_list_count( fTitle->list_audio ) != 0)
+    {
+        if (searchPrefixString)
         {
-            /* Try to find the desired search string */
-            if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
+            
+            for( int i = 0; i < [sender numberOfItems]; i++ )
             {
-                [sender selectItemAtIndex: i];
-                return;
+                /* Try to find the desired search string */
+                if ([[[sender itemAtIndex: i] title] hasPrefix:searchPrefixString])
+                {
+                    [sender selectItemAtIndex: i];
+                    return;
+                }
             }
+            /* couldn't find the string, so select the requested "search string not found" item */
+            /* index of 0 means select the "none" item */
+            /* index of 1 means select the first audio track */
+            [sender selectItemAtIndex: selectIndexIfNotFound];
         }
-        /* couldn't find the string, so select the requested "search string not found" item */
-        /* index of 0 means select the "none" item */
-        /* index of 1 means select the first audio track */
-        [sender selectItemAtIndex: selectIndexIfNotFound];
-       }
+        else
+        {
+            /* if no search string is provided, then select the selectIndexIfNotFound item */
+            [sender selectItemAtIndex: selectIndexIfNotFound];
+        }
+    }
     else
     {
-        /* if no search string is provided, then select the selectIndexIfNotFound item */
-        [sender selectItemAtIndex: selectIndexIfNotFound];
+        [sender selectItemAtIndex: 0];
     }
 
 }
@@ -5164,14 +5552,15 @@ the user is using "Custom" settings by determining the sender*/
         {
             case 0:
                 /* MP4 */
-                // FAAC
-                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
-                [menuItem setTag: HB_ACODEC_FAAC];
-
                 // CA_AAC
                 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
                 [menuItem setTag: HB_ACODEC_CA_AAC];
-
+                // FAAC
+                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
+                [menuItem setTag: HB_ACODEC_FAAC];
+                // MP3
+                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
+                [menuItem setTag: HB_ACODEC_LAME];
                 // AC3 Passthru
                 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
                 [menuItem setTag: HB_ACODEC_AC3];
@@ -5179,12 +5568,12 @@ the user is using "Custom" settings by determining the sender*/
                 
             case 1:
                 /* MKV */
-                // FAAC
-                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
-                [menuItem setTag: HB_ACODEC_FAAC];
                 // CA_AAC
                 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (CoreAudio)" action: NULL keyEquivalent: @""];
                 [menuItem setTag: HB_ACODEC_CA_AAC];
+                // FAAC
+                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AAC (faac)" action: NULL keyEquivalent: @""];
+                [menuItem setTag: HB_ACODEC_FAAC];
                 // AC3 Passthru
                 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
                 [menuItem setTag: HB_ACODEC_AC3];
@@ -5198,26 +5587,6 @@ the user is using "Custom" settings by determining the sender*/
                 menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
                 [menuItem setTag: HB_ACODEC_VORBIS];
                 break;
-                
-            case 2: 
-                /* AVI */
-                // MP3
-                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
-                [menuItem setTag: HB_ACODEC_LAME];
-                // AC3 Passthru
-                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"AC3 Passthru" action: NULL keyEquivalent: @""];
-                [menuItem setTag: HB_ACODEC_AC3];
-                break;
-                
-            case 3:
-                /* OGM */
-                // Vorbis
-                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"Vorbis (vorbis)" action: NULL keyEquivalent: @""];
-                [menuItem setTag: HB_ACODEC_VORBIS];
-                // MP3
-                menuItem = [[audiocodecPopUp menu] addItemWithTitle:@"MP3 (lame)" action: NULL keyEquivalent: @""];
-                [menuItem setTag: HB_ACODEC_LAME];
-                break;
         }
         [audiocodecPopUp selectItemAtIndex:0];
     }
@@ -5238,6 +5607,12 @@ the user is using "Custom" settings by determining the sender*/
     
     /* make sure we have a selected title before continuing */
     if (fTitle == NULL) return;
+    /* make sure we have a source audio track before continuing */
+    if (hb_list_count( fTitle->list_audio ) == 0)
+    {
+        [sender selectItemAtIndex:0];
+        return;
+    }
     /* if the sender is the lanaguage popup and there is nothing in the codec popup, lets call
     * audioAddAudioTrackCodecs on the codec popup to populate it properly before moving on
     */
@@ -5336,16 +5711,10 @@ the user is using "Custom" settings by determining the sender*/
         {
 
             /* find out if our selected output audio codec supports mono and / or 6ch */
-            /* we also check for an input codec of AC3 or DCA,
-             as they are the only libraries able to do the mixdown to mono / conversion to 6-ch */
             /* audioCodecsSupportMono and audioCodecsSupport6Ch are the same for now,
              but this may change in the future, so they are separated for flexibility */
-            int audioCodecsSupportMono =
-                    (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
-                    (acodec != HB_ACODEC_LAME);
-            int audioCodecsSupport6Ch =
-                    (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
-                    (acodec != HB_ACODEC_LAME);
+            int audioCodecsSupportMono = (audio->in.codec && acodec != HB_ACODEC_LAME);
+            int audioCodecsSupport6Ch = (audio->in.codec && acodec != HB_ACODEC_LAME);
             
             /* check for AC-3 passthru */
             if (audio->in.codec == HB_ACODEC_AC3 && acodec == HB_ACODEC_AC3)
@@ -5489,37 +5858,19 @@ the user is using "Custom" settings by determining the sender*/
 
             }
             /* In the case of a source track that is not AC3 and the user tries to use AC3 Passthru (which does not work)
-             * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
-             * other containers.
+             * we force the Audio Codec choice back to a workable codec. We use CoreAudio aac for all containers.
              */
             if (audio->in.codec != HB_ACODEC_AC3 && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_AC3)
             {
-                /* If we are using the avi container, we select MP3 as there is no aac available*/
-                if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
-                {
-                    [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
-                }
-                else
-                {
-                    [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
-                }
+                [audiocodecPopUp selectItemWithTag: HB_ACODEC_CA_AAC];
             }
             
             /* In the case of a source track that is not DTS and the user tries to use DTS Passthru (which does not work)
-             * we force the Audio Codec choice back to a workable codec. We use MP3 for avi and aac for all
-             * other containers.
+             * we force the Audio Codec choice back to a workable codec. We use CoreAudio aac for all containers.
              */
             if (audio->in.codec != HB_ACODEC_DCA && [[audiocodecPopUp selectedItem] tag] == HB_ACODEC_DCA)
             {
-                /* If we are using the avi container, we select MP3 as there is no aac available*/
-                if ([[fDstFormatPopUp selectedItem] tag] == HB_MUX_AVI)
-                {
-                    [audiocodecPopUp selectItemWithTag: HB_ACODEC_LAME];
-                }
-                else
-                {
-                    [audiocodecPopUp selectItemWithTag: HB_ACODEC_FAAC];
-                }
+                [audiocodecPopUp selectItemWithTag: HB_ACODEC_CA_AAC];
             }
             
             /* Setup our samplerate and bitrate popups we will need based on mixdown */
@@ -5598,19 +5949,18 @@ the user is using "Custom" settings by determining the sender*/
             /* check if we have a 6ch discrete conversion in either audio track */
             if ([[mixdownPopUp selectedItem] tag] == HB_AMIXDOWN_6CH)
             {
-                /* FAAC is happy using our min bitrate of 32 kbps, even for 6ch */
-                minbitrate = 32;
-                /* If either mixdown popup includes 6-channel discrete, then allow up to 384 kbps */
-                maxbitrate = 384;
+                /* FAAC has a minimum of 192 kbps for 6-channel discrete */
+                minbitrate = 192;
+                /* If either mixdown popup includes 6-channel discrete, then allow up to 768 kbps */
+                maxbitrate = 768;
                 break;
             }
             else
             {
                 /* FAAC is happy using our min bitrate of 32 kbps for stereo or mono */
                 minbitrate = 32;
-                /* FAAC won't honour anything more than 160 for stereo, so let's not offer it */
                 /* note: haven't dealt with mono separately here, FAAC will just use the max it can */
-                maxbitrate = 160;
+                maxbitrate = 320;
                 break;
             }
 
@@ -5662,7 +6012,7 @@ the user is using "Custom" settings by determining the sender*/
     }
     
     /* make sure we have a selected title before continuing */
-    if (fTitle == NULL) return;
+    if (fTitle == NULL || hb_list_count( fTitle->list_audio ) == 0) return;
     /* get the audio so we can find out what input rates are*/
     hb_audio_config_t * audio;
     audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [audiotrackPopUp indexOfSelectedItem] - 1 );
@@ -5734,7 +6084,7 @@ the user is using "Custom" settings by determining the sender*/
         [bitratePopUp setEnabled: NO];
         [sampleratePopUp setEnabled: NO];
         
-        [drcSlider setFloatValue: 1.00];
+        [drcSlider setFloatValue: 0.00];
         [self audioDRCSliderChanged: drcSlider];
         [drcSlider setEnabled: NO];
         [drcField setEnabled: NO];
@@ -6350,6 +6700,7 @@ return YES;
         {
             
             /* pointer to this track's mixdown, codec, sample rate and bitrate NSPopUpButton's */
+            NSPopUpButton * trackLangPreviousPopUp = nil;
             NSPopUpButton * trackLangPopUp = nil;
             NSPopUpButton * mixdownPopUp = nil;
             NSPopUpButton * audiocodecPopUp = nil;
@@ -6376,6 +6727,7 @@ return YES;
                 }
                 if( i == 2 )
                 {
+                    trackLangPreviousPopUp = fAudLang1PopUp;
                     trackLangPopUp = fAudLang2PopUp;
                     mixdownPopUp = fAudTrack2MixPopUp;
                     audiocodecPopUp = fAudTrack2CodecPopUp;
@@ -6385,6 +6737,7 @@ return YES;
                 }
                 if( i == 3 )
                 {
+                    trackLangPreviousPopUp = fAudLang2PopUp;
                     trackLangPopUp = fAudLang3PopUp;
                     mixdownPopUp = fAudTrack3MixPopUp;
                     audiocodecPopUp = fAudTrack3CodecPopUp;
@@ -6394,6 +6747,7 @@ return YES;
                 }
                 if( i == 4 )
                 {
+                    trackLangPreviousPopUp = fAudLang3PopUp;
                     trackLangPopUp = fAudLang4PopUp;
                     mixdownPopUp = fAudTrack4MixPopUp;
                     audiocodecPopUp = fAudTrack4CodecPopUp;
@@ -6405,12 +6759,22 @@ return YES;
                 
                 if ([trackLangPopUp indexOfSelectedItem] == 0)
                 {
-                    [trackLangPopUp selectItemAtIndex: 1];
+                    if (i ==1)
+                    {
+                        [trackLangPopUp selectItemAtIndex: 1];
+                    }
+                    else
+                    {
+                        /* if we are greater than track 1, select
+                         * the same track as the previous track */
+                        [trackLangPopUp selectItemAtIndex: [trackLangPreviousPopUp indexOfSelectedItem]];
+                    }
                 }
                 [self audioTrackPopUpChanged: trackLangPopUp];
                 [audiocodecPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioEncoder"]];
-                /* check our pref for core audio and use it in place of faac if applicable */
-                if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
+                /* check our pref for core audio and use it in place of faac if preset is a built in  */
+                if ([[chosenPreset objectForKey:@"Type"] intValue] == 0 && 
+                    [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
                     [[tempObject objectForKey:@"AudioEncoder"] isEqualToString: @"AAC (faac)"])
                 {
                     [audiocodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
@@ -6418,17 +6782,25 @@ return YES;
                 
                 [self audioTrackPopUpChanged: audiocodecPopUp];
                 [mixdownPopUp selectItemWithTitle:[tempObject objectForKey:@"AudioMixdown"]];
-                /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
+                [self audioTrackMixdownChanged: mixdownPopUp];
+                /* check to see if the selection was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
                  * mixdown*/
                 if  ([mixdownPopUp selectedItem] == nil)
                 {
                     [self audioTrackPopUpChanged: audiocodecPopUp];
+                    [self writeToActivityLog: "presetSelected mixdown not selected, rerun audioTrackPopUpChanged"];
                 }
                 [sampleratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioSamplerate"]];
                 /* We set the presets bitrate if it is *not* an AC3 track since that uses the input bitrate */
                 if (![[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"])
                 {
                     [bitratePopUp selectItemWithTitle:[tempObject objectForKey:@"AudioBitrate"]];
+                    /* check to see if the bitrate selection was available, if not, rerun audioTrackMixdownChanged using the mixdown to just set the
+                     *default mixdown bitrate*/
+                    if ([bitratePopUp selectedItem] == nil)
+                    {
+                        [self audioTrackMixdownChanged: mixdownPopUp];
+                    }
                 }
                 [drcSlider setFloatValue:[[tempObject objectForKey:@"AudioTrackDRCSlider"] floatValue]];
                 [self audioDRCSliderChanged: drcSlider];
@@ -6445,7 +6817,7 @@ return YES;
                         hb_audio_config_t * audio;
                         /* get the audio source audio codec */
                         audio = (hb_audio_config_t *) hb_list_audio_config_item( fTitle->list_audio, [trackLangPopUp indexOfSelectedItem] - 1 );
-                        if ([[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"] && audio->in.codec != HB_ACODEC_AC3 ||
+                        if (audio != NULL && [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"AC3 Passthru"] && audio->in.codec != HB_ACODEC_AC3 ||
                             [[tempObject objectForKey:@"AudioEncoder"] isEqualToString:@"DTS Passthru"] && audio->in.codec != HB_ACODEC_DCA )
                         {
                             /* We have a preset using ac3 passthru but no ac3 source audio, so set the track to "None" and bail */
@@ -6496,12 +6868,14 @@ return YES;
                 }
                 [self audioTrackPopUpChanged: fAudLang1PopUp];
                 [fAudTrack1CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Encoder"]];
-                /* check our pref for core audio and use it in place of faac if applicable */
-                if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
+                /* check our pref for core audio and use it in place of faac if preset is built in */
+                if ([[chosenPreset objectForKey:@"Type"] intValue] == 0 && 
+                    [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
                     [[chosenPreset objectForKey:@"Audio1Encoder"] isEqualToString: @"AAC (faac)"])
                 {
                     [fAudTrack1CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
                 }
+                
                 [self audioTrackPopUpChanged: fAudTrack1CodecPopUp];
                 [fAudTrack1MixPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio1Mixdown"]];
                 /* check to see if the selections was available, if not, rerun audioTrackPopUpChanged using the codec to just set the default
@@ -6528,8 +6902,9 @@ return YES;
                 }
                 [self audioTrackPopUpChanged: fAudLang2PopUp];
                 [fAudTrack2CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio2Encoder"]];
-                /* check our pref for core audio and use it in place of faac if applicable */
-                if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
+                /* check our pref for core audio and use it in place of faac if preset is built in */
+                if ([[chosenPreset objectForKey:@"Type"] intValue] == 0 && 
+                    [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
                     [[chosenPreset objectForKey:@"Audio2Encoder"] isEqualToString: @"AAC (faac)"])
                 {
                     [fAudTrack2CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
@@ -6559,8 +6934,9 @@ return YES;
                 }
                 [self audioTrackPopUpChanged: fAudLang3PopUp];
                 [fAudTrack3CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio3Encoder"]];
-                /* check our pref for core audio and use it in place of faac if applicable */
-                if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
+                /* check our pref for core audio and use it in place of faac if preset is built in */
+                if ([[chosenPreset objectForKey:@"Type"] intValue] == 0 && 
+                    [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
                     [[chosenPreset objectForKey:@"Audio3Encoder"] isEqualToString: @"AAC (faac)"])
                 {
                     [fAudTrack3CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
@@ -6590,8 +6966,9 @@ return YES;
                 }
                 [self audioTrackPopUpChanged: fAudLang4PopUp];
                 [fAudTrack4CodecPopUp selectItemWithTitle:[chosenPreset objectForKey:@"Audio4Encoder"]];
-                /* check our pref for core audio and use it in place of faac if applicable */
-                if ([[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
+                /* check our pref for core audio and use it in place of faac if preset is built in */
+                if ([[chosenPreset objectForKey:@"Type"] intValue] == 0 && 
+                    [[NSUserDefaults standardUserDefaults] boolForKey: @"UseCoreAudio"] == YES && 
                     [[chosenPreset objectForKey:@"Audio4Encoder"] isEqualToString: @"AAC (faac)"])
                 {
                     [fAudTrack4CodecPopUp selectItemWithTitle:@"AAC (CoreAudio)"];
@@ -6675,7 +7052,16 @@ return YES;
                 
             }
             
-            
+            /* Set modulus */
+            if ([chosenPreset objectForKey:@"PictureModulus"])
+            {
+                job->modulus = [[chosenPreset objectForKey:@"PictureModulus"]  intValue];
+            }
+            else
+            {
+                job->modulus = 16;
+            }
+             
             /* Check to see if the objectForKey:@"UsesPictureSettings is 2 which is "Use Max for the source */
             if ([[chosenPreset objectForKey:@"UsesPictureSettings"]  intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"]  intValue] == 1)
             {
@@ -7050,6 +7436,7 @@ return YES;
         [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->anamorphic.mode] forKey:@"PicturePAR"];
+        [preset setObject:[NSNumber numberWithInt:fTitle->job->modulus] forKey:@"PictureModulus"];
         
         /* Set crop settings here */
         [preset setObject:[NSNumber numberWithInt:[fPictureController autoCrop]] forKey:@"PictureAutoCrop"];