diff options
-rw-r--r-- | raul/Array.hpp | 10 | ||||
-rw-r--r-- | raul/Atom.hpp | 4 | ||||
-rw-r--r-- | raul/AtomLiblo.hpp | 6 | ||||
-rw-r--r-- | raul/Command.hpp | 7 | ||||
-rw-r--r-- | raul/DoubleBuffer.hpp | 6 | ||||
-rw-r--r-- | raul/JackDriver.hpp | 16 | ||||
-rw-r--r-- | raul/List.hpp | 26 | ||||
-rw-r--r-- | raul/ListImpl.hpp | 49 | ||||
-rw-r--r-- | raul/Path.hpp | 37 | ||||
-rw-r--r-- | raul/Process.hpp | 3 | ||||
-rw-r--r-- | raul/RingBuffer.hpp | 2 | ||||
-rw-r--r-- | raul/SMFReader.hpp | 16 | ||||
-rw-r--r-- | raul/SMFWriter.hpp | 2 | ||||
-rw-r--r-- | raul/Slave.hpp | 3 | ||||
-rw-r--r-- | raul/TableImpl.hpp | 7 | ||||
-rw-r--r-- | src/Path.cpp | 27 | ||||
-rw-r--r-- | src/SMFReader.cpp | 25 | ||||
-rw-r--r-- | src/SMFWriter.cpp | 73 |
18 files changed, 73 insertions, 246 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); } diff --git a/src/Path.cpp b/src/Path.cpp index 284cf16..04f89e7 100644 --- a/src/Path.cpp +++ b/src/Path.cpp @@ -17,6 +17,8 @@ #include <raul/Path.hpp> +using namespace std; + namespace Raul { @@ -124,27 +126,6 @@ Path::nameify(const std::basic_string<char>& str) void Path::replace_invalid_chars(string& str, bool replace_slash) { -#if 0 - for (size_t i=0; i < str.length(); ++i) { - if (str[i] == ' ' || str[i] == '_') { - str[i+1] = std::toupper(str[i+1]); // capitalize next char - str = str.substr(0, i) + str.substr(i+1); // chop space/underscore - --i; - } else if (str[i] == '[' || str[i] == '{') { - str[i] = '('; - } else if (str[i] == ']' || str[i] == '}') { - str[i] = ')'; - } else if (str[i] < 32 || str.at(i) > 126 - || str[i] == '#' - || str[i] == '*' - || str[i] == ',' - || str[i] == '?' - || (replace_slash && str[i] == '/')) { - str[i] = '.'; - } - } -#endif - size_t open_bracket = str.find_first_of('('); if (open_bracket != string::npos) str = str.substr(0, open_bracket-1); @@ -165,10 +146,8 @@ Path::replace_invalid_chars(string& str, bool replace_slash) // Kill CamelCase in favour of god_fearing_symbol_names for (size_t i=1; i < str.length(); ++i) { - if (str[i] >= 'A' && str[i] <= 'Z' && str[i-1] >= 'a' && str[i-1] <= 'z') { - //str[i] = std::tolower(str[i]); + if (str[i] >= 'A' && str[i] <= 'Z' && str[i-1] >= 'a' && str[i-1] <= 'z') str = str.substr(0, i) + '_' + str.substr(i); - } } for (size_t i=0; i < str.length(); ++i) { diff --git a/src/SMFReader.cpp b/src/SMFReader.cpp index 9b2e4de..a27939d 100644 --- a/src/SMFReader.cpp +++ b/src/SMFReader.cpp @@ -73,6 +73,7 @@ midi_event_size(unsigned char status) SMFReader::SMFReader() : _fd(NULL) , _ppqn(0) + , _track(0) , _track_size(0) { } @@ -127,14 +128,6 @@ SMFReader::open(const string& filename) _ppqn = GUINT16_FROM_BE(ppqn_be); seek_to_track(1); - // Read Track size (skip bytes 14..17 'Mtrk') - // FIXME: first track read only - /*fseek(_fd, 18, SEEK_SET); - uint32_t track_size_be = 0; - fread(&track_size_be, 4, 1, _fd); - _track_size = GUINT32_FROM_BE(track_size_be); - std::cerr << "SMF - read track size " << _track_size << std::endl; - */ return true; } else { @@ -147,12 +140,12 @@ SMFReader::open(const string& filename) * Returns true if specified track was found. */ bool -SMFReader::seek_to_track(unsigned track) +SMFReader::seek_to_track(unsigned track) throw (std::logic_error) { assert(track > 0); if (!_fd) - throw logic_error("Attempt to seek to track on unopen SMF file."); + throw logic_error("Attempt to seek to track on unopened SMF file."); unsigned track_pos = 0; @@ -182,7 +175,7 @@ SMFReader::seek_to_track(unsigned track) } if (!feof(_fd) && track_pos == track) { - //_track = track; + _track = track; _track_size = chunk_size; return true; } else { @@ -205,10 +198,14 @@ SMFReader::seek_to_track(unsigned track) * set to the actual size of the event. */ int -SMFReader::read_event(size_t buf_len, unsigned char* buf, uint32_t* ev_size, uint32_t* delta_time) +SMFReader::read_event(size_t buf_len, + uint8_t* buf, + uint32_t* ev_size, + uint32_t* delta_time) throw (std::logic_error) { - // - 4 is for the EOT event, which we don't actually want to read - //if (feof(_fd) || ftell(_fd) >= HEADER_SIZE + _track_size - 4) { + if (_track == 0) + throw logic_error("Attempt to read from unopened SMF file"); + if (!_fd || feof(_fd)) { return -1; } diff --git a/src/SMFWriter.cpp b/src/SMFWriter.cpp index b339b46..b141e30 100644 --- a/src/SMFWriter.cpp +++ b/src/SMFWriter.cpp @@ -71,48 +71,6 @@ SMFWriter::start(const string& filename, return (_fd == 0) ? -1 : 0; } -#if 0 -jack_nframes_t -SMFWriter::write_unlocked (MidiRingBuffer& src, jack_nframes_t cnt) -{ - //cerr << "SMF WRITE -- " << _length << "--" << cnt << endl; - - MidiBuffer buf(1024); // FIXME: allocation, size? - src.read(buf, /*_length*/0, _length + cnt); // FIXME? - - fseek(_fd, 0, SEEK_END); - - // FIXME: start of source time? - - for (size_t i=0; i < buf.size(); ++i) { - const MidiEvent& ev = buf[i]; - assert(ev.time >= _timeline_position); - uint32_t delta_time = (ev.time - _timeline_position) - _last_ev_time; - - /*printf("SMF - writing event, delta = %u, size = %zu, data = ", - delta_time, ev.size); - for (size_t i=0; i < ev.size; ++i) { - printf("%X ", ev.buffer[i]); - } - printf("\n"); - */ - size_t stamp_size = write_var_len(delta_time); - fwrite(ev.buffer, 1, ev.size, _fd); - _last_ev_time += delta_time; - _track_size += stamp_size + ev.size; - } - - fflush(_fd); - - if (buf.size() > 0) { - ViewDataRangeReady (_length, cnt); /* EMIT SIGNAL */ - } - - update_length(_length, cnt); - return cnt; -} -#endif - /** Write an event at the end of the file. * @@ -184,9 +142,9 @@ SMFWriter::write_header() assert(_fd); - const uint16_t type = GUINT16_TO_BE(0); // SMF Type 0 (single track) - const uint16_t ntracks = GUINT16_TO_BE(1); // Number of tracks (always 1 for Type 0) - const uint16_t division = GUINT16_TO_BE(_ppqn); // Number of tracks (always 1 for Type 0) + const uint16_t type = GUINT16_TO_BE(0); // SMF Type 0 (single track) + const uint16_t ntracks = GUINT16_TO_BE(1); // Number of tracks (always 1 for Type 0) + const uint16_t division = GUINT16_TO_BE(_ppqn); // Number of tracks (always 1 for Type 0) char data[6]; memcpy(data, &type, 2); @@ -264,30 +222,5 @@ SMFWriter::write_var_len(uint32_t value) } -#if 0 -uint32_t -SMFWriter::read_var_len() const -{ - assert(!feof(_fd)); - - //int offset = ftell(_fd); - //cerr << "SMF - reading var len at " << offset << endl; - - uint32_t value; - unsigned char c; - - if ( (value = getc(_fd)) & 0x80 ) { - value &= 0x7F; - do { - assert(!feof(_fd)); - value = (value << 7) + ((c = getc(_fd)) & 0x7F); - } while (c & 0x80); - } - - return value; -} -#endif - - } // namespace Raul |