void ManifestTest::testManifest()
{
    Manifest<MfTestBase> manifest;
    assert (manifest.empty());
    assert (manifest.size() == 0);
    assert (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject1")));
    assert (!manifest.empty());
    assert (manifest.size() == 1);
    assert (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject2")));
    MetaObject<MfTestObject, MfTestBase>* pMeta = new MetaObject<MfTestObject, MfTestBase>("MfTestObject2");
    assert (!manifest.insert(pMeta));
    delete pMeta;
    assert (!manifest.empty());
    assert (manifest.size() == 2);
    assert (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject3")));
    assert (manifest.size() == 3);

    assert (manifest.find("MfTestObject1") != manifest.end());
    assert (manifest.find("MfTestObject2") != manifest.end());
    assert (manifest.find("MfTestObject3") != manifest.end());
    assert (manifest.find("MfTestObject4") == manifest.end());

    std::set<std::string> classes;

    Manifest<MfTestBase>::Iterator it = manifest.begin();
    assert (it != manifest.end());
    classes.insert(it->name());
    ++it;
    assert (it != manifest.end());
    classes.insert(it->name());
    ++it;
    assert (it != manifest.end());
    classes.insert(it->name());
    it++;
    assert (it == manifest.end());

    assert (classes.find("MfTestObject1") != classes.end());
    assert (classes.find("MfTestObject2") != classes.end());
    assert (classes.find("MfTestObject3") != classes.end());

    manifest.clear();
    assert (manifest.empty());
    assert (manifest.size() == 0);
    assert (manifest.insert(new MetaObject<MfTestObject, MfTestBase>("MfTestObject4")));
    assert (!manifest.empty());
    assert (manifest.size() == 1);
    it = manifest.begin();
    assert (it != manifest.end());
    assert (std::string(it->name()) == "MfTestObject4");
    ++it;
    assert (it == manifest.end());
}
Example #2
0
void
write_plugin(AudioEffectX* effect, const string& lib_file_name)
{
	const string base_name = lib_file_name.substr(0, lib_file_name.find_last_of("."));
	const string data_file_name = base_name + ".ttl";

	fstream os(data_file_name.c_str(), ios::out);
	effect->getProductString(name_buf);

	os << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> ." << endl;
	os << "@prefix doap: <http://usefulinc.com/ns/doap#> ." << endl << endl;
	os << "<" << effect->getURI() << ">" << endl;
	os << "\tlv2:symbol \"" << effect->getUniqueID() << "\" ;" << endl;
	os << "\tdoap:name \"" << name_buf << "\" ;" << endl;
	os << "\tdoap:license <http://usefulinc.com/doap/licenses/gpl> ;" << endl;
	os << "\tlv2:pluginProperty lv2:hardRTCapable";

	uint32_t num_params     = effect->getNumParameters();
	uint32_t num_audio_ins  = effect->getNumInputs();
	uint32_t num_audio_outs = effect->getNumOutputs();
	uint32_t num_ports      = num_params + num_audio_ins + num_audio_outs;

	if (num_ports > 0)
		os << " ;" << endl << "\tlv2:port [" << endl;
	else
		os << " ." << endl;

	uint32_t idx = 0;

	for (uint32_t i = idx; i < num_params; ++i, ++idx) {
		effect->getParameterName(i, name_buf);
		os << "\t\ta lv2:InputPort, lv2:ControlPort ;" << endl;
		os << "\t\tlv2:index" << " " << idx << " ;" << endl;
		os << "\t\tlv2:name \"" << name_buf << "\" ;" << endl;
		os << "\t\tlv2:symbol \"" << symbolify(name_buf) << "\" ;" << endl;
		os << "\t\tlv2:default " << lvz_translate_parameter(effect, i, effect->getParameter(i)) << " ;" << endl;
		os << "\t\tlv2:minimum " << lvz_translate_parameter(effect, i, 0.0f) << " ;" << endl;
		os << "\t\tlv2:maximum " << lvz_translate_parameter(effect, i, 1.0f) << " ;" << endl;
		os << ((idx == num_ports - 1) ? "\t] ." : "\t] , [") << endl;
	}

	for (uint32_t i = 0; i < num_audio_ins; ++i, ++idx) {
		os << "\t\ta lv2:InputPort, lv2:AudioPort ;" << endl;
		os << "\t\tlv2:index" << " " << idx << " ;" << endl;
		os << "\t\tlv2:symbol \"in" << i+1 << "\" ;" << endl;
		os << "\t\tlv2:name \"Input " << i+1 << "\" ;" << endl;
		os << ((idx == num_ports - 1) ? "\t] ." : "\t] , [") << endl;
	}

	for (uint32_t i = 0; i < num_audio_outs; ++i, ++idx) {
		os << "\t\ta lv2:OutputPort, lv2:AudioPort ;" << endl;
		os << "\t\tlv2:index " << idx << " ;" << endl;
		os << "\t\tlv2:symbol \"out" << i+1 << "\" ;" << endl;
		os << "\t\tlv2:name \"Output " << i+1 << "\" ;" << endl;
		os << ((idx == num_ports - 1) ? "\t] ." : "\t] , [") << endl;
	}

	os.close();

	Manifest::iterator i = manifest.find(effect->getURI());
	if (i != manifest.end()) {
		i->second.base_name = base_name;
	} else {
		manifest.insert(std::make_pair(effect->getURI(), Record(base_name)));
	}

	if (effect->getNumPrograms() > 1) {
		std::string preset_file = base_name + "-presets.ttl";

		fstream pos(preset_file.c_str(), ios::out);
		pos << "@prefix lv2: <http://lv2plug.in/ns/lv2core#> ." << endl;
		pos << "@prefix pset: <http://lv2plug.in/ns/ext/presets#> ." << endl;
		pos << "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ." << endl << endl;
		for (int32_t i = 0; i < effect->getNumPrograms(); ++i) {
			effect->setProgram(i);
			effect->getProgramName(name_buf);

			if (!strcmp(name_buf, "Empty Patch"))
				continue;

			std::string preset_uri = string("http://moddevices.com/plugins/mda/presets#") + base_name + "-" + symbolify(name_buf, '-');

			// Write manifest entry
			std::cout << "<" << preset_uri << ">"
			          << "\n\ta pset:Preset ;\n\tlv2:appliesTo <"
			          << effect->getURI() << "> ;\n\t"
			          << "rdfs:seeAlso <" << preset_file << "> .\n" << std::endl;

			// Write preset file
			pos << "<" << preset_uri << ">"
			    << "\n\ta pset:Preset ;\n\tlv2:appliesTo <"
			    << effect->getURI() << "> ;\n\t"
			    << "rdfs:label \"" << name_buf << "\"";
			for (uint32_t i = 0; i < num_params; ++i) {
				effect->getParameterName(i, name_buf);
				pos << " ;\n\tlv2:port [" << endl;
				pos << "\t\tlv2:symbol \"" << symbolify(name_buf) << "\" ;" << endl;
				pos << "\t\tpset:value " << lvz_translate_parameter(effect, i, effect->getParameter(i)) << " ;" << endl;
				pos << "\t]";
			}
			pos << " .\n" << endl;
		}
		pos.close();
	}
}