From b663b60b70a3a7a6678e4cc2cc29d5394e2e6539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Tue, 29 Mar 2016 16:45:39 +0200 Subject: API Refactoring for events --- src/drumgizmo.cc | 4 +-- src/events.cc | 27 ++++++++-------- src/events.h | 98 +++++++++++++++++++++++++++++++------------------------- 3 files changed, 70 insertions(+), 59 deletions(-) diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index d9afbfa..853e93d 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -315,7 +315,7 @@ bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) while(evs != activeevents[ch.num].end()) { Event *ev = *evs; - if(ev->type() == Event::sample) + if(ev->getType() == Event::sample) { EventSample *sev = (EventSample*)ev; if(sev->group == i->getGroup() && sev->instrument != i) @@ -498,7 +498,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) Event* event = *i; - Event::type_t type = event->type(); + Event::type_t type = event->getType(); switch(type) { case Event::sample: { diff --git a/src/events.cc b/src/events.cc index 8149c08..a7ce715 100644 --- a/src/events.cc +++ b/src/events.cc @@ -26,25 +26,26 @@ */ #include "events.h" -void EventQueue::post(Event *event, timepos_t time) +void EventQueue::post(Event* event, timepos_t time) { - MutexAutolock lock(mutex); - event->offset = time; - queue.insert(std::pair(time, event)); + MutexAutolock lock(mutex); + event->offset = time; + queue.insert(std::pair(time, event)); } -Event *EventQueue::take(timepos_t time) +Event* EventQueue::take(timepos_t time) { - MutexAutolock lock(mutex); - std::multimap::iterator i = queue.find(time); - if(i == queue.end()) return NULL; - Event *event = i->second; - queue.erase(i); - return event; + MutexAutolock lock(mutex); + std::multimap::iterator i = queue.find(time); + if(i == queue.end()) + return NULL; + Event* event = i->second; + queue.erase(i); + return event; } bool EventQueue::hasEvent(timepos_t time) { - MutexAutolock lock(mutex); - return queue.find(time) != queue.end(); + MutexAutolock lock(mutex); + return queue.find(time) != queue.end(); } diff --git a/src/events.h b/src/events.h index a965bd3..bbbb7ea 100644 --- a/src/events.h +++ b/src/events.h @@ -24,8 +24,7 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_EVENTS_H__ -#define __DRUMGIZMO_EVENTS_H__ +#pragma once #include #include @@ -39,62 +38,73 @@ typedef unsigned int timepos_t; -class Event { +class Event +{ public: - virtual ~Event() {} + virtual ~Event() + { + } - typedef enum { - sample - } type_t; - - virtual type_t type() = 0; + typedef enum + { + sample + } type_t; - channel_t channel; - timepos_t offset; + virtual type_t getType() const = 0; + + channel_t channel; + timepos_t offset; }; #define NO_RAMPDOWN -1 -class EventSample : public Event { +class EventSample : public Event +{ public: - EventSample(channel_t c, float g, AudioFile *af, std::string grp, - void *instr) - { - cache_id = CACHE_NOID; - channel = c; - gain = g; - t = 0; - file = af; - group = grp; - instrument = instr; - rampdown = NO_RAMPDOWN; - ramp_start = 0; - } + EventSample(channel_t c, float g, AudioFile* af, + const std::string& grp, void* instr) + { + cache_id = CACHE_NOID; + channel = c; + gain = g; + t = 0; + file = af; + group = grp; + instrument = instr; + rampdown = NO_RAMPDOWN; + ramp_start = 0; + } - Event::type_t type() { return Event::sample; } + Event::type_t getType() const + { + return Event::sample; + } - cacheid_t cache_id; - sample_t *buffer; - size_t buffer_size; + cacheid_t cache_id; + sample_t* buffer; + size_t buffer_size; - float gain; - unsigned int t; - AudioFile *file; - std::string group; - void *instrument; - int rampdown; - int ramp_start; + float gain; + unsigned int t; + AudioFile* file; + std::string group; + void* instrument; + int rampdown; + int ramp_start; }; -class EventQueue { +class EventQueue +{ public: - void post(Event *event, timepos_t time); - Event *take(timepos_t time); - bool hasEvent(timepos_t time); - size_t size() { return queue.size(); } + void post(Event* event, timepos_t time); + Event* take(timepos_t time); + bool hasEvent(timepos_t time); + size_t getSize() const + { + return queue.size(); + } private: - std::multimap< timepos_t, Event* > queue; - Mutex mutex; + std::multimap queue; + Mutex mutex; }; -#endif/*__DRUMGIZMO_EVENTS_H__*/ -- cgit v1.2.3