OSDN Git Service

MacGui: tweaks the deinterlacing parameters.
[handbrake-jp/handbrake-jp-git.git] / macosx / QueueController.mm
1 #include "QueueController.h"
2
3 @implementation QueueController
4
5 - (void) SetHandle: (hb_handle_t *) handle
6 {
7     fHandle = handle;
8 }
9
10 - (void) AddTextField: (NSString *) string rect: (NSRect *) rect
11 {
12     NSTextField * textField;
13
14     rect->origin.x     = 0;
15     rect->origin.y    -= 15;
16     rect->size.width   = 700;
17         rect->size.height  = 15;
18     textField = [[NSTextField alloc] initWithFrame: *rect];
19     [textField setEditable: NO];
20     [textField setSelectable: NO];
21     [textField setDrawsBackground: NO];
22         [textField setBordered: NO];
23         [textField setFont: [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
24     [textField setStringValue: string];
25
26     [fTaskView addSubview: textField];
27         
28 }
29
30 - (void) removeTask: (id) sender
31 {
32     hb_rem( fHandle, hb_job( fHandle, [sender tag] ) );
33     [self performSelectorOnMainThread: @selector( Update: )
34         withObject: sender waitUntilDone: NO];
35 }
36
37 - (void) AddButton: (NSRect *) rect tag: (int) tag
38 {
39     NSButton * button;
40     
41     rect->origin.x     = rect->size.width - 60;
42     rect->origin.y    -= 20;
43         rect->size.width   = 60;
44     rect->size.height  = 20;
45
46     button = [[NSButton alloc] initWithFrame: *rect];
47     rect->size.width   = rect->origin.x + 90;
48
49     [button setTitle: @"Remove"];
50     [button setBezelStyle: NSRoundedBezelStyle];
51     [button setFont: [NSFont systemFontOfSize:
52         [NSFont systemFontSizeForControlSize: NSMiniControlSize]]];
53         [[button cell] setControlSize: NSMiniControlSize];
54
55     [button setTag: tag];
56     [button setTarget: self];
57     [button setAction: @selector( removeTask: )];
58
59     [fTaskView addSubview: button];
60
61     NSBox * box;
62
63     rect->origin.x     = 15;
64     rect->origin.y    -= 10;
65     rect->size.width  -= 10;
66     rect->size.height  = 1;
67     box = [[NSBox alloc] initWithFrame: *rect];
68     [box setBoxType: NSBoxSeparator];
69     rect->origin.y    -= 10;
70    rect->size.width   -= 30;
71
72     [fTaskView addSubview: box];
73 }
74
75 - (IBAction) Update: (id) sender
76 {
77     int i;
78     hb_job_t * j;
79     hb_title_t * title;
80
81     NSSize size = [fScrollView contentSize];
82     int height = MAX( 20 + 145 * hb_count( fHandle ), size.height );
83     [fTaskView setFrame: NSMakeRect(0,0,size.width,height)];
84
85     NSRect rect = NSMakeRect(10,height-10,size.width-20,10);
86
87     NSArray * subviews = [fTaskView subviews];
88     while( [subviews count] > 0 )
89     {
90         [[subviews objectAtIndex: 0]
91             removeFromSuperviewWithoutNeedingDisplay];
92     }
93
94      for( i = 0; i < hb_count( fHandle ); i++ )
95     {
96         j = hb_job( fHandle, i );
97         title = j->title;
98        /* show the name of the source Note: use title->name instead of
99            title->dvd since name is just the chosen folder, instead of dvd which is the full path*/ 
100         [self AddTextField: [NSString stringWithFormat:
101             @"Task: %d Source: %s  Title: %d   Chapters: %d to %d   Pass: %d of %d",i+1, title->name, title->index , j->chapter_start, j->chapter_end,MAX( 1, j->pass ), MIN( 2, j->pass + 1 )] rect: &rect];
102        /* Muxer settings (File Format in the gui) */
103                 if (j->mux == 65536 || j->mux == 131072 || j->mux == 1048576)
104                 {
105                 jobFormat = @"MP4"; // HB_MUX_MP4,HB_MUX_PSP,HB_MUX_IPOD
106                 }
107                 if (j->mux == 262144)
108                 {
109                 jobFormat = @"AVI"; // HB_MUX_AVI
110                 }
111                 if (j->mux == 524288)
112                 {
113                 jobFormat = @"OGM"; // HB_MUX_OGM
114                 }
115                 if (j->mux == 2097152)
116                 {
117                 jobFormat = @"MKV"; // HB_MUX_MKV
118                 }
119                 // 2097152
120                 /* Video Codec settings (Encoder in the gui) */
121                 if (j->vcodec == 1)
122                 {
123                 jobVideoCodec = @"FFmpeg"; // HB_VCODEC_FFMPEG
124                 }
125                 if (j->vcodec == 2)
126                 {
127                 jobVideoCodec = @"XviD"; // HB_VCODEC_XVID
128                 }
129                 if (j->vcodec == 4)
130                 {
131                         /* Deterimine for sure how we are now setting iPod uuid atom */
132                         if (j->h264_level) // We are encoding for iPod
133                         {
134                         jobVideoCodec = @"x264 (H.264 iPod)"; // HB_VCODEC_X264 
135                         }
136                         else
137                         {
138                         jobVideoCodec = @"x264 (H.264 Main)"; // HB_VCODEC_X264
139                         }
140                 }
141                 /* Audio Codecs (Second half of Codecs in the gui) */
142                 if (j->acodec == 256)
143                 {
144                 jobAudioCodec = @"AAC"; // HB_ACODEC_FAAC
145                 }
146                 if (j->acodec == 512)
147                 {
148                 jobAudioCodec = @"MP3"; // HB_ACODEC_LAME
149                 }
150                 if (j->acodec == 1024)
151                 {
152                 jobAudioCodec = @"Vorbis"; // HB_ACODEC_VORBIS
153                 }
154                 if (j->acodec == 2048)
155                 {
156                 jobAudioCodec = @"AC3"; // HB_ACODEC_AC3
157                 }
158                 /* Show Basic File info */
159                 if (j->chapter_markers == 1)
160                 {
161                         [self AddTextField: [NSString stringWithFormat: @"Format: %@   Codecs: %@ Video / %@ Audio  Chapter Markers", jobFormat, jobVideoCodec, jobAudioCodec]
162                                                   rect: &rect];
163                 }
164                 else
165                 {
166                         [self AddTextField: [NSString stringWithFormat: @"Format: %@   Codecs: %@ Video / %@ Audio", jobFormat, jobVideoCodec, jobAudioCodec]
167                                                   rect: &rect];
168                 }
169                         
170                 /*Picture info*/
171                 /*integers for picture values deinterlace, crop[4], keep_ratio, grayscale, pixel_ratio, pixel_aspect_width, pixel_aspect_height,
172                  maxWidth, maxHeight */
173                 if (j->pixel_ratio == 1)
174                 {
175                 int titlewidth = title->width - j->crop[2] - j->crop[3];
176                 int displayparwidth = titlewidth * j->pixel_aspect_width / j->pixel_aspect_height;
177             int displayparheight = title->height - j->crop[0] - j->crop[1];
178                 jobPictureDetail = [NSString stringWithFormat: @"Picture: %d x %d Anamorphic", displayparwidth, displayparheight];
179                 //jobPictureDetail = [NSString stringWithFormat: @"Picture: Anamorphic"];
180                 }
181                 else
182                 {
183                 jobPictureDetail = [NSString stringWithFormat: @"Picture: %d x %d", j->width, j->height];
184                 }
185                 if (j->keep_ratio == 1)
186                 {
187                 jobPictureDetail = [jobPictureDetail stringByAppendingString: @" Keep Aspect Ratio"];
188                 }
189                 
190                 if (j->grayscale == 1)
191                 {
192                 jobPictureDetail = [jobPictureDetail stringByAppendingString: @" ,Grayscale"];
193                 }
194                 
195                 if (j->deinterlace == 1)
196                 {
197                 jobPictureDetail = [jobPictureDetail stringByAppendingString: @" ,Deinterlace"];
198                 }
199                 /* Show Picture info */ 
200                 [self AddTextField: [NSString stringWithFormat: @"%@", jobPictureDetail]rect: &rect];
201                 
202                 /* Detailed Video info */
203                 if (j->vquality <= 0 || j->vquality >= 1)
204                 {
205                         jobVideoQuality =[NSString stringWithFormat: @"%d (kbps)", j->vbitrate]; 
206                 }
207                 else
208                 {
209                 NSNumber * vidQuality;
210                 vidQuality = [NSNumber numberWithInt: j->vquality * 100];
211                         /* this is screwed up kind of. Needs to be formatted properly */
212                         if (j->crf == 1)
213                         {
214                                 jobVideoQuality =[NSString stringWithFormat: @"%@ %% (crf)", vidQuality];
215                         }
216                         else
217                         {
218                                 jobVideoQuality =[NSString stringWithFormat: @"%@ %% (cqp)", vidQuality];
219                         }
220                 }
221                 
222                 
223                 jobVideoDetail = [NSString stringWithFormat:@"Video: %@ %@ FPS: %d", jobVideoCodec, jobVideoQuality, j->vrate / j->vrate_base];
224                 
225                 
226                 /* Add the video detail string to the job filed in the window */
227                 [self AddTextField: [NSString stringWithFormat:@"%@", jobVideoDetail] rect: &rect];
228                 
229                 /* if there is an x264 option string, lets add it here*/
230                 /*NOTE: Due to size, lets get this in a tool tip*/
231                 
232                 if (j->x264opts)
233                 {
234                         [self AddTextField: [NSString stringWithFormat:@"x264 Options: %@", [NSString stringWithUTF8String:j->x264opts]] rect: &rect];
235                 }
236                 
237                 /* Audio Detail abitrate arate*/
238                 if ([jobAudioCodec isEqualToString: @"AC3"])
239                 {
240                 jobAudioDetail = [NSString stringWithFormat:@"Audio: %@ Pass-Through", jobAudioCodec];
241                 }
242                 else
243                 {
244                 jobAudioDetail = [NSString stringWithFormat:@"Audio: %@ Bitrate:%d (kbps) Sample Rate:%d (khz)", jobAudioCodec, j->abitrate, j->arate];
245                 }
246                 
247                 /* we now get the audio mixdown info for each of the two gui audio tracks */
248                 /* lets do it the long way here to get a handle on things.
249                         Hardcoded for two tracks for gui: audio_mixdowns[i] audio_mixdowns[i] */
250                 int ai; // counter for each audios [] , macgui only allows for two audio tracks currently
251                 for( ai = 0; ai < 2; ai++ )
252                 {
253                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_MONO)
254                         { 
255                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@" ,Track %d: Mono",ai + 1]];
256                         }
257                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_STEREO)
258                         { 
259                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@" ,Track %d: Stero",ai + 1]];
260                         }
261                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_DOLBY)
262                         { 
263                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@" ,Track %d: Dolby Surround",ai + 1]];
264                         }
265                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_DOLBYPLII)
266                         { 
267                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@" ,Track %d: DPL2",ai + 1]];
268                         }
269                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_6CH)
270                         { 
271                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@" ,Track %d: 6 Channel Discreet",ai + 1]];
272                         }
273                 }
274                 //jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@" ,MixDown: %d",j->audio_mixdowns]];
275                 /* Add the Audio detail string to the job filed in the window */
276                 [self AddTextField: [NSString stringWithFormat:@"%@", jobAudioDetail] rect: &rect];
277                 
278                 /*Destination Field */
279                 [self AddTextField: [NSString stringWithFormat: @"Destination: %s", j->file] rect: &rect];
280         /* Show remove button */
281                 [self AddButton: &rect tag: i];
282     }
283
284     [fTaskView scrollPoint: NSMakePoint(0,height)];
285     [fTaskView setNeedsDisplay: YES];
286     
287 }
288
289 - (IBAction) ClosePanel: (id) sender
290 {
291     [NSApp stopModal];
292 }
293
294 @end