Skip to content

Commit 68e78f0

Browse files
committed
made color an optional parameter in addMarker and added examples for making tracks for A and B
Signed-off-by: Yingjie Wang <[email protected]>
1 parent 0082c32 commit 68e78f0

File tree

2 files changed

+54
-39
lines changed

2 files changed

+54
-39
lines changed

src/py-opentimelineio/opentimelineio/console/otiodiff/clipData.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def checkSame(self, cA):
7878
# Note: check in relation to left and right?
7979
# know if moved in seq rather than everything shifted over because of lengthen/shorten of other clips
8080
isSame = True
81-
self.note = "moved"
81+
self.note = "shifted laterally in track"
8282
else:
8383
# print("source range different", cA.name, self.name)
8484
# print(self.media_ref)

src/py-opentimelineio/opentimelineio/console/otiodiff/makeOtio.py

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,29 @@
44

55
def sortClips(trackClips):
66
"""Sort ClipDatas based on start time on the timeline"""
7-
# sort by clip start time in timeline
87
return sorted(trackClips, key=lambda clipData: clipData.timeline_range.start_time.value)
98

109
def addRavenColor(clip, color):
1110
"""Add color of clip to metadata of raven so clips are correctly color-coded in raven viewer.
1211
Specific to raven only."""
13-
1412
# parses name of color from otio.core.Color and puts into format that raven can read
1513
color = color.name.upper()
1614

17-
# TODO: if raven not in metadata, add empty dict
18-
19-
if "raven" in clip.metadata:
20-
clip.metadata["raven"]["color"] = color
21-
else:
22-
colorData = {"color" : color}
23-
clip.metadata["raven"] = colorData
15+
if "raven" not in clip.metadata:
16+
clip.metadata["raven"] = {"color" : None}
17+
clip.metadata["raven"]["color"] = color
2418

2519
return clip
2620

27-
def addMarker(newClip, color, clipData):
21+
def addMarker(newClip, clipData, color=None):
2822
"""Add marker of specified color and name to clip"""
2923
newMarker = otio.schema.Marker()
3024
newMarker.marked_range = clipData.source_range
3125

3226
# parses name of color from otio.core.Color and puts into format that markers can read
33-
colorName = color.name.upper()
34-
newMarker.color = colorName
35-
36-
if(colorName == "GREEN"):
37-
newMarker.name = "added"
38-
elif(colorName == "PINK"):
39-
newMarker.name = "deleted"
27+
if color is not None:
28+
colorName = color.name.upper()
29+
newMarker.color = colorName
4030

4131
if isinstance(clipData, ClipData) and clipData.note is not None:
4232
# print("edit note added")
@@ -46,14 +36,15 @@ def addMarker(newClip, color, clipData):
4636

4737
return newClip
4838

39+
# TODO: make variables for add, edit, delete, move colors?
40+
4941
def makeSeparaterTrack(trackType):
5042
"""Make empty track that separates the timeline A tracks from the timeline B tracks"""
5143
return otio.schema.Track(name="=====================", kind=trackType)
5244

5345
def makeTrack(trackName, trackKind, trackClips, clipColor=None, markersOn=False):
5446
"""Make OTIO track from ClipDatas with option to add markers and color to all clips on track"""
55-
# make new blank track with name of kind
56-
# print("make track of kind: ", trackKind)
47+
# make new blank track with name and kind from parameters
5748
track = otio.schema.Track(name=trackName, kind=trackKind)
5849

5950
# sort clips by start time in timeline
@@ -87,54 +78,78 @@ def makeTrack(trackName, trackKind, trackClips, clipColor=None, markersOn=False)
8778
newClip = addRavenColor(newClip, clipColor)
8879
newClip.color = clipColor
8980

90-
# TODO: move out of if and make clipColor optional with default color
91-
if markersOn:
92-
newClip = addMarker(newClip, clipColor, clipData)
81+
if markersOn:
82+
newClip = addMarker(newClip, clipData, clipColor)
9383
track.append(newClip)
9484

9585
return track
9686

