add binfolder path relative filters, fix gbrp color model, vwdw timebar tweaks, title...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / vmodule.C
index 6d69dc3c454acad0f656caed4f423ecd79da85f2..3ef17f0436d714bf0aa4175ed9f6e292a3f1cf89 100644 (file)
@@ -105,54 +105,31 @@ CICache* VModule::get_cache()
 
 
 
-int VModule::import_frame(VFrame *output,
-       VEdit *current_edit,
-       int64_t input_position,
-       double frame_rate,
-       int direction,
-       int use_opengl)
+int VModule::import_frame(VFrame *output, VEdit *current_edit,
+       int64_t input_position, double frame_rate, int direction, int use_opengl)
 {
        int64_t direction_position;
 // Translation of edit
-       float in_x;
-       float in_y;
-       float in_w;
-       float in_h;
-       float out_x;
-       float out_y;
-       float out_w;
-       float out_h;
+       float in_x, in_y, in_w, in_h;
+       float out_x, out_y, out_w, out_h;
        int result = 0;
        const int debug = 0;
        double edl_rate = get_edl()->session->frame_rate;
 
        int64_t input_position_project = Units::to_int64(input_position *
-               edl_rate /
-               frame_rate +
-               0.001);
-
-
-
-
-
-
+               edl_rate / frame_rate + 0.001);
 
        if(!output) printf("VModule::import_frame %d output=%p\n", __LINE__, output);
        //output->dump_params();
 
-
        if(debug) printf("VModule::import_frame %d this=%p input_position=%lld direction=%d\n",
-               __LINE__,
-               this,
-               (long long)input_position,
-               direction);
+               __LINE__, this, (long long)input_position, direction);
 
 // Convert to position corrected for direction
        direction_position = input_position;
-       if(direction == PLAY_REVERSE)
-       {
-               direction_position--;
-               input_position_project--;
+       if(direction == PLAY_REVERSE) {
+               if( direction_position > 0 ) direction_position--;
+               if( input_position_project > 0 ) input_position_project--;
        }
        if(!output) printf("VModule::import_frame %d output=%p\n", __LINE__, output);
 
@@ -168,33 +145,24 @@ int VModule::import_frame(VFrame *output,
        }
 
        if(!output) printf("VModule::import_frame %d output=%p x11_device=%p nested_edl=%p\n",
-               __LINE__,
-               output,
-               x11_device,
-               nested_edl);
-
+               __LINE__, output, x11_device, nested_edl);
 
        if(debug) printf("VModule::import_frame %d current_edit=%p\n",
-               __LINE__,
-               current_edit);
-
+               __LINE__, current_edit);
 
 // Load frame into output
 
 // Create objects for nested EDL
