direct integrals for floatautos, clipboard fix
authorGood Guy <good1.2guy@gmail.com>
Sat, 9 Sep 2017 15:22:32 +0000 (09:22 -0600)
committerGood Guy <good1.2guy@gmail.com>
Sat, 9 Sep 2017 15:22:32 +0000 (09:22 -0600)
cinelerra-5.1/cinelerra/amodule.C
cinelerra-5.1/cinelerra/autos.C
cinelerra-5.1/cinelerra/clippopup.C
cinelerra-5.1/cinelerra/floatautos.C
cinelerra-5.1/cinelerra/floatautos.h
cinelerra-5.1/cinelerra/mwindowedit.C
cinelerra-5.1/cinelerra/vmodule.C
cinelerra-5.1/guicast/bcclipboard.C

index 1ef4a4fa4009c31870591b82870b8e971e8016a9..7fc0140bc8735f57b03f7fa0d79cdb1066a27026 100644 (file)
@@ -282,15 +282,8 @@ speed_fragment_len);
                FloatAuto *previous = 0;
                FloatAuto *next = 0;
                FloatAutos *speed_autos = (FloatAutos*)track->automation->autos[AUTOMATION_SPEED];
-               for(int64_t i = edit_startproject; i < start_project; i++)
-               {
-                       double speed = speed_autos->get_value(i,
-                               PLAY_FORWARD,
-                               previous,
-                               next);
-                       speed_position += speed;
-               }
-
+               speed_position += speed_autos->automation_intergal(edit_startproject,
+                               start_project-edit_startproject, PLAY_FORWARD);
                speed_position1 = speed_position;
 
 
index 1f169df2d2a10edcccb2b95991905ea2e94eae65..0ca1efcf85d52a45942e3a9f376a8c17daa3c32c 100644 (file)
@@ -204,7 +204,7 @@ Auto* Autos::get_prev_auto(int64_t position,
                        while(current && current->position > position) current = PREVIOUS;
                }
 
