Exemple #1
0
void Loudspeaker::init_from_xml(const xmlpp::Element* nodeElement){
	// this node will need to establish a jack stream via the jack system, it should kill the port when done

	ObjectId id = get_attribute_string(nodeElement,"id");
	connectionName_ = get_attribute_string(nodeElement,"port");
	port_ = new JackPort(id, JackPortIsOutput ,&SESSION());
	port_->connect(connectionName_);

	type_ = get_optional_attribute_string(nodeElement,"type");
	pos_.x = get_optional_attribute_float(nodeElement,"x");
	pos_.y = get_optional_attribute_float(nodeElement,"y");
	pos_.z = get_optional_attribute_float(nodeElement,"z");
	az_ = get_optional_attribute_float(nodeElement,"az");
	el_ = get_optional_attribute_float(nodeElement,"el");
	
	gain_ = get_optional_attribute_float(nodeElement,"gain",1.0);

	std::cout << "Loudspeaker " << id << " type=" << type_ << std::endl;

	jack_nframes_t s = SESSION().get_buffer_size();
	buffer_.allocate(s);

        // register the buffer
        BufferRef ref;
        std::stringstream str;
        str << "bus." << id;
        ref.id =  str.str();
        ref.isAlias = false;
        ref.isBus = true;
        ref.creator = id;
        ref.buffer = &buffer_;
        SESSION().register_buffer(ref);

	DynamicObject::init_from_xml(nodeElement);
}
Exemple #2
0
Behaviour* ResoundSession::create_behaviour_from_node(const xmlpp::Node* node){
	assert(node);
	const xmlpp::Element* nodeElement = get_element(node);
	ObjectId id = get_attribute_string(nodeElement,"id");
	std::string factoryName = get_attribute_string(nodeElement,"class");
	BehaviourFactoryMap::iterator it = behaviourFactories_.find(factoryName);
	if(it != behaviourFactories_.end()){
		Behaviour* p = (it->second)(); // implicity registers the dynamic object
		return p;
	} else {
		throw Exception("factory not found");
	}
}
Exemple #3
0
void DynamicObject::init_from_xml(const xmlpp::Element* nodeElement){
	assert(nodeElement);
	std::string name = nodeElement->get_name();
	id_ = get_attribute_string(nodeElement,"id");
	// attempt to register
	SESSION().register_dynamic_object(id_, this);
}
Exemple #4
0
void AliasSet::init_from_xml(const xmlpp::Element* nodeElement){

        ObjectId id = get_attribute_string(nodeElement,"id");
	// look for aliases
	xmlpp::Node::NodeList nodes;
	nodes = nodeElement->get_children();
	xmlpp::Node::NodeList::iterator it;
	for(it = nodes.begin(); it != nodes.end(); ++it){
		const xmlpp::Element* child = dynamic_cast<const xmlpp::Element*>(*it);
		if(child){
			std::string name = child->get_name();
			if(name=="alias"){
				Alias* alias = new Alias(child,id);
				ObjectId id = alias->get_id();
				AliasMap::iterator it = aliases_.find(id);
				if(it == aliases_.end()){
					aliases_[id] = alias;
					std::cout << "Alias found " << id << std::endl;
				} else {
					throw Exception("non-unique name for alias within AliasSet");
				}	
			}
		}	
	}
//	for( AliasMap::iterator it = aliases_.begin(); it != aliases_.end(); ++it){ }

	DynamicObject::init_from_xml(nodeElement);
}
Exemple #5
0
Alias::Alias(const xmlpp::Node* node, ObjectId parent){
	const xmlpp::Element* nodeElement = get_element(node);
	id_= get_attribute_string(nodeElement,"id");
	ref_= get_attribute_string(nodeElement,"ref");

        BufferRefVector v = SESSION().lookup_buffer(ref_);
        if(v.size() == 1){
            BufferRef bref = v[0];
            bref.id = parent + std::string(".") + id_;
            bref.isAlias = true;
            bref.creator = parent ;

            SESSION().register_buffer(bref);
        } else {
            throw Exception("Alias could not find a reference to the buffer requested.");
        }
        
}
Exemple #6
0
float xml_data_node::get_attribute_float(const char *attribute, float defvalue) const
{
	char const *const string = get_attribute_string(attribute, nullptr);
	float value;

	if (string == nullptr || sscanf(string, "%f", &value) != 1)
		return defvalue;
	return value;
}
Exemple #7
0
xml_data_node::int_format xml_data_node::get_attribute_int_format(const char *attribute) const
{
	char const *const string = get_attribute_string(attribute, nullptr);

	if (!string)
		return int_format::DECIMAL;
	else if (string[0] == '$')
		return int_format::HEX_DOLLAR;
	else if (string[0] == '0' && string[1] == 'x')
		return int_format::HEX_C;
	if (string[0] == '#')
		return int_format::DECIMAL_HASH;
	else
		return int_format::DECIMAL;
}
Exemple #8
0
int xml_data_node::get_attribute_int(const char *attribute, int defvalue) const
{
	char const *const string = get_attribute_string(attribute, nullptr);
	int value;
	unsigned int uvalue;

	if (string == nullptr)
		return defvalue;
	if (string[0] == '$')
		return (sscanf(&string[1], "%X", &uvalue) == 1) ? uvalue : defvalue;
	if (string[0] == '0' && string[1] == 'x')
		return (sscanf(&string[2], "%X", &uvalue) == 1) ? uvalue : defvalue;
	if (string[0] == '#')
		return (sscanf(&string[1], "%d", &value) == 1) ? value : defvalue;
	return (sscanf(&string[0], "%d", &value) == 1) ? value : defvalue;
}