~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/sequencer.c

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-06-24 11:13:28 UTC
  • mto: (14.1.6 experimental) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20110624111328-27ribg6l36edf2ay
Tags: upstream-2.58-svn37702
ImportĀ upstreamĀ versionĀ 2.58-svn37702

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
* $Id: sequencer.c 36276 2011-04-21 15:53:30Z campbellbarton $
 
2
* $Id: sequencer.c 37303 2011-06-07 18:34:33Z campbellbarton $
3
3
 *
4
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
79
79
#define snprintf _snprintf
80
80
#endif
81
81
 
82
 
/* **** XXX ******** */
83
 
//static void waitcursor(int val) {}
84
 
//static int blender_test_break() {return 0;}
 
82
 
 
83
static ImBuf* seq_render_strip_stack( 
 
84
        SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown);
 
85
 
 
86
static ImBuf * seq_render_strip(
 
87
        SeqRenderData context, Sequence * seq, float cfra);
 
88
 
 
89
static void seq_free_animdata(Scene *scene, Sequence *seq);
 
90
 
85
91
 
86
92
/* **** XXX ******** */
87
93
#define SELECT 1
177
183
        MEM_freeN(strip);
178
184
}
179
185
 
180
 
static void seq_free_animdata(Scene *scene, Sequence *seq);
181
 
 
182
186
void seq_free_sequence(Scene *scene, Sequence *seq)
183
187
{
184
188
        if(seq->strip) seq_free_strip(seq->strip);
191
195
                sh.free(seq);
192
196
        }
193
197
 
 
198
        if(seq->sound) {
 
199
                ((ID *)seq->sound)->us--; 
 
200
        }
 
201
 
194
202
        /* clipboard has no scene and will never have a sound handle or be active */
195
203
        if(scene) {
196
204
                Editing *ed = scene->ed;
446
454
  * in metastrips!)
447
455
  **********************************************************************
448
456
*/
449
 
#if 0 /* UNUSED */
450
 
static void do_seq_count(ListBase *seqbase, int *totseq)
451
 
{
452
 
        Sequence *seq;
453
 
 
454
 
        seq= seqbase->first;
455
 
        while(seq) {
456
 
                (*totseq)++;
457
 
                if(seq->seqbase.first) do_seq_count(&seq->seqbase, totseq);
458
 
                seq= seq->next;
459
 
        }
460
 
}
461
 
 
462
 
static void do_build_seqar(ListBase *seqbase, Sequence ***seqar, int depth)
463
 
{
464
 
        Sequence *seq;
465
 
 
466
 
        seq= seqbase->first;
467
 
        while(seq) {
468
 
                seq->depth= depth;
469
 
                if(seq->seqbase.first) do_build_seqar(&seq->seqbase, seqar, depth+1);
470
 
                **seqar= seq;
471
 
                (*seqar)++;
472
 
                seq= seq->next;
473
 
        }
474
 
}
475
 
 
476
 
static void build_seqar(ListBase *seqbase, Sequence  ***seqar, int *totseq)
477
 
{
478
 
        Sequence **tseqar;
479
 
 
480
 
        *totseq= 0;
481
 
        do_seq_count(seqbase, totseq);
482
 
 
483
 
        if(*totseq==0) {
484
 
                *seqar= NULL;
485
 
                return;
486
 
        }
487
 
        *seqar= MEM_mallocN(sizeof(void *)* *totseq, "seqar");
488
 
        tseqar= *seqar;
489
 
 
490
 
        do_build_seqar(seqbase, seqar, 0);
491
 
        *seqar= tseqar;
492
 
}
493
 
#endif /* UNUSED */
494
457
 
495
458
static void do_seq_count_cb(ListBase *seqbase, int *totseq,
496
459
                                int (*test_func)(Sequence * seq))
624
587
                if (seq->seq1) {
625
588
                        seq->start= seq->startdisp= MAX3(seq->seq1->startdisp, seq->seq2->startdisp, seq->seq3->startdisp);
626
589
                        seq->enddisp= MIN3(seq->seq1->enddisp, seq->seq2->enddisp, seq->seq3->enddisp);
 
590
                        /* we cant help if strips don't overlap, it wont give useful results.
 
591
                         * but at least ensure 'len' is never negative which causes bad bugs elsewhere. */
 
592
                        if(seq->enddisp < seq->startdisp) {
 
593
                                /* simple start/end swap */
 
594
                                seq->start= seq->enddisp;
 
595
                                seq->enddisp = seq->startdisp;
 
596
                                seq->startdisp= seq->start;
 
597
                                seq->flag |= SEQ_INVALID_EFFECT;
 
598
                        }
 
599
                        else {
 
600
                                seq->flag &= ~SEQ_INVALID_EFFECT;
 
601
                        }
 
602
 
627
603
                        seq->len= seq->enddisp - seq->startdisp;
628
 
                } else {
 
604
                }
 
