remove old midi-note name API
[ardour.git] / libs / evoral / evoral / Event.hpp
index 21f83e40b83907c4d1f1960143a5e33547cae416..cbb62e2f4cc289fade9ad1c0d31e51d1a5e050bd 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Evoral.
- * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
+ * Copyright (C) 2008 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
 #ifndef EVORAL_EVENT_HPP
 #define EVORAL_EVENT_HPP
 
-#include <stdint.h>
 #include <cstdlib>
 #include <cstring>
 #include <sstream>
-#include <assert.h>
+#include <stdint.h>
+
+#include "evoral/visibility.h"
 #include "evoral/types.hpp"
 
 /** If this is not defined, all methods of MidiEvent are RT safe
 
 namespace Evoral {
 
-event_id_t event_id_counter();
-event_id_t next_event_id();
-void init_event_id_counter (event_id_t n);
+LIBEVORAL_API event_id_t event_id_counter();
+LIBEVORAL_API event_id_t next_event_id();
+LIBEVORAL_API void init_event_id_counter(event_id_t n);
 
 /** An event (much like a type generic jack_midi_event_t)
  *
  * Template parameter Time is the type of the time stamp used for this event.
  */
 template<typename Time>
-struct Event {
+class LIBEVORAL_API Event {
+public:
 #ifdef EVORAL_EVENT_ALLOC
-       Event (EventType type=0, Time time=0, uint32_t size=0, uint8_t* buf=NULL, bool alloc=false);
+       Event (EventType type=0, 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);
 
        /** Copy \a copy.
         *
@@ -55,45 +59,11 @@ struct Event {
         */
        Event(const Event& copy, bool alloc);
 
-       ~Event();
+        ~Event();
 
-       inline const Event& operator=(const Event& copy) {
-               _id = copy.id(); // XXX is this right? do we want ID copy semantics?
-               _type = copy._type;
-               _original_time = copy._original_time;
-               _nominal_time = copy._nominal_time;
-               if (_owns_buf) {
-                       if (copy._buf) {
-                               if (copy._size > _size) {
-                                       _buf = (uint8_t*)::realloc(_buf, copy._size);
-                               }
-                               memcpy(_buf, copy._buf, copy._size);
-                       } else {
-                               free(_buf);
-                               _buf = NULL;
-                       }
-               } else {
-                       _buf = copy._buf;
-               }
-
-               _size = copy._size;
-               return *this;
-       }
-
-       inline void set(uint8_t* buf, uint32_t size, Time t) {
-               if (_owns_buf) {
-                       if (_size < size) {
-                               _buf = (uint8_t*) ::realloc(_buf, size);
-                       }
-                       memcpy (_buf, buf, size);
-               } else {
-                       _buf = buf;
-               }
+       void assign (const Event& other);
 
-               _original_time = t;
-               _nominal_time = t;
-               _size = size;
-       }
+       void set(const uint8_t* buf, uint32_t size, Time t);
 
        inline bool operator==(const Event& other) const {
                if (_type != other._type)
@@ -122,6 +92,11 @@ struct Event {
 
        inline bool owns_buffer() const { return _owns_buf; }
 
+       /** set event data (e.g. midi data)
+        * @param size number of bytes
+        * @param buf raw 8bit data
+        * @param own set to true if the buffer owns the data (copy, allocate/free) or false to reference previously allocated data.
+        */
        inline void set_buffer(uint32_t size, uint8_t* buf, bool own) {
                if (_owns_buf) {
                        free(_buf);
@@ -145,11 +120,11 @@ struct Event {
        }
 
        inline void clear() {
-               _type = 0;
-               _original_time = 0;
-               _nominal_time = 0;
-               _size = 0;
-               _buf  = NULL;
+               _type          = 0;
+               _original_time = Time();
+               _nominal_time  = Time();
+               _size          = 0;
+               _buf           = NULL;
        }
 
 #else
@@ -158,42 +133,35 @@ struct Event {
 
 #endif // EVORAL_EVENT_ALLOC
 
-       inline EventType   event_type()            const { return _type; }
-       inline void        set_event_type(EventType t)   { _type = t; }
-       inline Time        time()                  const { return _nominal_time; }
-       inline Time&       time()                        { return _nominal_time; }
-       inline Time        original_time()         const { return _original_time; }
-       inline Time&       original_time()               { return _original_time; }
-       inline uint32_t    size()                  const { return _size; }
-       inline uint32_t&   size()                        { return _size; }
+       inline EventType      event_type()    const { return _type; }
+       inline Time           time()          const { return _nominal_time; }
+       inline Time           original_time() const { return _original_time; }
+       inline uint32_t       size()          const { return _size; }
+       inline const uint8_t* buffer()        const { return _buf; }
+       inline uint8_t*       buffer()              { return _buf; }
 
-       inline const uint8_t* buffer()             const { return _buf; }
-       inline uint8_t*&      buffer()                   { return _buf; }
+       inline void set_event_type(EventType t) { _type = t; }
 
-       void set_time (Time);
-       void set_original_time (Time);
+       void set_time(Time);
+       void set_original_time(Time);
 
-       inline event_id_t id() const { return _id; }
-       inline void set_id (event_id_t n) { _id = n; }
+       inline event_id_t id() const           { return _id; }
+       inline void       set_id(event_id_t n) { _id = n; }
 
 protected:
-       EventType _type; /**< Type of event (application relative, NOT MIDI 'type') */
-       Time      _original_time; /**< Sample index (or beat time) at which event is valid */
-       Time      _nominal_time; /**< Quantized version of _time, used in preference */
-       uint32_t  _size; /**< Number of uint8_ts of data in \a buffer */
-       uint8_t*  _buf;  /**< Raw MIDI data */
-
+       EventType  _type; /**< Type of event (application relative, NOT MIDI 'type') */
+       Time       _original_time; /**< Sample index (or beat time) at which event is valid */
+       Time       _nominal_time; /**< Quantized version of _time, used in preference */
+       uint32_t   _size; /**< Number of uint8_ts of data in \a buffer */
+       uint8_t*   _buf;  /**< Raw MIDI data */
+       event_id_t _id; /** UUID for each event, should probably be 64bit or at least unsigned */
 #ifdef EVORAL_EVENT_ALLOC
-       bool      _owns_buf; /**< Whether buffer is locally allocated */
+       bool       _owns_buf; /**< Whether buffer is locally allocated */
 #endif
-       event_id_t  _id; /** UUID for each event, should probably be 64bit or at least unsigned */
 };
 
-} // namespace Evoral
-
-
 template<typename Time>
-std::ostream& operator<<(std::ostream& o, const Evoral::Event<Time>& ev) {
+/*LIBEVORAL_API*/ std::ostream& operator<<(std::ostream& o, const Evoral::Event<Time>& ev) {
        o << "Event #" << ev.id() << " type = " << ev.event_type() << " @ " << ev.time();
        o << std::hex;
        for (uint32_t n = 0; n < ev.size(); ++n) {
@@ -203,6 +171,7 @@ std::ostream& operator<<(std::ostream& o, const Evoral::Event<Time>& ev) {
        return o;
 }
 
+} // namespace Evoral
 
 #endif // EVORAL_EVENT_HPP