Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve create_shot_clip code readability. #50

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions client/ayon_hiero/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,6 @@ class PublishClip:
Returns:
hiero.core.TrackItem: hiero track item object with AYON tag
"""
vertical_clip_match = {}
vertical_clip_used = {}
tag_data = {}

types = {
Expand Down Expand Up @@ -696,18 +694,18 @@ class PublishClip:
"reviewableSource",
}

@classmethod
def restore_all_caches(cls):
cls.vertical_clip_match = {}
cls.vertical_clip_used = {}

def __init__(
self,
track_item,
vertical_clip_match,
vertical_clip_used,
pre_create_data=None,
data=None,
rename_index=0):

self.vertical_clip_match = vertical_clip_match
self.vertical_clip_used = vertical_clip_used

self.rename_index = rename_index

# adding ui inputs if any
Expand Down Expand Up @@ -812,6 +810,7 @@ def get(key):
self.product_type = get("productType") or self.product_type_default
self.vertical_sync = get("vSyncOn") or self.vertical_sync_default
self.driving_layer = get("vSyncTrack") or self.driving_layer_default
self.driving_layer = self.driving_layer.replace(" ", "_")
self.review_source = (
get("reviewableSource") or self.review_source_default)
self.audio = get("audio") or False
Expand Down
107 changes: 35 additions & 72 deletions client/ayon_hiero/plugins/create/create_shot_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,23 @@ def get_attr_defs_for_instance(self, instance):
disabled=True,
)
]

if self.product_type in ("audio", "plate"):
instance_attributes.append(
BoolDef(
"review",
label="Review",
tooltip="Switch to reviewable instance",
default=False,
)
)

if self.product_type == "plate":
# Review track visibility
current_review = instance.creator_attributes.get("review", False)

instance_attributes.extend(
[
BoolDef(
"review",
label="Review",
tooltip="Switch to reviewable instance",
default=False,
),
EnumDef(
"reviewableSource",
label="Reviewable Source",
Expand Down Expand Up @@ -268,57 +273,13 @@ class EditorialPlateInstanceCreator(_HieroInstanceClipCreatorBase):
product_type = "plate"
label = "Editorial Plate"

def create(self, instance_data, _):
"""Return a new CreateInstance for new shot from Resolve.

Args:
instance_data (dict): global data from original instance

Return:
CreatedInstance: The created instance object for the new shot.
"""
return super().create(instance_data, None)


class EditorialAudioInstanceCreator(_HieroInstanceClipCreatorBase):
"""Audio product type creator class"""
identifier = "io.ayon.creators.hiero.audio"
product_type = "audio"
label = "Editorial Audio"

def get_product_name(
self,
project_name,
folder_entity,
task_entity,
variant,
host_name=None,
instance=None,
project_entity=None):
return f"{self.product_type}Main"

def get_attr_defs_for_instance(self, instance):

instance_attributes = [
TextDef(
"parentInstance",
label="Linked to",
disabled=True,
)
]

instance_attributes.extend(
[
BoolDef(
"review",
label="Review",
tooltip="Switch to reviewable instance",
default=False,
),
]
)
return instance_attributes


class CreateShotClip(plugin.HieroCreator):
"""Publishable clip"""
Expand All @@ -336,8 +297,6 @@ class CreateShotClip(plugin.HieroCreator):
"""
create_allow_thumbnail = False

shot_instances = {}

def get_pre_create_attr_defs(self):

def header_label(text):
Expand Down Expand Up @@ -579,13 +538,19 @@ def create(self, subset_name, instance_data, pre_create_data):
}

instances = []
all_shot_instances = {}
vertical_clip_match = {}
vertical_clip_used = {}

for idx, track_item in enumerate(sorted_selected_track_items):
_instance_data = copy.deepcopy(instance_data)
_instance_data["clip_index"] = track_item.guid()

