Skip to content

plugin

ClipLoader

Bases: LoaderPlugin

A basic clip loader for Flame

This will implement the basic behavior for a loader to inherit from that will containerize the reference and will implement the remove and update logic.

Source code in client/ayon_flame/api/plugin.py
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
class ClipLoader(LoaderPlugin):
    """A basic clip loader for Flame

    This will implement the basic behavior for a loader to inherit from that
    will containerize the reference and will implement the `remove` and
    `update` logic.

    """
    log = log

    options = [
        qargparse.Boolean(
            "handles",
            label="Set handles",
            default=0,
            help="Also set handles to clip as In/Out marks"
        )
    ]

    _mapping = None
    _host_settings = None

    @classmethod
    def apply_settings(cls, project_settings):

        plugin_type_settings = (
            project_settings
            .get("flame", {})
            .get("load", {})
        )

        if not plugin_type_settings:
            return

        plugin_name = cls.__name__

        plugin_settings = None
        # Look for plugin settings in host specific settings
        if plugin_name in plugin_type_settings:
            plugin_settings = plugin_type_settings[plugin_name]

        if not plugin_settings:
            return

        print(">>> We have preset for {}".format(plugin_name))
        for option, value in plugin_settings.items():
            if option == "enabled" and value is False:
                print("  - is disabled by preset")
            elif option == "representations":
                continue
            else:
                print("  - setting `{}`: `{}`".format(option, value))
            setattr(cls, option, value)

    def get_colorspace(self, context):
        """Get colorspace name

        Look either to version data or representation data.

        Args:
            context (dict): version context data

        Returns:
            str: colorspace name or None
        """
        version_entity = context["version"]
        version_attributes = version_entity["attrib"]
        colorspace = version_attributes.get("colorSpace")

        if (
            not colorspace
            or colorspace == "Unknown"
        ):
            colorspace = context["representation"]["data"].get(
                "colorspace")

        return colorspace

    @classmethod
    def get_native_colorspace(cls, input_colorspace):
        """Return native colorspace name.

        Args:
            input_colorspace (str | None): colorspace name

        Returns:
            str: native colorspace name defined in mapping or None
        """
        # TODO: rewrite to support only pipeline's remapping
        if not cls._host_settings:
            cls._host_settings = get_current_project_settings()["flame"]

        # [Deprecated] way of remapping
        if not cls._mapping:
            mapping = (
                cls._host_settings["imageio"]["profilesMapping"]["inputs"])
            cls._mapping = {
                input["ocioName"]: input["flameName"]
                for input in mapping
            }

        native_name = cls._mapping.get(input_colorspace)

        if not native_name:
            native_name = get_remapped_colorspace_to_native(
                input_colorspace, "flame", cls._host_settings["imageio"])

        return native_name

    def _get_formatting_data(self, context, options):
        return deepcopy(context["representation"]["context"])

    def load(self, context, name, namespace, options):
        # get flame objects
        fproject = flame.project.current_project
        self.fpd = fproject.current_workspace.desktop

        # load clip to timeline and get main variables
        version_entity = context["version"]
        representation_name = context["representation"]["name"]
        project_name = context["project"]["name"]

        repre_context = deepcopy(
            context["representation"]["context"]
        )
        if not repre_context.get("output"):
            repre_context["output"] = repre_context["representation"]

        clip_name = StringTemplate(self.clip_name_template).format(
            repre_context
        )

        # create workfile path
        workfile_dir = os.environ["AYON_WORKDIR"]
        openclip_dir = os.path.join(
            workfile_dir, clip_name
        )
        openclip_path = os.path.join(
            openclip_dir, clip_name + ".clip"
        )
        if not os.path.exists(openclip_dir):
            os.makedirs(openclip_dir)

        clip_solver = OpenClipSolver(
            openclip_path, self.layer_rename_patterns
        )
        rename_clip = clip_solver.out_clip_data is None
        if not version_entity["taskId"]:
            all_versions = [version_entity]
        else:
            all_versions = ayon_api.get_versions(
                project_name,
                product_ids=[version_entity["productId"]],
                task_ids=[version_entity["taskId"]],
            )

        repres_by_version_id = {
            version["id"]: None
            for version in all_versions
        }
        for repre_entity in ayon_api.get_representations(
             project_name,
             representation_names={representation_name},
             version_ids=set(repres_by_version_id),
         ):
             version_id = repre_entity["versionId"]
             repres_by_version_id[version_id] = repre_entity

        for version in all_versions:
            representation = repres_by_version_id[version["id"]]

            version_context = deepcopy(context)
            version_context["version"] = version
            version_context["representation"] = representation

            version_name = version["name"]
            colorspace = self.get_colorspace(version_context)

            layer_rename_template = self.layer_rename_template

            # in case output is not in context replace key to representation
            if not representation["context"].get("output"):
                layer_rename_template = self.layer_rename_template.replace(
                    "output", "representation"
                )

            # convert colorspace with ocio to flame mapping
            # in imageio flame section
            colorspace = self.get_native_colorspace(colorspace)

            # prepare clip data from context ad send it to openClipLoader
            path = self.filepath_from_context(version_context)

            clip_solver.add_feed(
                path,
                version_name,
                colorspace,
                representation["context"],
                layer_rename_template,
            )

        clip_solver.set_current_version(
            f"v{version_entity['version']:03}"
        )

        clip_solver.write()

        # prepare Reel group in actual desktop
        opc = self._get_clip(
            clip_name,
            openclip_path
        )

        if len(all_versions) == 1 and rename_clip:
            opc.name = f"{clip_name} [v{version_entity['version']:03}]"
        else:
            opc.name = clip_name

        if not version_entity["taskId"]:
            flame.messages.show_in_dialog(
                "Import Warning",
                (
                    "Version doesn't have set task."
                    "\nUnable to import any other versions alongside"
                    " the current selection."
                    "\nThis may result in unordered versions within the"
                    " clip. Deleting the clip and reloading it will resolve"
                    " this issue."
                ),
                "warning",
                ["OK"],
            )

        return opc

    def _get_clip(self, name, clip_path):
        reel = self._get_reel()
        # with maintained openclip as opc
        for cl in reel.clips:
            if cl.name.get_value().startswith(name):
                return cl

        created_clips = flame.import_clips(str(clip_path), reel)
        return created_clips.pop()

    def _get_reel(self):
        raise NotImplementedError()

