diff options
Diffstat (limited to 'src/engine/Updates.cpp')
-rw-r--r-- | src/engine/Updates.cpp | 109 |
1 files changed, 17 insertions, 92 deletions
diff --git a/src/engine/Updates.cpp b/src/engine/Updates.cpp index d093df4..aabd4fb 100644 --- a/src/engine/Updates.cpp +++ b/src/engine/Updates.cpp @@ -15,6 +15,8 @@ * along with Machina. If not, see <http://www.gnu.org/licenses/>. */ +#include "lv2/lv2plug.in/ns/ext/atom/atom.h" + #include "raul/Atom.hpp" #include "raul/SharedPtr.hpp" @@ -23,94 +25,6 @@ namespace Machina { -static inline void -write_atom(SharedPtr<UpdateBuffer> buf, - const Raul::Atom& value) -{ - const Raul::Atom::Type type = value.type(); - buf->write(sizeof(type), &type); - int32_t ival; - float fval; - size_t szval; - switch (value.type()) { - case Raul::Atom::INT: - ival = value.get_int32(); - buf->write(sizeof(ival), &ival); - break; - case Raul::Atom::FLOAT: - ival = value.get_float(); - buf->write(sizeof(fval), &fval); - break; - case Raul::Atom::BOOL: - ival = value.get_bool() ? 1 : 0; - buf->write(sizeof(ival), &ival); - break; - case Raul::Atom::STRING: - szval = value.data_size(); - buf->write(sizeof(size_t), &szval); - buf->write(value.data_size(), value.get_string()); - break; - case Raul::Atom::URI: - szval = value.data_size(); - buf->write(sizeof(size_t), &szval); - buf->write(value.data_size(), value.get_uri()); - break; - default: - assert(false); - } -} - -uint32_t -read_atom(SharedPtr<UpdateBuffer> buf, - Raul::Atom* value) -{ - Raul::Atom::Type type; - buf->read(sizeof(type), &type); - - int32_t ival; - float fval; - char* sval; - size_t val_size; - switch (type) { - case Raul::Atom::INT: - val_size = sizeof(ival); - buf->read(val_size, &ival); - *value = Raul::Atom(ival); - break; - case Raul::Atom::FLOAT: - val_size = sizeof(fval); - buf->read(val_size, &fval); - *value = Raul::Atom(fval); - break; - case Raul::Atom::BOOL: - val_size = sizeof(ival); - buf->read(val_size, &ival); - assert(ival == 0 || ival == 1); - *value = Raul::Atom(bool(ival)); - break; - case Raul::Atom::STRING: - buf->read(sizeof(val_size), &val_size); - sval = (char*)malloc(val_size); - buf->read(val_size, sval); - val_size += sizeof(val_size); - *value = Raul::Atom(sval); - free(sval); - break; - case Raul::Atom::URI: - buf->read(sizeof(val_size), &val_size); - sval = (char*)malloc(val_size); - buf->read(val_size, sval); - val_size += sizeof(val_size); - *value = Raul::Atom(Raul::Atom::URI, sval); - free(sval); - break; - default: - assert(false); - } - - return sizeof(type) + val_size; -} - void write_set(SharedPtr<UpdateBuffer> buf, uint64_t subject, @@ -121,7 +35,10 @@ write_set(SharedPtr<UpdateBuffer> buf, buf->write(sizeof(update_type), &update_type); buf->write(sizeof(subject), &subject); buf->write(sizeof(key), &key); - write_atom(buf, value); + + const LV2_Atom atom = { value.size(), value.type() }; + buf->write(sizeof(LV2_Atom), &atom); + buf->write(value.size(), value.get_body()); } uint32_t @@ -132,12 +49,20 @@ read_set(SharedPtr<UpdateBuffer> buf, { uint32_t update_type; buf->read(sizeof(update_type), &update_type); - assert(update_type == UPDATE_SET); + if (update_type != UPDATE_SET) { + return 0; + } + buf->read(sizeof(*subject), subject); buf->read(sizeof(*key), key); - const uint32_t value_size = read_atom(buf, value); - return sizeof(update_type) + sizeof(*subject) + sizeof(*key) + value_size; + LV2_Atom atom; + buf->read(sizeof(LV2_Atom), &atom); + *value = Raul::Atom(atom.size, atom.type, NULL); + buf->read(atom.size, value->get_body()); + + return sizeof(update_type) + sizeof(*subject) + sizeof(*key) + + sizeof(LV2_Atom) + atom.size; } } |