9787
def makeTrackB(clipGroup, trackNum, trackKind):
9888
"""Make an annotated track from timeline B. Shows added and edited clips as well as
99-
clips that have moved between tracks."""
89+
clips that have moved between tracks.
90+
91+
Algorithm makes individual tracks for each clip category the track contains,
92+
then flattens them to form the final track. Since blanks are left in all of the individual tracks,
93+
flattening should allow all clips to simmply slot down into place on the flattened track
94+
95+
Ex. track 1 has added and unchanged clips
96+
Algorithm steps:
97+
1) Make a track containing only the unchanged clips of track 1
98+
2) Make another track containing only the added clips of track 1 and color them green
99+
3) Flatten the added clips track on top of the unchanged clips track to create a track containing both
100+
"""
101+
102+
# for each category of clips, make an indivdual track and color code accordingly
103+
tSame = makeTrack("same", trackKind, clipGroup.same)
100104
tAdd = makeTrack("added", trackKind, clipGroup.add, otio.core.Color.GREEN)
101105
tEdited = makeTrack("edited", trackKind, clipGroup.edit, otio.core.Color.ORANGE, markersOn=True)
102-
tSame = makeTrack("same", trackKind, clipGroup.same)
103106
tMoved = makeTrack("moved", trackKind, clipGroup.move, otio.core.Color.PURPLE, markersOn=True)
104107

108+
# put all the tracks into a list and flatten them down to a single track that contains all the color-coded clips
109+
105110
flatB = otio.core.flatten_stack([tSame, tEdited, tAdd, tMoved])
111+
112+
# update track name and kind
106113
if trackKind == otio.schema.Track.Kind.Video:
107-
flatB.name = "Video B" + str(trackNum)
114+
flatB.name = trackKind + " B" + str(trackNum)
108115
elif trackKind == otio.schema.Track.Kind.Audio:
109-
flatB.name = "Audio B" + str(trackNum)
110-
116+
flatB.name = trackKind + " B" + str(trackNum)
111117
flatB.kind = trackKind
112118

113119
return flatB
114120

115121
def makeTrackA(clipGroup, trackNum, trackKind):
116122
"""Make an annotated track from timeline A. Shows deleted clips and the original clips
117-
corresponding to clips edited in timeline B."""
123+
corresponding to clips edited in timeline B.
124+
125+
Algorithm makes individual tracks for each clip category the track contains,
126+
then flattens them to form the final track. Since blanks are left in all of the individual tracks,
127+
flattening should allow all clips to simmply slot down into place on the flattened track
128+
129+
Ex. track 1 has deleted and unchanged clips
130+
Algorithm steps:
131+
1) Make a track containing only the unchanged clips of track 1
132+
2) Make another track containing only the deleted clips of track 1 and color them red
133+
3) Flatten the deleted clips track on top of the unchanged clips track to create a track containing both
134+
"""
135+
136+
# for each category of clips, make an indivdual track and color code accordingly
118137
tSame = makeTrack("same", trackKind, clipGroup.same)
119138
# grab the original pair from all the edit clipDatas
120-
121139
prevEdited = []
122-
prevMoved = []
123140
for e in clipGroup.edit:
124141
prevEdited.append(e.matched_clipData)
125-
tEdited = makeTrack("edited", trackKind, prevEdited, otio.core.Color.ORANGE)
126-
142+
tEdited = makeTrack("edited", trackKind, prevEdited, otio.core.Color.ORANGE)
127143
tDel = makeTrack("deleted", trackKind, clipGroup.delete, otio.core.Color.PINK)
128-
129-
# TODO: explain the make sep then merge flatten tracks thing
144+
145+
# put all the tracks into a list and flatten them down to a single track that contains all the color-coded clips
130146
flatA = otio.core.flatten_stack([tSame, tEdited, tDel])
131147

132-
# TODO: change video to directly use trackKind
148+
# update track name and kind
133149
if trackKind == otio.schema.Track.Kind.Video:
134-
flatA.name = "Video A" + str(trackNum)
150+
flatA.name = trackKind + " A" + str(trackNum)
135151
elif trackKind == otio.schema.Track.Kind.Audio:
136-
flatA.name = "Audio A" + str(trackNum)
137-
152+
flatA.name = trackKind + " A" + str(trackNum)
138153
flatA.kind = trackKind
139154

140155
return flatA

0 commit comments

Comments
 (0)