diff options
author | Christian Glöckner <cgloeckner@freenet.de> | 2016-03-29 16:45:39 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-03-31 17:44:25 +0200 |
commit | b663b60b70a3a7a6678e4cc2cc29d5394e2e6539 (patch) | |
tree | cdfee424061766e74bf4ecec3ad8befe8140c7a9 | |
parent | 4f4ac639f9bea3fcacf439213aabd0b70c678ecb (diff) |
API Refactoring for events
-rw-r--r-- | src/drumgizmo.cc | 4 | ||||
-rw-r--r-- | src/events.cc | 27 | ||||
-rw-r--r-- | 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<timepos_t, Event*>(time, event)); + MutexAutolock lock(mutex); + event->offset = time; + queue.insert(std::pair<timepos_t, Event*>(time, event)); } -Event *EventQueue::take(timepos_t time) +Event* EventQueue::take(timepos_t time) { - MutexAutolock lock(mutex); - std::multimap<timepos_t, Event*>::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<timepos_t, Event*>::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 <map> #include <stdio.h> @@ -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<timepos_t, Event*> queue; + Mutex mutex; }; -#endif/*__DRUMGIZMO_EVENTS_H__*/ |