get_colorspace(context)

Get colorspace name

Look either to version data or representation data.

Parameters:

Name Type Description Default
context dict

version context data

required

Returns:

Name Type Description
str

colorspace name or None

Source code in client/ayon_flame/api/plugin.py
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
def get_colorspace(self, context):
    """Get colorspace name

    Look either to version data or representation data.

    Args:
        context (dict): version context data

    Returns:
        str: colorspace name or None
    """
    version_entity = context["version"]
    version_attributes = version_entity["attrib"]
    colorspace = version_attributes.get("colorSpace")

    if (
        not colorspace
        or colorspace == "Unknown"
    ):
        colorspace = context["representation"]["data"].get(
            "colorspace")

    return colorspace

get_native_colorspace(input_colorspace) classmethod

Return native colorspace name.

Parameters:

Name Type Description Default
input_colorspace str | None

colorspace name

required

Returns:

Name Type Description
str

native colorspace name defined in mapping or None

Source code in client/ayon_flame/api/plugin.py
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
@classmethod
def get_native_colorspace(cls, input_colorspace):
    """Return native colorspace name.

    Args:
        input_colorspace (str | None): colorspace name

    Returns:
        str: native colorspace name defined in mapping or None
    """
    # TODO: rewrite to support only pipeline's remapping
    if not cls._host_settings:
        cls._host_settings = get_current_project_settings()["flame"]

    # [Deprecated] way of remapping
    if not cls._mapping:
        mapping = (
            cls._host_settings["imageio"]["profilesMapping"]["inputs"])
        cls._mapping = {
            input["ocioName"]: input["flameName"]
            for input in mapping
        }

    native_name = cls._mapping.get(input_colorspace)

    if not native_name:
        native_name = get_remapped_colorspace_to_native(
            input_colorspace, "flame", cls._host_settings["imageio"])

    return native_name

FlameCreator

Bases: Creator

Creator class wrapper

Source code in client/ayon_flame/api/plugin.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class FlameCreator(Creator):
    """Creator class wrapper
    """
    skip_discovery = True
    settings_category = "flame"

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.project = flib.get_current_project()

    def create(self, product_name, instance_data, pre_create_data):
        """Prepare data for new instance creation.

        Args:
            product_name(str): Product name of created instance.
            instance_data(dict): Base data for instance.
            pre_create_data(dict): Data based on pre creation attributes.
                Those may affect how creator works.
        """
        instance_data["flame_context"] = flib.CTX.context
        selected = pre_create_data.get("use_selection", False)
        self.selected = flib.get_clips_in_reels(
            self.project,
            selected=selected
        )

