def list_track_indexes_with_matching_title(regex): """ List the existing tracks with a name matching to the given regex """ return [ i for i in range(mc.shotTrack(numTracks=True, query=True), 0, -1) if re.findall(regex, mc.shotTrack(track=i, query=True, title=True)) ]
def find_track_index(track_title): """ Find the first track holding the given title. :param str track_title: :rtype: int """ for i in range(mc.shotTrack(numTracks=True, query=True), 0, -1): if mc.shotTrack(track=i, query=True, title=True) == track_title: return i
def append_sequencer_track(title=""): """ Append a track at the end of the camera sequencer. :param str title: Name of the track. :rtype: int :return: Index of the created track. """ index = mc.shotTrack(numTracks=True, query=True) + 1 mc.shotTrack(insertTrack=index, title=title) return index
def remove_unused_sequencer_tracks(): """ For some reasons, mc.shotTrack(removeEmptyTracks=True) doesn't remove any track. This function do that. """ used_tracks_indexes = list_used_sequencer_track_indexes() for i in range(mc.shotTrack(numTracks=True, query=True), 0, -1): if i in used_tracks_indexes: continue mc.shotTrack(removeTrack=i)
def list_track_titles(): """ List all the track titles sorted by index. :rtype: list[str] """ tracks = mc.shotTrack(query=True, numTracks=True) return [ mc.shotTrack(track=i, query=True, title=True) for i in range(1, tracks + 1) ]
def clear_sequencer_track_shots(index): """ Remove all shots found on the corresponding to the given index :param int index: """ shots = [ shot for shot in mc.ls(type="shot") if mc.getAttr(shot + ".track") == index ] for shot in shots: mc.shot(shot, edit=True, lock=False) mc.delete(shots) mc.shotTrack(removeTrack=index)
def tracks_to_lists(): """ Convert tracks to lists of shot. Create a shot list by track. :rtype: list[list[str]] """ shots = mc.ls(type="shot") tracks = [[]] * mc.shotTrack(query=True, numTracks=True) for shot in shots: # Tracks count start at 1 instead of 0. track = mc.getAttr(shot + ".track") - 1 tracks[track].append(shot) return tracks
def _readTrack(self, track, isVideo): track_info = self.translator.getTrack(track) # Ensure that track frame rate matches sequence frame rate self._checkFrameRates(track, track_info) trackNum = 0 if isVideo: trackNum = cmds.shotTrack(q=1, numTracks=1) + 1 else: trackNum = cmds.audioTrack(q=1, numTracks=1) + 1 locked = track_info.get("locked", False) # Precompute the real start, stop and centers for every clipItem # these aren't necessarily the one read from the file when transition clips are involved # in these cases values are always -1 transitions = [ ] #boolean that indicates if the clip at index is a clip or a transition starts = [] ends = [] alignments = [ ] # alignment value read from the XML file, valid only for transitions in_adjustments = [ ] # media offset that must be apply to the right due to the removal of overlaps # Initialise the starts and ends with the XML file values for clip in track_info["clip_list"]: isTransition, start, end, alignment = self._getTransitionInfo(clip) transitions.append(isTransition) starts.append(start) ends.append(end) alignments.append(alignment) in_adjustments.append(0.0) # Find the transition clips and check how they should be applied for i, clip in enumerate(track_info["clip_list"]): if transitions[i]: # defermine on which side(s) the clip should be applied the fix applyLeft = False applyRight = False if i > 0 and ends[i - 1] == -1: applyLeft = True if i < len(starts) - 1 and starts[i + 1] == -1: applyRight = True # Compute a transiton time matching the determine the transition alignment transitionTime = 0 if alignments[i] == "center": transitionTime = float(int((ends[i] + starts[i]) / 2)) elif alignments[i] == "start-black" or alignments[i] == "start": transitionTime = starts[i] elif alignments[i] == "end-black" or alignments[i] == "end": transitionTime = ends[i] elif applyLeft and applyRight: transitionTime = float(int((ends[i] + starts[i]) / 2)) elif applyLeft: transitionTime = ends[i] elif applyRight: transitionTime = starts[i] # apply computed transition time to prev and next clips if applyLeft: ends[i - 1] = transitionTime if applyRight: starts[i + 1] = transitionTime in_adjustments[i + 1] = transitionTime - starts[i] # Read the clips (without the transitions) for i, clip in enumerate(track_info["clip_list"]): if not transitions[i]: # we got a shot shot = self._readClip(clip, isVideo, starts[i], ends[i], in_adjustments[i]) # TODO: make sure trackNum and shot -determineTrack return the # same number! if isVideo: cmds.setAttr((shot + ".track"), int(track_info["trackNumber"])) cmds.shotTrack(shot, lock=locked) else: cmds.setAttr((shot + ".order"), trackNum)