605
                else {
629
606
                        calc_sequence_disp(scene, seq);
630
607
                }
631
608
 
916
893
        case SEQ_TRANSFORM:  return "Transform";
917
894
        case SEQ_COLOR:      return "Color";
918
895
        case SEQ_MULTICAM:   return "Multicam";
 
896
        case SEQ_ADJUSTMENT: return "Adjustment";
919
897
        case SEQ_SPEED:      return "Speed";
920
898
        default:
921
899
                return NULL;
1013
991
        int sta = seq->start;
1014
992
        int end = seq->start+seq->len-1;
1015
993
 
1016
 
        if(seq->len == 0) return -1;
 
994
        if (seq->type & SEQ_EFFECT) {
 
995
                end = seq->enddisp;
 
996
        } 
 
997
 
 
998
        if(end < sta) {
 
999
                return -1;
 
1000
        }
1017
1001
 
1018
1002
        if(seq->flag&SEQ_REVERSE_FRAMES) {      
1019
1003
                /*reverse frame in this sequence */
1020
 
                if(cfra <= sta) nr= seq->len-1;
 
1004
                if(cfra <= sta) nr= end - sta;
1021
1005
                else if(cfra >= end) nr= 0;
1022
1006
                else nr= end - cfra;
1023
1007
        } else {
1024
1008
                if(cfra <= sta) nr= 0;
1025
 
                else if(cfra >= end) nr= seq->len-1;
 
1009
                else if(cfra >= end) nr= end - sta;
1026
1010
                else nr= cfra - sta;
1027
1011
        }
1028
1012
        
