summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-05-20 00:30:50 +0000
committerDavid Robillard <d@drobilla.net>2008-05-20 00:30:50 +0000
commit264ce503aebaa87d275f23d1ea1a33034083b190 (patch)
tree11678189d20b58da4d1ddc7b70704f203a433c6a
parent5ae0c93b92008a9f2145bb809d8086ee4f9ee24b (diff)
downloadraul-264ce503aebaa87d275f23d1ea1a33034083b190.tar.gz
raul-264ce503aebaa87d275f23d1ea1a33034083b190.tar.bz2
raul-264ce503aebaa87d275f23d1ea1a33034083b190.zip
Fix various problems with control port values.
Fix control port feedback issues with LV2 plugin UIs. git-svn-id: http://svn.drobilla.net/lad/raul@1218 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--raul/Atom.hpp56
1 files changed, 45 insertions, 11 deletions
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
index b9d81ec..3416067 100644
--- a/raul/Atom.hpp
+++ b/raul/Atom.hpp
@@ -77,12 +77,9 @@ public:
case FLOAT: _float_val = copy._float_val; break;
case BOOL: _bool_val = copy._bool_val; break;
case STRING: _string_val = strdup(copy._string_val); break;
-
case BLOB: _blob_val = malloc(_blob_size);
memcpy(_blob_val, copy._blob_val, _blob_size);
break;
-
- default: break;
}
}
@@ -101,16 +98,56 @@ public:
case FLOAT: _float_val = other._float_val; break;
case BOOL: _bool_val = other._bool_val; break;
case STRING: _string_val = strdup(other._string_val); break;
-
case BLOB: _blob_val = malloc(_blob_size);
memcpy(_blob_val, other._blob_val, _blob_size);
break;
-
- default: break;
}
return *this;
}
+ inline bool operator==(const Atom& other) const {
+ if (_type == other.type()) {
+ switch (_type) {
+ case NIL: return true;
+ case INT: return _int_val == other._int_val;
+ case FLOAT: return _float_val == other._float_val;
+ case BOOL: return _bool_val == other._bool_val;
+ case STRING: return strcmp(_string_val, other._string_val) == 0;
+ case BLOB: return _blob_val == other._blob_val;
+ }
+ }
+ return false;
+ }
+
+ inline bool operator!=(const Atom& other) const { return ! operator==(other); }
+
+ inline bool operator<(const Atom& other) const {
+ if (_type == other.type()) {
+ switch (_type) {
+ case NIL: return true;
+ case INT: return _int_val < other._int_val;
+ case FLOAT: return _float_val < other._float_val;
+ case BOOL: return _bool_val < other._bool_val;
+ case STRING: return strcmp(_string_val, other._string_val) < 0;
+ case BLOB: return _blob_val < other._blob_val;
+ }
+ }
+ return _type < other.type();
+ }
+
+ inline size_t data_size() {
+ switch (_type) {
+ case NIL: return 0;
+ case INT: return sizeof(uint32_t);
+ case FLOAT: return sizeof(float);
+ case BOOL: return sizeof(bool);
+ case STRING: return strlen(_string_val);
+ case BLOB: return _blob_size;
+ }
+ }
+
+ inline bool is_valid() const { return (_type != NIL); }
+
/** Type of this atom. Always check this before attempting to get the
* value - attempting to get the incorrectly typed value is a fatal error.
*/
@@ -122,12 +159,9 @@ public:
inline const char* get_string() const { assert(_type == STRING); return _string_val; }
inline const void* get_blob() const { assert(_type == BLOB); return _blob_val; }
- inline operator bool() const { return (_type != NIL); }
-
private:
- Type _type;
-
- size_t _blob_size; ///< always a multiple of 32
+ Type _type;
+ size_t _blob_size; ///< Always a multiple of 32
union {
int32_t _int_val;