diff options
author | David Robillard <d@drobilla.net> | 2016-11-07 05:14:55 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-12-03 15:28:19 -0500 |
commit | 398a318934769dae51efe972f7ffdefc52ea2963 (patch) | |
tree | 5b68a8fac44f0c154e7e00fd45d9e7f2c16e35fb /libs/evoral/evoral | |
parent | bfbc4566ad82573a57e1ec84d583f308ee35eef0 (diff) |
Fix event type and parameter type confusion
I'm not sure if this is really the best way to do event types (should it
just be a completely static enum in evoral, or completely dynamic and
provided by the type map, or a mix like currently?), but previously the
event type was frequently set to either total garbage, or parameter
types, which are a different thing.
This fixes all those cases, and makes Evoral::EventType an enum so the
compiler will warn about implicit conversions from int.
Diffstat (limited to 'libs/evoral/evoral')
-rw-r--r-- | libs/evoral/evoral/Event.hpp | 4 | ||||
-rw-r--r-- | libs/evoral/evoral/Parameter.hpp | 15 | ||||
-rw-r--r-- | libs/evoral/evoral/PatchChange.hpp | 6 | ||||
-rw-r--r-- | libs/evoral/evoral/TypeMap.hpp | 6 | ||||
-rw-r--r-- | libs/evoral/evoral/types.hpp | 21 |
5 files changed, 34 insertions, 18 deletions
diff --git a/libs/evoral/evoral/Event.hpp b/libs/evoral/evoral/Event.hpp index 526513b3fe..696fb995ab 100644 --- a/libs/evoral/evoral/Event.hpp +++ b/libs/evoral/evoral/Event.hpp @@ -48,7 +48,7 @@ template<typename Time> class LIBEVORAL_API Event { public: #ifdef EVORAL_EVENT_ALLOC - Event(EventType type=0, Time time=Time(), uint32_t size=0, uint8_t* buf=NULL, bool alloc=false); + Event(EventType type=NO_EVENT, Time time=Time(), uint32_t size=0, uint8_t* buf=NULL, bool alloc=false); Event(EventType type, Time time, uint32_t size, const uint8_t* buf); @@ -108,7 +108,7 @@ public: } inline void clear() { - _type = 0; + _type = NO_EVENT; _original_time = Time(); _nominal_time = Time(); _size = 0; diff --git a/libs/evoral/evoral/Parameter.hpp b/libs/evoral/evoral/Parameter.hpp index 1412699b4d..2614a03d86 100644 --- a/libs/evoral/evoral/Parameter.hpp +++ b/libs/evoral/evoral/Parameter.hpp @@ -25,6 +25,7 @@ #include <boost/shared_ptr.hpp> #include "evoral/visibility.h" +#include "evoral/types.hpp" namespace Evoral { @@ -40,13 +41,13 @@ namespace Evoral { class LIBEVORAL_API Parameter { public: - inline Parameter(uint32_t type, uint8_t channel=0, uint32_t id=0) + inline Parameter(ParameterType type, uint8_t channel=0, uint32_t id=0) : _type(type), _id(id), _channel(channel) {} - inline uint32_t type() const { return _type; } - inline uint8_t channel() const { return _channel; } - inline uint32_t id() const { return _id; } + inline ParameterType type() const { return _type; } + inline uint8_t channel() const { return _channel; } + inline uint32_t id() const { return _id; } /** Equivalence operator * It is obvious from the definition that this operator @@ -80,9 +81,9 @@ public: inline operator bool() const { return (_type != 0); } private: - uint32_t _type; - uint32_t _id; - uint8_t _channel; + ParameterType _type; + uint32_t _id; + uint8_t _channel; }; } // namespace Evoral diff --git a/libs/evoral/evoral/PatchChange.hpp b/libs/evoral/evoral/PatchChange.hpp index a775a72cc3..90d3dba732 100644 --- a/libs/evoral/evoral/PatchChange.hpp +++ b/libs/evoral/evoral/PatchChange.hpp @@ -39,9 +39,9 @@ public: * @param b Bank number (counted from 0, 14-bit). */ PatchChange (Time t, uint8_t c, uint8_t p, int b) - : _bank_change_msb (0, t, 3, 0, true) - , _bank_change_lsb (0, t, 3, 0, true) - , _program_change (0, t, 2, 0, true) + : _bank_change_msb (MIDI_EVENT, t, 3, 0, true) + , _bank_change_lsb (MIDI_EVENT, t, 3, 0, true) + , _program_change (MIDI_EVENT, t, 2, 0, true) { _bank_change_msb.buffer()[0] = MIDI_CMD_CONTROL | c; _bank_change_msb.buffer()[1] = MIDI_CTL_MSB_BANK; diff --git a/libs/evoral/evoral/TypeMap.hpp b/libs/evoral/evoral/TypeMap.hpp index d09439daa6..0ebc81370b 100644 --- a/libs/evoral/evoral/TypeMap.hpp +++ b/libs/evoral/evoral/TypeMap.hpp @@ -24,6 +24,7 @@ #include <string> #include "evoral/visibility.h" +#include "evoral/types.hpp" namespace Evoral { @@ -47,9 +48,8 @@ public: */ virtual uint8_t parameter_midi_type(const Parameter& param) const = 0; - /** The type ID for a MIDI event with the given status byte - */ - virtual uint32_t midi_event_type(uint8_t status) const = 0; + /** The parameter type for the given MIDI event. */ + virtual ParameterType midi_parameter_type(const uint8_t* buf, uint32_t len) const = 0; /** Return the description of a parameter. */ virtual ParameterDescriptor descriptor(const Parameter& param) const = 0; diff --git a/libs/evoral/evoral/types.hpp b/libs/evoral/evoral/types.hpp index a5d4a8ca1e..72b95f8460 100644 --- a/libs/evoral/evoral/types.hpp +++ b/libs/evoral/evoral/types.hpp @@ -1,5 +1,5 @@ /* This file is part of Evoral. - * Copyright (C) 2008 David Robillard <http://drobilla.net> + * Copyright (C) 2008-2016 David Robillard <http://drobilla.net> * Copyright (C) 2000-2008 Paul Davis * * Evoral is free software; you can redistribute it and/or modify it under the @@ -37,8 +37,23 @@ namespace Evoral { */ typedef int32_t event_id_t; -/** Type of an event (opaque, mapped by application) */ -typedef uint32_t EventType; +/** Type of an event (opaque, mapped by application, e.g. MIDI). + * + * Event types are really an arbitrary integer provided by the type map, and it + * is safe to use values not in this enum, but this enum exists so the compiler + * can catch mistakes like setting the event type to a MIDI status byte. Event + * types come from the type map and describe a format/protocol like MIDI, and + * must not be confused with the payload (such as a note on or CC change). + * There is a static value for MIDI as this type is handled specially by + * various parts of Evoral. + */ +enum EventType { + NO_EVENT, + MIDI_EVENT +}; + +/** Type of a parameter (opaque, mapped by application, e.g. gain) */ +typedef uint32_t ParameterType; class Beats; |