create(product_name, instance_data, pre_create_data)

Prepare data for new instance creation.

Parameters:

Name Type Description Default
product_name str

Product name of created instance.

required
instance_data dict

Base data for instance.

required
pre_create_data dict

Data based on pre creation attributes. Those may affect how creator works.

required
Source code in client/ayon_flame/api/plugin.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def create(self, product_name, instance_data, pre_create_data):
    """Prepare data for new instance creation.

    Args:
        product_name(str): Product name of created instance.
        instance_data(dict): Base data for instance.
        pre_create_data(dict): Data based on pre creation attributes.
            Those may affect how creator works.
    """
    instance_data["flame_context"] = flib.CTX.context
    selected = pre_create_data.get("use_selection", False)
    self.selected = flib.get_clips_in_reels(
        self.project,
        selected=selected
    )

FlameEditorialCreator

Bases: FlameCreator

Creator class wrapper for Editorial usage.

Source code in client/ayon_flame/api/plugin.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class FlameEditorialCreator(FlameCreator):
    """Creator class wrapper for Editorial usage.
    """
    skip_discovery = True

    def create(self, product_name, instance_data, pre_create_data):
        """Prepare data for new instance creation.

        Args:
            product_name(str): Product name of created instance.
            instance_data(dict): Base data for instance.
            pre_create_data(dict): Data based on pre creation attributes.
                Those may affect how creator works.
        """
        super().create(product_name, instance_data, pre_create_data)
        self.sequence = flib.get_current_sequence(flib.CTX.selection)
        selected = pre_create_data.get("use_selection", False)
        self.selected = flib.get_sequence_segments(
            self.sequence,
            selected=selected,
        )

create(product_name, instance_data, pre_create_data)

Prepare data for new instance creation.

Parameters:

Name Type Description Default
product_name str

Product name of created instance.

required
instance_data dict

Base data for instance.

required
pre_create_data dict

Data based on pre creation attributes. Those may affect how creator works.

required
Source code in client/ayon_flame/api/plugin.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def create(self, product_name, instance_data, pre_create_data):
    """Prepare data for new instance creation.

    Args:
        product_name(str): Product name of created instance.
        instance_data(dict): Base data for instance.
        pre_create_data(dict): Data based on pre creation attributes.
            Those may affect how creator works.
    """
    super().create(product_name, instance_data, pre_create_data)
    self.sequence = flib.get_current_sequence(flib.CTX.selection)
    selected = pre_create_data.get("use_selection", False)
    self.selected = flib.get_sequence_segments(
        self.sequence,
        selected=selected,
    )

HiddenFlameCreator

Bases: HiddenCreator

HiddenCreator class wrapper

Source code in client/ayon_flame/api/plugin.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class HiddenFlameCreator(HiddenCreator):
    """HiddenCreator class wrapper
    """
    skip_discovery = True
    settings_category = "flame"

    def collect_instances(self):
        pass

    def update_instances(self, update_list):
        pass

    def remove_instances(self, instances):
        pass

PublishableClip

Convert a segment to publishable instance

Parameters:

Name Type Description Default
segment PySegment

flame api object

required
kwargs optional

additional data needed for rename=True (presets)

required

Returns:

Type Description

flame.PySegment: flame api object

