Example #1
0
def _remove_source_from_views(source_group):
    """
    Remove a source group from all views.
    """
    for view in commands.viewNodes():
        view_inputs = commands.nodeConnections(view)[0]
        if source_group in view_inputs:
            view_inputs.remove(source_group)
            commands.setNodeInputs(view, view_inputs)
Example #2
0
 def menu_state_add_audio(self):
     """Return current state of the 'Add Audio to Sequence' menu item."""
     # If the user is currently viewing a sequence with any inputs, enable the menu item.
     current_view = commands.viewNode()
     if commands.nodeType(current_view) == "RVSequenceGroup":
         inputs, _ = commands.nodeConnections(current_view, True)
         if inputs:
             return commands.NeutralMenuState
     return commands.DisabledMenuState
Example #3
0
    def expand_sources(self):
        """
        Expand any movie movieproc otioFile sources.
        """
        # disable caching for load speed
        cache_mode = commands.cacheMode()
        commands.setCacheMode(commands.CacheOff)

        try:
            # find sources with a movieproc with an otioFile=foo.otio tag
            default_inputs, _ = commands.nodeConnections('defaultSequence')
            for src in commands.nodesOfType('RVSource'):
                src_group = commands.nodeGroup(src)
                if src_group not in default_inputs:
                    # not in default sequence, already processed
                    continue

                # get the source file name
                paths = [
                    info['file'] for info in commands.sourceMediaInfoList(src)
                    if 'file' in info
                ]
                for info_path in paths:
                    # Looking for: 'blank,otioFile=/foo.otio.movieproc'
                    parts = info_path.split("=", 1)
                    itype = parts[0]
                    if not itype.startswith('blank,otioFile'):
                        continue
                    # remove the .movieproc extension
                    path, _ = os.path.splitext(parts[1])

                    # remove temp movieproc source from current view, and all
                    # the default views
                    _remove_source_from_views(src_group)

                    result = otio_reader.read_otio_file(path)
                    commands.setViewNode(result)
                    break
        finally:
            # turn cache mode back on and go back to sleep
            commands.setCacheMode(cache_mode)
            self.mode = Mode.sleeping
Example #4
-1
    def add_audio(self, event):
        """Ask the user for a file and add it as audio to the currently selected sequences."""
        # The idea here is to use RVs stack to create two "tracks". The first input will be a
        # sequence of all the current sources, and the second the selected audio file.
        selected_files = commands.openMediaFileDialog(False, commands.OneExistingFile, "", "", "")

        # Find all the sources connected to the current sequence, and save them for later.
        current_sources = []
        current_sequence = commands.viewNode()
        inputs, _ = commands.nodeConnections(current_sequence, False)
        for node in inputs:
            if commands.nodeType(node) == "RVSourceGroup":
                current_sources.append(node)

        # Create a new source for the selected file. We'll do this here to fail early
        # and not leave junk nodes laying around.
        audio_source = commands.addSourceVerbose([selected_files[0]], "")
        audio_group = commands.nodeGroup(audio_source)

        # Create a new sequence and connect the sources. We're assuming here that the current sequence 
        # is the default sequence, which always contains all sources known to RV. We'll need our own copy 
        # since we want to keep the audio out of our "video track".
        sequence = commands.newNode("RVSequenceGroup", "SequenceForAudioStack")
        commands.setNodeInputs(sequence, current_sources)

        # Create the stack and connect the two sources.
        stack = commands.newNode("RVStackGroup", "StackWithAudio")
        commands.setNodeInputs(stack, [sequence, audio_group])

        # Find the actual stack node and configure it to to use the topmost 
        # source (no compositing) and only the audio we just loaded. This should mean
        # that if the user selects a file containing both audio and video as the audio
        # source, they will still get the expected result.
        for node in commands.nodesInGroup(stack):
            if commands.nodeType(node) == "RVStack":
                commands.setStringProperty("%s.composite.type" % (node), ["topmost"], False)
                commands.setStringProperty("%s.output.chosenAudioInput" % (node), [audio_group], False)
                break

        commands.setViewNode(stack)