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
def group_member_of_type(node, member_type): """ Checks a node group for a node of a specific type. :param node: name of node type to find :param member_type: node group to search """ for n in commands.nodesInGroup(node): if commands.nodeType(n) == member_type: return n return None
def get_type(self): return commands.nodeType(self.name)
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)