summaryrefslogtreecommitdiffstats
path: root/raul
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-01-01 19:52:36 +0000
committerDavid Robillard <d@drobilla.net>2008-01-01 19:52:36 +0000
commitcb21a7b08354134307637eb822a3c1ad9cb7ed23 (patch)
treefed8b9484141e723317a00886b0bd8bc841c9397 /raul
parent143d9b1599a82a35165fd8e17f249998f95f15d0 (diff)
downloadraul-cb21a7b08354134307637eb822a3c1ad9cb7ed23.tar.gz
raul-cb21a7b08354134307637eb822a3c1ad9cb7ed23.tar.bz2
raul-cb21a7b08354134307637eb822a3c1ad9cb7ed23.zip
RAUL code cleanup.
git-svn-id: http://svn.drobilla.net/lad/raul@999 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul')
-rw-r--r--raul/Array.hpp10
-rw-r--r--raul/Atom.hpp4
-rw-r--r--raul/AtomLiblo.hpp6
-rw-r--r--raul/Command.hpp7
-rw-r--r--raul/DoubleBuffer.hpp6
-rw-r--r--raul/JackDriver.hpp16
-rw-r--r--raul/List.hpp26
-rw-r--r--raul/ListImpl.hpp49
-rw-r--r--raul/Path.hpp37
-rw-r--r--raul/Process.hpp3
-rw-r--r--raul/RingBuffer.hpp2
-rw-r--r--raul/SMFReader.hpp16
-rw-r--r--raul/SMFWriter.hpp2
-rw-r--r--raul/Slave.hpp3
-rw-r--r--raul/TableImpl.hpp7
15 files changed, 56 insertions, 138 deletions
diff --git a/raul/Array.hpp b/raul/Array.hpp
index db0c182..0dfa75f 100644
--- a/raul/Array.hpp
+++ b/raul/Array.hpp
@@ -28,7 +28,9 @@ namespace Raul {
/** An array.
*
- * Has a stack-like push_back() too, for find_process_order...
+ * Has a stack-like push_back(), but is NOT a resizeable array (the size given
+ * to the constructor or alloc method is the maximum number of elements which
+ * can be pushed).
*/
template <class T>
class Array : public Deletable
@@ -56,7 +58,7 @@ public:
}
~Array() {
- free();
+ delete[] _elems;
}
void alloc(size_t num_elems) {
@@ -81,10 +83,6 @@ public:
_elems[i] = initial_value;
}
- void free() {
- delete[] _elems;
- }
-
void push_back(T n) {
assert(_top < _size);
_elems[_top++] = n;
diff --git a/raul/Atom.hpp b/raul/Atom.hpp
index e25f4bd..c1ca366 100644
--- a/raul/Atom.hpp
+++ b/raul/Atom.hpp
@@ -95,8 +95,8 @@ public:
// Gotta love C++ boilerplate:
Atom(const Atom& copy)
- : _type(copy._type)
- , _blob_size(copy._blob_size)
+ : _type(copy._type)
+ , _blob_size(copy._blob_size)
{
switch (_type) {
case NIL: _blob_val = 0; break;
diff --git a/raul/AtomLiblo.hpp b/raul/AtomLiblo.hpp
index 88adf1a..e21e6c3 100644
--- a/raul/AtomLiblo.hpp
+++ b/raul/AtomLiblo.hpp
@@ -34,9 +34,6 @@ class AtomLiblo {
public:
static void lo_message_add_atom(lo_message m, const Atom& atom) {
switch (atom.type()) {
- //case NIL:
- // (see below)
- //break;
case Atom::INT:
lo_message_add_int32(m, atom.get_int32());
break;
@@ -50,7 +47,8 @@ public:
// FIXME: is this okay? what does liblo do?
lo_message_add_blob(m, const_cast<void*>(atom.get_blob()));
break;
- default: // This catches Atom::Type::NIL too
+ case Atom::NIL:
+ default:
lo_message_add_nil(m);
break;
}
diff --git a/raul/Command.hpp b/raul/Command.hpp
index 296af10..572d3d9 100644
--- a/raul/Command.hpp
+++ b/raul/Command.hpp
@@ -28,13 +28,14 @@ namespace Raul {
*
* This is useful for calling simple parameterless commands from another thread
* (OSC, GUI, etc) and waiting on the result. Works well for coarsely timed
- * events. Realtime safe on the commend executing side.
+ * events (e.g. 'play' clicked in a GUI).
+ *
+ * Realtime safe on the commend executing side.
*
* \ingroup raul
*/
class Command : boost::noncopyable {
public:
-
inline Command() : _sem(0) {}
/** Caller context */
@@ -42,7 +43,7 @@ public:
/** Execution context */
inline bool pending() { return _sem.has_waiter(); }
- inline void finish() { _sem.post(); }
+ inline void finish() { _sem.post(); }
private:
Semaphore _sem;
diff --git a/raul/DoubleBuffer.hpp b/raul/DoubleBuffer.hpp
index 4f3907d..4f8f152 100644
--- a/raul/DoubleBuffer.hpp
+++ b/raul/DoubleBuffer.hpp
@@ -51,13 +51,11 @@ public:
_read_val = &_vals[0];
}
- inline T& get() const
- {
+ inline T& get() const {
return *_read_val.get();
}
- inline bool set(T new_val)
- {
+ inline bool set(T new_val) {
if (_state.compare_and_exchange(RAUL_DB_READ_WRITE, RAUL_DB_READ_LOCK)) {
// locked _vals[1] for write
diff --git a/raul/JackDriver.hpp b/raul/JackDriver.hpp
index d939cb4..f1b92f1 100644
--- a/raul/JackDriver.hpp
+++ b/raul/JackDriver.hpp
@@ -23,15 +23,13 @@
#include <jack/jack.h>
#include <jack/statistics.h>
-using std::string;
-
namespace Raul {
-/** Handles all externally driven functionality, registering ports etc.
+/** Jack based driver for an audio context.
*
- * Jack callbacks and connect methods and things like that live here.
- * Right now just for jack ports, but that will change...
+ * Apps can override the on_* methods of this class to implement reactions
+ * to Jack events (e.g. new port, process callback, etc).
*/
class JackDriver
{
@@ -39,7 +37,7 @@ public:
JackDriver();
virtual ~JackDriver();
- void attach(const string& client_name, string server_name="");
+ void attach(const std::string& client_name, std::string server_name="");
void detach();
void activate();
@@ -65,10 +63,10 @@ public:
inline jack_nframes_t sample_rate() { return jack_get_sample_rate(_client); }
inline size_t xruns() { return _xruns; }
- void reset_xruns();
+ void reset_xruns();
- inline float max_delay() { return jack_get_max_delayed_usecs(_client); }
- inline void reset_delay() { jack_reset_max_delayed_usecs(_client); }
+ inline float max_delay() { return jack_get_max_delayed_usecs(_client); }
+ inline void reset_delay() { jack_reset_max_delayed_usecs(_client); }
jack_client_t* jack_client() { return _client; }
diff --git a/raul/List.hpp b/raul/List.hpp
index c20a454..1a8b426 100644
--- a/raul/List.hpp
+++ b/raul/List.hpp
@@ -44,8 +44,7 @@ public:
* than the list reader, and insert (e.g. via an Event) it later in the
* reader thread.
*/
- class Node : public Raul::Deletable
- {
+ class Node : public Raul::Deletable {
public:
Node(T elem) : _elem(elem) {}
virtual ~Node() {}
@@ -59,7 +58,6 @@ public:
void prev(Node* ln) { _prev = ln; }
Node* next() const { return _next.get(); }
void next(Node* ln) { _next = ln; }
-
T& elem() { return _elem;}
const T& elem() const { return _elem; }
@@ -70,19 +68,15 @@ public:
};
- // List
-
- List()
- : _size(0), _end_iter(this), _const_end_iter(this)
- {
+ List() : _size(0), _end_iter(this), _const_end_iter(this) {
_end_iter._listnode = NULL;
_const_end_iter._listnode = NULL;
}
~List();
- void push_back(Node* elem); // realtime safe
- void push_back(T& elem); // NOT realtime safe
+ void push_back(Node* elem); ///< Realtime Safe
+ void push_back(T& elem); ///< NOT Realtime Safe
void append(List<T>& list);
@@ -97,8 +91,7 @@ public:
class iterator;
/** Realtime safe const iterator for a List. */
- class const_iterator
- {
+ class const_iterator {
public:
const_iterator(const List<T>* const list);
const_iterator(const iterator& i)
@@ -121,8 +114,7 @@ public:
/** Realtime safe iterator for a List. */
- class iterator
- {
+ class iterator {
public:
iterator(List<T>* const list);
@@ -147,11 +139,9 @@ public:
iterator find(const T& val);
- iterator begin();
- const iterator end() const;
-
+ iterator begin();
const_iterator begin() const;
- //const_iterator end() const;
+ const iterator end() const;
private:
AtomicPtr<Node> _head;
diff --git a/raul/ListImpl.hpp b/raul/ListImpl.hpp
index ef3a945..ec1fde4 100644
--- a/raul/ListImpl.hpp
+++ b/raul/ListImpl.hpp
@@ -147,42 +147,6 @@ List<T>::append(List<T>& list)
}
-/** Remove all elements equal to @a val from the list.
- *
- * This function is realtime safe - it is the caller's responsibility to
- * delete the returned ListNode, or there will be a leak.
- */
-#if 0
-template <typename T>
-ListNode<T>*
-List<T>::remove(const T val)
-{
- // FIXME: atomicity?
- ListNode<T>* n = _head;
- while (n) {
- if (n->elem() == elem)
- break;
- n = n->next();
- }
- if (n) {
- if (n == _head) _head = _head->next();
- if (n == _tail) _tail = _tail->prev();
- if (n->prev())
- n->prev()->next(n->next());
- if (n->next())
- n->next()->prev(n->prev());
- --_size;
-
- if (_size == 0)
- _head = _tail = NULL; // FIXME: Shouldn't be necessary
-
- return n;
- }
- return NULL;
-}
-#endif
-
-
/** Find an element in the list.
*
* This will only return the first element found. If there are duplicated,
@@ -411,19 +375,6 @@ List<T>::begin() const
return iter;
}
-#if 0
-template <typename T>
-inline typename List<T>::const_iterator
-List<T>::end() const
-{
- /*typename List<T>::const_iterator iter(this);
- iter._listnode = NULL;
- iter._next = NULL;
- return iter;*/
- return _const_end_iter;
-}
-#endif
-
} // namespace Raul
diff --git a/raul/Path.hpp b/raul/Path.hpp
index b6a1395..d14f21e 100644
--- a/raul/Path.hpp
+++ b/raul/Path.hpp
@@ -22,8 +22,6 @@
#include <cctype>
#include <string>
#include <cassert>
-#include <iostream>
-using std::string;
namespace Raul {
@@ -54,7 +52,7 @@ public:
* use is_valid first to check.
*/
Path(const std::basic_string<char>& path)
- : std::basic_string<char>(path)
+ : std::basic_string<char>(path)
{
assert(is_valid(path));
}
@@ -66,22 +64,21 @@ public:
* use is_valid first to check.
*/
Path(const char* cpath)
- : std::basic_string<char>(cpath)
+ : std::basic_string<char>(cpath)
{
assert(is_valid(cpath));
}
static bool is_valid(const std::basic_string<char>& path);
- static bool is_valid_name(const std::basic_string<char>& name)
- {
- return name.length() > 0 && is_valid(string("/").append(name));
+ static bool is_valid_name(const std::basic_string<char>& name) {
+ return name.length() > 0 && is_valid(std::string("/").append(name));
}
- static string pathify(const std::basic_string<char>& str);
- static string nameify(const std::basic_string<char>& str);
+ static std::string pathify(const std::basic_string<char>& str);
+ static std::string nameify(const std::basic_string<char>& str);
- static void replace_invalid_chars(string& str, bool replace_slash = false);
+ static void replace_invalid_chars(std::string& str, bool replace_slash = false);
bool is_child_of(const Path& parent) const;
bool is_parent_of(const Path& child) const;
@@ -90,8 +87,7 @@ public:
/** Return the name of this object (everything after the last '/').
* This is the "method name" for OSC paths.
*/
- inline std::basic_string<char> name() const
- {
+ inline std::basic_string<char> name() const {
if ((*this) == "/")
return "";
else
@@ -104,22 +100,18 @@ public:
* Calling this on the path "/" will return "/".
* This is the (deepest) "container path" for OSC paths.
*/
- inline Path parent() const
- {
+ inline Path parent() const {
std::basic_string<char> parent = substr(0, find_last_of("/"));
return (parent == "") ? "/" : parent;
}
- /** Parent path with a "/" appended.
+ /** Return path with a trailing "/".
*
- * This exists to avoid needing to be careful about the special case of "/".
- * To create a child of a path, use parent.base() + child_name.
- * Returned value is always a valid path, with the single exception that
- * the last character is "/".
+ * Returned value is guaranteed to be a valid parent path, i.e. a valid
+ * child path can be made using parent.base() + child_name.
*/
- inline const string base() const
- {
+ inline const std::string base() const {
if ((*this) == "/")
return *this;
else
@@ -127,8 +119,7 @@ public:
}
/** Return true if \a child is equal to, or a descendant of \a parent */
- static bool descendant_comparator(const Path& parent, const Path& child)
- {
+ static bool descendant_comparator(const Path& parent, const Path& child) {
return ( child == parent || (child.length() > parent.length() &&
(!strncmp(parent.c_str(), child.c_str(), parent.length())
&& (parent == "/" || child[parent.length()] == '/'))) );
diff --git a/raul/Process.hpp b/raul/Process.hpp
index 2f5e286..8827a9e 100644
--- a/raul/Process.hpp
+++ b/raul/Process.hpp
@@ -40,8 +40,7 @@ public:
*
* @param command can be a typical shell command with parameters, the PATH is searched etc.
*/
- static bool launch(std::string command)
- {
+ static bool launch(const std::string& command) {
const std::string executable = (command.find(" ") != std::string::npos)
? command.substr(0, command.find(" "))
: command;
diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp
index b746bce..4098a2f 100644
--- a/raul/RingBuffer.hpp
+++ b/raul/RingBuffer.hpp
@@ -93,7 +93,7 @@ protected:
mutable gint _read_ptr;
size_t _size; ///< Size (capacity) in bytes
- T* _buf; ///< size, event, size, event...
+ T* _buf; ///< size, event, size, event...
};
diff --git a/raul/SMFReader.hpp b/raul/SMFReader.hpp
index bc7035d..51ebdc7 100644
--- a/raul/SMFReader.hpp
+++ b/raul/SMFReader.hpp
@@ -19,6 +19,8 @@
#define RAUL_SMF_READER_HPP
#include <stdexcept>
+#include <string>
+#include <inttypes.h>
namespace Raul {
@@ -34,19 +36,20 @@ public:
bool open(const std::string& filename);
- bool seek_to_track(unsigned track);
+ bool seek_to_track(unsigned track) throw (std::logic_error);
uint16_t type() const { return _type; }
uint16_t ppqn() const { return _ppqn; }
size_t num_tracks() { return _num_tracks; }
- int read_event(size_t buf_len, unsigned char* buf, uint32_t* ev_size, uint32_t* ev_delta_time);
+ int read_event(size_t buf_len,
+ uint8_t* buf,
+ uint32_t* ev_size,
+ uint32_t* ev_delta_time) throw (std::logic_error);
void close();
protected:
- //static const uint32_t VAR_LEN_MAX = 0x0FFFFFFF;
-
/** size of SMF header, including MTrk chunk header */
static const uint32_t HEADER_SIZE = 22;
@@ -57,11 +60,8 @@ protected:
uint16_t _type;
uint16_t _ppqn;
uint16_t _num_tracks;
- //uint32_t _track;
+ uint32_t _track;
uint32_t _track_size;
-/* Raul::BeatTime _start_time;
- Raul::BeatTime _last_ev_time; ///< Time last event was written relative to _start_time
- */
};
diff --git a/raul/SMFWriter.hpp b/raul/SMFWriter.hpp
index 1ccb631..df91909 100644
--- a/raul/SMFWriter.hpp
+++ b/raul/SMFWriter.hpp
@@ -53,8 +53,6 @@ protected:
void write_chunk_header(const char id[4], uint32_t length);
void write_chunk(const char id[4], uint32_t length, void* data);
size_t write_var_len(uint32_t val);
- //uint32_t read_var_len() const;
- //int read_event(MidiEvent& ev) const;
std::string _filename;
FILE* _fd;
diff --git a/raul/Slave.hpp b/raul/Slave.hpp
index 91c90f3..387a6c5 100644
--- a/raul/Slave.hpp
+++ b/raul/Slave.hpp
@@ -52,8 +52,7 @@ protected:
Semaphore _whip;
private:
- inline void _run()
- {
+ inline void _run() {
while (true) {
_whip.wait();
_whipped();
diff --git a/raul/TableImpl.hpp b/raul/TableImpl.hpp
index 4d6be6d..4f1f6aa 100644
--- a/raul/TableImpl.hpp
+++ b/raul/TableImpl.hpp
@@ -26,10 +26,7 @@
namespace Raul {
-/* This is all a god awful mess.
- * Whoever decided you shouldn't be able to get an index from an
- * std::vector::iterator or vice-versa should be shot and pissed on.
- */
+/* FIXME: This could be a lot less code... */
#ifdef TABLE_SORT_DEBUG
template <typename K, typename T>
@@ -125,7 +122,7 @@ template <typename K, typename T>
typename Table<K,T>::const_iterator
Table<K,T>::find_range_end(const_iterator start, bool (*comp)(const K&,const K&)) const
{
- return ((Table<K, T>*)this)->find_range_end(*((iterator*)&start), comp);
+ return (const_cast<Table<K, T>&>(*this)).find_range_end(*((iterator*)&start), comp);
}