summaryrefslogtreecommitdiff
path: root/libs/midi++2/midi++/event.h
diff options
context:
space:
mode:
authorHans Baier <hansfbaier@googlemail.com>2008-05-25 23:35:23 +0000
committerHans Baier <hansfbaier@googlemail.com>2008-05-25 23:35:23 +0000
commit911c5717bcf8da0f59048d1fd3af0da09a21cbd7 (patch)
tree864ede432712a932b9b101206c63556df57e34df /libs/midi++2/midi++/event.h
parent5c60257b4aa9c31c25c6afea95208e4fffc8465b (diff)
* splitted midi++/event.h in header and implementation
* added to_string(), to_xml() and from_xml() to MIDI::Event * added partial support for midnam-Patchfiles (http://www.sonosphere.com/dtds/MIDINameDocument.dtd): midnam_patch.h/.cc * added validation support to xml++.cc/.h * added XMLNode::add_property(const char *name, const long value) * added test to pbd/tests/xpath.cc git-svn-id: svn://localhost/ardour2/branches/3.0@3412 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/midi++2/midi++/event.h')
-rw-r--r--libs/midi++2/midi++/event.h64
1 files changed, 20 insertions, 44 deletions
diff --git a/libs/midi++2/midi++/event.h b/libs/midi++2/midi++/event.h
index 123ff8f7fc..64f99090ad 100644
--- a/libs/midi++2/midi++/event.h
+++ b/libs/midi++2/midi++/event.h
@@ -29,6 +29,7 @@
#include <midi++/types.h>
#include <midi++/events.h>
+#include <pbd/xml++.h>
/** If this is not defined, all methods of MidiEvent are RT safe
* but MidiEvent will never deep copy and (depending on the scenario)
@@ -46,21 +47,7 @@ namespace MIDI {
*/
struct Event {
#ifdef MIDI_EVENT_ALLOW_ALLOC
- Event(double t=0, uint32_t s=0, uint8_t* b=NULL, bool owns_buffer=false)
- : _time(t)
- , _size(s)
- , _buffer(b)
- , _owns_buffer(owns_buffer)
- {
- if (owns_buffer) {
- _buffer = (uint8_t*)malloc(_size);
- if (b) {
- memcpy(_buffer, b, _size);
- } else {
- memset(_buffer, 0, _size);
- }
- }
- }
+ Event(double t=0, uint32_t s=0, uint8_t* b=NULL, bool owns_buffer=false);
/** Copy \a copy.
*
@@ -68,27 +55,14 @@ struct Event {
* is NOT REALTIME SAFE. Otherwise both events share a buffer and
* memory management semantics are the caller's problem.
*/
- Event(const Event& copy, bool owns_buffer)
- : _time(copy._time)
- , _size(copy._size)
- , _buffer(copy._buffer)
- , _owns_buffer(owns_buffer)
- {
- if (owns_buffer) {
- _buffer = (uint8_t*)malloc(_size);
- if (copy._buffer) {
- memcpy(_buffer, copy._buffer, _size);
- } else {
- memset(_buffer, 0, _size);
- }
- }
- }
+ Event(const Event& copy, bool owns_buffer);
- ~Event() {
- if (_owns_buffer) {
- free(_buffer);
- }
- }
+ /**
+ * see the MIDI XML specification: http://www.midi.org/dtds/MIDIEvents10.dtd
+ */
+ Event(const XMLNode &event);
+
+ ~Event();
inline const Event& operator=(const Event& copy) {
_time = copy._time;
@@ -179,6 +153,7 @@ struct Event {
_size = size;
}
+
#else
inline void set_buffer(uint8_t* buf) { _buffer = buf; }
@@ -218,15 +193,16 @@ struct Event {
inline bool is_sysex() const { return _buffer[0] == 0xF0 || _buffer[0] == 0xF7; }
inline const uint8_t* buffer() const { return _buffer; }
inline uint8_t*& buffer() { return _buffer; }
- inline std::string to_string() const {
- std::ostringstream result(std::ios::ate);
- result << "MIDI::Event type:" << std::hex << "0x" << int(type()) << " buffer: ";
-
- for(uint32_t i = 0; i < size(); ++i) {
- result << " 0x" << int(_buffer[i]);
- }
- return result.str();
- }
+
+ /**
+ * mainly used for debugging purposes
+ */
+ std::string to_string() const;
+
+ /**
+ * see the MIDI XML specification: http://www.midi.org/dtds/MIDIEvents10.dtd
+ */
+ boost::shared_ptr<XMLNode> to_xml() const;
private:
double _time; /**< Sample index (or beat time) at which event is valid */