OSDN Git Service

Improved debug messages for Cell start/stop with Cell number and block.
[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         if (j->pass == -1)
101         {
102             /*
103              * Scan pass
104              */
105             [self AddTextField: [NSString stringWithFormat:
106             @"Task: %d   Source: %s, Title %d, Chapters %d-%d   Pass: Scan",i+1, title->name, title->index , j->chapter_start, j->chapter_end] rect: &rect];
107         } else {
108             /*
109              * Normal pass
110              */
111             [self AddTextField: [NSString stringWithFormat:
112             @"Task: %d   Source: %s, Title %d, Chapters %d-%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];       /* Muxer settings (File Format in the gui) */
113                 if (j->mux == 65536 || j->mux == 131072 || j->mux == 1048576)
114                 {
115                 jobFormat = @"MP4"; // HB_MUX_MP4,HB_MUX_PSP,HB_MUX_IPOD
116                 }
117                 if (j->mux == 262144)
118                 {
119                 jobFormat = @"AVI"; // HB_MUX_AVI
120                 }
121                 if (j->mux == 524288)
122                 {
123                 jobFormat = @"OGM"; // HB_MUX_OGM
124                 }
125                 if (j->mux == 2097152)
126                 {
127                 jobFormat = @"MKV"; // HB_MUX_MKV
128                 }
129                 // 2097152
130                 /* Video Codec settings (Encoder in the gui) */
131                 if (j->vcodec == 1)
132                 {
133                 jobVideoCodec = @"FFmpeg"; // HB_VCODEC_FFMPEG
134                 }
135                 if (j->vcodec == 2)
136                 {
137                 jobVideoCodec = @"XviD"; // HB_VCODEC_XVID
138                 }
139                 if (j->vcodec == 4)
140                 {
141                         /* Deterimine for sure how we are now setting iPod uuid atom */
142                         if (j->h264_level) // We are encoding for iPod
143                         {
144                         jobVideoCodec = @"x264 (H.264 iPod)"; // HB_VCODEC_X264 
145                         }
146                         else
147                         {
148                         jobVideoCodec = @"x264 (H.264 Main)"; // HB_VCODEC_X264
149                         }
150                 }
151                 /* Audio Codecs (Second half of Codecs in the gui) */
152                 if (j->acodec == 256)
153                 {
154                 jobAudioCodec = @"AAC"; // HB_ACODEC_FAAC
155                 }
156                 if (j->acodec == 512)
157                 {
158                 jobAudioCodec = @"MP3"; // HB_ACODEC_LAME
159                 }
160                 if (j->acodec == 1024)
161                 {
162                 jobAudioCodec = @"Vorbis"; // HB_ACODEC_VORBIS
163                 }
164                 if (j->acodec == 2048)
165                 {
166                 jobAudioCodec = @"AC3"; // HB_ACODEC_AC3
167                 }
168                 /* Show Basic File info */
169                 if (j->chapter_markers == 1)
170                 {
171         [self AddTextField: [NSString stringWithFormat: @"Format: %@ Container, %@ Video + %@ Audio, Chapter Markers", jobFormat, jobVideoCodec, jobAudioCodec] 
172                                   rect: &rect];
173                 }
174                 else
175                 {
176                         [self AddTextField: [NSString stringWithFormat: @"Format: %@ Container, %@ Video + %@ Audio", jobFormat, jobVideoCodec, jobAudioCodec]
177                                                   rect: &rect];
178                 }
179                         
180                 /*Picture info*/
181                 /*integers for picture values deinterlace, crop[4], keep_ratio, grayscale, pixel_ratio, pixel_aspect_width, pixel_aspect_height,
182                  maxWidth, maxHeight */
183                 if (j->pixel_ratio == 1)
184                 {
185                 int titlewidth = title->width - j->crop[2] - j->crop[3];
186                 int displayparwidth = titlewidth * j->pixel_aspect_width / j->pixel_aspect_height;
187             int displayparheight = title->height - j->crop[0] - j->crop[1];
188                 jobPictureDetail = [NSString stringWithFormat: @"Picture: %dx%d (%dx%d Anamorphic)", displayparwidth, displayparheight, j->width, displayparheight];
189                 }
190                 else
191                 {
192                 jobPictureDetail = [NSString stringWithFormat: @"Picture: %dx%d", j->width, j->height];
193                 }
194                 if (j->keep_ratio == 1)
195                 {
196                 jobPictureDetail = [jobPictureDetail stringByAppendingString: @" Keep Aspect Ratio"];
197                 }
198                 
199                 if (j->grayscale == 1)
200                 {
201                 jobPictureDetail = [jobPictureDetail stringByAppendingString: @", Grayscale"];
202                 }
203                 
204                 if (j->deinterlace == 1)
205                 {
206                 jobPictureDetail = [jobPictureDetail stringByAppendingString: @", Deinterlace"];
207                 }
208                 /* Show Picture info */ 
209                 [self AddTextField: [NSString stringWithFormat: @"%@", jobPictureDetail]rect: &rect];
210                 
211                 /* Detailed Video info */
212                 if (j->vquality <= 0 || j->vquality >= 1)
213                 {
214                 jobVideoQuality =[NSString stringWithFormat: @"%d kbps", j->vbitrate];
215                 }
216                 else
217                 {
218                 NSNumber * vidQuality;
219                 vidQuality = [NSNumber numberWithInt: j->vquality * 100];
220                         /* this is screwed up kind of. Needs to be formatted properly */
221                         if (j->crf == 1)
222                         {
223                         jobVideoQuality =[NSString stringWithFormat: @"%@%% CRF", vidQuality];                  
224                         }
225                         else
226                         {
227                         jobVideoQuality =[NSString stringWithFormat: @"%@%% CQP", vidQuality];
228                         }
229                 }
230                 
231                 
232                         if (j->vrate_base == 1126125)
233                         {
234                                 /* NTSC FILM 23.976 */
235                                 jobVideoDetail = [NSString stringWithFormat:@"Video: %@, %@, 23.976 fps", jobVideoCodec, jobVideoQuality];
236                         }
237                         else if (j->vrate_base == 900900)
238                         {
239                                 /* NTSC 29.97 */
240                                 jobVideoDetail = [NSString stringWithFormat:@"Video: %@, %@, 29.97 fps", jobVideoCodec, jobVideoQuality];
241                         }
242                         else
243                         {
244                                 /* Everything else */
245                                 jobVideoDetail = [NSString stringWithFormat:@"Video: %@, %@, %d fps", jobVideoCodec, jobVideoQuality, j->vrate / j->vrate_base];
246                         }
247                 
248                 /* Add the video detail string to the job filed in the window */
249                 [self AddTextField: [NSString stringWithFormat:@"%@", jobVideoDetail] rect: &rect];
250                 
251                 /* if there is an x264 option string, lets add it here*/
252                 /*NOTE: Due to size, lets get this in a tool tip*/
253                 
254                 if (j->x264opts)
255                 {
256                         [self AddTextField: [NSString stringWithFormat:@"x264 Options: %@", [NSString stringWithUTF8String:j->x264opts]] rect: &rect];
257                 }
258                 
259                 /* Audio Detail */
260                 if ([jobAudioCodec isEqualToString: @"AC3"])
261                 {
262                 jobAudioDetail = [NSString stringWithFormat:@"Audio: %@, Pass-Through", jobAudioCodec];
263                 }
264                 else
265                 {
266                 jobAudioDetail = [NSString stringWithFormat:@"Audio: %@, %d kbps, %d Hz", jobAudioCodec, j->abitrate, j->arate];
267                 }
268                 
269                 /* we now get the audio mixdown info for each of the two gui audio tracks */
270                 /* lets do it the long way here to get a handle on things.
271                         Hardcoded for two tracks for gui: audio_mixdowns[i] audio_mixdowns[i] */
272                 int ai; // counter for each audios [] , macgui only allows for two audio tracks currently
273                 for( ai = 0; ai < 2; ai++ )
274                 {
275                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_MONO)
276                         { 
277                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@", Track %d: Mono",ai + 1]];
278                         }
279                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_STEREO)
280                         { 
281                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@", Track %d: Stereo",ai + 1]];
282                         }
283                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_DOLBY)
284                         { 
285                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@", Track %d: Dolby Surround",ai + 1]];
286                         }
287                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_DOLBYPLII)
288                         { 
289                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@", Track %d: Dolby Pro Logic II",ai + 1]];
290                         }
291                         if (j->audio_mixdowns[ai] == HB_AMIXDOWN_6CH)
292                         { 
293                                 jobAudioDetail = [jobAudioDetail stringByAppendingString: [NSString stringWithFormat:@", Track %d: 6-channel discreet",ai + 1]];
294                         }
295                 }
296                 
297                 /* Add the Audio detail string to the job filed in the window */
298                 [self AddTextField: [NSString stringWithFormat:@"%@", jobAudioDetail] rect: &rect];
299                 
300                 /*Destination Field */
301                 [self AddTextField: [NSString stringWithFormat: @"Destination: %s", j->file] rect: &rect];
302                 }
303         /* Show remove button */
304                 [self AddButton: &rect tag: i];
305     }
306
307     [fTaskView scrollPoint: NSMakePoint(0,height)];
308     [fTaskView setNeedsDisplay: YES];
309     
310 }
311
312 - (IBAction) ClosePanel: (id) sender
313 {
314     [NSApp stopModal];
315 }
316
317 @end