Source code in client/ayon_flame/api/plugin.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
class PublishableClip:
    """
    Convert a segment to publishable instance

    Args:
        segment (flame.PySegment): flame api object
        kwargs (optional): additional data needed for rename=True (presets)

    Returns:
        flame.PySegment: flame api object
    """
    vertical_clip_match = {}
    vertical_clip_used = {}
    marker_data = {}
    types = {
        "shot": "shot",
        "folder": "folder",
        "episode": "episode",
        "sequence": "sequence",
        "track": "sequence",
    }

    # parents search pattern
    parents_search_pattern = r"\{([a-z]*?)\}"

    # default templates for non-ui use
    rename_default = False
    hierarchy_default = "{_folder_}/{_sequence_}/{_track_}"
    clip_name_default = "shot_{_trackIndex_:0>3}_{_clipIndex_:0>4}"
    review_source_default = None
    base_product_variant_default = "<track_name>"
    product_base_type = "plate"
    product_type = product_base_type
    count_from_default = 10
    count_steps_default = 10
    vertical_sync_default = False
    driving_layer_default = ""
    index_from_segment_default = False
    use_shot_name_default = False
    include_handles_default = False
    retimed_handles_default = True
    retimed_framerange_default = True

    def __init__(
        self,
        segment: object,
        pre_create_data: dict[str, Any],
        data: dict[str, Any],
        rename_index: int,
        log: logging.Logger,
    ):
        self.rename_index = rename_index
        self.log = log
        self.pre_create_data = pre_create_data or {}

        # get main parent objects
        self.current_segment = segment
        sequence_name = flib.get_current_sequence([segment]).name.get_value()
        self.sequence_name = str(sequence_name).replace(" ", "_")
        self.clip_data = flib.get_segment_attributes(segment)

        # segment (clip) main attributes
        self.cs_name = self.clip_data["segment_name"]
        self.cs_index = int(self.clip_data["segment"])
        self.shot_name = self.clip_data["shot_name"]

        # get track name and index
        self.track_index = int(self.clip_data["track"])
        track_name = self.clip_data["track_name"]
        self.track_name = (
            # make sure no space and other special characters are in track name
            # default track name is `*`
            str(track_name)
            .replace(" ", "_")
            .replace("*", f"noname{self.track_index}")
        )

        # add publish attribute to marker data
        self.marker_data.update({"active": True})

        # adding input data if any
        if data:
            self.marker_data.update(data)

        # populate default data before we get other attributes
        self._populate_segment_default_data()

        # use all populated default data to create all important attributes
        self._populate_attributes()

        # create parents with correct types
        self._create_parents()

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

    def convert(self):

        # solve segment data and add them to marker data
        self._convert_to_marker_data()

        # if track name is in review track name and also if driving track name
        # is not in review track name: skip tag creation
        if (self.track_name in self.reviewable_source) and (
                self.driving_layer not in self.reviewable_source):
            return

        # deal with clip name
        new_name = self.marker_data.pop("newClipName")
        hierarchy_filled = self.marker_data["hierarchy"]

        if self.rename and not self.use_shot_name:
            # rename segment
            self.current_segment.name = str(new_name)
            self.marker_data.update({
                "folderName": str(new_name),
                "folderPath": f"/{hierarchy_filled}/{new_name}"
            })

        elif self.use_shot_name:
            if not self.shot_name:
                raise CreatorError(
                    f"Shot name is not set on segment: {self.cs_name}")
            self.marker_data.update({
                "folderName": self.shot_name,
                "folderPath": f"/{hierarchy_filled}/{self.shot_name}",
                "hierarchyData": {
                    "shot": self.shot_name
                }
            })
        else:
            self.marker_data.update({
                "folderName": self.cs_name,
                "folderPath": f"/{hierarchy_filled}/{self.cs_name}",
                "hierarchyData": {
                    "shot": self.cs_name
                }
            })

        return self.current_segment

    def _populate_segment_default_data(self):
        """ Populate default formatting data from segment. """

        self.current_segment_default_data = {
            "_folder_": "shots",
            "_sequence_": self.sequence_name,
            "_track_": self.track_name,
            "_clip_": self.cs_name,
            "_trackIndex_": self.track_index,
            "_clipIndex_": self.cs_index
        }

    def _populate_attributes(self):
        """ Populate main object attributes. """
        # segment frame range and parent track name for vertical sync check
        self.clip_in = int(self.clip_data["record_in"])
        self.clip_out = int(self.clip_data["record_out"])

        # define ui inputs if non gui mode was used
        self.shot_num = self.cs_index
        self.log.debug(f"____ self.shot_num: {self.shot_num}")

        # Use pre-create data or default values if gui was not used
        self.rename = self.pre_create_data.get(
            "clipRename") or self.rename_default
        self.use_shot_name = self.pre_create_data.get(
            "useShotName") or self.use_shot_name_default
        self.clip_name = self.pre_create_data.get(
            "clipName") or self.clip_name_default
        self.hierarchy = self.pre_create_data.get(
            "hierarchy") or self.hierarchy_default
        self.hierarchy_data = self.pre_create_data.get(
            "hierarchyData") or self.current_segment_default_data.copy()
        self.index_from_segment = self.pre_create_data.get(
            "segmentIndex") or self.index_from_segment_default
        self.count_from = self.pre_create_data.get(
            "countFrom") or self.count_from_default
        self.count_steps = self.pre_create_data.get(
            "countSteps") or self.count_steps_default
        self.base_product_variant = self.pre_create_data.get(
            "clipVariant") or self.base_product_variant_default
        self.product_type = (
            self.pre_create_data.get("plate_product_type")
            or self.product_base_type
        )
        self.vertical_sync = self.pre_create_data.get(
            "vSyncOn") or self.vertical_sync_default
        self.driving_layer = self.pre_create_data.get(
            "vSyncTrack") or self.driving_layer_default
        self.review_source = self.pre_create_data.get(
            "reviewableSource") or self.review_source_default
        self.audio = self.pre_create_data.get("export_audio") or False
        self.include_handles = self.pre_create_data.get(
            "includeHandles") or self.include_handles_default
        self.retimed_handles = (
            self.pre_create_data.get("retimedHandles")
            or self.retimed_handles_default
        )
        self.retimed_framerange = (
            self.pre_create_data.get("retimedFramerange")
            or self.retimed_framerange_default
        )

        # build product name from layer name
        if self.base_product_variant == "<track_name>":
            self.variant = self.track_name
        else:
            self.variant = self.base_product_variant

        # create product name for publishing
        # TODO: Use creator's `get_product_name` to correctly define name
        self.product_name = (
            f"{self.product_base_type}{self.variant.capitalize()}"
        )

        self.hierarchy_data = {
            key: self.pre_create_data.get(key)
            for key in ["folder", "episode", "sequence", "track", "shot"]
        }

    def _replace_hash_to_expression(self, name, text):
        """ Replace hash with number in correct padding. """
        _spl = text.split("#")
        _len = (len(_spl) - 1)
        _repl = "{{{0}:0>{1}}}".format(name, _len)
        return text.replace(("#" * _len), _repl)

    def _convert_to_marker_data(self):
        """ Convert internal data to marker data.

        Populating the marker data into internal variable self.marker_data
        """
        # define vertical sync attributes
        hero_track = True
        self.reviewable_source = ""

        if (
            self.vertical_sync and
            self.track_name not in self.driving_layer
        ):
            # if it is not then define vertical sync as None
            hero_track = False

        # increasing steps by index of rename iteration
        if not self.index_from_segment:
            self.count_steps *= self.rename_index

        hierarchy_formatting_data = {}
        hierarchy_data = deepcopy(self.hierarchy_data)
        _data = self.current_segment_default_data.copy()

        if self.pre_create_data:

            # backward compatibility for reviewableSource (2024.12.02)
            if "reviewTrack" in self.pre_create_data:
                _value = self.marker_data.pop("reviewTrack")
                self.marker_data["reviewableSource"] = _value

            # driving layer is set as positive match
            if hero_track or self.vertical_sync:
                # mark review layer
                if self.review_source and (
                        self.review_source != self.review_source_default):
                    # if review layer is defined and not the same as default
                    self.reviewable_source  = self.review_source

                # shot num calculate
                if self.index_from_segment:
                    # use clip index from timeline
                    self.shot_num = self.count_steps * self.cs_index
                else:
                    if self.rename_index == 0:
                        self.shot_num = self.count_from
                    else:
                        self.shot_num = self.count_from + self.count_steps

            # clip name sequence number
            _data.update({"shot": self.shot_num})

            # solve # in test to pythonic expression
            for _k, _v in hierarchy_data.items():
                if "#" not in _v:
                    continue
                hierarchy_data[_k] = self._replace_hash_to_expression(_k, _v)

            # fill up pythonic expresisons in hierarchy data
            for k, _v in hierarchy_data.items():
                hierarchy_formatting_data[k] = str(_v).format(**_data)
        else:
            # if no gui mode then just pass default data
            hierarchy_formatting_data = hierarchy_data

        tag_instance_data = self._solve_tag_instance_data(
            hierarchy_formatting_data)

        tag_instance_data.update({"heroTrack": True})
        if hero_track and self.vertical_sync:
            self.vertical_clip_match.update({
                (self.clip_in, self.clip_out): tag_instance_data
            })

        if not hero_track and self.vertical_sync:
            # driving layer is set as negative match
            for (hero_in, hero_out), hero_data in self.vertical_clip_match.items():  # noqa
                """ Iterate over all clips in vertical sync match

                If clip frame range is outside of hero clip frame range
                then skip this clip and do not add to hierarchical shared
                metadata to them.
                """

                if self.clip_in < hero_in or self.clip_out > hero_out:
                    continue

                _distrib_data = deepcopy(hero_data)
                _distrib_data["heroTrack"] = False

                # form used clip unique key
                data_product_name = hero_data["productName"]
                new_clip_name = hero_data["newClipName"]

                # get used names list for duplicity check
                used_names_list = self.vertical_clip_used.setdefault(
                    f"{new_clip_name}{data_product_name}", []
                )
                self.log.debug(
                    f">> used_names_list: {used_names_list}"
                )
                clip_product_name = self.product_name
                variant = self.variant
                self.log.debug(
                    f">> clip_product_name: {clip_product_name}")

                # in case track name and product name is the same then add
                if self.variant == self.track_name:
                    clip_product_name = self.product_name

                # add track index in case duplicity of names in hero data
                # INFO: this is for case where hero clip product name
                #    is the same as current clip product name
                if clip_product_name in data_product_name:
                    clip_product_name = (
                        f"{clip_product_name}{self.track_index}")
                    variant = f"{variant}{self.track_index}"

                # in case track clip product name had been already used
                # then add product name with clip index
                if clip_product_name in used_names_list:
                    _clip_product_name = (
                        f"{clip_product_name}{self.cs_index}"
                    )
                    # just in case lets validate if new name is not used
                    # in case the track_index is the same as clip_index
                    if _clip_product_name in used_names_list:
                        _clip_product_name = (
                            f"{clip_product_name}"
                            f"{self.track_index}{self.cs_index}"
                        )
                    clip_product_name = _clip_product_name
                    variant = f"{variant}{self.cs_index}"

                self.log.debug(
                    f">> clip_product_name: {clip_product_name}")
                _distrib_data["productName"] = clip_product_name
                _distrib_data["variant"] = variant
                # assign data to return hierarchy data to tag
                tag_instance_data = _distrib_data

                # add used product name to used list to avoid duplicity
                used_names_list.append(clip_product_name)
                break

        # add data to return data dict
        self.marker_data.update(tag_instance_data)

        # add review track only to hero track
        if hero_track and self.reviewable_source:
            self.marker_data["reviewTrack"] = self.reviewable_source
        else:
            self.marker_data["reviewTrack"] = None

        # add only review related data if reviewable source is set
        if self.reviewable_source:
            review_switch = True
            reviewable_source = self.reviewable_source

            if self.vertical_sync and not hero_track:
                review_switch = False
                reviewable_source = False

            if review_switch:
                self.marker_data["review"] = True
            else:
                self.marker_data.pop("review", None)

            self.marker_data["reviewableSource"] = reviewable_source

    def _solve_tag_instance_data(self, hierarchy_formatting_data):
        """ Solve marker data from hierarchy data and templates. """
        # fill up clip name and hierarchy keys
        hierarchy_filled = self.hierarchy.format(**hierarchy_formatting_data)
        clip_name_filled = self.clip_name.format(**hierarchy_formatting_data)

        # remove shot from hierarchy data: is not needed anymore
        hierarchy_formatting_data.pop("shot")

        return {
            "newClipName": clip_name_filled,
            "hierarchy": hierarchy_filled,
            "parents": self.parents,
            "hierarchyData": hierarchy_formatting_data,
            "productName": self.product_name,
            "productType": self.product_type,
            "productBaseType": self.product_base_type,
            "variant": self.variant,
        }

    def _convert_to_entity(self, src_type, template):
        """ Converting input key to key with type. """
        # convert to entity type
        folder_type = self.types.get(src_type, None)

        assert folder_type, "Missing folder type for `{}`".format(
            src_type
        )

        # first collect formatting data to use for formatting template
        formatting_data = {}
        for _k, _v in self.hierarchy_data.items():
            value = str(_v).format(
                **self.current_segment_default_data)
            formatting_data[_k] = value

        return {
            "folder_type": folder_type,
            "entity_name": template.format(
                **formatting_data
            )
        }

    def _create_parents(self):
        """ Create parents and return it in list. """
        self.parents = []

        pattern = re.compile(self.parents_search_pattern)

        par_split = [(pattern.findall(t).pop(), t)
                     for t in self.hierarchy.split("/")]

        for type, template in par_split:
            parent = self._convert_to_entity(type, template)
            self.parents.append(parent)