# convert track item to timeline media pool item
publish_clip = plugin.PublishClip(
track_item,
vertical_clip_match,
vertical_clip_used,
pre_create_data=pre_create_data,
rename_index=idx,
data=_instance_data,
Expand Down Expand Up @@ -618,7 +583,7 @@ def create(self, subset_name, instance_data, pre_create_data):

# Create new product(s) instances.
shot_folder_path = _instance_data["folderPath"]
shot_instances = self.shot_instances.setdefault(
shot_instances = all_shot_instances.setdefault(
shot_folder_path, {})

# desable shot creator if heroTrack is not enabled
Expand Down Expand Up @@ -652,25 +617,27 @@ def create(self, subset_name, instance_data, pre_create_data):
"variant": "main",
"productType": "shot",
"productName": "shotMain",
"creator_attributes": {
"workfileFrameStart": sub_instance_data[
"workfileFrameStart"
],
"handleStart": sub_instance_data["handleStart"],
"handleEnd": sub_instance_data["handleEnd"],
"frameStart": workfileFrameStart,
"frameEnd": (
workfileFrameStart + track_item_duration),
"clipIn": track_item.timelineIn(),
"clipOut": track_item.timelineOut(),
"clipDuration": track_item_duration,
"sourceIn": track_item.sourceIn(),
"sourceOut": track_item.sourceOut(),
},
"label": (
f"{sub_instance_data['folderPath']} shotMain"),
}
)
creator_attributes.update(
{
"workfileFrameStart": sub_instance_data[
"workfileFrameStart"
],
"handleStart": sub_instance_data["handleStart"],
"handleEnd": sub_instance_data["handleEnd"],
"frameStart": workfileFrameStart,
"frameEnd": (
workfileFrameStart + track_item_duration),
"clipIn": track_item.timelineIn(),
"clipOut": track_item.timelineOut(),
"clipDuration": track_item_duration,
"sourceIn": track_item.sourceIn(),
"sourceOut": track_item.sourceOut(),
}
)

# Plate, Audio
# insert parent instance data to allow
Expand Down Expand Up @@ -730,10 +697,6 @@ def create(self, subset_name, instance_data, pre_create_data):
)
instances.append(instance)

# restore all caches
plugin.PublishClip.restore_all_caches()
self.shot_instances = {}

return instances

def _create_and_add_instance(self, data, creator_id,
Expand Down
14 changes: 12 additions & 2 deletions client/ayon_hiero/plugins/publish/collect_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ def process(self, instance):
"""
# Retrieve instance data from parent instance shot instance.
parent_instance_id = instance.data["parent_instance_id"]
edit_shared_data = instance.context.data["editorialSharedData"]
shot_instance_data = edit_shared_data[parent_instance_id]

try:
edit_shared_data = instance.context.data["editorialSharedData"]
shot_instance_data = edit_shared_data[parent_instance_id]

# Ensure shot instance related to the audio instance exists.
except KeyError:
raise PublishError(
f'Could not find shot instance for {instance.data["label"]}.'
" Please ensure it is set and enabled."
)

instance.data.update(shot_instance_data)

# Adjust instance data from parent otio timeline.
Expand Down
16 changes: 12 additions & 4 deletions client/ayon_hiero/plugins/publish/collect_plates.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ def process(self, instance):

# Retrieve instance data from parent instance shot instance.
parent_instance_id = instance.data["parent_instance_id"]
edit_shared_data = instance.context.data["editorialSharedData"]

instance.data.update(
edit_shared_data[parent_instance_id]
)
try:
edit_shared_data = instance.context.data["editorialSharedData"]
instance.data.update(
edit_shared_data[parent_instance_id]
)

# Ensure shot instance related to the audio instance exists.
except KeyError:
raise PublishError(
f'Could not find shot instance for {instance.data["label"]}.'
" Please ensure it is set and enabled."
)

track_item = instance.data["item"]
clip_colorspace = track_item.sourceMediaColourTransform()
Expand Down
Loading