1039
1023
{
1040
1024
        StripElem *se= seq->strip->stripdata;
1041
1025
 
1042
 
        if(seq->type != SEQ_MOVIE) { /* movie use the first */
 
1026
        if(seq->type == SEQ_IMAGE) { /* only 
 
1027
                                        IMAGE strips use the whole array,
 
1028
                                        MOVIE strips use only 
 
1029
                                        the first element, all other strips
 
1030
                                        don't use this... */
1043
1031
                int nr = (int) give_stripelem_index(seq, cfra);
1044
1032
 
1045
1033
                if (nr == -1 || se == NULL) return NULL;
1093
1081
        }
1094
1082
 
1095
1083
        if(evaluate_seq_frame_gen(seq_arr, seqbasep, cfra)) {
1096
 
                if (b > 0) {
1097
 
                        if (seq_arr[b] == NULL) {
1098
 
                                return 0;
1099
 
                        }
1100
 
                } else {
1101
 
                        for (b = MAXSEQ; b > 0; b--) {
1102
 
                                if (video_seq_is_rendered(seq_arr[b])) {
1103
 
                                        break;
1104
 
                                }
 
1084
                if (b == 0) {
 
1085
                        b = MAXSEQ;
 
1086
                }
 
1087
                for (; b > 0; b--) {
 
1088
                        if (video_seq_is_rendered(seq_arr[b])) {
 
1089
                                break;
1105
1090
                        }
1106
1091
                }
1107
1092
        }
1858
1843
        ImBuf * ibuf = NULL;
1859
1844
        float frame= seq->sfra + nr + seq->anim_startofs;
1860
1845
        float oldcfra;
1861
 
        Object *oldcamera;
 
1846
        Object *camera;
1862
1847
        ListBase oldmarkers;
1863
1848
        
1864
1849
        /* Old info:
1896
1881
        int doseq;
1897
1882
        int doseq_gl= G.rendering ? /*(scene->r.seq_flag & R_SEQ_GL_REND)*/ 0 : /*(scene->r.seq_flag & R_SEQ_GL_PREV)*/ 1;
1898
1883
        int have_seq= FALSE;
1899
 
        Scene *sce= seq->scene; /* dont refer to seq->scene above this point!, it can be NULL */
1900
 
        int sce_valid= FALSE;
1901
 
 
1902
 
        if(sce) {
1903
 
                have_seq= (sce->r.scemode & R_DOSEQ) && sce->ed && sce->ed->seqbase.first;
1904
 
                sce_valid= (sce->camera || have_seq);
1905
 
        }
1906
 
 
1907
 
        if (!sce_valid)
1908
 
                return NULL;
1909
 
 
1910
 
        oldcfra= seq->scene->r.cfra;
1911
 
        oldcamera= seq->scene->camera;
 
1884
        Scene *scene;
 
1885
 
 
1886
        /* dont refer to seq->scene above this point!, it can be NULL */
 
1887
        if(seq->scene == NULL) {
 
1888
                return NULL;
 
1889
        }
 
1890
 
 
1891
        scene= seq->scene;
 
1892
 
 
1893
        have_seq= (scene->r.scemode & R_DOSEQ) && scene->ed && scene->ed->seqbase.first;
 
1894
 
 
1895
        oldcfra= scene->r.cfra; 
 
1896
        scene->r.cfra= frame;
 
1897
 
 
1898
        if(seq->scene_camera)   
 
1899
                camera= seq->scene_camera;
 
1900
        else {  
 
1901
                scene_camera_switch_update(scene);
 
1902
                camera= scene->camera;
 
1903
        }
 
1904
 
 
1905
        if(have_seq==FALSE && camera==NULL) {
 
1906
                scene->r.cfra= oldcfra;
 
1907
                return NULL;
 
1908
        }
1912
1909
 
1913
1910
        /* prevent eternal loop */
1914
1911
        doseq= context.scene->r.scemode & R_DOSEQ;
1915
1912
        context.scene->r.scemode &= ~R_DOSEQ;
1916
1913
        
1917
 
        seq->scene->r.cfra= frame;
1918
 
        if(seq->scene_camera)   
1919
 
                seq->scene->camera= seq->scene_camera;
1920
 
        else    
1921
 
                scene_camera_switch_update(seq->scene);
1922
 
        
1923
1914
#ifdef DURIAN_CAMERA_SWITCH
1924
1915
        /* stooping to new low's in hackyness :( */
1925
 
        oldmarkers= seq->scene->markers;
1926
 
        seq->scene->markers.first= seq->scene->markers.last= NULL;
 
1916
        oldmarkers= scene->markers;
 
1917
        scene->markers.first= scene->markers.last= NULL;
1927
1918
#endif
1928
1919
        
1929
 
        if(sequencer_view3d_cb && BLI_thread_is_main() && doseq_gl && (seq->scene == context.scene || have_seq==0) && seq->scene->camera) {
 
1920
        if(sequencer_view3d_cb && BLI_thread_is_main() && doseq_gl && (scene == context.scene || have_seq==0) && camera) {
1930
1921
                char err_out[256]= "unknown";
1931
1922
                /* for old scened this can be uninitialized, should probably be added to do_versions at some point if the functionality stays */
1932
1923
                if(context.scene->r.seq_prev_type==0)
1933
1924
                        context.scene->r.seq_prev_type = 3 /* ==OB_SOLID */; 
1934
1925
 
1935
1926
                /* opengl offscreen render */
1936
 
                scene_update_for_newframe(context.bmain, seq->scene, seq->scene->lay);
1937
 
                ibuf= sequencer_view3d_cb(seq->scene, context.rectx, context.recty, IB_rect, context.scene->r.seq_prev_type, err_out);
 
1927
                scene_update_for_newframe(context.bmain, scene, scene->lay);
 
1928
                ibuf= sequencer_view3d_cb(scene, camera, context.rectx, context.recty, IB_rect, context.scene->r.seq_prev_type, err_out);
1938
1929
                if(ibuf == NULL) {
1939
1930
                        fprintf(stderr, "seq_render_scene_strip_impl failed to get opengl buffer: %s\n", err_out);
1940
1931
                }
1941
1932
        }
1942
1933
        else {
1943
 
                Render *re = RE_GetRender(sce->id.name);
 
1934
                Render *re = RE_GetRender(scene->id.name);
1944
1935
                RenderResult rres;
1945
1936
 
1946
1937
                /* XXX: this if can be removed when sequence preview rendering uses the job system */
1947
 
                if(rendering || context.scene != sce) {
 
1938
                if(rendering || context.scene != scene) {
1948
1939
                        if(re==NULL)
1949
 
                                re= RE_NewRender(sce->id.name);
 
1940
                                re= RE_NewRender(scene->id.name);
1950
1941
                        
1951
 
                        RE_BlenderFrame(re, context.bmain, sce, NULL, sce->lay, frame, FALSE);
 
1942
                        RE_BlenderFrame(re, context.bmain, scene, NULL, camera, scene->lay, frame, FALSE);
1952
1943
 
1953
1944
                        /* restore previous state after it was toggled on & off by RE_BlenderFrame */
1954
1945
                        G.rendering = rendering;
1981
1972
        /* restore */
1982
1973
        context.scene->r.scemode |= doseq;
1983
1974
        
1984
 
        seq->scene->r.cfra = oldcfra;
1985
 
        seq->scene->camera= oldcamera;
 
1975
        scene->r.cfra = oldcfra;
 
1976
 
1986
1977
        if(frame != oldcfra)
1987
 
                scene_update_for_newframe(context.bmain, seq->scene, seq->scene->lay);
 
1978
                scene_update_for_newframe(context.bmain, scene, scene->lay);
1988
1979
        
1989
1980
#ifdef DURIAN_CAMERA_SWITCH
1990
1981
        /* stooping to new low's in hackyness :( */
1991
 
        seq->scene->markers= oldmarkers;
 
1982
        scene->markers= oldmarkers;
1992
1983
#endif
1993
1984
 
1994
1985
        return ibuf;
2065
2056
                        break;
2066
2057
                }
2067
2058
                case SEQ_EFFECT:
2068
 
                {       
2069
 
                        ibuf = seq_render_effect_strip_impl(context, seq, cfra);
 
2059
                {
 
2060
                        ibuf = seq_render_effect_strip_impl(
 
2061
                                context, seq, seq->start + nr);
2070
2062
                        break;
2071
2063
                }
2072
2064
                case SEQ_IMAGE:
2849
2841
   since they work a bit differently to normal image seq's (during transform) */
2850
2842
int seq_single_check(Sequence *seq)
2851
2843
{
2852
 
        return (seq->len==1 && ELEM3(seq->type, SEQ_IMAGE, SEQ_COLOR, SEQ_MULTICAM));
 
2844
        return (seq->len==1 && (
 
2845
                        seq->type == SEQ_IMAGE 
 
2846
                        || ((seq->type & SEQ_EFFECT) && 
 
2847
                            get_sequence_effect_num_inputs(seq->type) == 0)));
2853
2848
}
2854
2849
 
2855
2850
/* check if the selected seq's reference unselected seq's */
3208
3203
        return NULL;
3209
3204
}
3210
3205
 
3211
 
int seq_swap(Sequence *seq_a, Sequence *seq_b)
 
3206
Sequence *seq_metastrip(ListBase * seqbase, Sequence * meta, Sequence *seq)
 
3207
{
 
3208
        Sequence * iseq;
 
3209
 
 
3210
        for(iseq = seqbase->first; iseq; iseq = iseq->next) {
 
3211
                Sequence * rval;
 
3212
 
 
3213
                if (seq == iseq) {
 
3214
                        return meta;
 
3215
                } else if(iseq->seqbase.first && 
 
3216
                        (rval = seq_metastrip(&iseq->seqbase, iseq, seq))) {
 
3217
                        return rval;
 
3218
                }
 
3219
        }
 
3220
 
 
3221
        return NULL;
 
3222
}
 
3223
 
 
3224
int seq_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str)
3212
3225
{
3213
3226
        char name[sizeof(seq_a->name)];
3214
3227
 
3215
3228
        if(seq_a->len != seq_b->len)
 
3229
                *error_str= "Strips must be the same length";
3216
3230
                return 0;
3217
3231
 
3218
3232
        /* type checking, could be more advanced but disalow sound vs non-sound copy */
3219
3233
        if(seq_a->type != seq_b->type) {
3220
3234
                if(seq_a->type == SEQ_SOUND || seq_b->type == SEQ_SOUND) {
 
3235
                        *error_str= "Strips were not compatible";
3221
3236
                        return 0;
3222
3237
                }
3223
3238
 
3224
3239
                /* disallow effects to swap with non-effects strips */
3225
3240
                if((seq_a->type & SEQ_EFFECT) != (seq_b->type & SEQ_EFFECT)) {
 
3241
                        *error_str= "Strips were not compatible";
3226
3242
                        return 0;
3227
3243
                }
3228
3244
 
3229
3245
                if((seq_a->type & SEQ_EFFECT) && (seq_b->type & SEQ_EFFECT)) {
3230
3246
                        if(get_sequence_effect_num_inputs(seq_a->type) != get_sequence_effect_num_inputs(seq_b->type)) {
 
3247
                                *error_str= "Strips must have the same number of inputs";
3231
3248
                                return 0;
3232
3249
                        }
3233
3250
                }
3517
3534
        strip->len = seq->len = ceil(info.length * FPS);
3518
3535
        strip->us= 1;
3519
3536
 
3520
 
        strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
 
3537
        /* we only need 1 element to store the filename */
 
3538
        strip->stripdata= se= MEM_callocN(sizeof(StripElem), "stripelem");
3521
3539
 
3522
3540
        BLI_split_dirfile(seq_load->path, strip->dir, se->name);
3523
3541
 
3566
3584
        strip->len = seq->len = IMB_anim_get_duration( an );
3567
3585
        strip->us= 1;
3568
3586
 
3569
 
        strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
 
3587
        /* we only need 1 element for MOVIE strips */
 
3588
        strip->stripdata= se= MEM_callocN(sizeof(StripElem), "stripelem");
3570
3589
 
3571
3590
        BLI_split_dirfile(seq_load->path, strip->dir, se->name);
3572
3591