aa072285556b6600ef6b3bd7754046d3c46db54c
[blender-staging.git] / source / blender / src / buttons_scene.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <time.h>
31 #include <math.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "MEM_guardedalloc.h"
36 #include "BLO_sys_types.h" // for intptr_t support
37 #include "DNA_node_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_sound_types.h"
42 #include "DNA_sequence_types.h"
43 #include "DNA_userdef_types.h"
44 #include "DNA_packedFile_types.h"
45
46 #include "BKE_global.h"
47 #include "BKE_main.h"
48 #include "BKE_node.h"
49 #include "BKE_library.h"
50 #include "BKE_scene.h"
51 #include "BKE_sound.h"
52 #include "BKE_packedFile.h"
53 #include "BKE_utildefines.h"
54 #include "BKE_idprop.h"
55
56 #include "BLI_blenlib.h"
57
58 #include "BSE_filesel.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_graphics.h"
62 #include "BIF_glutil.h"
63 #include "BIF_interface.h"
64 #include "BIF_imasel.h"
65 #include "BIF_keyval.h"
66 #include "BIF_mainqueue.h"
67 #include "BIF_mywindow.h"
68 #include "BIF_meshtools.h"
69 #include "BIF_resources.h"
70 #include "BIF_renderwin.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toolbox.h"
74 #include "BIF_editseq.h"
75
76 #include "BIF_butspace.h"
77
78 #include "mydevice.h"
79 #include "blendef.h"
80
81 /* -----includes for this file specific----- */
82
83 #include "DNA_image_types.h"
84
85 #include "BKE_writeavi.h"
86 #include "BKE_writeffmpeg.h"
87 #include "BKE_image.h"
88 #include "BKE_plugin_types.h"
89
90 #include "BLI_threads.h"
91
92 #include "BIF_editsound.h"
93 #include "BIF_writeimage.h"
94 #include "BIF_writeavicodec.h"
95
96 #include "BSE_headerbuttons.h"
97 #include "BSE_sequence.h"
98 #include "BSE_seqeffects.h"
99 #include "BSE_seqscopes.h"
100 #include "BSE_seqaudio.h"
101
102 #include "RE_pipeline.h"
103
104 #include "butspace.h" // own module
105
106 #ifdef WITH_QUICKTIME
107 #include "quicktime_export.h"
108 #endif
109
110 #ifdef WITH_FFMPEG
111
112 #include <libavcodec/avcodec.h> /* for PIX_FMT_* and CODEC_ID_* */
113 #include <libavformat/avformat.h>
114 #include <libavcodec/opt.h>
115
116 static int ffmpeg_preset_sel = 0;
117
118 extern int is_container(int);
119
120 extern void makeffmpegstring(char* string);
121
122 #endif
123
124 /* here the calls for scene buttons
125    - render
126    - world
127    - anim settings, audio
128 */
129
130 /* prototypes */
131 void playback_anim(void);
132
133 /* ************************ SOUND *************************** */
134 static void load_new_sample(char *str)  /* called from fileselect */
135 {
136         char name[FILE_MAX];
137         bSound *sound;
138         bSample *sample, *newsample;
139
140         sound = G.buts->lockpoin;
141         
142         /* No Sound or Selected the same sample as we alredy have, just ignore */
143         if (sound==NULL || str==sound->name)
144                 return;
145                 
146         if (sizeof(sound->sample->name) < strlen(str)) {
147                 error("Path too long: %s", str);
148                 return;
149         }
150                 
151         // save values
152         sample = sound->sample;
153         strcpy(name, sound->sample->name);      
154         strcpy(sound->name, str);
155         sound_set_sample(sound, NULL);
156         sound_initialize_sample(sound);
157
158         if (sound->sample->type == SAMPLE_INVALID) {
159                 error("Not a valid sample: %s", str);
160
161                 newsample = sound->sample;
162
163                 // restore values
164                 strcpy(sound->name, name);
165                 sound_set_sample(sound, sample);
166
167                 // remove invalid sample
168
169                 sound_free_sample(newsample);
170                 BLI_remlink(samples, newsample);
171                 MEM_freeN(newsample);
172                 return;
173         }
174         
175         BIF_undo_push("Load new audio file");
176         allqueue(REDRAWBUTSSCENE, 0);
177 }
178
179
180 void do_soundbuts(unsigned short event)
181 {
182         char name[FILE_MAX];
183         bSound *sound;
184         bSample *sample;
185         bSound* tempsound;
186         ID *id;
187         
188         sound = G.buts->lockpoin;
189         
190         switch(event) {
191         case B_SOUND_REDRAW:
192                 allqueue(REDRAWBUTSSCENE, 0);
193                 break;
194
195         case B_SOUND_LOAD_SAMPLE:
196                 if (sound) strcpy(name, sound->name);
197                 else strcpy(name, U.sounddir);
198                         
199                 activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
200                 break;
201
202         case B_SOUND_PLAY_SAMPLE:
203                 if (sound) {
204                         if (sound->sample->type != SAMPLE_INVALID) {
205                                 sound_play_sound(sound);
206                                 allqueue(REDRAWBUTSSCENE, 0);
207                         }
208                 }
209                 break;
210
211         case B_SOUND_MENU_SAMPLE:
212                 if (G.buts->menunr > 0) {
213                         sample = BLI_findlink(samples, G.buts->menunr - 1);
214                         if (sample && sound && sound->sample != sample) {
215                                 int wasrelative = (strncmp(sound->name, "//", 2)==0);
216                                 
217                                 BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
218                                 sound_set_sample(sound, sample);
219                                 
220                                 if (wasrelative)
221                                         BLI_makestringcode(G.sce, sound->name);
222                                         
223                                 do_soundbuts(B_SOUND_REDRAW);
224                         }
225                 }
226                         
227                 break;
228         case B_SOUND_NAME_SAMPLE:
229                 load_new_sample(sound->name);
230                 break;
231         
232         case B_SOUND_UNPACK_SAMPLE:
233                 if(sound && sound->sample) {
234                         sample = sound->sample;
235                         
236                         if (sample->packedfile) {
237                                 if (G.fileflags & G_AUTOPACK) {
238                                         if (okee("Disable AutoPack ?")) {
239                                                 G.fileflags &= ~G_AUTOPACK;
240                                         }
241                                 }
242                                 
243                                 if ((G.fileflags & G_AUTOPACK) == 0) {
244                                         unpackSample(sample, PF_ASK);
245                                 }
246                         } else {
247                                 sound_set_packedfile(sample, newPackedFile(sample->name));
248                         }
249                         allqueue(REDRAWHEADERS, 0);
250                         do_soundbuts(B_SOUND_REDRAW);
251                 }
252                 break;
253
254         case B_SOUND_COPY_SOUND:
255                 if (sound) {
256                         tempsound = sound_make_copy(sound);
257                         sound = tempsound;
258                         id = &sound->id;
259                         G.buts->lockpoin = (bSound*)id;
260                         BIF_undo_push("Copy sound");
261                         do_soundbuts(B_SOUND_REDRAW);
262                 }
263                 break;
264
265         case B_SOUND_RECALC:
266                 waitcursor(1);
267                 sound = G.main->sound.first;
268                 while (sound) {
269                         free(sound->stream);
270                         sound->stream = 0;
271                         audio_makestream(sound);
272                         sound = (bSound *) sound->id.next;
273                 }
274                 waitcursor(0);
275                 allqueue(REDRAWSEQ, 0);
276                 break;
277
278         case B_SOUND_RATECHANGED:
279
280                 allqueue(REDRAWBUTSSCENE, 0);
281                 allqueue(REDRAWSEQ, 0);
282                 break;
283
284         case B_SOUND_MIXDOWN:
285                 audio_mixdown();
286                 break;
287
288         default: 
289                 if (G.f & G_DEBUG) {
290                         printf("do_soundbuts: unhandled event %d\n", event);
291                 }
292         }
293 }
294
295
296 static void sound_panel_listener(void)
297 {
298         uiBlock *block;
299         int xco= 100, yco=100;
300         
301         block= uiNewBlock(&curarea->uiblocks, "sound_panel_listener", UI_EMBOSS, UI_HELV, curarea->win);
302         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
303
304         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
305
306         yco -= 30;
307         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
308                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
309         
310         yco -= 30;
311         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
312
313         yco -= 30;
314         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
315         xco,yco,195,24,&G.listener->dopplerfactor, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
316         
317         yco -=30;
318         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Velocity: ",
319         xco,yco,195,24,&G.listener->dopplervelocity,0.0,10000.0, 1.0,0, "Sets the propagation speed of sound");
320
321         
322 }
323
324 static void sound_panel_sequencer(void)
325 {
326         uiBlock *block;
327         short xco, yco;
328         char mixrateinfo[256];
329         
330         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sequencer", UI_EMBOSS, UI_HELV, curarea->win);
331         if(uiNewPanel(curarea, block, "Sequencer", "Sound", 640, 0, 318, 204)==0) return;
332
333         /* audio sequence engine settings ------------------------------------------------------------------ */
334
335         xco = 1010;
336         yco = 195;
337
338         uiDefBut(block, LABEL, 0, "Audio sequencer settings", xco,yco,295,20, 0, 0, 0, 0, 0, "");
339
340         yco -= 25;
341         sprintf(mixrateinfo, "Mixing/Sync (latency: %d ms)", (int)( (((float)U.mixbufsize)/(float)G.scene->audio.mixrate)*1000.0 ) );
342         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
343
344         yco -= 25;              
345         uiDefButI(block, ROW, B_SOUND_RATECHANGED, "44.1 kHz",  xco,yco,75,20, &G.scene->audio.mixrate, 2.0, 44100.0, 0, 0, "Mix at 44.1 kHz");
346         uiDefButI(block, ROW, B_SOUND_RATECHANGED, "48.0 kHz",          xco+80,yco,75,20, &G.scene->audio.mixrate, 2.0, 48000.0, 0, 0, "Mix at 48 kHz");
347         uiDefBut(block, BUT, B_SOUND_RECALC, "Recalc",          xco+160,yco,75,20, 0, 0, 0, 0, 0, "Recalculate samples");
348
349         yco -= 25;
350         uiDefButBitS(block, TOG, AUDIO_SYNC, B_SOUND_CHANGED, "Sync",   xco,yco,115,20, &G.scene->audio.flag, 0, 0, 0, 0, "Use sample clock for syncing animation to audio");
351         uiDefButBitS(block, TOG, AUDIO_SCRUB, B_SOUND_CHANGED, "Scrub",         xco+120,yco,115,20, &G.scene->audio.flag, 0, 0, 0, 0, "Scrub when changing frames");
352
353         yco -= 25;
354         uiDefBut(block, LABEL, 0, "Main mix", xco,yco,295,20, 0, 0, 0, 0, 0, "");
355
356         yco -= 25;              
357         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Main (dB): ",
358                 xco,yco,235,24,&G.scene->audio.main, -24.0, 6.0, 0, 0, "Set the audio master gain/attenuation in dB");
359
360         yco -= 25;
361         uiDefButBitS(block, TOG, AUDIO_MUTE, 0, "Mute", xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");         
362         
363         yco -= 35;
364         uiDefBut(block, BUT, B_SOUND_MIXDOWN, "MIXDOWN",        xco,yco,235,24, 0, 0, 0, 0, 0, "Create WAV file from sequenced audio (output goes to render output dir)");
365         
366 }
367
368 static char *make_sample_menu(void)
369 {
370         int len= BLI_countlist(samples);        /* BKE_sound.h */
371         
372         if(len) {
373                 bSample *sample;
374                 char *str;
375                 int nr, a=0;
376                 
377                 str= MEM_callocN(32*len, "menu");
378                 
379                 for(nr=1, sample= samples->first; sample; sample= sample->id.next, nr++) {
380                         a+= sprintf(str+a, "|%s %%x%d", sample->id.name+2, nr);
381                 }
382                 return str;
383         }
384         return NULL;
385 }
386
387 static void sound_panel_sound(bSound *sound)
388 {
389         static int packdummy=0;
390         ID *id, *idfrom;
391         uiBlock *block;
392         bSample *sample;
393         char *strp, ch[256];
394
395         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSS, UI_HELV, curarea->win);
396         if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
397         
398         uiDefBut(block, LABEL, 0, "Blender Sound block",10,180,195,20, 0, 0, 0, 0, 0, "");
399         
400         // warning: abuse of texnr here! (ton didnt code!)
401         buttons_active_id(&id, &idfrom);
402         std_libbuttons(block, 10, 160, 0, NULL, B_SOUNDBROWSE2, ID_SO, 0, id, idfrom, &(G.buts->texnr), 1, 0, 0, 0, 0);
403
404         if (sound) {
405         
406                 uiDefBut(block, BUT, B_SOUND_COPY_SOUND, "Copy sound", 220,160,90,20, 0, 0, 0, 0, 0, "Make another copy (duplicate) of the current sound");
407
408                 uiSetButLock(sound->id.lib!=0, ERROR_LIBDATA_MESSAGE);
409                 sound_initialize_sample(sound);
410                 sample = sound->sample;
411
412                 /* info string */
413                 if (sound->sample && sound->sample->len && sound->sample->channels && sound->sample->bits) {
414                         char *tmp;
415                         if (sound->sample->channels == 1) tmp= "Mono";
416                         else if (sound->sample->channels == 2) tmp= "Stereo";
417                         else tmp= "Unknown";
418                         
419                         sprintf(ch, "Sample: %s, %d bit, %d Hz, %d samples", tmp, sound->sample->bits, sound->sample->rate, (sound->sample->len/(sound->sample->bits/8)/sound->sample->channels));
420                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
421                 }
422                 else {
423                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
424                 }
425
426                 /* sample browse buttons */
427                 uiBlockBeginAlign(block);
428                 strp= make_sample_menu();
429                 if (strp) {
430                         uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
431                         MEM_freeN(strp);
432                 }
433                 uiDefBut(block, TEX, B_SOUND_NAME_SAMPLE, "",           35,120,250,20, sound->name, 0.0, 79.0, 0, 0, "The sample file used by this Sound");
434                 
435                 if (sound->sample->packedfile) packdummy = 1;
436                 else packdummy = 0;
437                 
438                 uiDefIconButBitI(block, TOG, 1, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
439                         285, 120,25,20, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
440                 
441                 uiBlockBeginAlign(block);
442                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
443
444                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
445                 
446                 uiBlockBeginAlign(block);
447                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
448                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Game engine only: Set the volume of this sound");
449
450                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
451                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Game engine only: Set the pitch of this sound");
452
453                 /* looping */
454                 uiBlockBeginAlign(block);
455                 uiDefButBitI(block, TOG, SOUND_FLAGS_LOOP, B_SOUND_REDRAW, "Loop",
456                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between looping on/off");
457
458                 if (sound->flags & SOUND_FLAGS_LOOP) {
459                         uiDefButBitI(block, TOG, SOUND_FLAGS_BIDIRECTIONAL_LOOP, B_SOUND_REDRAW, "Ping Pong",
460                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between A->B and A->B->A looping");
461                         
462                 }
463         
464
465                 /* 3D settings ------------------------------------------------------------------ */
466                 uiBlockBeginAlign(block);
467
468                 if (sound->sample->channels == 1) {
469                         uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
470                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Game engine only: Turns 3D sound on");
471                         
472                         if (sound->flags & SOUND_FLAGS_3D) {
473                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
474                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Game engine only: Sets the surround scaling factor for this sound");
475                                 
476                         }
477                 }
478         }
479 }
480
481 /* ************************* Sequencer *********************** */
482
483 #define SEQ_PANEL_EDITING 1
484 #define SEQ_PANEL_INPUT   2
485 #define SEQ_PANEL_FILTER  4
486 #define SEQ_PANEL_EFFECT  8
487 #define SEQ_PANEL_PROXY   16
488
489 static char* seq_panel_blend_modes()
490 {
491         static char string[2048];
492
493         Sequence *last_seq = get_last_seq();
494
495         sprintf(string, "Blend mode: %%t|%s %%x%d",
496                 "Replace", SEQ_BLEND_REPLACE);
497
498         /*
499           Blending can only work without effect strips. 
500           Otherwise, one would have
501           to decide, what the effect strips IPO should do:
502           - drive the effect _or_
503           - drive the blend mode ?
504
505           Also: effectdata is used by these implicit effects,
506           so that would collide also.
507         */
508
509         if ( seq_can_blend(last_seq) ) {
510                 int i;
511
512                 for (i = SEQ_EFFECT; i <= SEQ_EFFECT_MAX; i++) {
513                         if (get_sequence_effect_num_inputs(i) == 2) {
514                                 sprintf(string + strlen(string), 
515                                         "|%s %%x%d", 
516                                         give_seqname_by_type(i), i);
517                         }
518                 }
519         }
520         return string;
521 }
522
523 static char* seq_panel_scenes()
524 {
525         static char rstr[8192];
526         char * str;
527
528         IDnames_to_pupstring(&str, NULL, NULL, 
529                              &G.main->scene, (ID *)G.scene, NULL);
530
531         strncpy(rstr, str, 8192);
532         MEM_freeN(str);
533
534         return rstr;
535 }
536
537 static void seq_update_scenenr(Sequence * seq)
538 {
539         Scene * sce;
540         int nr;
541         if (seq->type != SEQ_SCENE) {
542                 return;
543         }
544
545         seq->scenenr = 0;
546
547         sce = G.main->scene.first;
548         nr = 1;
549         while(sce) {
550                 if (sce == seq->scene) {
551                         seq->scenenr = nr;
552                         break;
553                 }
554                 nr++;
555                 sce = sce->id.next;
556         }
557 }
558
559
560 static void seq_panel_editing()
561 {
562         Sequence *last_seq = get_last_seq();
563         uiBlock *block;
564         static char strdata[1024];
565         char * str = strdata;
566         char * p;
567         int yco;
568
569         block = uiNewBlock(&curarea->uiblocks, "seq_panel_editing", 
570                            UI_EMBOSS, UI_HELV, curarea->win);
571
572         if(uiNewPanel(curarea, block, "Edit", "Sequencer", 
573                       10, 230, 318, 204) == 0) return;
574
575         uiDefBut(block, LABEL, 
576                  0, give_seqname(last_seq), 
577                  10,140,60,19, 0, 
578                  0, 0, 0, 0, "");
579
580         uiDefBut(block, TEX, 
581                  B_NOP, "Name: ", 
582                  70,140,180,19, last_seq->name+2, 
583                  0.0, 21.0, 100, 0, "");
584
585         uiDefButI(block, MENU, B_SEQ_BUT_RELOAD, seq_panel_blend_modes(), 
586                   10, 120, 120, 19, &last_seq->blend_mode, 
587                   0,0,0,0, "Strip Blend Mode");
588
589         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Blend:",
590                   130, 120, 120, 19, &last_seq->blend_opacity, 
591                   0.0, 100.0, 100.0, 0, 
592                   "Blend opacity");
593
594         uiDefButBitI(block, TOG, SEQ_MUTE,
595                      B_SEQ_BUT_RELOAD_ALL, "Mute",
596                      10,100,60,19, &last_seq->flag,
597                      0.0, 1.0, 0, 0,
598                      "Mute the current strip.");
599
600         uiDefButBitI(block, TOG, SEQ_LOCK,
601                      B_REDR, "Lock",
602                      70,100,60,19, &last_seq->flag,
603                      0.0, 1.0, 0, 0,
604                      "Lock strip, so that it can't be transformed.");
605         
606         uiDefButBitI(block, TOG, SEQ_IPO_FRAME_LOCKED,
607                      B_SEQ_BUT_RELOAD_ALL, "IPO Frame locked",
608                      130,100,120,19, &last_seq->flag,
609                      0.0, 1.0, 0, 0,
610                      "Lock the IPO coordinates to the "
611                      "global frame counter.");
612         
613         if (!(last_seq->flag & SEQ_LOCK)) {
614                 uiDefButI(block, NUM, 
615                           B_SEQ_BUT_TRANSFORM, "Start", 
616                           10, 80, 120, 20, &last_seq->start, 
617                           -MAXFRAMEF, MAXFRAMEF, 0.0, 0.0, "Start of strip");
618                 uiDefButI(block, NUM, 
619                           B_SEQ_BUT_TRANSFORM, "Chan", 
620                           130, 80, 120, 20, &last_seq->machine, 
621                           0.0, MAXSEQ, 0.0, 0.0, "Channel used (Y position)");
622                 
623                 if (check_single_seq(last_seq) || last_seq->len == 0) {
624                         uiDefButI(block, NUM, 
625                                 B_SEQ_BUT_TRANSFORM, "End-Still", 
626                                 130, 60, 120, 19, &last_seq->endstill, 
627                                 0.0, MAXFRAMEF, 0.0, 0.0, "End still");
628                 } else {
629                         uiDefButI(block, NUM, 
630                                   B_SEQ_BUT_TRANSFORM, "Start-Still", 
631                                   10, 60, 120, 20, &last_seq->startstill, 
632                                   0.0, MAXFRAMEF, 0.0, 0.0, "Start still");
633                         uiDefButI(block, NUM, 
634                                   B_SEQ_BUT_TRANSFORM, "End-Still", 
635                                   130, 60, 120, 19, &last_seq->endstill, 
636                                   0.0, MAXFRAMEF, 0.0, 0.0, "End still");
637                         uiDefButI(block, NUM, 
638                                   B_SEQ_BUT_TRANSFORM, "Start-Ofs", 
639                                   10, 40, 120, 20, &last_seq->startofs, 
640                                   0.0, last_seq->len - last_seq->endofs, 
641                                   0.0, 0.0, "Start offset");
642                         uiDefButI(block, NUM, 
643                                   B_SEQ_BUT_TRANSFORM, "End-Ofs", 
644                                   130, 40, 120, 19, &last_seq->endofs, 
645                                   0.0, last_seq->len - last_seq->startofs, 
646                                   0.0, 0.0, "End offset");
647                 }
648         }
649
650
651         if(last_seq->type & SEQ_EFFECT)
652                 sprintf(str, "Len: %d\nFrom %d - %d\n", last_seq->len, last_seq->startdisp, last_seq->enddisp-1);
653         else
654                 sprintf(str, "Len: %d(%d)\n", last_seq->enddisp-last_seq->startdisp, last_seq->len);
655
656         str += strlen(str);
657
658         if(last_seq->type==SEQ_IMAGE) {
659                 if (last_seq->len > 1) {
660                         /* CURRENT */
661                         StripElem * se= give_stripelem(last_seq, CFRA);
662                         StripElem * last;
663
664                         /* FIRST AND LAST */
665         
666                         if(last_seq->strip) {
667                                 se= last_seq->strip->stripdata;
668                                 last= se+last_seq->len-1;
669                                 if(last_seq->startofs) se+= last_seq->startofs;
670                                 if(last_seq->endofs) last-= last_seq->endofs;
671         
672                                 sprintf(str, "First: %s at %d\nLast: %s at %d\n", se->name, last_seq->startdisp, last->name, last_seq->enddisp-1);
673                         }
674                 } else { /* single image */
675                         if (last_seq->strip) {
676                                 sprintf(str, "Len: %d\n", last_seq->enddisp-last_seq->startdisp);
677                         }
678                 }
679
680                 str += strlen(str);
681
682                 /* orig size */
683                 if(last_seq->strip) {
684                         sprintf(str, "OrigSize: %d x %d\n", last_seq->strip->orx, last_seq->strip->ory);
685                 }
686         }
687         else if(last_seq->type==SEQ_MOVIE) {
688                 int sta= last_seq->startofs;
689                 int end= last_seq->len-1-last_seq->endofs;
690
691                 sprintf(str, "First: %d at %d\nLast: %d at %d\nCur: %d\n",
692                         sta, last_seq->startdisp, end, last_seq->enddisp-1,  
693                         (G.scene->r.cfra)-last_seq->startdisp);
694
695                 str += strlen(str);
696                 /* orig size */
697                 if(last_seq->strip) {
698                         sprintf(str, "OrigSize: %d x %d\n", 
699                                 last_seq->strip->orx, last_seq->strip->ory);
700                 }
701         }
702         else if(last_seq->type==SEQ_SCENE) {
703                 TStripElem * se= give_tstripelem(last_seq,  (G.scene->r.cfra));
704                 if(se && last_seq->scene) {
705                         sprintf(str, "First: %d\nLast: %d\nCur: %d\n", last_seq->sfra+se->nr, last_seq->sfra, last_seq->sfra+last_seq->len-1); 
706                 }
707                 str += strlen(str);
708                 /* orig size */
709                 if(last_seq->strip) {
710                         sprintf(str, "OrigSize: %d x %d\n", 
711                                 last_seq->strip->orx, last_seq->strip->ory);
712                 }
713         }
714         else if(last_seq->type==SEQ_RAM_SOUND
715                 || last_seq->type == SEQ_HD_SOUND) {
716
717                 int sta= last_seq->startofs;
718                 int end= last_seq->len-1-last_seq->endofs;
719
720                 sprintf(str, "First: %d at %d\nLast: %d at %d\nCur: %d\n",
721                         sta, last_seq->startdisp, end, last_seq->enddisp-1,  
722                         (G.scene->r.cfra)-last_seq->startdisp);
723         }
724         else if(last_seq->type == SEQ_SPEED) {
725                 SpeedControlVars * vars = 
726                         (SpeedControlVars*) last_seq->effectdata;
727
728                 if (vars) {
729                         sprintf(str, "Last mapped frame: %d at %d\n", 
730                                 vars->lastValidFrame, 
731                                 vars->lastValidFrame 
732                                 + last_seq->startdisp);
733                 }
734         }
735
736         str = strdata;
737         yco = 20;
738
739         while ((p = strchr(str, '\n'))) {
740                 *p = 0;
741                 uiDefBut(block, LABEL, 0, str, 10,yco,240,17, 0, 
742                          0, 0, 0, 0, "");
743                 str = p+1;
744                 yco -= 18;
745         }
746 }
747
748 static void seq_panel_input()
749 {
750         Sequence *last_seq = get_last_seq();
751         uiBlock *block;
752
753         block = uiNewBlock(&curarea->uiblocks, "seq_panel_input", 
754                            UI_EMBOSS, UI_HELV, curarea->win);
755
756         if(uiNewPanel(curarea, block, "Input", "Sequencer", 
757                       10, 230, 318, 204) == 0) return;
758
759         if (SEQ_HAS_PATH(last_seq)) {
760                 uiDefBut(block, TEX, 
761                          B_SEQ_BUT_RELOAD_FILE, "Dir: ", 
762                          10,140,240,19, last_seq->strip->dir, 
763                          0.0, 160.0, 100, 0, "");
764         }
765
766         if (last_seq->type == SEQ_IMAGE) {
767                 int cfra = CFRA;
768                 StripElem * se;
769
770                 if(last_seq->startdisp >cfra) {
771                         cfra = last_seq->startdisp;
772                 } else if (last_seq->enddisp <= cfra) {
773                         cfra = last_seq->enddisp - 1;
774                 }
775
776                 se = give_stripelem(last_seq, cfra);
777
778                 if (se) {
779                         uiDefBut(block, TEX, 
780                                  B_SEQ_BUT_RELOAD_FILE, "File: ", 
781                                  10, 120, 190,19, se->name, 
782                                  0.0, 80.0, 100, 0, "");
783                 }
784
785         } else if (last_seq->type == SEQ_MOVIE || 
786                    last_seq->type == SEQ_HD_SOUND ||
787                    last_seq->type == SEQ_RAM_SOUND) {
788                 uiDefBut(block, TEX, 
789                          B_SEQ_BUT_RELOAD_FILE, "File: ", 
790                          10,120,190,19, last_seq->strip->stripdata->name, 
791                          0.0, 80.0, 100, 0, "");
792         } else if (last_seq->type == SEQ_SCENE) {
793                 seq_update_scenenr(last_seq);
794                 uiDefButI(block, MENU, B_SEQ_BUT_RELOAD_FILE, 
795                           seq_panel_scenes(), 
796                           10, 120, 190, 19, &last_seq->scenenr, 
797                           0,0,0,0, "Linked Scene");
798         }
799
800         uiDefBut(block, BUT, B_SEQ_BUT_RELOAD_FILE, 
801                  "Reload",
802                  200,120,50,19, 0, 0, 0, 0, 0, 
803                  "Reload files/scenes from disk and update strip length.");
804
805         if (last_seq->type == SEQ_MOVIE 
806             || last_seq->type == SEQ_IMAGE 
807             || last_seq->type == SEQ_SCENE
808             || last_seq->type == SEQ_META) {
809                 uiDefButBitI(block, TOG, SEQ_USE_CROP,
810                              B_SEQ_BUT_RELOAD, "Use Crop",
811                              10,100,240,19, &last_seq->flag,
812                              0.0, 1.0, 0, 0,
813                              "Crop image before processing.");
814
815                 if (last_seq->flag & SEQ_USE_CROP) {
816                         if (!last_seq->strip->crop) {
817                                 last_seq->strip->crop = 
818                                         MEM_callocN(sizeof(struct StripCrop), 
819                                                     "StripCrop");
820                         }
821                         uiDefButI(block, NUM, 
822                                   B_SEQ_BUT_RELOAD, "Top", 
823                                   10, 80, 120, 20, 
824                                   &last_seq->strip->crop->top, 
825                                   0.0, 4096, 0.0, 0.0, "Top of source image");
826                         uiDefButI(block, NUM, 
827                                   B_SEQ_BUT_RELOAD, "Bottom", 
828                                   130, 80, 120, 20, 
829                                   &last_seq->strip->crop->bottom, 
830                                   0.0, 4096, 0.0, 0.0,
831                                   "Bottom of source image");
832                         
833                         uiDefButI(block, NUM, 
834                                   B_SEQ_BUT_RELOAD, "Left", 
835                                   10, 60, 120, 20,
836                                   &last_seq->strip->crop->left, 
837                                   0.0, 4096, 0.0, 0.0, "Left");
838                         uiDefButI(block, NUM, 
839                                   B_SEQ_BUT_RELOAD, "Right", 
840                                   130, 60, 120, 19, 
841                                   &last_seq->strip->crop->right, 
842                                   0.0, 4096, 0.0, 0.0, "Right");
843                 }
844                 
845                 uiDefButBitI(block, TOG, SEQ_USE_TRANSFORM,
846                              B_SEQ_BUT_RELOAD, "Use Translate",
847                              10,40,240,19, &last_seq->flag,
848                              0.0, 1.0, 0, 0,
849                              "Translate image before processing.");
850                 
851                 if (last_seq->flag & SEQ_USE_TRANSFORM) {
852                         if (!last_seq->strip->transform) {
853                                 last_seq->strip->transform = 
854                                         MEM_callocN(
855                                                 sizeof(struct StripTransform), 
856                                                 "StripTransform");
857                         }
858                         uiDefButI(block, NUM, 
859                                   B_SEQ_BUT_RELOAD, "X-Ofs", 
860                                   10, 20, 120, 20, 
861                                   &last_seq->strip->transform->xofs, 
862                                   -4096.0, 4096, 0.0, 0.0, "X Offset");
863                         uiDefButI(block, NUM, 
864                                   B_SEQ_BUT_RELOAD, "Y-Ofs", 
865                                   130, 20, 120, 20, 
866                                   &last_seq->strip->transform->yofs, 
867                                   -4096.0, 4096, 0.0, 0.0, "Y Offset");
868                 }
869         }
870
871         uiDefButI(block, NUM, 
872                   B_SEQ_BUT_RELOAD_FILE, "A-Start", 
873                   10, 0, 120, 20, &last_seq->anim_startofs, 
874                   0.0, last_seq->len + last_seq->anim_startofs, 0.0, 0.0, 
875                   "Animation start offset (trim start)");
876         uiDefButI(block, NUM, 
877                   B_SEQ_BUT_RELOAD_FILE, "A-End", 
878                   130, 0, 120, 20, &last_seq->anim_endofs, 
879                   0.0, last_seq->len + last_seq->anim_endofs, 0.0, 0.0, 
880                   "Animation end offset (trim end)");
881
882
883         if (last_seq->type == SEQ_MOVIE) {
884                 uiDefButI(block, NUM, B_SEQ_BUT_RELOAD, "MPEG-Preseek:",
885                           10, -20, 240,19, &last_seq->anim_preseek, 
886                           0.0, 50.0, 100,0,
887                           "On MPEG-seeking preseek this many frames");
888         }
889
890 }
891
892 static void seq_panel_filter_video()
893 {
894         Sequence *last_seq = get_last_seq();
895         uiBlock *block;
896         block = uiNewBlock(&curarea->uiblocks, "seq_panel_filter", 
897                            UI_EMBOSS, UI_HELV, curarea->win);
898
899         if(uiNewPanel(curarea, block, "Filter", "Sequencer", 
900                       10, 230, 318, 204) == 0) return;
901
902
903         uiBlockBeginAlign(block);
904
905
906         uiDefButBitI(block, TOG, SEQ_MAKE_PREMUL, 
907                      B_SEQ_BUT_RELOAD, "Premul", 
908                      10,110,80,19, &last_seq->flag, 
909                      0.0, 21.0, 100, 0, 
910                      "Converts RGB values to become premultiplied with Alpha");
911
912         uiDefButBitI(block, TOG, SEQ_MAKE_FLOAT, 
913                      B_SEQ_BUT_RELOAD, "Float", 
914                      90,110,80,19, &last_seq->flag, 
915                      0.0, 21.0, 100, 0, 
916                      "Convert input to float data");
917
918         uiDefButBitI(block, TOG, SEQ_FILTERY, 
919                      B_SEQ_BUT_RELOAD_FILE, "De-Inter", 
920                      170,110,80,19, &last_seq->flag, 
921                      0.0, 21.0, 100, 0, 
922                      "For video movies to remove fields");
923
924         uiDefButBitI(block, TOG, SEQ_FLIPX, 
925                      B_SEQ_BUT_RELOAD, "FlipX", 
926                      10,90,80,19, &last_seq->flag, 
927                      0.0, 21.0, 100, 0, 
928                      "Flip on the X axis");
929         uiDefButBitI(block, TOG, SEQ_FLIPY, 
930                      B_SEQ_BUT_RELOAD, "FlipY", 
931                      90,90,80,19, &last_seq->flag, 
932                      0.0, 21.0, 100, 0, 
933                      "Flip on the Y axis");
934
935         uiDefButBitI(block, TOG, SEQ_REVERSE_FRAMES,
936                      B_SEQ_BUT_RELOAD, "Flip Time", 
937                      170,90,80,19, &last_seq->flag, 
938                      0.0, 21.0, 100, 0, 
939                      "Reverse frame order");
940                 
941         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Mul:",
942                   10,70,120,19, &last_seq->mul, 
943                   0.001, 20.0, 0.1, 0, 
944                   "Multiply colors");
945
946         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Strobe:",
947                   130,70,120,19, &last_seq->strobe, 
948                   1.0, 30.0, 100, 0, 
949                   "Only display every nth frame");
950
951         uiDefButBitI(block, TOG, SEQ_USE_COLOR_BALANCE,
952                      B_SEQ_BUT_RELOAD, "Use Color Balance", 
953                      10,50,240,19, &last_seq->flag, 
954                      0.0, 21.0, 100, 0, 
955                      "Activate Color Balance "
956                      "(3-Way color correction) on input");
957
958
959         if (last_seq->flag & SEQ_USE_COLOR_BALANCE) {
960                 if (!last_seq->strip->color_balance) {
961                         int c;
962                         StripColorBalance * cb 
963                                 = last_seq->strip->color_balance 
964                                 = MEM_callocN(
965                                         sizeof(struct StripColorBalance), 
966                                         "StripColorBalance");
967                         for (c = 0; c < 3; c++) {
968                                 cb->lift[c] = 1.0;
969                                 cb->gamma[c] = 1.0;
970                                 cb->gain[c] = 1.0;
971                         }
972                 }
973
974                 uiDefBut(block, LABEL, 0, "Lift",
975                          10,30,80,19, 0, 0, 0, 0, 0, "");
976                 uiDefBut(block, LABEL, 0, "Gamma",
977                          90,30,80,19, 0, 0, 0, 0, 0, "");
978                 uiDefBut(block, LABEL, 0, "Gain",
979                          170,30,80,19, 0, 0, 0, 0, 0, "");
980
981                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Lift",
982                           10,10,80,19, last_seq->strip->color_balance->lift, 
983                           0, 0, 0, 0, "Lift (shadows)");
984
985                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Gamma",
986                           90,10,80,19, last_seq->strip->color_balance->gamma, 
987                           0, 0, 0, 0, "Gamma (midtones)");
988
989                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Gain",
990                           170,10,80,19, last_seq->strip->color_balance->gain, 
991                           0, 0, 0, 0, "Gain (highlights)");
992
993                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_LIFT,
994                              B_SEQ_BUT_RELOAD, "Inv Lift", 
995                              10,-10,80,19, 
996                              &last_seq->strip->color_balance->flag, 
997                              0.0, 21.0, 100, 0, 
998                              "Inverse Lift");
999                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_GAMMA,
1000                              B_SEQ_BUT_RELOAD, "Inv Gamma", 
1001                              90,-10,80,19, 
1002                              &last_seq->strip->color_balance->flag, 
1003                              0.0, 21.0, 100, 0, 
1004                              "Inverse Gamma");
1005                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_GAIN,
1006                              B_SEQ_BUT_RELOAD, "Inv Gain", 
1007                              170,-10,80,19, 
1008                              &last_seq->strip->color_balance->flag, 
1009                              0.0, 21.0, 100, 0, 
1010                              "Inverse Gain");
1011         }
1012
1013
1014         uiBlockEndAlign(block);
1015
1016 }
1017
1018
1019 static void seq_panel_filter_audio()
1020 {
1021         Sequence *last_seq = get_last_seq();
1022         uiBlock *block;
1023         block = uiNewBlock(&curarea->uiblocks, "seq_panel_filter", 
1024                            UI_EMBOSS, UI_HELV, curarea->win);
1025
1026         if(uiNewPanel(curarea, block, "Filter", "Sequencer", 
1027                       10, 230, 318, 204) == 0) return;
1028
1029         uiBlockBeginAlign(block);
1030         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Gain (dB):", 10,50,150,19, &last_seq->level, -96.0, 6.0, 100, 0, "");
1031         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Pan:",         10,30,150,19, &last_seq->pan, -1.0, 1.0, 100, 0, "");
1032         uiBlockEndAlign(block);
1033 }
1034
1035 static void seq_panel_effect()
1036 {
1037         Sequence *last_seq = get_last_seq();
1038         uiBlock *block;
1039         block = uiNewBlock(&curarea->uiblocks, "seq_panel_effect", 
1040                            UI_EMBOSS, UI_HELV, curarea->win);
1041
1042         if(uiNewPanel(curarea, block, "Effect", "Sequencer", 
1043                       10, 230, 318, 204) == 0) return;
1044
1045         if(last_seq->type == SEQ_PLUGIN) {
1046                 PluginSeq *pis;
1047                 VarStruct *varstr;
1048                 int a, xco, yco;
1049
1050                 get_sequence_effect(last_seq);/* make sure, plugin is loaded */
1051
1052                 pis= last_seq->plugin;
1053                 if(pis->vars==0) return;
1054
1055                 varstr= pis->varstr;
1056                 if(varstr) {
1057                         for(a=0; a<pis->vars; a++, varstr++) {
1058                                 xco= 150*(a/6)+10;
1059                                 yco= 125 - 20*(a % 6)+1;
1060                                 uiDefBut(block, varstr->type, B_SEQ_BUT_PLUGIN, varstr->name, xco,yco,150,19, &(pis->data[a]), varstr->min, varstr->max, 100, 0, varstr->tip);
1061
1062                         }
1063                 }
1064                 return;
1065         } 
1066
1067         uiBlockBeginAlign(block);
1068
1069         if(last_seq->type==SEQ_WIPE){
1070                 WipeVars *wipe = (WipeVars *)last_seq->effectdata;
1071                 char formatstring[256];
1072                         
1073                 strncpy(formatstring, "Transition Type %t|Single Wipe%x0|Double Wipe %x1|Iris Wipe %x4|Clock Wipe %x5", 255);
1074                 uiDefButS(block, MENU,B_SEQ_BUT_EFFECT, formatstring,   10,65,220,22, &wipe->wipetype, 0, 0, 0, 0, "What type of wipe should be performed");
1075                 uiDefButF(block, NUM,B_SEQ_BUT_EFFECT,"Blur:",  10,40,220,22, &wipe->edgeWidth,0.0,1.0, 1, 2, "The percent width of the blur edge");
1076                 switch(wipe->wipetype){ /*Skip Types that do not require angle*/
1077                 case DO_IRIS_WIPE:
1078                 case DO_CLOCK_WIPE:
1079                         break;
1080                         
1081                 default:
1082                         uiDefButF(block, NUM,B_SEQ_BUT_EFFECT,"Angle:", 10,15,220,22, &wipe->angle,-90.0,90.0, 1, 2, "The Angle of the Edge");
1083                 }
1084                 uiDefButS(block, TOG,B_SEQ_BUT_EFFECT,"Wipe In",  10,-10,220,22, &wipe->forward,0,0, 0, 0, "Controls Primary Direction of Wipe");                               
1085         } else if(last_seq->type==SEQ_GLOW){
1086                 GlowVars *glow = (GlowVars *)last_seq->effectdata;
1087
1088                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Threshold:",   10,70,150,19, &glow->fMini, 0.0, 1.0, 0, 0, "Trigger Intensity");
1089                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Clamp:",                       10,50,150,19, &glow->fClamp, 0.0, 1.0, 0, 0, "Brightness limit of intensity");
1090                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Boost factor:",        10,30,150,19, &glow->fBoost, 0.0, 10.0, 0, 0, "Brightness multiplier");
1091                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Blur distance:",       10,10,150,19, &glow->dDist, 0.5, 20.0, 0, 0, "Radius of glow effect");
1092                 uiDefButI(block, NUM, B_NOP, "Quality:", 10,-5,150,19, &glow->dQuality, 1.0, 5.0, 0, 0, "Accuracy of the blur effect");
1093                 uiDefButI(block, TOG, B_NOP, "Only boost", 10,-25,150,19, &glow->bNoComp, 0.0, 0.0, 0, 0, "Show the glow buffer only");
1094         }
1095         else if(last_seq->type==SEQ_TRANSFORM){
1096                 TransformVars *transform = (TransformVars *)last_seq->effectdata;
1097
1098                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "xScale Start:",        10,70,150,19, &transform->ScalexIni, 0.0, 10.0, 0, 0, "X Scale Start");
1099                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "xScale End:",  160,70,150,19, &transform->ScalexFin, 0.0, 10.0, 0, 0, "X Scale End");
1100                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "yScale Start:",        10,50,150,19, &transform->ScaleyIni, 0.0, 10.0, 0, 0, "Y Scale Start");
1101                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "yScale End:",  160,50,150,19, &transform->ScaleyFin, 0.0, 10.0, 0, 0, "Y Scale End");
1102                 
1103                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Percent", 10, 30, 150, 19, &transform->percent, 0.0, 1.0, 0.0, 0.0, "Percent Translate");
1104                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Pixels", 160, 30, 150, 19, &transform->percent, 0.0, 0.0, 0.0, 0.0, "Pixels Translate");
1105                 if(transform->percent==1){
1106                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x Start:",     10,10,150,19, &transform->xIni, -500.0, 500.0, 0, 0, "X Position Start");
1107                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x End:",       160,10,150,19, &transform->xFin, -500.0, 500.0, 0, 0, "X Position End");
1108                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y Start:",     10,-10,150,19, &transform->yIni, -500.0, 500.0, 0, 0, "Y Position Start");
1109                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y End:",       160,-10,150,19, &transform->yFin, -500.0, 500.0, 0, 0, "Y Position End");
1110                 } else {
1111                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x Start:",     10,10,150,19, &transform->xIni, -10000.0, 10000.0, 0, 0, "X Position Start");
1112                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x End:",       160,10,150,19, &transform->xFin, -10000.0, 10000.0, 0, 0, "X Position End");
1113                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y Start:",     10,-10,150,19, &transform->yIni, -10000.0, 10000.0, 0, 0, "Y Position Start");
1114                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y End:",       160,-10,150,19, &transform->yFin, -10000.0, 10000.0, 0, 0, "Y Position End");
1115                         
1116                 }
1117                 
1118                 
1119                 
1120                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "rot Start:",10,-30,150,19, &transform->rotIni, 0.0, 360.0, 0, 0, "Rotation Start");
1121                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "rot End:",160,-30,150,19, &transform->rotFin, 0.0, 360.0, 0, 0, "Rotation End");
1122                 
1123                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "No Interpolat", 10, -50, 100, 19, &transform->interpolation, 0.0, 0.0, 0.0, 0.0, "No interpolation");
1124                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Bilinear", 101, -50, 100, 19, &transform->interpolation, 0.0, 1.0, 0.0, 0.0, "Bilinear interpolation");
1125                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Bicubic", 202, -50, 100, 19, &transform->interpolation, 0.0, 2.0, 0.0, 0.0, "Bicubic interpolation");
1126         } else if(last_seq->type==SEQ_COLOR) {
1127                 SolidColorVars *colvars = (SolidColorVars *)last_seq->effectdata;
1128                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "",10,90,150,19, colvars->col, 0, 0, 0, 0, "");
1129         } else if(last_seq->type==SEQ_SPEED){
1130                 SpeedControlVars *sp = 
1131                         (SpeedControlVars *)last_seq->effectdata;
1132                 
1133                 uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Global Speed:",        10,70,150,19, &sp->globalSpeed, 0.0, 100.0, 0, 0, "Global Speed");
1134                 
1135                 uiDefButBitI(block, TOG, SEQ_SPEED_INTEGRATE,
1136                              B_SEQ_BUT_RELOAD, 
1137                              "IPO is velocity",
1138                              10,50,150,19, &sp->flags, 
1139                              0.0, 1.0, 0, 0, 
1140                              "Interpret the IPO value as a "
1141                              "velocity instead of a frame number");
1142
1143                 uiDefButBitI(block, TOG, SEQ_SPEED_BLEND,
1144                              B_SEQ_BUT_RELOAD, 
1145                              "Enable frame blending",
1146                              10,30,150,19, &sp->flags, 
1147                              0.0, 1.0, 0, 0, 
1148                              "Blend two frames into the "
1149                              "target for a smoother result");
1150                 
1151                 uiDefButBitI(block, TOG, SEQ_SPEED_COMPRESS_IPO_Y,
1152                              B_SEQ_BUT_RELOAD, 
1153                              "IPO value runs from [0..1]",
1154                              10,10,150,19, &sp->flags, 
1155                              0.0, 1.0, 0, 0, 
1156                              "Scale IPO value to get the "
1157                              "target frame number.");
1158         }
1159
1160         uiBlockEndAlign(block);
1161 }
1162
1163 static void seq_panel_proxy()
1164 {
1165         Sequence *last_seq = get_last_seq();
1166         uiBlock *block;
1167         block = uiNewBlock(&curarea->uiblocks, "seq_panel_proxy", 
1168                            UI_EMBOSS, UI_HELV, curarea->win);
1169
1170         if(uiNewPanel(curarea, block, "Proxy", "Sequencer", 
1171                       10, 230, 318, 204) == 0) return;
1172
1173         uiBlockBeginAlign(block);
1174
1175         uiDefButBitI(block, TOG, SEQ_USE_PROXY, 
1176                      B_SEQ_BUT_RELOAD, "Use Proxy", 
1177                      10,140,120,19, &last_seq->flag, 
1178                      0.0, 21.0, 100, 0, 
1179                      "Use a preview proxy for this strip");
1180
1181         if (last_seq->flag & SEQ_USE_PROXY) {
1182                 if (!last_seq->strip->proxy) {
1183                         last_seq->strip->proxy = 
1184                                 MEM_callocN(sizeof(struct StripProxy),
1185                                             "StripProxy");
1186                 }
1187
1188                 uiDefButBitI(block, TOG, SEQ_USE_PROXY_CUSTOM_DIR, 
1189                              B_SEQ_BUT_RELOAD, "Custom Dir", 
1190                              130,140,120,19, &last_seq->flag, 
1191                              0.0, 21.0, 100, 0, 
1192                              "Use a custom directory to store data");
1193
1194                 if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) {
1195                         uiDefIconBut(block, BUT, B_SEQ_SEL_PROXY_DIR, 
1196                                      ICON_FILESEL, 10, 120, 20, 20, 0, 0, 0, 0, 0, 
1197                                      "Select the directory/name for "
1198                                      "the proxy storage");
1199
1200                         uiDefBut(block, TEX, 
1201                                  B_SEQ_BUT_RELOAD, "Dir: ", 
1202                                  30,120,220,20, last_seq->strip->proxy->dir, 
1203                                  0.0, 160.0, 100, 0, "");
1204                 }
1205         }
1206
1207         if (last_seq->flag & SEQ_USE_PROXY) {
1208                 if (G.scene->r.size == 100) {
1209                         uiDefBut(block, LABEL, 0, 
1210                                  "Full render size selected, ",
1211                                  10,100,240,19, 0, 0, 0, 0, 0, "");
1212                         uiDefBut(block, LABEL, 0, 
1213                                  "so no proxy enabled!",
1214                                  10,80,240,19, 0, 0, 0, 0, 0, "");
1215                 } else if (last_seq->type != SEQ_MOVIE 
1216                            && last_seq->type != SEQ_IMAGE
1217                            && !(last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) {
1218                         uiDefBut(block, LABEL, 0, 
1219                                  "Cannot proxy this strip without ",
1220                                  10,100,240,19, 0, 0, 0, 0, 0, "");
1221                         uiDefBut(block, LABEL, 0, 
1222                                  "custom directory selection!",
1223                                  10,80,240,19, 0, 0, 0, 0, 0, "");
1224
1225                 } else {
1226                         uiDefBut(block, BUT, B_SEQ_BUT_REBUILD_PROXY, 
1227                                  "Rebuild proxy",
1228                                  10,100,240,19, 0, 0, 0, 0, 0, 
1229                                  "Rebuild proxy for the "
1230                                  "currently selected strip.");
1231                 }
1232         }
1233
1234         uiBlockEndAlign(block);
1235 }
1236
1237
1238 void sequencer_panels()
1239 {
1240         Sequence *last_seq = get_last_seq();
1241         int panels = 0;
1242         int type;
1243
1244         if(last_seq == NULL) {
1245                 return;
1246         }
1247         
1248         type = last_seq->type;
1249
1250         panels = SEQ_PANEL_EDITING;
1251
1252         if (type == SEQ_MOVIE || type == SEQ_IMAGE || type == SEQ_SCENE
1253             || type == SEQ_META) {
1254                 panels |= SEQ_PANEL_INPUT | SEQ_PANEL_FILTER | SEQ_PANEL_PROXY;
1255         }
1256
1257         if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1258                 panels |= SEQ_PANEL_FILTER | SEQ_PANEL_INPUT;
1259         }
1260
1261         if (type == SEQ_PLUGIN || type >= SEQ_EFFECT) {
1262                 panels |= SEQ_PANEL_EFFECT | SEQ_PANEL_PROXY;
1263         }
1264
1265         if (panels & SEQ_PANEL_EDITING) {
1266                 seq_panel_editing();
1267         }
1268
1269         if (panels & SEQ_PANEL_INPUT) {
1270                 seq_panel_input();
1271         }
1272
1273         if (panels & SEQ_PANEL_FILTER) {
1274                 if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1275                         seq_panel_filter_audio();
1276                 } else {
1277                         seq_panel_filter_video();
1278                 }
1279         }
1280
1281         if (panels & SEQ_PANEL_EFFECT) {
1282                 seq_panel_effect();
1283         }
1284
1285         if (panels & SEQ_PANEL_PROXY) {
1286                 seq_panel_proxy();
1287         }
1288 }
1289
1290 static void sel_proxy_dir(char *name)
1291 {
1292         Sequence *last_seq = get_last_seq();
1293         strcpy(last_seq->strip->proxy->dir, name);
1294
1295         allqueue(REDRAWBUTSSCENE, 0);
1296
1297         BIF_undo_push("Change proxy directory");
1298 }
1299
1300 void do_sequencer_panels(unsigned short event)
1301 {
1302         Sequence *last_seq = get_last_seq();
1303         ScrArea * sa;
1304
1305         if (!last_seq) {
1306                 return;
1307         }
1308
1309         switch(event) {
1310         case B_SEQ_BUT_PLUGIN:
1311         case B_SEQ_BUT_EFFECT:
1312                 update_changed_seq_and_deps(last_seq, 0, 1);
1313                 break;
1314         case B_SEQ_BUT_RELOAD_FILE:
1315                 reload_sequence_new_file(last_seq);
1316                 break;
1317         case B_SEQ_BUT_REBUILD_PROXY:
1318                 seq_proxy_rebuild(last_seq);
1319                 break;
1320         case B_SEQ_SEL_PROXY_DIR:
1321                 sa= closest_bigger_area();
1322                 areawinset(sa->win);
1323                 activate_fileselect(FILE_SPECIAL, "SELECT PROXY DIR", 
1324                                     last_seq->strip->proxy->dir, 
1325                                     sel_proxy_dir);
1326                 break;
1327         case B_SEQ_BUT_RELOAD:
1328         case B_SEQ_BUT_RELOAD_ALL:
1329                 update_seq_ipo_rect(last_seq);
1330                 update_seq_icu_rects(last_seq);
1331
1332                 free_imbuf_seq();       // frees all
1333
1334                 break;
1335         case B_SEQ_BUT_TRANSFORM:
1336                 calc_sequence(last_seq);
1337                 if (test_overlap_seq(last_seq))
1338                         shuffle_seq(last_seq);
1339                 break;
1340         }
1341
1342         if (event == B_SEQ_BUT_RELOAD_ALL) {
1343                 allqueue(REDRAWALL, 0);
1344         } else {
1345                 allqueue(REDRAWSEQ, 0);
1346                 allqueue(REDRAWBUTSSCENE, 0);
1347         }
1348 }
1349
1350
1351 /* ************************* SCENE *********************** */
1352
1353
1354 static void output_pic(char *name)
1355 {
1356         strcpy(G.scene->r.pic, name);
1357         allqueue(REDRAWBUTSSCENE, 0);
1358         BIF_undo_push("Change output picture directory");
1359 }
1360
1361 static void backbuf_pic(char *name)
1362 {
1363         Image *ima;
1364         
1365         strcpy(G.scene->r.backbuf, name);
1366         allqueue(REDRAWBUTSSCENE, 0);
1367
1368         ima= BKE_add_image_file(name);
1369         if(ima)
1370                 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
1371
1372         BIF_undo_push("Change background picture");
1373 }
1374
1375 static void run_playanim(char *file) 
1376 {
1377         extern char bprogname[];        /* usiblender.c */
1378         char str[FILE_MAX*2]; /* FILE_MAX*2 is a bit arbitary, but this should roughly allow for the args + the max-file-length */
1379         int pos[2], size[2];
1380
1381         /* use current settings for defining position of window. it actually should test image size */
1382         calc_renderwin_rectangle((G.scene->r.xsch*G.scene->r.size)/100, 
1383                                                          (G.scene->r.ysch*G.scene->r.size)/100, G.winpos, pos, size);
1384 #ifdef WIN32
1385         sprintf(str, "%s -a -s %d -e %d -p %d %d -f %d %g -j %d \"%s\"", bprogname, G.scene->r.sfra, G.scene->r.efra, pos[0], pos[1], G.scene->r.frs_sec, G.scene->r.frs_sec_base, G.scene->frame_step, file);
1386 #else
1387         sprintf(str, "\"%s\" -a -s %d -e %d  -p %d %d -f %d %g -j %d \"%s\"", bprogname, G.scene->r.sfra, G.scene->r.efra, pos[0], pos[1], G.scene->r.frs_sec, G.scene->r.frs_sec_base, G.scene->frame_step, file);
1388 #endif
1389         system(str);
1390 }
1391
1392 void playback_anim(void)
1393 {       
1394         char file[FILE_MAX];
1395
1396         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
1397                 switch (G.scene->r.imtype) {
1398 #ifdef WITH_QUICKTIME
1399                         case R_QUICKTIME:
1400                                 makeqtstring(file);
1401                                 break;
1402 #endif
1403 #ifdef WITH_FFMPEG
1404                 case R_FFMPEG:
1405                         makeffmpegstring(file);
1406                         break;
1407 #endif
1408                 default:
1409                         makeavistring(&G.scene->r, file);
1410                         break;
1411                 }
1412                 if(BLI_exist(file)) {
1413                         run_playanim(file);
1414                 }
1415                 else error("Can't find movie: %s", file);
1416         }
1417         else {
1418                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
1419                 if(BLI_exist(file)) {
1420                         run_playanim(file);
1421                 }
1422                 else error("Can't find image: %s", file);
1423         }
1424 }
1425
1426 #ifdef WITH_FFMPEG
1427 static void set_ffmpeg_preset(int preset);
1428 static int ffmpeg_property_add_string(const char * type, const char * str);
1429 static char ffmpeg_option_to_add[255] = "";
1430 #endif
1431
1432 void do_render_panels(unsigned short event)
1433 {
1434         ScrArea *sa;
1435         ID *id;
1436
1437         switch(event) {
1438
1439         case B_DORENDER:
1440                 BIF_do_render(0);
1441                 break;
1442         case B_RTCHANGED:
1443                 allqueue(REDRAWALL, 0);
1444                 break;
1445         case B_SWITCHRENDER:
1446                 /* new panels added, so... */
1447                 G.buts->re_align= 1;
1448                 allqueue(REDRAWBUTSSCENE, 0);
1449                 break;
1450         case B_PLAYANIM:
1451                 playback_anim();
1452                 break;
1453                 
1454         case B_DOANIM:
1455                 BIF_do_render(1);
1456                 break;
1457         
1458         case B_FS_PIC:
1459                 sa= closest_bigger_area();
1460                 areawinset(sa->win);
1461                 if(G.qual == LR_CTRLKEY)
1462                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1463                 else
1464                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1465                 break;
1466
1467         case B_FS_BACKBUF:
1468                 sa= closest_bigger_area();
1469                 areawinset(sa->win);
1470                 if(G.qual == LR_CTRLKEY)
1471                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1472                 else
1473                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1474                 break;
1475         
1476         case B_PR_PAL:
1477                 G.scene->r.xsch= 720;
1478                 G.scene->r.ysch= 576;
1479                 G.scene->r.xasp= 54;
1480                 G.scene->r.yasp= 51;
1481                 G.scene->r.size= 100;
1482                 G.scene->r.frs_sec= 25;
1483                 G.scene->r.frs_sec_base= 1;
1484                 G.scene->r.mode &= ~R_PANORAMA;
1485                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1486 #ifdef WITH_FFMPEG
1487                 G.scene->r.ffcodecdata.gop_size = 15;
1488 #endif          
1489                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1490                 BIF_undo_push("Set PAL");
1491                 allqueue(REDRAWBUTSSCENE, 0);
1492                 allqueue(REDRAWVIEWCAM, 0);
1493                 break;
1494
1495         case B_FILETYPEMENU:
1496                 allqueue(REDRAWBUTSSCENE, 0);
1497 #ifdef WITH_FFMPEG
1498                 if (G.scene->r.imtype == R_FFMPEG) {
1499                         if (G.scene->r.ffcodecdata.type <= 0 ||
1500                             G.scene->r.ffcodecdata.codec <= 0 ||
1501                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
1502                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
1503                                 G.scene->r.ffcodecdata.codec 
1504                                         = CODEC_ID_MPEG2VIDEO;
1505                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
1506                         }
1507
1508                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
1509                                 G.scene->r.ffcodecdata.audio_codec 
1510                                         = CODEC_ID_MP2;
1511                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
1512                         }
1513                         break;
1514                 }
1515 #endif
1516 #if defined (_WIN32) || defined (__APPLE__)
1517                 // fall through to codec settings if this is the first
1518                 // time R_AVICODEC is selected for this scene.
1519                 if (((G.scene->r.imtype == R_AVICODEC) 
1520                          && (G.scene->r.avicodecdata == NULL)) ||
1521                         ((G.scene->r.imtype == R_QUICKTIME) 
1522                          && (G.scene->r.qtcodecdata == NULL))) {
1523                 } else {
1524                   break;
1525                 }
1526 #endif /*_WIN32 || __APPLE__ */
1527
1528         case B_SELECTCODEC:
1529 #if defined (_WIN32) || defined (__APPLE__)
1530                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
1531 #ifdef WITH_QUICKTIME
1532                         get_qtcodec_settings();
1533 #endif /* WITH_QUICKTIME */
1534                 }
1535 #if defined (_WIN32) && !defined(FREE_WINDOWS)
1536                 else
1537                         get_avicodec_settings();
1538 #endif /* _WIN32 && !FREE_WINDOWS */
1539 #endif /* _WIN32 || __APPLE__ */
1540                 break;
1541
1542         case B_PR_HD:
1543                 G.scene->r.xsch= 1920;
1544                 G.scene->r.ysch= 1080;
1545                 G.scene->r.xasp= 1;
1546                 G.scene->r.yasp= 1;
1547                 G.scene->r.size= 100;
1548                 G.scene->r.mode &= ~R_PANORAMA;
1549                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1550                 
1551                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1552                 BIF_undo_push("Set FULL");
1553                 allqueue(REDRAWBUTSSCENE, 0);
1554                 allqueue(REDRAWVIEWCAM, 0);
1555                 break;
1556         case B_PR_FULL:
1557                 G.scene->r.xsch= 1280;
1558                 G.scene->r.ysch= 1024;
1559                 G.scene->r.xasp= 1;
1560                 G.scene->r.yasp= 1;
1561                 G.scene->r.size= 100;
1562                 G.scene->r.mode &= ~R_PANORAMA;
1563                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1564
1565                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1566                 BIF_undo_push("Set FULL");
1567                 allqueue(REDRAWBUTSSCENE, 0);
1568                 allqueue(REDRAWVIEWCAM, 0);
1569                 break;
1570         case B_PR_PRV:
1571                 G.scene->r.xsch= 640;
1572                 G.scene->r.ysch= 512;
1573                 G.scene->r.xasp= 1;
1574                 G.scene->r.yasp= 1;
1575                 G.scene->r.size= 50;
1576                 G.scene->r.mode &= ~R_PANORAMA;
1577                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1578
1579                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1580                 allqueue(REDRAWVIEWCAM, 0);
1581                 allqueue(REDRAWBUTSSCENE, 0);
1582                 break;
1583         case B_PR_PAL169:
1584                 G.scene->r.xsch= 720;
1585                 G.scene->r.ysch= 576;
1586                 G.scene->r.xasp= 64;
1587                 G.scene->r.yasp= 45;
1588                 G.scene->r.size= 100;
1589                 G.scene->r.frs_sec= 25;
1590                 G.scene->r.frs_sec_base= 1;
1591                 G.scene->r.mode &= ~R_PANORAMA;
1592                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1593 #ifdef WITH_FFMPEG
1594                 G.scene->r.ffcodecdata.gop_size = 15;
1595 #endif          
1596
1597                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1598                 BIF_undo_push("Set PAL 16/9");
1599                 allqueue(REDRAWVIEWCAM, 0);
1600                 allqueue(REDRAWBUTSSCENE, 0);
1601                 break;
1602         case B_PR_PC:
1603                 G.scene->r.xsch= 640;
1604                 G.scene->r.ysch= 480;
1605                 G.scene->r.xasp= 100;
1606                 G.scene->r.yasp= 100;
1607                 G.scene->r.size= 100;
1608                 G.scene->r.mode &= ~R_PANORAMA;
1609                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1610
1611                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
1612                 BIF_undo_push("Set PC");
1613                 allqueue(REDRAWVIEWCAM, 0);
1614                 allqueue(REDRAWBUTSSCENE, 0);
1615                 break;
1616         case B_PR_PRESET:
1617                 G.scene->r.xsch= 720;
1618                 G.scene->r.ysch= 576;
1619                 G.scene->r.xasp= 54;
1620                 G.scene->r.yasp= 51;
1621                 G.scene->r.size= 100;
1622                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS+R_SSS;
1623                 G.scene->r.imtype= R_TARGA;
1624                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1625
1626                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1627                 BIF_undo_push("Set Default");
1628                 allqueue(REDRAWVIEWCAM, 0);
1629                 allqueue(REDRAWBUTSSCENE, 0);
1630                 break;
1631         case B_PR_PANO:
1632                 G.scene->r.xsch= 576;
1633                 G.scene->r.ysch= 176;
1634                 G.scene->r.xasp= 115;
1635                 G.scene->r.yasp= 100;
1636                 G.scene->r.size= 100;
1637                 G.scene->r.mode |= R_PANORAMA;
1638                 G.scene->r.xparts=  16;
1639                 G.scene->r.yparts= 1;
1640
1641                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1642                 BIF_undo_push("Set Panorama");
1643                 allqueue(REDRAWVIEWCAM, 0);
1644                 allqueue(REDRAWBUTSSCENE, 0);
1645                 break;
1646         case B_PR_NTSC:
1647                 G.scene->r.xsch= 720;
1648                 G.scene->r.ysch= 480;
1649                 G.scene->r.xasp= 10;
1650                 G.scene->r.yasp= 11;
1651                 G.scene->r.size= 100;
1652                 G.scene->r.frs_sec= 30;
1653                 G.scene->r.frs_sec_base = 1.001;
1654                 G.scene->r.mode &= ~R_PANORAMA;
1655                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1656 #ifdef WITH_FFMPEG
1657                 G.scene->r.ffcodecdata.gop_size = 18;
1658 #endif          
1659                 
1660                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1661                 BIF_undo_push("Set NTSC");
1662                 allqueue(REDRAWBUTSSCENE, 0);
1663                 allqueue(REDRAWVIEWCAM, 0);
1664                 break;
1665
1666         case B_SETBROWSE:
1667                 id= (ID*) G.scene->set;
1668                 
1669                 if (G.buts->menunr==-2) {
1670                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
1671                 } 
1672                 else if (G.buts->menunr>0) {
1673                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
1674                         
1675                         if (newset==G.scene)
1676                                 error("Can't use the same scene as its own set");
1677                         else if (newset) {
1678                                 G.scene->set= newset;
1679                                 if (scene_check_setscene(G.scene)==0)
1680                                         error("This would create a cycle");
1681
1682                                 allqueue(REDRAWBUTSSCENE, 0);
1683                                 allqueue(REDRAWVIEW3D, 0);
1684                                 BIF_undo_push("Change Set Scene");
1685                         }
1686                 }  
1687                 break;
1688         case B_CLEARSET:
1689                 G.scene->set= NULL;
1690                 allqueue(REDRAWBUTSSCENE, 0);
1691                 allqueue(REDRAWVIEW3D, 0);
1692                 BIF_undo_push("Clear Set Scene");
1693                 
1694                 break;
1695         case B_SET_EDGE:
1696                 allqueue(REDRAWBUTSSCENE, 0);
1697                 break;
1698         case B_SET_ZBLUR:
1699                 G.scene->r.mode &= ~R_EDGE;
1700                 allqueue(REDRAWBUTSSCENE, 0);
1701                 break;
1702         case B_ADD_RENDERLAYER:
1703                 if(G.scene->r.actlay==32767) {
1704                         scene_add_render_layer(G.scene);
1705                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
1706                 }
1707                 allqueue(REDRAWBUTSSCENE, 0);
1708                 allqueue(REDRAWNODE, 0);
1709                 break;
1710         case B_SET_PASS:
1711                 if(G.scene->nodetree) {
1712                         ntreeCompositForceHidden(G.scene->nodetree);
1713                         allqueue(REDRAWNODE, 0);
1714                 }
1715                 allqueue(REDRAWBUTSSCENE, 0);
1716                 allqueue(REDRAWOOPS, 0);
1717 #ifdef WITH_FFMPEG
1718         case B_ADD_FFMPEG_AUDIO_OPTION:
1719                 if (ffmpeg_property_add_string("audio", ffmpeg_option_to_add)){
1720                         *ffmpeg_option_to_add = 0;
1721                 }
1722                 allqueue(REDRAWBUTSSCENE, 0);
1723                 break;
1724         case B_ADD_FFMPEG_VIDEO_OPTION:
1725                 if (ffmpeg_property_add_string("video", ffmpeg_option_to_add)){
1726                         *ffmpeg_option_to_add = 0;
1727                 }
1728                 allqueue(REDRAWBUTSSCENE, 0);
1729                 break;
1730 #endif
1731         }
1732 }
1733
1734 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1735 static uiBlock *edge_render_menu(void *arg_unused)
1736 {
1737         uiBlock *block;
1738         
1739         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
1740                 
1741         /* use this for a fake extra empy space around the buttons */
1742         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
1743         
1744         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
1745                   "Sets edge intensity for Toon shading");
1746
1747         /* color settings for the toon shading */
1748         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
1749         
1750         uiBlockBeginAlign(block);
1751         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
1752                   "Color for edges in toon shading mode.");
1753         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
1754                   "Color for edges in toon shading mode.");
1755         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
1756                   "Color for edges in toon shading mode.");
1757
1758         
1759         uiBlockSetDirection(block, UI_TOP);
1760         
1761         return block;
1762 }
1763
1764
1765 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1766 static uiBlock *framing_render_menu(void *arg_unused)
1767 {
1768         uiBlock *block;
1769         short yco = 190, xco = 0;
1770         int randomcolorindex = 1234;
1771
1772         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
1773
1774         /* use this for a fake extra empy space around the buttons */
1775         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 224, NULL, 0, 0, 0, 0, "");
1776
1777         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
1778         uiBlockBeginAlign(block);
1779         uiDefButC(block, ROW, 0, "Stretch",     xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_SCALE , 0, 0, "Stretch or squeeze the viewport to fill the display window");
1780         uiDefButC(block, ROW, 0, "Expose",      xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_EXTEND, 0, 0, "Show the entire viewport in the display window, viewing more horizontally or vertically");
1781         uiDefButC(block, ROW, 0, "Letterbox",       xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_BARS  , 0, 0, "Show the entire viewport in the display window, using bar horizontally or vertically");
1782         uiBlockEndAlign(block);
1783
1784         yco -= 25;
1785         xco = 40;
1786
1787         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
1788
1789         uiBlockBeginAlign(block);
1790         uiDefButF(block, NUMSLI, 0, "R ", xco,yco,243,18, &G.scene->framing.col[0], 0.0, 1.0, randomcolorindex, 0, "Set the red component of the bars");
1791         yco -= 20;
1792         uiDefButF(block, NUMSLI, 0, "G ", xco,yco,243,18, &G.scene->framing.col[1], 0.0, 1.0, randomcolorindex, 0, "Set the green component of the bars");
1793         yco -= 20;
1794         uiDefButF(block, NUMSLI, 0, "B ", xco,yco,243,18, &G.scene->framing.col[2], 0.0, 1.0, randomcolorindex, 0, "Set the blue component of the bars");
1795         uiBlockEndAlign(block);
1796         
1797         xco = 0;
1798         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
1799         uiDefButS(block, TOG, 0, "Fullscreen", xco+70, yco, 68, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display");
1800         uiBlockBeginAlign(block);
1801         uiDefButS(block, NUM, 0, "X:",          xco+40, yco-=27, 100, 19, &G.scene->r.xplay, 10.0, 2000.0, 0, 0, "Displays current X screen/window resolution. Click to change.");
1802         uiDefButS(block, NUM, 0, "Y:",          xco+140, yco, 100, 19, &G.scene->r.yplay,    10.0, 2000.0, 0, 0, "Displays current Y screen/window resolution. Click to change.");
1803         uiDefButS(block, NUM, 0, "Freq:",       xco+40, yco-=21, 100, 19, &G.scene->r.freqplay, 10.0, 2000.0, 0, 0, "Displays clock frequency of fullscreen display. Click to change.");
1804         uiDefButS(block, NUM, 0, "Bits:",       xco+140, yco, 100, 19, &G.scene->r.depth, 8.0, 32.0, 800.0, 0, "Displays bit depth of full screen display. Click to change.");
1805         uiBlockEndAlign(block);
1806
1807         /* stereo settings */
1808         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
1809          * RAS_IRasterizer has definitions:
1810          * RAS_STEREO_NOSTEREO           1
1811          * RAS_STEREO_QUADBUFFERED 2
1812          * RAS_STEREO_ABOVEBELOW         3
1813          * RAS_STEREO_INTERLACED         4       future
1814          * RAS_STEREO_ANAGLYPH          5
1815          * RAS_STEREO_SIDEBYSIDE        6
1816          * RAS_STEREO_VINTERLACE        7
1817          */
1818         uiBlockBeginAlign(block);
1819         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
1820         uiDefButS(block, ROW, 0, "Pageflip", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 2.0, 0, 0, "Enables hardware pageflip stereo method");
1821         uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
1822         uiDefButS(block, ROW, 0, "Anaglyph", xco-=180, yco-=21, 88, 19, &(G.scene->r.stereomode), 7.0, 5.0, 0, 0, "Enables anaglyph (Red-Blue) stereo method");
1823         uiDefButS(block, ROW, 0, "Side by Side", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 6.0, 0, 0, "Enables side by side left and right images");
1824         uiDefButS(block, ROW, 0, "V Interlace", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 7.0, 0, 0, "Enables interlaced vertical strips for autostereo display");
1825         
1826         uiBlockEndAlign(block);
1827
1828         uiBlockSetDirection(block, UI_TOP);
1829
1830         return block;
1831 }
1832
1833 #ifdef WITH_FFMPEG
1834
1835 static char* ffmpeg_format_pup(void) 
1836 {
1837         static char string[2048];
1838         char formatstring[2048];
1839 #if 0
1840        int i = 0;
1841        int stroffs = 0;
1842        AVOutputFormat* next = first_oformat;
1843        formatstring = "FFMpeg format: %%t";
1844       sprintf(string, formatstring);
1845        formatstring = "|%s %%x%d";
1846        /* FIXME: This should only be generated once */
1847        while (next != NULL) {
1848                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
1849                        sprintf(string+stroffs, formatstring, next->name, i++);
1850                        stroffs += strlen(string+stroffs);
1851                }
1852                next = next->next;
1853        }
1854        return string;
1855 #endif
1856        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d"
1857 #if 0
1858 /* ifdef WITH_OGG, disabled, since broken within ffmpeg bundled with blender */
1859               "|%s %%x%d"
1860 #endif
1861               "|%s %%x%d");
1862        sprintf(string, formatstring,
1863                "MPEG-1", FFMPEG_MPEG1,
1864                "MPEG-2", FFMPEG_MPEG2,
1865                "MPEG-4", FFMPEG_MPEG4,
1866                "AVI",    FFMPEG_AVI,
1867                "Quicktime", FFMPEG_MOV,
1868                "DV", FFMPEG_DV,
1869                "H264", FFMPEG_H264,
1870                "XVid", FFMPEG_XVID,
1871 #if 0 
1872 /* ifdef WITH_OGG, disabled, since broken within ffmpeg bundled with blender */
1873                "OGG", FFMPEG_OGG,
1874 #endif
1875                "FLV", FFMPEG_FLV);
1876        return string;
1877 }
1878
1879 static char* ffmpeg_preset_pup(void) 
1880 {
1881         static char string[2048];
1882         char formatstring[2048];
1883
1884        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1885        sprintf(string, formatstring,
1886                "", FFMPEG_PRESET_NONE,
1887                "DVD", FFMPEG_PRESET_DVD,
1888                "SVCD", FFMPEG_PRESET_SVCD,
1889                "VCD", FFMPEG_PRESET_VCD,
1890                "DV", FFMPEG_PRESET_DV,
1891                "H264", FFMPEG_PRESET_H264);
1892        return string;
1893 }
1894
1895
1896 static char* ffmpeg_codec_pup(void) {
1897        static char string[2048];
1898        char formatstring[2048];
1899        strcpy(formatstring, 
1900               "FFMpeg format: %%t"
1901               "|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d"
1902 #ifdef WITH_OGG
1903               "|%s %%x%d"
1904 #endif
1905               "|%s %%x%d");
1906        sprintf(string, formatstring,
1907                "MPEG1", CODEC_ID_MPEG1VIDEO,
1908                "MPEG2", CODEC_ID_MPEG2VIDEO,
1909                "MPEG4(divx)", CODEC_ID_MPEG4,
1910                "HuffYUV", CODEC_ID_HUFFYUV,
1911                "DV", CODEC_ID_DVVIDEO,
1912                "H264", CODEC_ID_H264,
1913                "XVid", CODEC_ID_XVID,
1914 #ifdef WITH_OGG
1915                "Theora", CODEC_ID_THEORA,
1916 #endif
1917                "FlashVideo1", CODEC_ID_FLV1);
1918        return string;
1919
1920 }
1921
1922 static char* ffmpeg_audio_codec_pup(void) {
1923        static char string[2048];
1924        char formatstring[2048];
1925        strcpy(formatstring, 
1926               "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d"
1927 #ifdef WITH_OGG
1928               "|%s %%x%d"
1929 #endif
1930               "|%s %%x%d");
1931        sprintf(string, formatstring,
1932                "MP2", CODEC_ID_MP2,
1933                "MP3", CODEC_ID_MP3,
1934                "AC3", CODEC_ID_AC3,
1935                "AAC", CODEC_ID_AAC,
1936 #ifdef WITH_OGG
1937                "Vorbis", CODEC_ID_VORBIS,
1938 #endif
1939                "PCM", CODEC_ID_PCM_S16LE);
1940        return string;
1941
1942 }
1943
1944 #endif
1945
1946 static char *imagetype_pup(void)
1947 {
1948         static char string[1024];
1949         char formatstring[1024];
1950         char appendstring[1024];
1951
1952         strcpy(formatstring, "Save image as: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1953 #ifdef __sgi
1954         strcat(formatstring, "|%s %%x%d");      // add space for Movie
1955 #endif
1956
1957         strcat(formatstring, "|%s %%x%d");      // add space for PNG
1958 /*  Commented out until implemented
1959 #ifdef WITH_DDS
1960         strcat(formatstring, "|%s %%x%d");      // add space for DDS
1961 #endif
1962 */
1963 #ifdef WITH_OPENJPEG
1964         strcat(formatstring, "|%s %%x%d");      // add space for JP2
1965 #endif
1966         
1967         strcat(formatstring, "|%s %%x%d");      // add space for BMP
1968         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
1969         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
1970         strcat(formatstring, "|%s %%x%d");      // add space for DPX
1971         
1972 #ifdef _WIN32
1973         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
1974 #endif
1975
1976 #ifdef WITH_FFMPEG
1977        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
1978 #endif
1979        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
1980
1981 #ifdef WITH_QUICKTIME
1982         if(G.have_quicktime)
1983                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
1984 #endif
1985
1986         if(G.have_quicktime) {
1987                 sprintf(string, formatstring,
1988                         "Frameserver",   R_FRAMESERVER,
1989 #ifdef WITH_FFMPEG
1990                        "FFMpeg",         R_FFMPEG,
1991 #endif
1992                         "AVI Raw",        R_AVIRAW,
1993                         "AVI Jpeg",       R_AVIJPEG,
1994 #ifdef _WIN32
1995                         "AVI Codec",      R_AVICODEC,
1996 #endif
1997 #ifdef WITH_QUICKTIME
1998                         "QuickTime",      R_QUICKTIME,
1999 #endif
2000                         "Targa",          R_TARGA,
2001                         "Targa Raw",      R_RAWTGA,
2002                         "PNG",            R_PNG,
2003 /* commented out until implemented 
2004 #ifdef WITH_DDS
2005                         "DDS",            R_DDS,
2006 #endif
2007 */
2008 #ifdef WITH_OPENJPEG
2009                         "Jpeg 2000",   R_JP2,
2010 #endif
2011                         "BMP",            R_BMP,
2012                         "Jpeg",           R_JPEG90,
2013                         "HamX",           R_HAMX,
2014                         "Iris",           R_IRIS,
2015                         "Radiance HDR",   R_RADHDR,
2016                         "Cineon",                 R_CINEON,
2017                         "DPX",                    R_DPX
2018
2019 #ifdef __sgi
2020                         ,"Movie",          R_MOVIE
2021 #endif
2022                 );
2023         } else {
2024                 sprintf(string, formatstring,
2025                         "Frameserver",   R_FRAMESERVER,
2026 #ifdef WITH_FFMPEG
2027                        "FFMpeg",         R_FFMPEG,
2028 #endif
2029                         "AVI Raw",        R_AVIRAW,
2030                         "AVI Jpeg",       R_AVIJPEG,
2031 #ifdef _WIN32
2032                         "AVI Codec",      R_AVICODEC,
2033 #endif
2034                         "Targa",          R_TARGA,
2035                         "Targa Raw",      R_RAWTGA,
2036                         "PNG",            R_PNG,
2037 /*#ifdef WITH_DDS
2038                         "DDS",            R_DDS,
2039 #endif*/
2040 #ifdef WITH_OPENJPEG
2041                         "Jpeg 2000",   R_JP2,
2042 #endif
2043                         "BMP",            R_BMP,
2044                         "Jpeg",           R_JPEG90,
2045                         "HamX",           R_HAMX,
2046                         "Iris",           R_IRIS,
2047                         "Radiance HDR",   R_RADHDR,
2048                         "Cineon",                 R_CINEON,
2049                         "DPX",                    R_DPX
2050
2051
2052 #ifdef __sgi
2053                         ,"Movie",          R_MOVIE
2054 #endif
2055                 );
2056         }
2057
2058 #ifdef WITH_OPENEXR
2059         strcpy(formatstring, "|%s %%x%d");
2060         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
2061         strcat(string, appendstring);
2062         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
2063         strcat(string, appendstring);
2064 #endif
2065         
2066         if (G.have_libtiff) {
2067                 strcpy(formatstring, "|%s %%x%d");
2068                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
2069                 strcat(string, appendstring);
2070         }
2071
2072         return (string);
2073 }
2074
2075 #ifdef _WIN32
2076 static char *avicodec_str(void)
2077 {
2078         static char string[1024];
2079
2080         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
2081
2082         return string;
2083 }
2084 #endif
2085
2086 static void render_panel_output(void)
2087 {
2088         ID *id;
2089         int a,b;
2090         uiBlock *block;
2091         char *strp;
2092
2093         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
2094         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
2095         
2096         uiBlockBeginAlign(block);
2097         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for saving animations");
2098         uiDefBut(block, TEX,0,"",                                                       31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save animations, # characters defines the position and length of frame numbers");
2099         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for a Backbuf image");
2100         uiDefBut(block, TEX,0,"",                                                       31, 168, 259, 20,G.scene->r.backbuf, 0.0,79.0, 0, 0, "Image to use as background for rendering");
2101         uiDefIconButBitS(block, ICONTOG, R_BACKBUF, B_NOP, ICON_CHECKBOX_HLT-1, 290, 168, 20, 20, &G.scene->r.bufflag, 0.0, 0.0, 0, 0, "Enable/Disable use of Backbuf image");
2102         uiBlockEndAlign(block);
2103         
2104         uiDefButBitI(block, TOG, R_EXTENSION, B_NOP, "Extensions", 10, 142, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Adds filetype extensions to the filename when rendering animations");
2105         
2106         uiBlockBeginAlign(block);
2107         uiDefButBitI(block, TOG, R_TOUCH, B_NOP, "Touch",       170, 142, 50, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Create an empty file before rendering each frame, remove if cancelled (and empty)");
2108         uiDefButBitI(block, TOG, R_NO_OVERWRITE, B_NOP, "No Overwrite", 220, 142, 90, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Skip rendering frames when the file exists (image output only)");
2109         uiBlockEndAlign(block);
2110         
2111         /* SET BUTTON */
2112         uiBlockBeginAlign(block);
2113         id= (ID *)G.scene->set;
2114         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
2115         if(strp[0])
2116                 uiDefButS(block, MENU, B_SETBROWSE, strp,                       10, 114, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
2117         MEM_freeN(strp);
2118
2119         if(G.scene->set) {
2120                 uiSetButLock(1, NULL);
2121                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 114, 100, 20, &(G.scene->set), "Name of the Set");
2122                 uiClearButLock();
2123                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 114, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
2124         } else {
2125                 uiDefBut(block, LABEL, 0, "No Set Scene", 31, 114, 200, 20, 0, 0, 0, 0, 0, "");
2126         }
2127         uiBlockEndAlign(block);
2128
2129         uiBlockBeginAlign(block);
2130         uiDefIconButBitI(block, TOGN, R_FIXED_THREADS, B_REDR, ICON_AUTO,       10, 63, 20, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Automatically set the threads to the number of processors on the system");
2131         if ((G.scene->r.mode & R_FIXED_THREADS)==0) {
2132                 char thread_str[16];
2133                 sprintf(thread_str, " Threads: %d", BLI_system_thread_count());
2134                 uiDefBut(block, LABEL, 0, thread_str, 30, 63,80,20, 0, 0, 0, 0, 0, "");
2135         } else {
2136                 uiDefButS(block, NUM, B_NOP, "Threads:", 30, 63, 80, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render (takes advantage of multi-core and multi-processor computers)");
2137         }
2138         uiBlockEndAlign(block);
2139         
2140         uiBlockSetCol(block, TH_AUTO);
2141                 
2142         uiBlockBeginAlign(block);
2143         for(b=2; b>=0; b--)
2144                 for(a=0; a<3; a++)
2145                         uiDefButBitS(block, TOG, 1<<(3*b+a), 800,"",    (short)(10+18*a),(short)(10+14*b),16,12, &G.winpos, 0, 0, 0, 0, "Render window placement on screen");
2146         uiBlockEndAlign(block);
2147
2148 #ifdef WITH_OPENEXR
2149         uiBlockBeginAlign(block);
2150         uiDefButBitI(block, TOG, R_EXR_TILE_FILE, B_REDR, "Save Buffers", 72, 31, 120, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Save tiles for all RenderLayers and used SceneNodes to files in the temp directory (saves memory, allows Full Sampling)");
2151         if(G.scene->r.scemode & R_EXR_TILE_FILE)
2152                 uiDefButBitI(block, TOG, R_FULL_SAMPLE, B_REDR, "FullSample",    192, 31, 118, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Saves for every OSA sample the entire RenderLayer results (Higher quality sampling but slower)");
2153         uiBlockEndAlign(block);
2154 #endif
2155         
2156         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
2157                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
2158         
2159         /* Dither control */
2160         uiDefButF(block, NUM,B_DIFF, "Dither:",         10,89,100,19, &G.scene->r.dither_intensity, 0.0, 2.0, 0, 0, "The amount of dithering noise present in the output image (0.0 = no dithering)");
2161         
2162         /* Toon shading buttons */
2163         uiBlockBeginAlign(block);
2164         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   115, 89, 60, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
2165         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 175, 89, 135, 20, "Display Edge settings");
2166         uiBlockEndAlign(block);
2167         
2168         uiBlockBeginAlign(block);
2169         uiDefButBitI(block, TOG, R_NO_TEX, B_NOP, "Disable Tex", 115, 63, 75, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Disables Textures for render");
2170         uiDefButBitI(block, TOG, R_FREE_IMAGE, B_NOP, "Free Tex Images", 210, 63, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Frees all Images used by Textures after each render");
2171         uiBlockEndAlign(block);
2172 }
2173
2174 static void do_bake_func(void *unused_v, void *unused_p)
2175 {
2176         objects_bake_render_ui(0);
2177 }
2178
2179 static void render_panel_bake(void)
2180 {
2181         uiBlock *block;
2182         uiBut *but;
2183         
2184         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
2185         uiNewPanelTabbed("Anim", "Render");
2186         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
2187         
2188         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
2189         uiButSetFunc(but, do_bake_func, NULL, NULL);
2190
2191         uiBlockBeginAlign(block);
2192         uiDefButBitS(block, TOG, R_BAKE_TO_ACTIVE, B_DIFF, "Selected to Active", 10,120,190,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Bake shading on the surface of selected objects to the active object");
2193         uiDefButF(block, NUM, B_DIFF, "Dist:", 10,100,95,20,&G.scene->r.bake_maxdist, 0.0, 1000.0, 1, 0, "Maximum distance from active object to other object (in blender units)");
2194         uiDefButF(block, NUM, B_DIFF, "Bias:", 105,100,95,20,&G.scene->r.bake_biasdist, 0.0, 1000.0, 1, 0, "Bias towards faces further away from the object (in blender units)");
2195         uiBlockEndAlign(block);
2196
2197         if(G.scene->r.bake_mode == RE_BAKE_NORMALS)
2198                 uiDefButS(block, MENU, B_DIFF, "Normal Space %t|Camera %x0|World %x1|Object %x2|Tangent %x3", 
2199                         10,70,190,20, &G.scene->r.bake_normal_space, 0, 0, 0, 0, "Choose normal space for baking");
2200         else if(G.scene->r.bake_mode == RE_BAKE_AO || G.scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
2201                 uiDefButBitS(block, TOG, R_BAKE_NORMALIZE, B_DIFF, "Normalized", 10,70,190,20, &G.scene->r.bake_flag, 0.0, 0, 0, 0,
2202                                 G.scene->r.bake_mode == RE_BAKE_AO ?
2203                                  "Bake ambient occlusion normalized, without taking into acount material settings":
2204                                  "Normalized displacement value to fit the 'Dist' range"
2205                 );
2206         }
2207         
2208         uiDefButS(block, MENU, B_NOP, "Quad Split Order%t|Quad Split Auto%x0|Quad Split A (0,1,2) (0,2,3)%x1|Quad Split B (1,2,3) (1,3,0)%x2", 
2209                 10,10,190,20, &G.scene->r.bake_quad_split, 0, 0, 0, 0, "Method to divide quads (use A or B for external applications that use a fixed order)");
2210         
2211 #if 0   
2212         uiBlockBeginAlign(block);
2213         uiDefButBitS(block, TOG, R_BAKE_OSA, B_DIFF, "OSA",             10,120,190,20, &G.scene->r.bake_flag, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2214         uiDefButS(block, ROW,B_DIFF,"5",                        10,100,50,20,&G.scene->r.bake_osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
2215         uiDefButS(block, ROW,B_DIFF,"8",                        60,100,45,20,&G.scene->r.bake_osa,2.0,8.0, 0, 0, "Sets oversample level to 8");
2216         uiDefButS(block, ROW,B_DIFF,"11",                       105,100,45,20,&G.scene->r.bake_osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
2217         uiDefButS(block, ROW,B_DIFF,"16",                       150,100,50,20,&G.scene->r.bake_osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
2218 #endif  
2219         uiBlockBeginAlign(block);
2220         uiDefButS(block, ROW,B_REDR,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
2221         uiDefButS(block, ROW,B_REDR,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
2222         uiDefButS(block, ROW,B_REDR,"Shadow",                   210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_SHADOW, 0, 0, "");
2223         uiDefButS(block, ROW,B_REDR,"Normals",                  210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
2224         uiDefButS(block, ROW,B_REDR,"Textures",                 210,90,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
2225         uiDefButS(block, ROW,B_REDR,"Displacement",             210,70,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_DISPLACEMENT, 0, 0, "");
2226         uiBlockEndAlign(block);
2227         
2228         uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear",         210,40,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking");
2229         
2230         uiDefButS(block, NUM, B_DIFF,"Margin:",                         210,10,120,20,&G.scene->r.bake_filter, 0.0, 32.0, 0, 0, "Amount of pixels to extend the baked result with, as post process filter");
2231 }
2232
2233 static void render_panel_simplify(void)
2234 {
2235         uiBlock *block;
2236         
2237         block= uiNewBlock(&curarea->uiblocks, "render_panel_simplify", UI_EMBOSS, UI_HELV, curarea->win);
2238         uiNewPanelTabbed("Render", "Render");
2239         if(uiNewPanel(curarea, block, "Simplifcation", "Render", 320, 0, 318, 204)==0) return;
2240
2241         uiDefButBitI(block, TOG, R_SIMPLIFY, B_DIFF,"Render Simplification",    10,150,190,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable simplification of scene");
2242
2243         uiBlockBeginAlign(block);
2244         uiDefButI(block, NUM,B_DIFF, "Subsurf:",        10,120,190,20, &G.scene->r.simplify_subsurf, 0.0, 6.0, 0, 0, "Global maximum subsurf level percentage");
2245         uiDefButF(block, NUM,B_DIFF, "Child Particles:",        10,100,190,20, &G.scene->r.simplify_particles, 0.0, 1.0, 0, 0, "Global child particle percentage");
2246         uiBlockEndAlign(block);
2247
2248         uiBlockBeginAlign(block);
2249         uiDefButI(block, NUM,B_DIFF, "Shadow Samples:", 10,70,190,20, &G.scene->r.simplify_shadowsamples, 1.0, 16.0, 0, 0, "Global maximum shadow map samples");
2250         uiDefButF(block, NUM,B_DIFF, "AO and SSS:",     10,50,190,20, &G.scene->r.simplify_aosss, 0.0, 1.0, 0, 0, "Global approximate AO and SSS quality factor");
2251         uiBlockEndAlign(block);
2252 }
2253
2254 static void render_panel_render(void)
2255 {
2256         uiBlock *block;
2257         char str[256];
2258
2259         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
2260         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
2261
2262         uiBlockBeginAlign(block);
2263         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 164, 191,37, 0, 0, 0, 0, 0, "Render the current frame (F12)");
2264 #ifndef DISABLE_YAFRAY
2265         /* yafray: on request, render engine menu is back again, and moved to Render panel */
2266         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0|YafRay %x1", 
2267                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
2268 #else
2269         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0", 
2270                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
2271 #endif /* disable yafray */
2272
2273         uiBlockBeginAlign(block);
2274         if((G.scene->r.scemode & R_FULL_SAMPLE) && (G.scene->r.scemode & R_EXR_TILE_FILE))
2275                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "FSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Saves all samples, then composites, and then merges (for best Anti-aliasing)");
2276         else
2277                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2278         uiDefButS(block, ROW,B_DIFF,"5",                        369,88,29,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Render 5 samples per pixel for smooth edges (Fast)");
2279         uiDefButS(block, ROW,B_DIFF,"8",                        400,88,29,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Render 8 samples per pixel for smooth edges (Recommended)");
2280         uiDefButS(block, ROW,B_DIFF,"11",                       431,88,29,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Render 11 samples per pixel for smooth edges (High Quality)");
2281         uiDefButS(block, ROW,B_DIFF,"16",                       462,88,29,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Render 16 samples per pixel for smooth edges (Highest Quality)");
2282         uiBlockEndAlign(block);
2283
2284         uiBlockBeginAlign(block);
2285         uiDefButBitI(block, TOG, R_MBLUR, B_REDR, "MBLUR",      496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
2286         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
2287         uiBlockEndAlign(block);
2288
2289         uiBlockBeginAlign(block);
2290         uiDefButS(block, NUM,B_DIFF,"Xparts:",          369,46,95,29,&G.scene->r.xparts,1.0, 512.0, 0, 0, "Sets the number of horizontal parts to render image in (For panorama sets number of camera slices)");
2291         uiDefButS(block, NUM,B_DIFF,"Yparts:",          465,46,95,29,&G.scene->r.yparts,1.0, 64.0, 0, 0, "Sets the number of vertical parts to render image in");
2292         uiBlockEndAlign(block);
2293
2294         uiBlockBeginAlign(block);
2295         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
2296         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
2297         uiDefButS(block, ROW,800,"Key",         456,13,35,20,&G.scene->r.alphamode,3.0,2.0, 0, 0, "Alpha and color values remain unchanged");
2298         uiBlockEndAlign(block);
2299
2300         uiDefButS(block, MENU, B_DIFF,"Octree resolution %t|64 %x64|128 %x128|256 %x256|512 %x512",     496,13,64,20,&G.scene->r.ocres,0.0,0.0, 0, 0, "Octree resolution for ray tracing and baking, Use higher values for complex scenes");
2301
2302         uiBlockBeginAlign(block);
2303         uiDefButBitI(block, TOG, R_SHADOW, B_REDR,"Shadow",     565,172,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
2304         uiDefButBitI(block, TOG, R_SSS, B_REDR,"SSS",   617,172,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable subsurface scattering map rendering");
2305         uiDefButBitI(block, TOG, R_PANORAMA, B_REDR,"Pano",     649,172,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
2306         uiDefButBitI(block, TOG, R_ENVMAP, B_REDR,"EnvMap",     565,142,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
2307         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",617,142,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
2308         uiDefButBitI(block, TOG, R_RADIO, B_REDR,"Radio",       649,142,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
2309         uiBlockEndAlign(block);
2310         
2311         uiBlockBeginAlign(block);
2312         uiDefButS(block, ROW,B_DIFF,"100%",                     565,109,122,20,&G.scene->r.size,1.0,100.0, 0, 0, "Set render size to defined size");
2313         uiDefButS(block, ROW,B_DIFF,"75%",                      565,88,40,20,&G.scene->r.size,1.0,75.0, 0, 0, "Set render size to 3/4 of defined size");
2314         uiDefButS(block, ROW,B_DIFF,"50%",                      606,88,40,20,&G.scene->r.size,1.0,50.0, 0, 0, "Set render size to 1/2 of defined size");
2315         uiDefButS(block, ROW,B_DIFF,"25%",                      647,88,40,20,&G.scene->r.size,1.0,25.0, 0, 0, "Set render size to 1/4 of defined size");
2316         uiBlockEndAlign(block);
2317
2318         uiBlockBeginAlign(block);
2319         uiDefButBitI(block, TOG, R_FIELDS, B_REDR,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
2320         uiDefButBitI(block, TOG, R_ODDFIELD, B_REDR,"Odd",      627,55,39,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
2321         uiDefButBitI(block, TOG, R_FIELDSTILL, B_REDR,"X",              668,55,19,20,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
2322         
2323         sprintf(str, "Filter%%t|Box %%x%d|Tent %%x%d|Quad %%x%d|Cubic %%x%d|Gauss %%x%d|CatRom %%x%d|Mitch %%x%d", R_FILTER_BOX, R_FILTER_TENT, R_FILTER_QUAD, R_FILTER_CUBIC, R_FILTER_GAUSS, R_FILTER_CATROM, R_FILTER_MITCH);
2324         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
2325         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
2326         
2327         uiDefButBitI(block, TOG, R_BORDER, REDRAWVIEWCAM, "Border",     565,13,122,20, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image (Shift+B to set in the camera view)");
2328         uiBlockEndAlign(block);
2329
2330 }
2331
2332 static void render_panel_anim(void)
2333 {
2334         uiBlock *block;
2335
2336
2337         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2338         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
2339
2340
2341         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Render the animation to disk from start to end frame, (Ctrl+F12)");
2342
2343         uiBlockSetCol(block, TH_BUT_SETTING1);
2344         uiBlockBeginAlign(block);
2345         uiDefButBitI(block, TOG, R_DOSEQ, B_NOP, "Do Sequence",692,114,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Enables sequence output rendering (Default: 3D rendering)");
2346         uiDefButBitI(block, TOG, R_DOCOMP, B_NOP, "Do Composite",692,90,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Uses compositing nodes for output rendering");
2347         uiBlockEndAlign(block);
2348
2349         uiBlockSetCol(block, TH_AUTO);
2350         uiDefBut(block, BUT,B_PLAYANIM, "PLAY",692,50,94,33, 0, 0, 0, 0, 0, "Play rendered images/avi animation (Ctrl+F11), (Play Hotkeys: A-Noskip, P-PingPong)");
2351         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,50,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
2352
2353         uiBlockBeginAlign(block);
2354         uiDefButI(block, NUM,REDRAWSEQ,"Sta:",692,20,94,24, &G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "The start frame of the animation (inclusive)");
2355         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,20,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation  (inclusive)");
2356         uiDefButI(block, NUM,REDRAWSEQ,"Step:",692,0,192,18, &G.scene->frame_step, 1.0, MAXFRAMEF, 0, 0, "Frame Step");
2357         uiBlockEndAlign(block);
2358 }
2359
2360 #ifdef WITH_FFMPEG
2361
2362 static void ffmpeg_property_del(void *type, void *prop_)
2363 {
2364         struct IDProperty *prop = (struct IDProperty *) prop_;
2365         IDProperty * group;
2366         
2367         if (!G.scene->r.ffcodecdata.properties) {
2368                 return;
2369         }
2370
2371         group = IDP_GetPropertyFromGroup(
2372                 G.scene->r.ffcodecdata.properties, (char*) type);
2373         if (group && prop) {
2374                 IDP_RemFromGroup(group, prop);
2375                 IDP_FreeProperty(prop);
2376                 MEM_freeN(prop);
2377         }
2378         allqueue(REDRAWBUTSSCENE, 0);
2379 }
2380
2381 static IDProperty * ffmpeg_property_add(
2382         char * type, int opt_index, int parent_index)
2383 {
2384         AVCodecContext c;
2385         const AVOption * o;
2386         const AVOption * parent;
2387         IDProperty * group;
2388         IDProperty * prop;
2389         IDPropertyTemplate val;
2390         int idp_type;
2391         char name[256];
2392
2393         avcodec_get_context_defaults(&c);
2394
2395         o = c.av_class->option + opt_index;
2396         parent = c.av_class->option + parent_index;
2397
2398         if (!G.scene->r.ffcodecdata.properties) {
2399                 IDPropertyTemplate val;
2400
2401                 G.scene->r.ffcodecdata.properties 
2402                         = IDP_New(IDP_GROUP, val, "ffmpeg"); 
2403         }
2404
2405         group = IDP_GetPropertyFromGroup(
2406                 G.scene->r.ffcodecdata.properties, (char*) type);
2407         
2408         if (!group) {
2409                 IDPropertyTemplate val;
2410                 
2411                 group = IDP_New(IDP_GROUP, val, (char*) type); 
2412                 IDP_AddToGroup(G.scene->r.ffcodecdata.properties, group);
2413         }
2414
2415         if (parent_index) {
2416                 sprintf(name, "%s:%s", parent->name, o->name);
2417         } else {
2418                 strcpy(name, o->name);
2419         }
2420
2421         fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n",
2422                 type, parent_index, opt_index, name);
2423
2424         prop = IDP_GetPropertyFromGroup(group, name);
2425         if (prop) {
2426                 return prop;
2427         }
2428
2429         switch (o->type) {
2430         case FF_OPT_TYPE_INT:
2431         case FF_OPT_TYPE_INT64:
2432                 val.i = o->default_val;
2433                 idp_type = IDP_INT;
2434                 break;
2435         case FF_OPT_TYPE_DOUBLE:
2436         case FF_OPT_TYPE_FLOAT:
2437                 val.f = o->default_val;
2438                 idp_type = IDP_FLOAT;
2439                 break;
2440         case FF_OPT_TYPE_STRING:
2441                 val.str = "                                                                               ";
2442                 idp_type = IDP_STRING;
2443                 break;
2444         case FF_OPT_TYPE_CONST:
2445                 val.i = 1;
2446                 idp_type = IDP_INT;
2447                 break;
2448         default:
2449                 return NULL;
2450         }
2451         prop = IDP_New(idp_type, val, name);
2452         IDP_AddToGroup(group, prop);
2453         return prop;
2454 }
2455
2456 /* not all versions of ffmpeg include that, so here we go ... */
2457
2458 static const AVOption *my_av_find_opt(void *v, const char *name, 
2459                                       const char *unit, int mask, int flags){
2460         AVClass *c= *(AVClass**)v; 
2461         const AVOption *o= c->option;
2462
2463         for(;o && o->name; o++){
2464                 if(!strcmp(o->name, name) && 
2465                    (!unit || (o->unit && !strcmp(o->unit, unit))) && 
2466                    (o->flags & mask) == flags )
2467                         return o;
2468         }
2469         return NULL;
2470 }
2471
2472 static int ffmpeg_property_add_string(const char * type, const char * str)
2473 {
2474         AVCodecContext c;
2475         const AVOption * o = 0;
2476         const AVOption * p = 0;
2477         char name_[128];
2478         char * name;
2479         char * param;
2480         IDProperty * prop;
2481         
2482         avcodec_get_context_defaults(&c);
2483
2484         strncpy(name_, str, 128);
2485
2486         name = name_;
2487         while (*name == ' ') name++;
2488
2489         param = strchr(name, ':');
2490
2491         if (!param) {
2492                 param = strchr(name, ' ');
2493         }
2494         if (param) {
2495                 *param++ = 0;
2496                 while (*param == ' ') param++;
2497         }
2498         
2499         o = my_av_find_opt(&c, name, NULL, 0, 0);       
2500         if (!o) {
2501                 return FALSE;
2502         }
2503         if (param && o->type == FF_OPT_TYPE_CONST) {
2504                 return FALSE;
2505         }
2506         if (param && o->type != FF_OPT_TYPE_CONST && o->unit) {
2507                 p = my_av_find_opt(&c, param, o->unit, 0, 0);   
2508                 prop = ffmpeg_property_add(
2509                         (char*) type, p - c.av_class->option, 
2510                         o - c.av_class->option);
2511         } else {
2512                 prop = ffmpeg_property_add(
2513                         (char*) type, o - c.av_class->option, 0);
2514         }
2515                 
2516
2517         if (!prop) {
2518                 return FALSE;
2519         }
2520
2521         if (param && !p) {
2522                 switch (prop->type) {
2523                 case IDP_INT:
2524                         IDP_Int(prop) = atoi(param);
2525                         break;
2526                 case IDP_FLOAT:
2527                         IDP_Float(prop) = atof(param);
2528                         break;
2529                 case IDP_STRING:
2530                         strncpy(IDP_String(prop), param, prop->len);
2531                         break;
2532                 }
2533         }
2534         return TRUE;
2535 }
2536
2537 static void ffmpeg_property_add_using_menu(void * type, int opt_indices)
2538 {
2539         int opt_index = opt_indices & 65535;
2540         int parent_index = opt_indices >> 16;
2541
2542         ffmpeg_property_add((char*) type, opt_index, parent_index);
2543
2544         allqueue(REDRAWBUTSSCENE, 0);
2545 }
2546
2547 static uiBlock *ffmpeg_property_add_submenu(AVOption * parent, char * type) 
2548 {
2549         AVCodecContext c;
2550         const AVOption * o;
2551         uiBlock *block;
2552         int yco = 0;
2553         int flags = 0;
2554         int parent_index = 0;
2555
2556         if (strcmp(type, "audio") == 0) {
2557                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM;
2558         } else if (strcmp(type, "video") == 0) {
2559                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM;
2560         } else {
2561                 return NULL;
2562         }
2563
2564         block= uiNewBlock(&curarea->uiblocks, "ffmpeg_property_add_submenu",
2565                           UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2566         uiBlockSetButmFunc(block, ffmpeg_property_add_using_menu, type);
2567
2568         avcodec_get_context_defaults(&c);
2569
2570         if (parent) {
2571                 parent_index = (parent - c.av_class->option);
2572         }
2573         
2574         for(o = c.av_class->option; o && o->name; o++){
2575                 if (o->help && 
2576                     (strstr(o->help, "experimental")
2577                      || strstr(o->help, "obsolete")
2578                      || strstr(o->help, "useless")
2579                      || strstr(o->help, "deprecated"))) {
2580                         continue;
2581                 }
2582                 if((o->flags & flags) == flags) {
2583                         if((!parent && !o->unit) 
2584                            || (o->unit && parent 
2585                                && strcmp(o->unit, parent->unit) == 0 
2586                                && o->type == FF_OPT_TYPE_CONST)) {
2587                                 uiDefBut(block, BUTM, B_REDR, 
2588                                          (char*) (o->help && o->help[0] ? 
2589                                                   o->help : o->name),
2590                                          0, yco, 160, 15, 
2591                                          NULL, 0, 0, 1, 
2592                                          (o - c.av_class->option) | 
2593                                          (parent_index << 16),
2594                                          "");
2595                                 yco -= 16;
2596                         }
2597                 }
2598         }
2599         
2600         uiTextBoundsBlock(block, 50);
2601         uiBlockSetDirection(block, UI_RIGHT);
2602
2603         return block;
2604 }
2605
2606 static uiBlock *ffmpeg_property_add_submenu_audio(void* opt)
2607 {
2608         return ffmpeg_property_add_submenu((AVOption*) opt, "audio");
2609 }
2610
2611 static uiBlock *ffmpeg_property_add_submenu_video(void* opt)
2612 {
2613         return ffmpeg_property_add_submenu((AVOption*) opt, "video");
2614 }
2615
2616 static uiBlock *ffmpeg_property_add_menu(void* type_) 
2617 {
2618         char * type = (char*) type_;
2619         AVCodecContext c;
2620         const AVOption * o;
2621         uiBlock *block;
2622         int yco = 0;
2623         int flags = 0;
2624         uiBlockFuncFP add_submenu = NULL;
2625
2626         if (strcmp(type, "audio") == 0) {
2627                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM;
2628                 add_submenu = ffmpeg_property_add_submenu_audio;
2629         } else if (strcmp(type, "video") == 0) {
2630                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM;
2631                 add_submenu = ffmpeg_property_add_submenu_video;
2632         } else {
2633                 return NULL;
2634         }
2635
2636         block= uiNewBlock(&curarea->uiblocks, "ffmpeg_property_add_menu",
2637                           UI_EMBOSSP, UI_HELV, curarea->win);
2638
2639         avcodec_get_context_defaults(&c);
2640         
2641         for(o = c.av_class->option; o && o->name; o++){
2642                 if((o->flags & flags) == flags) {
2643                         if (o->type == FF_OPT_TYPE_CONST) {
2644                                 continue;
2645                         }
2646                         if (o->help && 
2647                             (strstr(o->help, "experimental")
2648                              || strstr(o->help, "obsolete")
2649                              || strstr(o->help, "useless")
2650                              || strstr(o->help, "deprecated"))) {
2651                                 continue;
2652                         }
2653
2654                         if (o->unit) {
2655         
2656                                 uiDefIconTextBlockBut(
2657                                         block, 
2658                                         add_submenu, 
2659                                         (void*) o, 
2660                                         ICON_RIGHTARROW_THIN,
2661                                         (char*) (o->help ? 
2662                                                  o->help : o->name), 
2663                                         0, yco, 160, 15, "");
2664                                 yco -= 16;
2665                         } 
2666                 }
2667         }
2668
2669         uiDefIconTextBlockBut(
2670                 block, 
2671                 add_submenu, 
2672                 NULL, 
2673                 ICON_RIGHTARROW_THIN,
2674                 "Value / string options", 
2675                 0, yco, 160, 15, "");
2676         
2677         uiTextBoundsBlock(block, 50);
2678         uiBlockSetDirection(block, UI_DOWN);
2679
2680         return block;
2681 }
2682
2683 static int render_panel_ffmpeg_property_option(
2684         uiBlock *block, int xofs, int yofs, IDProperty * curr,
2685         const char * type)
2686 {
2687         AVCodecContext c;
2688         const AVOption * o;
2689         uiBut *but;
2690         char name[128];
2691         char * param;
2692
2693         strcpy(name, curr->name);
2694         param = strchr(name, ':');
2695
2696         if (param) {
2697                 *param++ = 0;
2698         }
2699
2700         avcodec_get_context_defaults(&c);
2701
2702         o = my_av_find_opt(&c, param ? param : name, NULL, 0, 0);
2703         if (!o) {
2704                 return yofs;
2705         }
2706
2707         switch (curr->type) {
2708         case IDP_STRING:
2709                 uiDefBut(block, TEX, 
2710                          B_REDR, curr->name, 
2711                          xofs,yofs, 200,19, 
2712                          IDP_String(curr), 
2713                          0.0, curr->len - 1, 100, 0, 
2714                          (char*) o->help);
2715                 break;
2716         case IDP_FLOAT:
2717                 uiDefButF(block, NUM, B_REDR, curr->name, 
2718                           xofs, yofs, 200, 19, 
2719                           &IDP_Float(curr), 
2720                           o->min, o->max, 0, 0, (char*) o->help);
2721                 break;
2722         case IDP_INT:
2723                 if (o->type == FF_OPT_TYPE_CONST) {
2724                         uiDefButBitI(block, TOG, 1, B_REDR,
2725                                      curr->name,
2726                                      xofs, yofs, 200, 19, 
2727                                      &IDP_Int(curr), 
2728                                      0, 1, 0,0, (char*) o->help);
2729                 } else {
2730                         uiDefButI(block, NUM, B_REDR, curr->name, 
2731                                   xofs, yofs, 200, 19, 
2732                                   &IDP_Int(curr), 
2733                                   o->min, o->max, 0, 0, (char*) o->help);
2734                 }
2735                 break;
2736         }
2737
2738         but = uiDefIconBut(block, BUT, B_REDR, VICON_X, 
2739                            xofs + 220, yofs, 16, 16, NULL, 
2740                            0.0, 0.0, 0.0, 0.0, "Delete property");
2741
2742         uiButSetFunc(but, ffmpeg_property_del, (void*) type, curr);
2743
2744         yofs -= 25;
2745
2746         return yofs;
2747 }
2748
2749 static int render_panel_ffmpeg_properties(uiBlock *block, const char * type,
2750                                           int xofs, int yofs)
2751 {
2752         short event = B_NOP;
2753
2754         yofs -= 5;
2755         
2756         if (strcmp(type, "audio") == 0) {
2757                 event = B_ADD_FFMPEG_AUDIO_OPTION;
2758         } else if (strcmp(type, "video") == 0) {
2759                 event = B_ADD_FFMPEG_VIDEO_OPTION;
2760         }
2761                 
2762         uiDefBut(block, TEX, event, "", xofs, yofs, 
2763                  170, 19, ffmpeg_option_to_add, 0.0, 255.0, 100, 0, 
2764                  "FFMPEG option to add");
2765
2766         uiDefBut(block, BUT, event, "Add", xofs+170,yofs,
2767                  30, 19, 0, 0, 0, 0, 0, 
2768                  "Add FFMPEG option");
2769
2770         uiDefBlockBut(block, ffmpeg_property_add_menu, (void*) type, 
2771                       "Menu", xofs + 200, yofs, 40, 20, 
2772                       "Add FFMPEG option using menu");
2773         yofs -= 20;
2774
2775         if (G.scene->r.ffcodecdata.properties) {
2776                 IDProperty * prop;
2777                 void * iter;
2778                 IDProperty * curr;
2779
2780                 prop = IDP_GetPropertyFromGroup(
2781                         G.scene->r.ffcodecdata.properties, (char*) type);
2782                 if (prop) {
2783                         iter = IDP_GetGroupIterator(prop);
2784
2785                         while ((curr = IDP_GroupIterNext(iter)) != NULL) {
2786                                 yofs = render_panel_ffmpeg_property_option(
2787                                         block, xofs, yofs, curr, type);
2788                         }
2789                 }
2790         }
2791
2792         uiNewPanelHeight(block, 204-yofs);
2793
2794         return yofs;
2795 }
2796
2797 static void set_ffmpeg_preset(int preset)
2798 {
2799         int isntsc = (G.scene->r.frs_sec != 25);
2800         switch (preset) {
2801         case FFMPEG_PRESET_VCD:
2802                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
2803                 G.scene->r.ffcodecdata.video_bitrate = 1150;
2804                 G.scene->r.xsch = 352;
2805                 G.scene->r.ysch = isntsc ? 240 : 288;
2806                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2807                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
2808                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
2809                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
2810                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2811                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
2812                 break;
2813         case FFMPEG_PRESET_SVCD:
2814                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2815                 G.scene->r.ffcodecdata.video_bitrate = 2040;
2816                 G.scene->r.xsch = 480;
2817                 G.scene->r.ysch = isntsc ? 480 : 576;
2818                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2819                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
2820                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2821                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2822                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2823                 G.scene->r.ffcodecdata.mux_rate = 0;
2824                 
2825                 break;
2826         case FFMPEG_PRESET_DVD:
2827                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2828                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2829                 G.scene->r.xsch = 720;
2830                 G.scene->r.ysch = isntsc ? 480 : 576;
2831                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2832                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2833                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2834                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2835                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2836                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2837                 
2838                 break;
2839         case FFMPEG_PRESET_DV:
2840                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
2841                 G.scene->r.xsch = 720;
2842                 G.scene->r.ysch = isntsc ? 480 : 576;
2843                 break;
2844         case FFMPEG_PRESET_H264:
2845                 G.scene->r.ffcodecdata.type = FFMPEG_AVI;
2846                 G.scene->r.ffcodecdata.codec = CODEC_ID_H264;
2847                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2848                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2849                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2850                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2851                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2852                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2853                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2854
2855                 ffmpeg_property_add_string("video", "coder:vlc");
2856                 ffmpeg_property_add_string("video", "flags:loop");
2857                 ffmpeg_property_add_string("video", "cmp:chroma");
2858                 ffmpeg_property_add_string("video", "partitions:parti4x4");
2859                 ffmpeg_property_add_string("video", "partitions:partp8x8");
2860                 ffmpeg_property_add_string("video", "partitions:partb8x8");
2861                 ffmpeg_property_add_string("video", "me:hex");
2862                 ffmpeg_property_add_string("video", "subq:5");
2863                 ffmpeg_property_add_string("video", "me_range:16");
2864                 ffmpeg_property_add_string("video", "keyint_min:25");
2865                 ffmpeg_property_add_string("video", "sc_threshold:40");
2866                 ffmpeg_property_add_string("video", "i_qfactor:0.71");
2867                 ffmpeg_property_add_string("video", "b_strategy:1");
2868
2869                 break;
2870         }
2871 }
2872
2873 static void render_panel_ffmpeg_video(void)
2874 {
2875         uiBlock *block;
2876         int yofs;
2877         int xcol1;
2878         int xcol2;
2879         
2880         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
2881                                            UI_EMBOSS, UI_HELV, curarea->win);
2882         
2883         uiNewPanelTabbed("Format", "Render");
2884         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
2885                 return;
2886         
2887         if (ffmpeg_preset_sel != 0) {
2888                 set_ffmpeg_preset(ffmpeg_preset_sel);
2889                 ffmpeg_preset_sel = 0;
2890                 allqueue(REDRAWBUTSSCENE, 0);
2891         }
2892         
2893         xcol1 = 872;
2894         xcol2 = 1002;
2895         
2896         yofs = 54;
2897         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
2898                          110, 20, 0, 0, 0, 0, 0, "");
2899         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
2900                          110, 20, 0, 0, 0, 0, 0, "");
2901         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
2902                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
2903                           0,0,0,0, "output file format");
2904         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2905                           xcol1, yofs+44, 110, 20, 
2906                           &G.scene->r.ffcodecdata.video_bitrate, 
2907                           1, 14000, 0, 0, "Video bitrate(kb/s)");
2908         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
2909                   xcol1, yofs+22, 110, 20, 
2910                   &G.scene->r.ffcodecdata.rc_min_rate, 
2911                   0, G.scene->r.ffcodecdata.rc_max_rate, 
2912                   0, 0, "Rate control: min rate(kb/s)");
2913         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
2914                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
2915                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
2916         
2917         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
2918                           xcol1, yofs-22, 110, 20, 
2919                           &G.scene->r.ffcodecdata.mux_rate, 
2920                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
2921         
2922         
2923         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
2924                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
2925                           0,0,0,0, "Output file format preset selection");
2926         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
2927                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
2928                           0, 100, 0, 0, "Distance between key frames");
2929         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
2930                           xcol2, yofs+22, 110, 20,
2931                           &G.scene->r.ffcodecdata.rc_buffer_size, 
2932                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
2933         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
2934                           xcol2, yofs, 110, 20, 
2935                           &G.scene->r.ffcodecdata.mux_packet_size, 
2936                           0, 16384, 0, 0, "Mux packet size (byte)");
2937         
2938         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
2939                                  "Autosplit Output", 
2940                                  xcol2, yofs-22, 110, 20, 
2941                                  &G.scene->r.ffcodecdata.flags, 
2942                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
2943         
2944         
2945         if (ELEM4(G.scene->r.ffcodecdata.type, FFMPEG_AVI, 
2946                   FFMPEG_MOV, FFMPEG_MKV, FFMPEG_OGG)) {
2947                 uiDefBut(block, LABEL, 0, "Codec", 
2948                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
2949                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
2950                                   xcol1, yofs-66, 110, 20, 
2951                                   &G.scene->r.ffcodecdata.codec, 
2952                                   0,0,0,0, "FFMpeg codec to use");
2953         }
2954
2955         render_panel_ffmpeg_properties(block, "video", xcol1, yofs-86);
2956 }
2957
2958 static void render_panel_ffmpeg_audio(void)
2959 {
2960         uiBlock *block;
2961         int yofs;
2962         int xcol;
2963         
2964         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
2965         uiNewPanelTabbed("Format", "Render");
2966         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
2967         
2968         yofs = 54;
2969         xcol = 892;
2970         
2971         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
2972                                  "Multiplex audio", xcol, yofs, 225, 20, 
2973                                  &G.scene->r.ffcodecdata.flags, 
2974                                  0, 1, 0,0, "Interleave audio with the output video");
2975         uiDefBut(block, LABEL, 0, "Codec", 
2976                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
2977         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
2978                           xcol, yofs-44, 225, 20, 
2979                           &G.scene->r.ffcodecdata.audio_codec, 
2980                           0,0,0,0, "FFMpeg codec to use");
2981         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2982                           xcol, yofs-66, 110, 20, 
2983                           &G.scene->r.ffcodecdata.audio_bitrate, 
2984                           32, 384, 0, 0, "Audio bitrate(kb/s)");
2985
2986         render_panel_ffmpeg_properties(block, "audio", xcol, yofs-86);
2987 }
2988 #endif
2989
2990 static void render_panel_stamp(void)
2991 {
2992         uiBlock *block;
2993         int yofs=0, xofs=550;
2994
2995         block= uiNewBlock (&curarea->uiblocks, "render_panel_stamp", UI_EMBOSS, UI_HELV, curarea->win);
2996         uiNewPanelTabbed ("Format", "Render");
2997         if(uiNewPanel (curarea, block, "Stamp", "Render", 960, 0, 318, 204)==0) return;
2998
2999         if (G.scene->r.scemode & R_STAMP_INFO) {
3000                 uiBlockBeginAlign(block);
3001                 uiDefButBitI(block, TOG, R_STAMP_NOTE, B_REDR, "Note", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp user data");
3002                 uiDefBut(block, TEX, B_NOP, "", xofs+120, yofs, 180, 19, &G.scene->r.stamp_udata, 0.0, 128.0, 100, 0, "User Note");
3003                 uiBlockEndAlign(block);
3004                 yofs += 30; /* gap */
3005                 
3006                 
3007                 yofs += 80;
3008                 /* Order is important for alligning ... grr */
3009                 uiBlockBeginAlign(block);
3010                 uiDefButBitI(block, TOG, R_STAMP_FILENAME, B_REDR, "Filename", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp blend filename");
3011                 yofs -= 20;
3012                 uiDefButBitI(block, TOG, R_STAMP_SCENE, B_REDR, "Scene", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp scene name");
3013                 uiDefButBitI(block, TOG, R_STAMP_CAMERA, B_REDR, "Camera", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp camera name");
3014                 yofs -= 20;
3015                 uiDefButBitI(block, TOG, R_STAMP_TIME, B_REDR, "Time", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp time (HH:MM:SS)");
3016                 uiDefButBitI(block, TOG, R_STAMP_DATE, B_REDR, "Date", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp date");
3017                 yofs -= 20;
3018                 uiDefButBitI(block, TOG, R_STAMP_FRAME, B_REDR, "Frame", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp frame number");
3019                 uiDefButBitI(block, TOG, R_STAMP_MARKER, B_REDR, "Marker", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the last marker");
3020                 yofs -= 20;
3021                 uiDefButBitI(block, TOG, R_STAMP_SEQSTRIP, B_REDR, "Sequence Strip", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the forground sequence strip name");
3022                 uiBlockEndAlign(block);
3023                 yofs += 80;
3024                 
3025                 /* draw font selector */
3026                 if (G.scene->r.stamp & R_STAMP_DRAW) {
3027                         uiDefButS(block, MENU, B_REDR, "Stamp Font Size%t|Tiny Text%x1|Small Text%x2|Medium Text%x3|Large Text%x0|Extra Large Text%x4|",
3028                                         xofs+130, yofs, 170, 19, &G.scene->r.stamp_font_id, 0, 0, 0, 0, "Choose stamp text size");
3029                         
3030                         /* draw fg/bg next to the scene */
3031                         yofs -= 25;
3032                         uiDefBut(block, LABEL, B_NOP, "Text Color", xofs+130, yofs, 70, 19, 0, 0, 0, 0, 0, "");
3033                         uiDefBut(block, LABEL, B_NOP, "Background", xofs+215, yofs, 70, 19, 0, 0, 0, 0, 0, "");
3034                         yofs -= 20;
3035                         uiDefButF(block, COL, B_NOP, "", xofs+130, yofs, 80, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
3036                         uiDefButF(block, COL, B_NOP, "", xofs+220, yofs, 80, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
3037                         yofs -= 30;
3038                         uiDefButF(block, NUMSLI, B_NOP, "A ", xofs+130, yofs, 170, 19, &G.scene->r.bg_stamp[3], 0, 1.0, 0, 0, "Alpha for text background");
3039                         yofs += 105;
3040                 } else {
3041                         yofs += 30;
3042                 }
3043                 
3044                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, yofs, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Disable stamp info in images metadata");
3045                 uiDefButBitI(block, TOG, R_STAMP_DRAW, B_REDR, "Draw Stamp", xofs+130, yofs, 170, 20, &G.scene->r.stamp, 0, 0, 0, 0, "Draw the stamp info into each frame");
3046                 yofs += 20;
3047         }
3048         else {
3049                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, 142, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Enable stamp info to image metadata");
3050                 yofs += 20;
3051        &nb