-               if(!current)
+               if(!current && first && first->position <= position)
                {
                        for(current = last;
                                current && current->position > position;
@@ -222,7 +222,7 @@ Auto* Autos::get_prev_auto(int64_t position,
                        while(current && current->position < position) current = NEXT;
                }
 
-               if(!current)
+               if(!current && last && last->position >= position)
                {
                        for(current = first;
                                current && current->position < position;
@@ -311,7 +311,7 @@ Auto* Autos::get_next_auto(int64_t position, int direction, Auto* &current, int
                        while(current && current->position < position) current = NEXT;
                }
 
-               if(!current)
+               if(!current && last && last->position > position)
                {
                        for(current = first;
                                current && current->position <= position;
@@ -330,7 +330,7 @@ Auto* Autos::get_next_auto(int64_t position, int direction, Auto* &current, int
                        while(current && current->position > position) current = PREVIOUS;
                }
 
-               if(!current)
+               if(!current && first && first->position <= position)
                {
                        for(current = last;
                                current && current->position > position;
index 4fd6af6975e6139c42d4965f31d16f43b604151a..602fbbd03802354f344e7e57026ee571973eb82d 100644 (file)
@@ -354,7 +354,7 @@ int ClipPasteToFolder::handle_event()
        gui->lock_window("ClipPasteToFolder::handle_event 1");
        int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
        if( len ) {
-               char *string = new char[len + 1];
+               char *string = new char[len];
                gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
                const char *clip_header = "<EDL VERSION=";
                if( !strncmp(clip_header, string, strlen(clip_header)) ) {
index 80e9c8bfb54e10dee21e6c59d4aeab8b2c89ac9b..458016cf98fd185e72ac216c0894114e8793cb8f 100644 (file)
@@ -424,3 +424,54 @@ void FloatAutos::dump()
                        FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
        }
 }
+
+double FloatAutos::automation_intergal(int64_t start, int64_t length, int direction)
+{
+       if( direction == PLAY_REVERSE )
+               start -= length;
+       if( start < 0 ) {
+               length += start;
+               start = 0;
+       }
+       int64_t end = start + length;
+       double value = 0, track_length = track->get_length();
+       int64_t pos = start, len = track->to_units(track_length,0);
+       if( end > len ) end = len;
+       while( pos < end ) {
+               int64_t prev_pos = 0, next_pos = len;
+               FloatAuto *prev = 0, *next = 0;
+               prev = (FloatAuto*)get_prev_auto(pos, direction, (Auto* &)prev, 0);
+               if( prev ) prev_pos = prev->position;
+               next = (FloatAuto*)get_next_auto(pos, direction, (Auto* &)next, 0);
+               if( next ) next_pos = next->position;
+               if( !prev && !next ) prev = next = (FloatAuto*)default_auto;
+               else if( !prev ) prev = next;
+               else if( !next ) next = prev;
+
+               double dt = next_pos - prev_pos;
+               double t0 = (pos - prev_pos) / dt;
+               if( (pos = next_pos) > end ) pos = end;
+               double t1 = (pos - prev_pos) / dt;
+
+               double y0 = prev->get_value(), y1 = y0 + prev->get_control_out_value();
+               double y3 = next->get_value(), y2 = y3 + next->get_control_in_value();
+               if( y0 != y1 || y1 != y2 || y2 != y3 ) {
+// bezier definite integral t0..t1
+                       double f4 = -y0/4 + 3*y1/4 - 3*y2/4 + y3/4;
+                       double f3 = y0 - 2*y1 + y2;
+                       double f2 = -3*y0/2 + 3*y1/2;
+                       double f1 = y0, t = t0;
+                       double t2 = t*t, t3 = t2*t, t4 = t3*t;
+                       t0 = t4*f4 + t3*f3 + t2*f2 + t*f1;
+                       t = t1;  t2 = t*t;  t3 = t2*t;  t4 = t3*t;
+                       t1 = t4*f4 + t3*f3 + t2*f2 + t*f1;
+               }
+               else {
+                       t0 *= y0;  t1 *= y0;
+               }
+               value += dt * (t1 - t0);
+       }
+
+       return value + 1e-6;
+}
+
index 433a81393c4a9946711d131c2267b01a4b77cba8..8c8e7359bdb21db8ce53f50d69dae466c2991325 100644 (file)
@@ -63,6 +63,7 @@ public:
                int64_t unit_end);
 
        void set_automation_mode(int64_t start, int64_t end, int mode);
+       double automation_intergal(int64_t start, int64_t length, int direction);
 
        void dump();
        Auto* new_auto();
index 8fba7bfc95d48b110516db5e6ef81c743d8e59df..7710d4ada162471c62cb6c0d81b1fae6fd5156ed 100644 (file)
@@ -1084,7 +1084,7 @@ void MWindow::paste()
        int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
 
        if( len ) {
-               char *string = new char[len + 1];
+               char *string = new char[len];
                undo->update_undo_before();
                gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
                FileXML file;
@@ -1203,7 +1203,7 @@ int MWindow::paste_automation()
 
        if( len ) {
                undo->update_undo_before();
-               char *string = new char[len + 1];
+               char *string = new char[len];
                gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
                FileXML file;
                file.read_from_string(string);
@@ -1234,7 +1234,7 @@ int MWindow::paste_default_keyframe()
 
        if( len ) {
                undo->update_undo_before();
-               char *string = new char[len + 1];
+               char *string = new char[len];
                gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
                FileXML file;
                file.read_from_string(string);
index e8016e1b5e3bc5e8f084dca2252f8000347ad33b..d345cbc47b7302db44c306c8946f5bbfe28579c8 100644 (file)
@@ -266,17 +266,9 @@ int VModule::import_frame(VFrame *output, VEdit *current_edit,
                        {
 // 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_intergal(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;
                        }
index 4ef144bcb8e74455c8abb7300f1f931361584dd9..bae148fc1b1ec8737f40b966ab58bfcfee8e43f1 100644 (file)
@@ -194,7 +194,7 @@ long BC_Clipboard::clipboard_len(int clipboard_num)
        char *bfr;
        long len = from_clipboard(clipboard_num, bfr, 0);
        if( bfr ) XFree(bfr);
-       return len < 0 ? 0 : len;
+       return len < 0 ? 0 : len+1;
 }
 
 long BC_Clipboard::from_clipboard(int clipboard_num, char *&bfr, long maxlen)