diff options
author | David Robillard <d@drobilla.net> | 2011-04-28 18:19:28 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-28 18:19:28 +0000 |
commit | 8513a822501175e510591ff15418022a145ddc81 (patch) | |
tree | fbc3668f48d5c5392b895b8084237956252ad3e2 /src/engine | |
parent | f87b2217c0108e263669d2c5a80b87bab41f0002 (diff) | |
download | machina-8513a822501175e510591ff15418022a145ddc81.tar.gz machina-8513a822501175e510591ff15418022a145ddc81.tar.bz2 machina-8513a822501175e510591ff15418022a145ddc81.zip |
Improve RingBuffer implementation.
Previous implementation was broken when written to full capacity, and
this version is significantly faster as well.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@3213 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/Controller.cpp | 7 | ||||
-rw-r--r-- | src/engine/Recorder.cpp | 17 | ||||
-rw-r--r-- | src/engine/Recorder.hpp | 14 |
3 files changed, 30 insertions, 8 deletions
diff --git a/src/engine/Controller.cpp b/src/engine/Controller.cpp index edde2b1..1b92e5f 100644 --- a/src/engine/Controller.cpp +++ b/src/engine/Controller.cpp @@ -15,6 +15,8 @@ * along with Machina. If not, see <http://www.gnu.org/licenses/>. */ +#include "raul/log.hpp" + #include "client/ClientModel.hpp" #include "client/ClientObject.hpp" #include "machina/Controller.hpp" @@ -139,10 +141,11 @@ Controller::disconnect(uint64_t tail_id, uint64_t head_id) SharedPtr<Machina::Node> head = PtrCast<Machina::Node>(find(head_id)); SharedPtr<Edge> edge = tail->remove_edge_to(head); - if (edge) + if (edge) { _client_model.erase_object(edge->id()); - else + } else { Raul::error << "Edge not found" << std::endl; + } } void diff --git a/src/engine/Recorder.cpp b/src/engine/Recorder.cpp index c03d725..0a6b5a0 100644 --- a/src/engine/Recorder.cpp +++ b/src/engine/Recorder.cpp @@ -40,9 +40,20 @@ Recorder::_whipped() size_t size; unsigned char buf[4]; - while (_record_buffer.read(&t, &size, buf)) { - _builder->set_time(t); - _builder->event(TimeStamp(_unit), size, buf); + while (true) { + bool success = _record_buffer.read(sizeof(TimeStamp), (uint8_t*)&t); + if (success) { + success = _record_buffer.read(sizeof(size_t), (uint8_t*)&size); + } + if (success) { + success = _record_buffer.read(size, buf); + } + if (success) { + _builder->set_time(t); + _builder->event(TimeStamp(_unit), size, buf); + } else { + break; + } } } diff --git a/src/engine/Recorder.hpp b/src/engine/Recorder.hpp index c7f78f4..714b2a9 100644 --- a/src/engine/Recorder.hpp +++ b/src/engine/Recorder.hpp @@ -18,9 +18,10 @@ #ifndef MACHINA_RECORDER_HPP #define MACHINA_RECORDER_HPP +#include "raul/log.hpp" #include "raul/Slave.hpp" #include "raul/SharedPtr.hpp" -#include "raul/EventRingBuffer.hpp" +#include "raul/RingBuffer.hpp" #include "machina/Machine.hpp" @@ -33,7 +34,14 @@ public: Recorder(size_t buffer_size, TimeUnit unit, double q, bool step); inline void write(Raul::TimeStamp time, size_t size, const unsigned char* buf) { - _record_buffer.write(time, size, buf); + if (_record_buffer.write_space() < (sizeof(TimeStamp) + sizeof(size_t) + size)) { + Raul::warn << "Record buffer overflow" << std::endl; + return; + } else { + _record_buffer.write(sizeof(TimeStamp), (uint8_t*)&time); + _record_buffer.write(sizeof(size_t), (uint8_t*)&size); + _record_buffer.write(size, buf); + } } SharedPtr<Machine> finish(); @@ -42,7 +50,7 @@ private: virtual void _whipped(); TimeUnit _unit; - Raul::EventRingBuffer _record_buffer; + Raul::RingBuffer _record_buffer; SharedPtr<MachineBuilder> _builder; }; |