|
41 | 41 | from classes.assets import get_assets_path
|
42 | 42 | from windows.views.find_file import find_missing_file
|
43 | 43 |
|
| 44 | +from .keyframe_scaler import KeyframeScaler |
| 45 | + |
44 | 46 |
|
45 | 47 | class ProjectDataStore(JsonDataStore, UpdateInterface):
|
46 | 48 | """ This class allows advanced searching of data structure, implements changes interface """
|
@@ -394,65 +396,16 @@ def load(self, file_path, clear_thumbnails=True):
|
394 | 396 | from classes.app import get_app
|
395 | 397 | get_app().updates.load(self._data)
|
396 | 398 |
|
397 |
| - def scale_keyframe_value(self, original_value, scale_factor): |
398 |
| - """Scale keyframe X coordinate by some factor, except for 1 (leave that alone)""" |
399 |
| - if original_value == 1.0: |
400 |
| - # This represents the first frame of a clip (so we want to maintain that) |
401 |
| - return original_value |
402 |
| - else: |
403 |
| - # Round to nearest INT |
404 |
| - return round(original_value * scale_factor) |
405 |
| - |
406 | 399 | def rescale_keyframes(self, scale_factor):
|
407 | 400 | """Adjust all keyframe coordinates from previous FPS to new FPS (using a scale factor)
|
408 | 401 | and return scaled project data without modifing the current project."""
|
409 |
| - log.info('Scale all keyframes by a factor of %s' % scale_factor) |
410 |
| - |
411 |
| - # Create copy of active project data |
412 |
| - data = copy.deepcopy(self._data) |
413 |
| - |
414 |
| - # Rescale the the copied project data |
415 |
| - # Loop through all clips (and look for Keyframe objects) |
416 |
| - # Scale the X coordinate by factor (which represents the frame #) |
417 |
| - for clip in data.get('clips', []): |
418 |
| - for attribute in clip: |
419 |
| - if type(clip.get(attribute)) == dict and "Points" in clip.get(attribute): |
420 |
| - for point in clip.get(attribute).get("Points"): |
421 |
| - if "co" in point: |
422 |
| - point["co"]["X"] = self.scale_keyframe_value(point["co"].get("X", 0.0), scale_factor) |
423 |
| - if type(clip.get(attribute)) == dict and "red" in clip.get(attribute): |
424 |
| - for color in clip.get(attribute): |
425 |
| - for point in clip.get(attribute).get(color).get("Points"): |
426 |
| - if "co" in point: |
427 |
| - point["co"]["X"] = self.scale_keyframe_value(point["co"].get("X", 0.0), scale_factor) |
428 |
| - for effect in clip.get("effects", []): |
429 |
| - for attribute in effect: |
430 |
| - if type(effect.get(attribute)) == dict and "Points" in effect.get(attribute): |
431 |
| - for point in effect.get(attribute).get("Points"): |
432 |
| - if "co" in point: |
433 |
| - point["co"]["X"] = self.scale_keyframe_value(point["co"].get("X", 0.0), scale_factor) |
434 |
| - if type(effect.get(attribute)) == dict and "red" in effect.get(attribute): |
435 |
| - for color in effect.get(attribute): |
436 |
| - for point in effect.get(attribute).get(color).get("Points"): |
437 |
| - if "co" in point: |
438 |
| - point["co"]["X"] = self.scale_keyframe_value(point["co"].get("X", 0.0), scale_factor) |
439 |
| - |
440 |
| - # Loop through all effects/transitions (and look for Keyframe objects) |
441 |
| - # Scale the X coordinate by factor (which represents the frame #) |
442 |
| - for effect in data.get('effects', []): |
443 |
| - for attribute in effect: |
444 |
| - if type(effect.get(attribute)) == dict and "Points" in effect.get(attribute): |
445 |
| - for point in effect.get(attribute).get("Points"): |
446 |
| - if "co" in point: |
447 |
| - point["co"]["X"] = self.scale_keyframe_value(point["co"].get("X", 0.0), scale_factor) |
448 |
| - if type(effect.get(attribute)) == dict and "red" in effect.get(attribute): |
449 |
| - for color in effect.get(attribute): |
450 |
| - for point in effect.get(attribute).get(color).get("Points"): |
451 |
| - if "co" in point: |
452 |
| - point["co"]["X"] = self.scale_keyframe_value(point["co"].get("X", 0.0), scale_factor) |
453 |
| - |
454 |
| - # return the copied and scaled project data |
455 |
| - return data |
| 402 | + # |
| 403 | + log.info('Scale all keyframes by a factor of %s', scale_factor) |
| 404 | + # Create a scaler instance |
| 405 | + scaler = KeyframeScaler(factor=scale_factor) |
| 406 | + # Create copy of active project data and scale |
| 407 | + scaled = scaler(copy.deepcopy(self._data)) |
| 408 | + return scaled |
456 | 409 |
|
457 | 410 | def read_legacy_project_file(self, file_path):
|
458 | 411 | """Attempt to read a legacy version 1.x openshot project file"""
|
|
0 commit comments