-       if(current_edit &&
-               current_edit->nested_edl)
-       {
+       if(current_edit && current_edit->nested_edl) {
                int command;
                if(debug) printf("VModule::import_frame %d nested_edl=%p current_edit->nested_edl=%p\n",
-                       __LINE__,
-                       nested_edl,
-                       current_edit->nested_edl);
+                       __LINE__, nested_edl, current_edit->nested_edl);
 
 // Convert requested direction to command
-               if(renderengine->command->command == CURRENT_FRAME)
+               if( renderengine->command->command == CURRENT_FRAME ||
+                   renderengine->command->command == LAST_FRAME )
                {
-                       command = CURRENT_FRAME;
+                       command = renderengine->command->command;
                }
                else
                if(direction == PLAY_REVERSE)
@@ -233,11 +201,7 @@ int VModule::import_frame(VFrame *output,
                                nested_command->get_edl()->copy_all(nested_edl);
                                nested_command->change_type = CHANGE_ALL;
                                nested_command->realtime = renderengine->command->realtime;
-                               nested_renderengine = new RenderEngine(0,
-                                       get_preferences(),
-                                       0,
-                                       renderengine ? renderengine->channeldb : 0,
-                                       1);
+                               nested_renderengine = new RenderEngine(0, get_preferences(), 0, 1);
                                nested_renderengine->set_vcache(get_cache());
                                nested_renderengine->arm_command(nested_command);
                        }
@@ -259,7 +223,14 @@ int VModule::import_frame(VFrame *output,
        }
        if(debug) printf("VModule::import_frame %d\n", __LINE__);
 
-       if(!output) printf("VModule::import_frame %d output=%p\n", __LINE__, output);
+       if( output ) {
+               if( use_opengl )
+                       x11_device->clear_input(output);
+               else
+                       output->clear_frame();
+       }
+       else
+               printf("VModule::import_frame %d output=%p\n", __LINE__, output);
 
        if(current_edit &&
                (current_edit->asset ||
@@ -267,11 +238,8 @@ int VModule::import_frame(VFrame *output,
        {
                File *file = 0;
 
-               if(debug) printf("VModule::import_frame %d cache=%p\n",
-                       __LINE__,
-                       get_cache());
-               if(current_edit->asset)
-               {
+//printf("VModule::import_frame %d cache=%p\n", __LINE__, get_cache());
+               if( current_edit->asset ) {
                        get_cache()->age();
                        file = get_cache()->check_out(current_edit->asset,
                                get_edl());
@@ -303,17 +271,9 @@ int VModule::import_frame(VFrame *output,
                        {
 // integrate position from start of edit.
                                double speed_position = edit_startsource;
-                               FloatAuto *previous = 0;
-                               FloatAuto *next = 0;
                                FloatAutos *speed_autos = (FloatAutos*)track->automation->autos[AUTOMATION_SPEED];
-                               for(int64_t i = edit_startproject; i < direction_position; i++)
-                               {
-                                       double speed = speed_autos->get_value(i,
-                                               PLAY_FORWARD,
-                                               previous,
-                                               next);
-                                       speed_position += speed;
-                               }
+                               speed_position += speed_autos->automation_integral(edit_startproject,
+                                               direction_position-edit_startproject, PLAY_FORWARD);
 //printf("VModule::import_frame %d %lld %lld\n", __LINE__, position, (int64_t)speed_position);
                                position = (int64_t)speed_position;
                        }
@@ -341,7 +301,7 @@ int VModule::import_frame(VFrame *output,
                        }
                        else
                        {
-                               max_position = Units::to_int64(nested_edl->tracks->total_playable_length() *
+                               max_position = Units::to_int64(nested_edl->tracks->total_length() *
                                        frame_rate - 1);
                        }
 
@@ -352,18 +312,19 @@ int VModule::import_frame(VFrame *output,
 
                        int use_cache = renderengine &&
                                renderengine->command->single_frame();
-                       int use_asynchronous = !use_cache && renderengine &&
+//                     int use_asynchronous = !use_cache &&
+//                             renderengine &&
 // Try to make rendering go faster.
 // But converts some formats to YUV420, which may degrade input format.
-//                             renderengine->command->realtime &&
-                               renderengine->get_edl()->session->video_asynchronous;
+////                           renderengine->command->realtime &&
+//                             renderengine->get_edl()->session->video_asynchronous;
 
                        if(file)
                        {
                                if(debug) printf("VModule::import_frame %d\n", __LINE__);
-                               if(use_asynchronous)
-                                       file->start_video_decode_thread();
-                               else
+//                             if(use_asynchronous)
+//                                     file->start_video_decode_thread();
+//                             else
                                        file->stop_video_thread();
 
                                int64_t normalized_position = Units::to_int64(position *
@@ -453,7 +414,7 @@ int VModule::import_frame(VFrame *output,
 //                     current_edit->asset->interlace_fixmethod);
 
                        // Determine the interlacing method to use.
-                       int interlace_fixmethod = !current_edit->asset ? BC_ILACE_FIXMETHOD_NONE :
+                       int interlace_fixmethod = !current_edit->asset ? ILACE_FIXMETHOD_NONE :
                                 ilaceautofixmethod2(get_edl()->session->interlace_mode,
                                        current_edit->asset->interlace_autofixoption,
                                        current_edit->asset->interlace_mode,
@@ -465,13 +426,13 @@ int VModule::import_frame(VFrame *output,
 
                        // Compensate for the said interlacing...
                        switch (interlace_fixmethod) {
-                               case BC_ILACE_FIXMETHOD_NONE:
+                               case ILACE_FIXMETHOD_NONE:
 
                                break;
-                               case BC_ILACE_FIXMETHOD_UPONE:
+                               case ILACE_FIXMETHOD_UPONE:
                                        out_y--;
                                break;
-                               case BC_ILACE_FIXMETHOD_DOWNONE:
+                               case ILACE_FIXMETHOD_DOWNONE:
                                        out_y++;
                                break;
                                default:
@@ -490,7 +451,7 @@ int VModule::import_frame(VFrame *output,
                                !EQUIV(in_w, asset_w) ||
                                !EQUIV(in_h, asset_h))
                        {
-                               if(debug) printf("VModule::import_frame %d file -> temp -> output\n", __LINE__);
+//printf("VModule::import_frame %d file -> temp -> output\n", __LINE__);
 
 
 
@@ -525,12 +486,9 @@ int VModule::import_frame(VFrame *output,
 
                                if(!(*input))
                                {
-                                       (*input) = new VFrame(0,
-                                               -1,
-                                               asset_w,
-                                               asset_h,
-                                               get_edl()->session->color_model,
-                                               -1);
+                                       (*input) =
+                                               new VFrame(asset_w, asset_h,
+                                                       get_edl()->session->color_model);
                                }
 
 
@@ -770,7 +728,13 @@ output->get_opengl_state(),
                                                get_edl()->session->interpolation_type);
                                }
                                result = 1;
+                               
                                output->copy_stacks((*input));
+                               
+                               
+//printf("VModule::import_frame %d\n", __LINE__); 
+//(*input)->dump_params();
+//output->dump_params();
                        }
                        else
 // file -> output
@@ -914,17 +878,13 @@ current_cmodel);
                else
 // Source not found
                {
-                       if(debug) printf("VModule::import_frame %d\n", __LINE__);
-                       if(use_opengl)
-                       {
-                               x11_device->clear_input(output);
-                       }
-                       else
-                       {
-                               output->clear_frame();
-                       }
                        result = 1;
                }
+
+//             printf("VModule::import_frame %d cache=%p\n", 
+//                     __LINE__,
+//                     get_cache());
+
        }
        else
 // Source is silence
@@ -976,7 +936,7 @@ int VModule::render(VFrame *output,
 //printf("VModule::render %d %p %ld %d\n", __LINE__, current_edit, start_position_project, direction);
 
        if(debug_render)
-               printf("    VModule::render %d %d %ld %s transition=%p opengl=%d current_edit=%p output=%p\n",
+               printf("    VModule::render %d %d %jd %s transition=%p opengl=%d current_edit=%p output=%p\n",
                        __LINE__,
                        use_nudge,
                        start_position_project,
@@ -1025,12 +985,9 @@ int VModule::render(VFrame *output,
 // Load incoming frame
                if(!(*transition_input))
                {
-                       (*transition_input) = new VFrame(0,
-                               -1,
-                               track->track_w,
-                               track->track_h,
-                               get_edl()->session->color_model,
-                               -1);
+                       (*transition_input) =
+                               new VFrame(track->track_w, track->track_h,
+                                       get_edl()->session->color_model);
                }
 
                (*transition_input)->copy_stacks(output);