def test_serialize_chromakey_effect_to_dictionary(): effect = ChromaKeyEffect( defringe=0.3, inverted=True, softness=0.2, tolerance=0.05, hue=RGBA( red=255, green=127, blue=63, alpha=31, ), ) schema = EffectSchema() actual = schema.dump(effect) pprint(actual) expected = { 'effectName': 'ChromaKey', 'category': 'categoryVisualEffects', 'parameters': { 'clrCompensation': 0.0, 'color-alpha': 0.12156862745098039, 'color-blue': 0.24705882352941178, 'color-green': 0.4980392156862745, 'color-red': 1.0, 'defringe': 0.3, 'enabled': 1, 'invertEffect': 1.0, 'softness': 0.2, 'tolerance': 0.05, } } assert actual == expected
def __setitem__(self, index, effect): effect_schema = EffectSchema() effect_data = effect_schema.dump(effect) self._effects.insert(index, effect_data) for key in effect.metadata: del self._metadata[key] self._metadata.update(effect.metadata) del self._effects[index + 1]
def _image_record(self, bin_media, start, duration, effects=None): if effects is None: effects = [] effect_schema = EffectSchema() return { "id": self._next_media_id(), "_type": "IMFile", "src": bin_media.id, "trackNumber": 0, "trimStartSum": 0, "attributes": { "ident": bin_media.identity }, "parameters": { "scale0": { "type": "double", "defaultValue": 1.0, "interp": "eioe" }, "scale1": { "type": "double", "defaultValue": 1.0, "interp": "eioe" } }, "effects": [ effect_schema.dump(effect) for effect in effects ], "start": start, "duration": 150 if duration is None else duration, "mediaStart": bin_media.range[0].to_frame(), "mediaDuration": bin_media.range[1].to_frame(), "scalar": 1, "metadata": dict(ChainMap( { "clipSpeedAttribute": False, "default-scale": "1.0", "effectApplied": "none" if len(effects) == 0 else effects[-1].name, }, *(effect.metadata for effect in effects) )), "animationTracks": { } }
def test_serialize_default_chromakey_effect_to_dictionary(): effect = ChromaKeyEffect() schema = EffectSchema() actual = schema.dump(effect) pprint(actual) expected = { 'effectName': 'ChromaKey', 'category': 'categoryVisualEffects', 'parameters': { 'clrCompensation': 0.0, 'color-alpha': 1.0, 'color-blue': 0.0, 'color-green': 1.0, 'color-red': 0.0, 'defringe': 0.0, 'enabled': 1, 'invertEffect': 0.0, 'softness': 0.1, 'tolerance': 0.1, } } assert actual == expected
def _audio_record(self, bin_media, start, duration, effects): duration = bin_media.range[1].to_frame() if duration is None else duration if duration > bin_media.range[1].to_frame(): return self._stiched_video_record(bin_media, start, duration) if effects is None: effects = [] effect_schema = EffectSchema() return { "id": self._next_media_id(), "_type": "AMFile", "src": bin_media.id, "trackNumber": 0, # TODO: Is this correct? What is this? "attributes": { "ident": bin_media.identity, "gain": 1.0, "mixToMono": False, "channelNumber": "0,1" }, "effects": [ ], "start": start, "duration": duration, "mediaStart": bin_media.range[0].to_frame(), "mediaDuration": duration, "scalar": 1, "metadata": dict(ChainMap( { "clipSpeedAttribute": False, "effectApplied": "none" if len(effects) == 0 else effects[-1].name, }, *(effect.metadata for effect in effects) )), "animationTracks": { } }
def _video_record(self, bin_media, start, duration, effects): duration = bin_media.range[1].to_frame() if duration is None else duration if duration > bin_media.range[1].to_frame(): return self._stiched_video_record(bin_media, start, duration) if effects is None: effects = [] effect_schema = EffectSchema() return { "id": self._next_media_id(), "_type": "ScreenVMFile", "src": bin_media.id, "trackNumber": 0, # TODO: Is this correct? What is this? "attributes": { "ident": bin_media.identity }, "parameters": { "scale0": { "type": "double", "defaultValue": 1.0, "interp": "eioe" }, "scale1": { "type": "double", "defaultValue": 1.0, "interp": "eioe" }, "cursorScale": { "type": "double", "defaultValue": 1.0, "interp": "linr" }, "cursorOpacity": { "type": "double", "defaultValue": 1.0, "interp": "linr" } }, "effects": [ effect_schema.dump(effect) for effect in effects ], "start": start, "duration": duration, "mediaStart": bin_media.range[0].to_frame(), "mediaDuration": duration, "scalar": 1, "metadata": dict(ChainMap( { "clipSpeedAttribute": False, "default-scale": "1.0", "effectApplied": "none" if len(effects) == 0 else effects[-1].name, }, *(effect.metadata for effect in effects) )), "animationTracks": { } }
def __getitem__(self, index): effect_data = self._effects[index] effect_schema = EffectSchema() effect = effect_schema.load(effect_data) return effect
def add_effect(self, effect): effect_schema = EffectSchema() effect_data = effect_schema.dump(effect) self._effects.append(effect_data) self._metadata.update(effect.metadata)
def test_roundtrip_default_chromakey_effect(): effect = ChromaKeyEffect() schema = EffectSchema() serialized = schema.dump(effect) loaded_effect = schema.load(serialized) assert loaded_effect == effect