[gegl] use set_clip_position to get proper quantization for frames



commit 908b198dba657422f0f6b9dd52f1127da2245463
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed May 15 01:13:13 2019 +0200

    use set_clip_position to get proper quantization for frames

 bin/lua/init.lua   |  2 ++
 bin/lua/viewer.lua | 29 ++++++++++++++++-------------
 bin/ui-core.c      | 11 ++++++++---
 bin/ui.h           |  1 +
 4 files changed, 27 insertions(+), 16 deletions(-)
---
diff --git a/bin/lua/init.lua b/bin/lua/init.lua
index 33dc92ebf..f41395ade 100644
--- a/bin/lua/init.lua
+++ b/bin/lua/init.lua
@@ -265,6 +265,7 @@ char *get_item_path    (GeState *o);  /* currently selected path */
 char *get_item_path_no (GeState *o, int child_no);
 
 void g_free (void *data);
+void set_clip_position (GeState *o, double position);
 
 ]]
 
@@ -272,6 +273,7 @@ o = ffi.C.app_state()
 mrg = o.mrg
 
 ffi.metatype('GeState', {__index = {
+   set_clip_position = function(...) return ffi.C.set_clip_position(...) end;
    get_key_int = function(...) return ffi.C.meta_get_key_int(...) end;
    items_count = function(...) return ffi.C.ui_items_count(...) end;
    item_no = function(...) return ffi.C.get_item_no(...) end;
diff --git a/bin/lua/viewer.lua b/bin/lua/viewer.lua
index 768dbcadb..1d1da7060 100644
--- a/bin/lua/viewer.lua
+++ b/bin/lua/viewer.lua
@@ -341,19 +341,22 @@ if 1 ~= 0 then
 
   cr:rectangle(height * .1 , height * .9, width - height * .2, height *.1)
   mrg:listen(Mrg.DRAG, function(event)
-
-      o.pos = (event.x - height *.15) / (width - height * .3) * frames
-
-      sink:set_time(o.pos + o.start)
-      if o.is_video ~= 0 then
-         source = GObject.Object(STATE).source
-         local frames = source:get_property('frames').value
-         local pos = (event.x - height *.15) / (width - height * .3)
-    source:set_property('frame',
-       GObject.Value(GObject.Type.INT,
-            math.floor(pos * frames)
-    ))
-      end
+      o:set_clip_position((event.x - height *.15) / (width - height * .3) * frames)
+    -- the following commented out lua is deprecated by above, the below
+    -- lua does not do the correct time to fps quantization that set_clip_position does
+
+    --o.pos = (event.x - height *.15) / (width - height * .3) * frames
+
+    --sink:set_time(o.pos + o.start)
+    --if o.is_video ~= 0 then
+    --  source = GObject.Object(STATE).source
+    --   local frames = source:get_property('frames').value
+    --   local pos = (event.x - height *.15) / (width - height * .3)
+    --source:set_property('frame',
+    --   GObject.Value(GObject.Type.INT,
+    --        math.floor(pos * frames)
+    --))
+    --end
       event:stop_propagate()
   end)
   cr:new_path()
diff --git a/bin/ui-core.c b/bin/ui-core.c
index 0a6f6201d..995a33802 100644
--- a/bin/ui-core.c
+++ b/bin/ui-core.c
@@ -4512,7 +4512,7 @@ static void iterate_frame (GeState *o)
      int frames = 0;
      int frame_delay = 0;
      gegl_node_get (o->source, "frames", &frames, "frame-delay", &frame_delay, NULL);
-     if (o->prev_ms + frame_delay  < mrg_ms (mrg))
+     if (prev_ms + frame_delay < mrg_ms (mrg))
      {
        int frame_no;
        gegl_node_get (o->source, "frame", &frame_no, NULL);
@@ -4521,8 +4521,7 @@ static void iterate_frame (GeState *o)
        if (frame_no >= frames)
          frame_no = 0;
        gegl_node_set (o->source, "frame", frame_no, NULL);
-       o->prev_ms = mrg_ms (mrg);
-       //queue_draw (o);
+       prev_ms = mrg_ms (mrg);
     }
     mrg_queue_draw (o->mrg, NULL);
    }
@@ -4538,6 +4537,12 @@ static void iterate_frame (GeState *o)
     {
       if (frame_accum > 1000 / o->fps)
       {
+        /*
+         *  this mechanism makes us iterate time-line ahead in increments
+         *  according to fps in real-time when able to keep up, and otherwise
+         *  slowing down increments accordingly while pretending to have
+         *  been realtime
+         */
         set_clip_position (o, o->pos + 1.0 / o->fps);
         frame_accum = frame_accum-1000/o->fps;
       }
diff --git a/bin/ui.h b/bin/ui.h
index 634ec2dde..fbc31b13f 100644
--- a/bin/ui.h
+++ b/bin/ui.h
@@ -313,5 +313,6 @@ char *get_item_path_no (GeState *o, int child_no);
 GeState *global_state;
 
 void populate_path_list (GeState *o);
+void set_clip_position (GeState *o, double position);
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]