Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compute graph example - multiple outputs? #188

Closed
aparks5 opened this issue Aug 17, 2023 · 1 comment
Closed

Compute graph example - multiple outputs? #188

aparks5 opened this issue Aug 17, 2023 · 1 comment

Comments

@aparks5
Copy link

aparks5 commented Aug 17, 2023

Hi,
Are multiple outputs possible in apps based on the compute graph example?

I know that imnodes can certainly render multiple output pins, but it looks like if for example:

ImNodes::BeginNode(params[NODEID])
...
ImNodes::BeginOutputAttribute(params[NODE_ID]);
ImNodes::EndOutputAttribute();
ImNodes::EndNode();

will correctly display one output pin. I have observed that linking will not work unless NODE_ID matches Node and OutputAttribute.
However, additional outputs such as:

ImNodes::BeginOutputAttribute(params[STEREO_L]);
ImNodes::EndOutputAttribute();
ImNodes::BeginOutputAttribute(params[STEREO_R]);
ImNodes::EndOutputAttribute();
ImNodes::EndNode();

make it impossible to link to another node.

Multiple inputs are quite easy to deal with.

Perhaps I need to dig into graph.h to understand why there is the expectation that in order for Nodes to link to each other the NODE_ID needs to match the Output attribute ID.

Many thanks
-Anthony

@aparks5
Copy link
Author

aparks5 commented Aug 17, 2023

UPDATE: I SOLVED IT (but it wasn't easy and I still don't know exactly why this works)

Since Links don't display for Values, I needed to create another value type node called a "Relay" whose sole is to allow me to call push() multiple times in a node.

I am able to create multiple outputs by calling process() on a Node in a circular way.

ADDITIONALLY
another edge needs to be created from the output to the node id. It is backwards from the inputs.
e.g.

	else if (ImGui::IsKeyReleased((ImGuiKey)SDL_SCANCODE_M)) {
			auto node = std::make_shared<MIDI>();
			auto extra = std::make_shared<Relay>();
			auto id = m_graph.insert_node(node);
			auto extraId = m_graph.insert_node(extra);
			m_graph.insert_edge(extraId, id);
			node->params[MIDI::NODE_ID] = id;
			node->params[MIDI::EXTRA_OUT_ID] = extraId;
			m_nodes.push_back(node);
			// outputs have to be inserted after the process node
			const ImVec2 click_pos = ImGui::GetMousePosOnOpeningCurrentPopup();
			ImNodes::SetNodeScreenSpacePos(id, click_pos);
		}

MIDI::process()
{
// fill voices etc.
...
	// N calls to process will return N voices
	// this module should push N values to the stack
	float val = m_voices[m_cycle];
	m_cycle++;
	if (m_cycle >= m_voices.size()) {
		m_cycle = 0;
	}
	return m_voices[m_cycle];

}

image

@aparks5 aparks5 closed this as completed Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant