summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ingen/Configuration.hpp113
-rw-r--r--src/Configuration.cpp83
-rw-r--r--src/World.cpp3
-rw-r--r--src/ingen/main.cpp2
-rw-r--r--src/server/Engine.cpp2
-rw-r--r--src/server/ingen_jack.cpp3
-rw-r--r--src/server/ingen_lv2.cpp5
-rw-r--r--src/socket/SocketListener.cpp2
8 files changed, 72 insertions, 141 deletions
diff --git a/ingen/Configuration.hpp b/ingen/Configuration.hpp
index 0ede7059..cdec5e4b 100644
--- a/ingen/Configuration.hpp
+++ b/ingen/Configuration.hpp
@@ -26,6 +26,9 @@
#include <map>
#include <string>
+#include "ingen/Forge.hpp"
+
+#include "raul/Atom.hpp"
#include "raul/Exception.hpp"
namespace Ingen {
@@ -35,82 +38,7 @@ namespace Ingen {
*/
class Configuration {
public:
- Configuration();
-
- enum OptionType {
- NOTHING,
- BOOL,
- INT,
- STRING
- };
-
- class Value {
- public:
- Value() : _type(NOTHING) { _val._string = NULL; }
- Value(bool v) : _type(BOOL) { _val._bool = v; }
- Value(int v) : _type(INT) { _val._int = v; }
-
- Value(const char* v) : _type(STRING) {
- const size_t len = strlen(v);
- _val._string = (char*)calloc(len + 1, 1);
- memcpy(_val._string, v, len + 1);
- }
-
- Value(const std::string& v) : _type(STRING) {
- _val._string = (char*)calloc(v.length() + 1, 1);
- memcpy(_val._string, v.c_str(), v.length() + 1);
- }
-
- Value(const Value& copy)
- : _type(copy._type)
- , _val(copy._val)
- {
- if (_type == STRING) {
- const size_t len = strlen(copy.get_string());
- _val._string = (char*)malloc(len + 1);
- memcpy(_val._string, copy.get_string(), len + 1);
- }
- }
-
- Value& operator=(const Value& other)
- {
- if (&other == this) {
- return *this;
- }
- if (_type == STRING) {
- free(_val._string);
- }
- _type = other._type;
- _val = other._val;
- if (_type == STRING) {
- const size_t len = strlen(other.get_string());
- _val._string = (char*)malloc(len + 1);
- memcpy(_val._string, other.get_string(), len + 1);
- }
- return *this;
- }
-
- ~Value() {
- if (_type == STRING) {
- free(_val._string);
- }
- }
-
- inline OptionType type() const { return _type; }
- inline bool is_valid() const { return _type != NOTHING; }
-
- inline int32_t get_int() const { assert(_type == INT); return _val._int; }
- inline bool get_bool() const { assert(_type == BOOL); return _val._bool; }
- inline const char* get_string() const { assert(_type == STRING); return _val._string; }
-
- private:
- OptionType _type;
- union {
- bool _bool;
- int32_t _int;
- char* _string;
- } _val;
- };
+ Configuration(Forge& forge);
/** Add a configuration option.
*
@@ -121,12 +49,12 @@ public:
* @param type Type
* @param value Default value
*/
- Configuration& add(const std::string& key,
- const std::string& name,
- char letter,
- const std::string& desc,
- const OptionType type,
- const Value& value);
+ Configuration& add(const std::string& key,
+ const std::string& name,
+ char letter,
+ const std::string& desc,
+ const Raul::Atom::TypeID type,
+ const Raul::Atom& value);
void print_usage(const std::string& program, std::ostream& os);
@@ -150,8 +78,8 @@ public:
void print(std::ostream& os, const std::string mime_type="text/plain") const;
- const Value& option(const std::string& long_name) const;
- bool set(const std::string& long_name, const Value& value);
+ const Raul::Atom& option(const std::string& long_name) const;
+ bool set(const std::string& long_name, const Raul::Atom& value);
const std::list<std::string>& files() const { return _files; }
@@ -159,15 +87,15 @@ private:
struct Option {
public:
Option(const std::string& n, char l, const std::string& d,
- const OptionType type, const Value& def)
+ const Raul::Atom::TypeID type, const Raul::Atom& def)
: name(n), letter(l), desc(d), type(type), value(def)
{}
- std::string name;
- char letter;
- std::string desc;
- OptionType type;
- Value value;
+ std::string name;
+ char letter;
+ std::string desc;
+ Raul::Atom::TypeID type;
+ Raul::Atom value;
};
struct OptionNameOrder {
@@ -184,6 +112,7 @@ private:
int set_value_from_string(Configuration::Option& option, const std::string& value)
throw (Configuration::CommandLineError);
+ Forge& _forge;
const std::string _shortdesc;
const std::string _desc;
Options _options;
@@ -196,14 +125,16 @@ private:
} // namespace Ingen
static inline std::ostream&
-operator<<(std::ostream& os, const Ingen::Configuration::Value& value)
+operator<<(std::ostream& os, const Raul::Atom& value)
{
+ #if 0
switch (value.type()) {
case Ingen::Configuration::NOTHING: return os << "(nil)";
case Ingen::Configuration::INT: return os << value.get_int();
case Ingen::Configuration::BOOL: return os << (value.get_bool() ? "true" : "false");
case Ingen::Configuration::STRING: return os << value.get_string();
}
+ #endif
return os;
}
diff --git a/src/Configuration.cpp b/src/Configuration.cpp
index d453d43b..f3b59f3b 100644
--- a/src/Configuration.cpp
+++ b/src/Configuration.cpp
@@ -27,8 +27,9 @@
namespace Ingen {
-Configuration::Configuration()
- : _shortdesc("A realtime modular audio processor.")
+Configuration::Configuration(Forge& forge)
+ : _forge(forge)
+ , _shortdesc("A realtime modular audio processor.")
, _desc(
"Ingen is a flexible modular system that be used in various ways.\n"
"The engine can run as a stand-alone server controlled via network protocol,\n"
@@ -43,29 +44,29 @@ Configuration::Configuration()
" ingen -egl foo.ingen # Run an engine and a GUI and load a graph")
, _max_name_length(0)
{
- add("clientPort", "client-port", 'C', "Client port", INT, Value());
- add("connect", "connect", 'c', "Connect to engine URI", STRING, Value("unix:///tmp/ingen.sock"));
- add("engine", "engine", 'e', "Run (JACK) engine", BOOL, Value(false));
- add("enginePort", "engine-port", 'E', "Engine listen port", INT, Value(16180));
- add("socket", "socket", 'S', "Engine socket path", STRING, Value("/tmp/ingen.sock"));
- add("gui", "gui", 'g', "Launch the GTK graphical interface", BOOL, Value(false));
- add("", "help", 'h', "Print this help message", BOOL, Value(false));
- add("jackName", "jack-name", 'n', "JACK name", STRING, Value("ingen"));
- add("jackServer", "jack-server", 's', "JACK server name", STRING, Value(""));
- add("uuid", "uuid", 'u', "JACK session UUID", STRING, Value());
- add("load", "load", 'l', "Load graph", STRING, Value());
- add("path", "path", 'L', "Target path for loaded graph", STRING, Value());
- add("queueSize", "queue-size", 'q', "Event queue size", INT, Value(4096));
- add("run", "run", 'r', "Run script", STRING, Value());
+ add("clientPort", "client-port", 'C', "Client port", forge.Int, Raul::Atom());
+ add("connect", "connect", 'c', "Connect to engine URI", forge.String, forge.alloc("unix:///tmp/ingen.sock"));
+ add("engine", "engine", 'e', "Run (JACK) engine", forge.Bool, forge.make(false));
+ add("enginePort", "engine-port", 'E', "Engine listen port", forge.Int, forge.make(16180));
+ add("socket", "socket", 'S', "Engine socket path", forge.String, forge.alloc("/tmp/ingen.sock"));
+ add("gui", "gui", 'g', "Launch the GTK graphical interface", forge.Bool, forge.make(false));
+ add("", "help", 'h', "Print this help message", forge.Bool, forge.make(false));
+ add("jackName", "jack-name", 'n', "JACK name", forge.String, forge.alloc("ingen"));
+ add("jackServer", "jack-server", 's', "JACK server name", forge.String, forge.alloc(""));
+ add("uuid", "uuid", 'u', "JACK session UUID", forge.String, Raul::Atom());
+ add("load", "load", 'l', "Load graph", forge.String, Raul::Atom());
+ add("path", "path", 'L', "Target path for loaded graph", forge.String, Raul::Atom());
+ add("queueSize", "queue-size", 'q', "Event queue size", forge.Int, forge.make(4096));
+ add("run", "run", 'r', "Run script", forge.String, Raul::Atom());
}
Configuration&
-Configuration::add(const std::string& key,
- const std::string& name,
- char letter,
- const std::string& desc,
- const OptionType type,
- const Value& value)
+Configuration::add(const std::string& key,
+ const std::string& name,
+ char letter,
+ const std::string& desc,
+ const Raul::Atom::TypeID type,
+ const Raul::Atom& value)
{
assert(value.type() == type || value.type() == 0);
_max_name_length = std::max(_max_name_length, name.length());
@@ -104,24 +105,20 @@ Configuration::set_value_from_string(Configuration::Option& option,
const std::string& value)
throw (Configuration::CommandLineError)
{
- int intval = 0;
- char* endptr = NULL;
- switch (option.type) {
- case INT:
- intval = static_cast<int>(strtol(value.c_str(), &endptr, 10));
+ if (option.type == _forge.Int) {
+ char* endptr = NULL;
+ int intval = static_cast<int>(strtol(value.c_str(), &endptr, 10));
if (endptr && *endptr == '\0') {
- option.value = Value(intval);
+ option.value = _forge.make(intval);
} else {
throw CommandLineError(
(Raul::fmt("option `%1%' has non-integer value `%2%'")
% option.name % value).str());
}
- break;
- case STRING:
- option.value = Value(value.c_str());
- assert(option.value.type() == STRING);
- break;
- default:
+ } else if (option.type == _forge.String) {
+ option.value = _forge.alloc(value.c_str());
+ assert(option.value.type() == _forge.String);
+ } else {
throw CommandLineError(
(Raul::fmt("bad option type `%1%'") % option.name).str());
}
@@ -142,8 +139,8 @@ Configuration::parse(int argc, char** argv) throw (Configuration::CommandLineErr
throw CommandLineError(
(Raul::fmt("unrecognized option `%1%'") % name).str());
}
- if (o->second.type == BOOL) {
- o->second.value = Value(true);
+ if (o->second.type == _forge.Bool) {
+ o->second.value = _forge.make(true);
} else {
if (++i >= argc)
throw CommandLineError(
@@ -160,13 +157,13 @@ Configuration::parse(int argc, char** argv) throw (Configuration::CommandLineErr
(Raul::fmt("unrecognized option `%1%'") % letter).str());
Options::iterator o = _options.find(n->second);
if (j < len - 1) {
- if (o->second.type != BOOL)
+ if (o->second.type != _forge.Bool)
throw CommandLineError(
(Raul::fmt("missing value for `%1%'") % letter).str());
- o->second.value = Value(true);
+ o->second.value = _forge.make(true);
} else {
- if (o->second.type == BOOL) {
- o->second.value = Value(true);
+ if (o->second.type == _forge.Bool) {
+ o->second.value = _forge.make(true);
} else {
if (++i >= argc)
throw CommandLineError(
@@ -248,10 +245,10 @@ Configuration::print(std::ostream& os, const std::string mime_type) const
}
}
-const Configuration::Value&
+const Raul::Atom&
Configuration::option(const std::string& long_name) const
{
- static const Value nil;
+ static const Raul::Atom nil;
Options::const_iterator o = _options.find(long_name);
if (o == _options.end()) {
return nil;
@@ -261,7 +258,7 @@ Configuration::option(const std::string& long_name) const
}
bool
-Configuration::set(const std::string& long_name, const Value& value)
+Configuration::set(const std::string& long_name, const Raul::Atom& value)
{
Options::iterator o = _options.find(long_name);
if (o != _options.end()) {
diff --git a/src/World.cpp b/src/World.cpp
index f5421579..a7e3fc02 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -106,6 +106,7 @@ public:
, forge(new Forge(*uri_map))
, uris(new URIs(*forge, uri_map))
, log(lv2_log, *uris)
+ , conf(*forge)
, lilv_world(lilv_world_new())
{
// Parse default configuration files
@@ -181,7 +182,6 @@ public:
int& argc;
char**& argv;
- Configuration conf;
LV2Features* lv2_features;
Sord::World* rdf_world;
URIMap* uri_map;
@@ -189,6 +189,7 @@ public:
URIs* uris;
LV2_Log_Log* lv2_log;
Log log;
+ Configuration conf;
SharedPtr<Interface> interface;
SharedPtr<EngineBase> engine;
SharedPtr<Serialisation::Serialiser> serialiser;
diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp
index 99fa079a..f89a356a 100644
--- a/src/ingen/main.cpp
+++ b/src/ingen/main.cpp
@@ -155,7 +155,7 @@ main(int argc, char** argv)
boost::optional<Raul::Path> parent;
boost::optional<Raul::Symbol> symbol;
- const Configuration::Value& path_option = conf.option("path");
+ const Raul::Atom& path_option = conf.option("path");
if (path_option.is_valid()) {
if (Raul::Path::is_valid(path_option.get_string())) {
const Raul::Path p(path_option.get_string());
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp
index 4a1afb86..7e1e2ffc 100644
--- a/src/server/Engine.cpp
+++ b/src/server/Engine.cpp
@@ -112,7 +112,7 @@ Engine::store() const
size_t
Engine::event_queue_size() const
{
- return world()->conf().option("queue-size").get_int();
+ return world()->conf().option("queue-size").get_int32();
}
void
diff --git a/src/server/ingen_jack.cpp b/src/server/ingen_jack.cpp
index c6c5e005..f273a209 100644
--- a/src/server/ingen_jack.cpp
+++ b/src/server/ingen_jack.cpp
@@ -21,6 +21,7 @@
#include "ingen/Log.hpp"
#include "ingen/Module.hpp"
#include "ingen/World.hpp"
+#include "raul/Atom.hpp"
#include "JackDriver.hpp"
#include "Engine.hpp"
@@ -37,7 +38,7 @@ struct IngenJackModule : public Ingen::Module {
Server::JackDriver* driver = new Server::JackDriver(
*(Server::Engine*)world->engine().get());
- const Configuration::Value& s = world->conf().option("jack-server");
+ const Raul::Atom& s = world->conf().option("jack-server");
const std::string server_name = s.is_valid() ? s.get_string() : "";
driver->attach(server_name,
world->conf().option("jack-name").get_string(),
diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp
index f64e9c45..f0a4c2df 100644
--- a/src/server/ingen_lv2.cpp
+++ b/src/server/ingen_lv2.cpp
@@ -564,8 +564,9 @@ ingen_instantiate(const LV2_Descriptor* descriptor,
plugin->world->log().info(
Raul::fmt("Block: %1% frames, Sequence: %2% bytes\n")
% block_length % seq_size);
- plugin->world->conf().set("queue-size",
- std::max(block_length, seq_size) * 4);
+ plugin->world->conf().set(
+ "queue-size",
+ plugin->world->forge().make(std::max(block_length, seq_size) * 4));
SharedPtr<Server::Engine> engine(new Server::Engine(plugin->world));
plugin->world->set_engine(engine);
diff --git a/src/socket/SocketListener.cpp b/src/socket/SocketListener.cpp
index 351dbcab..13049a24 100644
--- a/src/socket/SocketListener.cpp
+++ b/src/socket/SocketListener.cpp
@@ -51,7 +51,7 @@ SocketListener::SocketListener(Ingen::World& world)
_world.log().info(Raul::fmt("Listening on socket %1%\n") % unix_uri);
// Create TCP socket
- int port = world.conf().option("engine-port").get_int();
+ int port = world.conf().option("engine-port").get_int32();
std::ostringstream ss;
ss << "tcp://localhost:";
ss << port;