[pitivi] render: Allow using the project's framerate Fixes #489



commit 67194eadad70b25e7fd6a3df2957671b9ccce5ce
Author: Ayush Mittal <ayush mittal9398 gmail com>
Date:   Sun Apr 5 22:06:26 2020 +0530

    render: Allow using the project's framerate
    Fixes #489

 pitivi/render.py    | 11 +++++++++--
 pitivi/utils/ui.py  | 50 +++++++++++++++++++++++++++++++++++---------------
 tests/test_utils.py | 23 +++++++++++++++++++++++
 3 files changed, 67 insertions(+), 17 deletions(-)
---
diff --git a/pitivi/render.py b/pitivi/render.py
index 7894d3f9..ef72a2c1 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -37,6 +37,7 @@ from pitivi.utils.ripple_update_group import RippleUpdateGroup
 from pitivi.utils.ui import AUDIO_CHANNELS
 from pitivi.utils.ui import AUDIO_RATES
 from pitivi.utils.ui import beautify_eta
+from pitivi.utils.ui import create_frame_rates_model
 from pitivi.utils.ui import FRAME_RATES
 from pitivi.utils.ui import get_combo_value
 from pitivi.utils.ui import set_combo_value
@@ -451,7 +452,6 @@ class RenderDialog(Loggable):
         self.preferred_aencoder = self.project.aencoder
         self.__replaced_assets = {}
 
-        self.frame_rate_combo.set_model(FRAME_RATES)
         self.channels_combo.set_model(AUDIO_CHANNELS)
         self.sample_rate_combo.set_model(AUDIO_RATES)
         self.__initialize_muxers_model()
@@ -639,6 +639,9 @@ class RenderDialog(Loggable):
     def _display_settings(self):
         """Applies the project settings to the UI."""
         # Video settings
+        fr_datum = (self.project.videorate.num, self.project.videorate.denom)
+        model = create_frame_rates_model(fr_datum)
+        self.frame_rate_combo.set_model(model)
         set_combo_value(self.frame_rate_combo, self.project.videorate)
 
         # Audio settings
@@ -799,10 +802,13 @@ class RenderDialog(Loggable):
         template = [t for t in factory.get_static_pad_templates()
                     if t.direction == Gst.PadDirection.SINK][0]
 
+        fr_datum = (self.project.videorate.num, self.project.videorate.denom)
+        model = create_frame_rates_model(fr_datum)
+
         caps = template.static_caps.get()
         self._update_valid_restriction_values(
             caps, self.frame_rate_combo,
-            "video/x-raw,framerate=(GstFraction)%d/%d", FRAME_RATES,
+            "video/x-raw,framerate=(GstFraction)%d/%d", model,
             self.project.videorate,
             caps_template_expander=fraction_expander_func)
 
@@ -1212,6 +1218,7 @@ class RenderDialog(Loggable):
         from pitivi.project import ProjectSettingsDialog
         dialog = ProjectSettingsDialog(self.window, self.project, self.app)
         dialog.window.run()
+        self._display_settings()
 
     def _audio_output_checkbutton_toggled_cb(self, unused_audio):
         self._update_audio_widgets_sensitivity()
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index ffdbb43d..24e9f25b 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -770,6 +770,27 @@ def create_model(columns, data):
     return ret
 
 
+def create_frame_rates_model(*extra_frames):
+    """Create a framerate model from the list of standard frames list and extra frames(if any).
+
+    Args:
+        extra_frames (tuple): extra frames to include in model.
+    """
+    final_list = list(standard_frames_list)
+    for frame in extra_frames:
+        if frame not in final_list:
+            final_list.append(frame)
+    final_list.sort(key=lambda x: x[0] / x[1])
+
+    items = []
+    for fps in final_list:
+        fraction = Gst.Fraction(*fps)
+        item = (format_framerate(fraction), fraction)
+        items.append(item)
+
+    return create_model((str, object), items)
+
+
 def set_combo_value(combo, value):
     def select_specific_row(model, unused_path, iter_, found):
         model_value = model.get_value(iter_, 1)
@@ -845,21 +866,20 @@ AUDIO_CHANNELS = create_model((str, int),
                               [(format_audiochannels(ch), ch)
                                for ch in (8, 6, 4, 2, 1)])
 
-FRAME_RATES = create_model((str, object),
-                           [(format_framerate(Gst.Fraction(*fps)), Gst.Fraction(*fps)) for fps in (
-                               (12, 1),
-                               (15, 1),
-                               (20, 1),
-                               (24000, 1001),
-                               (24, 1),
-                               (25, 1),
-                               (30000, 1001),
-                               (30, 1),
-                               (50, 1),
-                               (60000, 1001),
-                               (60, 1),
-                               (120, 1)
-                           )])
+standard_frames_list = [(12, 1),
+                        (15, 1),
+                        (20, 1),
+                        (24000, 1001),
+                        (24, 1),
+                        (25, 1),
+                        (30000, 1001),
+                        (30, 1),
+                        (50, 1),
+                        (60000, 1001),
+                        (60, 1),
+                        (120, 1)
+                        ]
+FRAME_RATES = create_frame_rates_model()
 
 AUDIO_RATES = create_model((str, int),
                            [(format_audiorate(rate), rate) for rate in (
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 20008c0c..3b73cec8 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -29,6 +29,7 @@ from pitivi.check import GtkDependency
 from pitivi.utils.misc import fixate_caps_with_default_values
 from pitivi.utils.ui import beautify_last_updated_timestamp
 from pitivi.utils.ui import beautify_length
+from pitivi.utils.ui import create_frame_rates_model
 from pitivi.utils.ui import format_audiochannels
 from pitivi.utils.ui import format_audiorate
 from pitivi.utils.ui import format_framerate_value
@@ -271,3 +272,25 @@ class TestColors(common.TestCase):
         self.assertEqual(
             (0x01FF, 0x02FF, 0x04FF, 0x08FF),
             unpack_color_64(0x01FF02FF04FF08FF))
+
+
+class TestCreateFramerateModel(common.TestCase):
+
+    def test_create_framerate_model(self):
+        model = create_frame_rates_model((25, 2), (130, 1))
+        sorted_frameslist = [(12, 1),
+                             (25, 2),
+                             (15, 1),
+                             (20, 1),
+                             (24000, 1001),
+                             (24, 1),
+                             (25, 1),
+                             (30000, 1001),
+                             (30, 1),
+                             (50, 1),
+                             (60000, 1001),
+                             (60, 1),
+                             (120, 1),
+                             (130, 1)
+                             ]
+        self.assertListEqual([(row[1].num, row[1].denom) for row in model], sorted_frameslist)


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