Пример #1
0
	NodeDefinition SynthTemplate::parse_root(const NodeRef &node)
	{
		NodeDefinition def(node->name);
		def.set_id(this->last_id++);

		if (node->name == "constant")
		{
			Constant *constant = (Constant *) node.get();
			def.set_value(constant->value);
		}
		else
		{
			for (auto param : node->params)
			{
				NodeRef param_node = *(param.second);
				if (param_node)
				{
					NodeDefinition param_def = this->parse_root(param_node);
					def.add_input(param.first, &param_def);
				}
			}
		}

		std::string input_name = this->get_input_name(node);
		if (!input_name.empty())
		{
			def.input_name = input_name;
		}

		return def;
	}
Пример #2
0
void Synth::set_input(std::string name, float value)
{
	NodeRef current = this->inputs[name];
	signal_assert(this->inputs[name] != nullptr, "Synth has no such parameter: %s", name.c_str());
	NodeRef input = this->inputs[name];
	Constant *constant = (Constant *) input.get();
	constant->value = value;
}
Пример #3
0
	std::string SynthTemplate::get_input_name(const NodeRef &node)
	{
		for (auto input : this->inputs)
		{
			std::string name = input.first;
			Node *node_ptr = input.second;
			if (node_ptr == node.get())
				return name;
		}

		return "";
	}
Пример #4
0
 bool InternalNode::addChildNode(const NodeRef &node) {
     // Create a shared_ptr for passing it to contains() with a No-Op deleter so that "this" will not be deleted.
     NodeRef thisRef(this, [](void* ptr){});
     if (node->contains(thisRef) || this == node.get()) {
         printf("This causes a circular reference.\n");
         return false;
     }
     if (node->isInstanced()) {
         auto it = std::find(m_childNodes.begin(), m_childNodes.end(), node);
         if (it != m_childNodes.end()) {
             printf("Another instanced node already exists in this node.\n");
             return false;
         }
     }
     else {
         if (contains(node)) {
             printf("This node already has the given node.\n");
             return false;
         }
     }
     m_childNodes.push_back(node);
     return true;
 }
Пример #5
0
void Synth::set_input(std::string name, NodeRef value)
{
	/*------------------------------------------------------------------------
	 * Replace a named input with another node.
	 * Iterate over this synth's nodes, replacing the prior input with
	 * the new node. (Inefficient, should be rethought.)
	 *-----------------------------------------------------------------------*/
	signal_assert(this->inputs[name] != nullptr, "Synth has no such parameter: %s", name.c_str());
	NodeRef current = this->inputs[name];
	for (NodeRef node : this->nodes)
	{
		for (auto param : node->params)
		{
			if ((param.second)->get() == current.get())
			{
				// Update routing
				// printf("Updating '%s' input of %s\n", param.first.c_str(), node->name.c_str());
				node->set_input(param.first, value);
			}
		}
	}
	this->inputs[name] = value;
}