From fb992677cf62b6aa982476538faae43e5bbbd87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 12 Jan 2020 15:41:39 +0100 Subject: Introduce EventsDS to handle all the events and enable new features. Also: * Added an id.h class to make IDs with type * Added a range class to easily use range based for loops --- src/events.h | 68 +++++++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) (limited to 'src/events.h') diff --git a/src/events.h b/src/events.h index 18f9af3..1b3c376 100644 --- a/src/events.h +++ b/src/events.h @@ -1,6 +1,6 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /*************************************************************************** - * event.h + * events.h * * Sat Sep 18 22:02:16 CEST 2010 * Copyright 2010 Bent Bisballe Nyeng @@ -34,39 +34,48 @@ #include "audiofile.h" #include "audio.h" #include "audiocache.h" +#include "id.h" -typedef unsigned int timepos_t; +using timepos_t = unsigned int; + +class InputEvent; // just used as template argument for the ID +using InputEventID = ID; +using InputEventIDs = std::vector; + +class EventGroup; // just used as template argument for the ID +using EventGroupID = ID; +using EventGroupIDs = std::vector; + +class Event; +using EventID = ID; +using EventIDs = std::vector; class Event { public: - Event(channel_t channel, timepos_t offset = 0) - : channel(channel), offset(offset) - { - } + enum class Type { + SampleEvent, + }; - virtual ~Event() - { - } + Event(Type type, channel_t channel, timepos_t offset = 0) + : type(type), channel(channel), offset(offset) {} - typedef enum - { - sample - } type_t; - - virtual type_t getType() const = 0; + virtual ~Event() {} + EventID id; + EventGroupID group_id; + Type type; channel_t channel; timepos_t offset; //< Global position (ie. not relative to buffer) }; -class EventSample +class SampleEvent : public Event { public: - EventSample(channel_t c, float g, AudioFile* af, - const std::string& grp, std::size_t instrument_id) - : Event(c) + SampleEvent(channel_t ch, float g, AudioFile* af, const std::string& grp, + std::size_t instrument_id) + : Event(Event::Type::SampleEvent, ch) , cache_id(CACHE_NOID) , gain(g) , t(0) @@ -78,11 +87,6 @@ public: { } - Event::type_t getType() const - { - return Event::sample; - } - bool rampdownInProgress() const { return rampdown_count != -1; @@ -104,19 +108,3 @@ public: float scale{1.0f}; std::size_t instrument_id; }; - -class EventQueue -{ -public: - 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 queue; - std::mutex mutex; -}; -- cgit v1.2.3