diff options
Diffstat (limited to 'libs/midi++2')
-rw-r--r-- | libs/midi++2/SConscript | 2 | ||||
-rw-r--r-- | libs/midi++2/event.cc | 97 | ||||
-rw-r--r-- | libs/midi++2/jack_midiport.cc | 8 | ||||
-rw-r--r-- | libs/midi++2/midi++/event.h | 183 | ||||
-rw-r--r-- | libs/midi++2/midi++/jack.h | 2 | ||||
-rw-r--r-- | libs/midi++2/midi++/midnam_patch.h | 2 | ||||
-rw-r--r-- | libs/midi++2/midnam_patch.cc | 7 |
7 files changed, 16 insertions, 285 deletions
diff --git a/libs/midi++2/SConscript b/libs/midi++2/SConscript index 222e9e249a..95b64a0599 100644 --- a/libs/midi++2/SConscript +++ b/libs/midi++2/SConscript @@ -9,6 +9,7 @@ Import('env libraries install_prefix') midi2 = env.Clone() midi2.Merge([ libraries['sigc2'], libraries['xml'], + libraries['evoral'], libraries['glibmm2'], libraries['glib2'], libraries['pbd'], @@ -25,7 +26,6 @@ midi2.Append(DOMAIN=domain,MAJOR=2,MINOR=1,MICRO=1) sources = Split(""" fd_midiport.cc fifomidi.cc -event.cc midi.cc midichannel.cc midifactory.cc diff --git a/libs/midi++2/event.cc b/libs/midi++2/event.cc deleted file mode 100644 index 09e3fcf732..0000000000 --- a/libs/midi++2/event.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include "midi++/event.h" - -namespace MIDI { - -#ifdef MIDI_EVENT_ALLOW_ALLOC -Event::Event(double t, uint32_t s, uint8_t* b, bool owns_buffer) - : _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::Event(const XMLNode& event) -{ - string name = event.name(); - - if (name == "ControlChange") { - - } else if (name == "ProgramChange") { - - } -} - -Event::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::~Event() { - if (_owns_buffer) { - free(_buffer); - } -} - - -#endif // MIDI_EVENT_ALLOW_ALLOC - -std::string -Event::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(); -} - -boost::shared_ptr<XMLNode> -Event::to_xml() const -{ - XMLNode *result = 0; - - switch (type()) { - case MIDI_CMD_CONTROL: - result = new XMLNode("ControlChange"); - result->add_property("Channel", channel()); - result->add_property("Control", cc_number()); - result->add_property("Value", cc_value()); - break; - - case MIDI_CMD_PGM_CHANGE: - result = new XMLNode("ProgramChange"); - result->add_property("Channel", channel()); - result->add_property("number", pgm_number()); - break; - - default: - // The implementation is continued as needed - break; - } - - return boost::shared_ptr<XMLNode>(result); -} - -} // namespace MIDI diff --git a/libs/midi++2/jack_midiport.cc b/libs/midi++2/jack_midiport.cc index bcaa683bf8..fc1ba234a3 100644 --- a/libs/midi++2/jack_midiport.cc +++ b/libs/midi++2/jack_midiport.cc @@ -93,7 +93,7 @@ JACK_MidiPort::write(byte * msg, size_t msglen, timestamp_t timestamp) if (!is_process_thread()) { Glib::Mutex::Lock lm (non_process_thread_fifo_lock); - RingBuffer<Event>::rw_vector vec; + RingBuffer<Evoral::Event>::rw_vector vec; non_process_thread_fifo.get_write_vector (&vec); @@ -157,7 +157,7 @@ JACK_MidiPort::write(byte * msg, size_t msglen, timestamp_t timestamp) void JACK_MidiPort::flush (void* jack_port_buffer) { - RingBuffer<Event>::rw_vector vec; + RingBuffer<Evoral::Event>::rw_vector vec; size_t written; non_process_thread_fifo.get_read_vector (&vec); @@ -167,7 +167,7 @@ JACK_MidiPort::flush (void* jack_port_buffer) } if (vec.len[0]) { - Event* evp = vec.buf[0]; + Evoral::Event* evp = vec.buf[0]; for (size_t n = 0; n < vec.len[0]; ++n, ++evp) { jack_midi_event_write (jack_port_buffer, @@ -176,7 +176,7 @@ JACK_MidiPort::flush (void* jack_port_buffer) } if (vec.len[1]) { - Event* evp = vec.buf[1]; + Evoral::Event* evp = vec.buf[1]; for (size_t n = 0; n < vec.len[1]; ++n, ++evp) { jack_midi_event_write (jack_port_buffer, diff --git a/libs/midi++2/midi++/event.h b/libs/midi++2/midi++/event.h index 64f99090ad..8973ef48bd 100644 --- a/libs/midi++2/midi++/event.h +++ b/libs/midi++2/midi++/event.h @@ -35,186 +35,11 @@ * but MidiEvent will never deep copy and (depending on the scenario) * may not be usable in STL containers, signals, etc. */ -#define MIDI_EVENT_ALLOW_ALLOC 1 +#define EVENT_ALLOW_ALLOC 1 -namespace MIDI { +/** Support serialisation of MIDI events to/from XML */ +#define EVENT_WITH_XML 1 - -/** Identical to jack_midi_event_t, but with double timestamp - * - * time is either a frame time (from/to Jack) or a beat time (internal - * tempo time, used in MidiModel) depending on context. - */ -struct Event { -#ifdef MIDI_EVENT_ALLOW_ALLOC - Event(double t=0, uint32_t s=0, uint8_t* b=NULL, bool owns_buffer=false); - - /** Copy \a copy. - * - * If \a owns_buffer is true, the buffer will be copied and this method - * 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); - - /** - * 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; - if (_owns_buffer) { - if (copy._buffer) { - if (copy._size > _size) { - _buffer = (uint8_t*)::realloc(_buffer, copy._size); - } - memcpy(_buffer, copy._buffer, copy._size); - } else { - free(_buffer); - _buffer = NULL; - } - } else { - _buffer = copy._buffer; - } - - _size = copy._size; - return *this; - } - - inline void shallow_copy(const Event& copy) { - if (_owns_buffer) { - free(_buffer); - _buffer = false; - _owns_buffer = false; - } - - _time = copy._time; - _size = copy._size; - _buffer = copy._buffer; - } - - inline void set(uint8_t* buf, size_t size, double t) { - if (_owns_buffer) { - if (_size < size) { - _buffer = (uint8_t*) ::realloc(_buffer, size); - } - memcpy (_buffer, buf, size); - } else { - _buffer = buf; - } - - _size = size; - _time = t; - } - - inline bool operator==(const Event& other) const { - if (_time != other._time) - return false; - - if (_size != other._size) - return false; - - if (_buffer == other._buffer) - return true; - - for (size_t i=0; i < _size; ++i) - if (_buffer[i] != other._buffer[i]) - return false; - - return true; - } - - inline bool operator!=(const Event& other) const { return ! operator==(other); } - - inline bool owns_buffer() const { return _owns_buffer; } - - inline void set_buffer(size_t size, uint8_t* buf, bool own) { - if (_owns_buffer) { - free(_buffer); - _buffer = NULL; - } - _size = size; - _buffer = buf; - _owns_buffer = own; - } - - inline void realloc(size_t size) { - if (_owns_buffer) { - if (size > _size) - _buffer = (uint8_t*) ::realloc(_buffer, size); - } else { - _buffer = (uint8_t*) ::malloc(size); - _owns_buffer = true; - } - - _size = size; - } - - -#else - - inline void set_buffer(uint8_t* buf) { _buffer = buf; } - -#endif // MIDI_EVENT_ALLOW_ALLOC - - inline double time() const { return _time; } - inline double& time() { return _time; } - inline uint32_t size() const { return _size; } - inline uint32_t& size() { return _size; } - inline uint8_t type() const { return (_buffer[0] & 0xF0); } - inline void set_type(uint8_t type) { _buffer[0] = (0x0F & _buffer[0]) | (0xF0 & type); } - inline uint8_t channel() const { return (_buffer[0] & 0x0F); } - inline void set_channel(uint8_t channel) { _buffer[0] = (0xF0 & _buffer[0]) | (0x0F & channel); } - inline bool is_note_on() const { return (type() == MIDI_CMD_NOTE_ON); } - inline bool is_note_off() const { return (type() == MIDI_CMD_NOTE_OFF); } - inline bool is_cc() const { return (type() == MIDI_CMD_CONTROL); } - inline bool is_pitch_bender() const { return (type() == MIDI_CMD_BENDER); } - inline bool is_pgm_change() const { return (type() == MIDI_CMD_PGM_CHANGE); } - inline bool is_note() const { return (is_note_on() || is_note_off()); } - inline bool is_aftertouch() const { return (type() == MIDI_CMD_NOTE_PRESSURE); } - inline bool is_channel_aftertouch() const { return (type() == MIDI_CMD_CHANNEL_PRESSURE); } - inline uint8_t note() const { return (_buffer[1]); } - inline uint8_t velocity() const { return (_buffer[2]); } - inline uint8_t cc_number() const { return (_buffer[1]); } - inline uint8_t cc_value() const { return (_buffer[2]); } - inline uint8_t pitch_bender_lsb() const { return (_buffer[1]); } - inline uint8_t pitch_bender_msb() const { return (_buffer[2]); } - inline uint16_t pitch_bender_value() const { return (((0x7F & _buffer[2]) << 7) | (0x7F & _buffer[1])); } - inline uint8_t pgm_number() const { return (_buffer[1]); } - inline void set_pgm_number(uint8_t number){ _buffer[1] = number; } - inline uint8_t aftertouch() const { return (_buffer[1]); } - inline uint8_t channel_aftertouch() const { return (_buffer[1]); } - // midi channel events range from 0x80 to 0xE0 - inline bool is_channel_event() const { return (0x80 <= type()) && (type() <= 0xE0); } - inline bool is_smf_meta_event() const { return _buffer[0] == 0xFF; } - 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; } - - /** - * 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 */ - uint32_t _size; /**< Number of uint8_ts of data in \a buffer */ - uint8_t* _buffer; /**< Raw MIDI data */ - -#ifdef MIDI_EVENT_ALLOW_ALLOC - bool _owns_buffer; /**< Whether buffer is locally allocated */ -#endif -}; - - -} +#include <evoral/Event.hpp> #endif /* __libmidipp_midi_event_h__ */ diff --git a/libs/midi++2/midi++/jack.h b/libs/midi++2/midi++/jack.h index 6d3e3341bc..10a121baee 100644 --- a/libs/midi++2/midi++/jack.h +++ b/libs/midi++2/midi++/jack.h @@ -80,7 +80,7 @@ private: static pthread_t _process_thread; static bool is_process_thread(); - RingBuffer<MIDI::Event> non_process_thread_fifo; + RingBuffer<Evoral::Event> non_process_thread_fifo; Glib::Mutex non_process_thread_fifo_lock; }; diff --git a/libs/midi++2/midi++/midnam_patch.h b/libs/midi++2/midi++/midnam_patch.h index 50c51b317f..d4f8dbf466 100644 --- a/libs/midi++2/midi++/midnam_patch.h +++ b/libs/midi++2/midi++/midnam_patch.h @@ -18,7 +18,7 @@ namespace Name class Patch : public PBD::Stateful { public: - typedef std::list<MIDI::Event> PatchMidiCommands; + typedef std::list<Evoral::Event> PatchMidiCommands; Patch() {}; Patch(string a_number, string a_name) : _number(a_number), _name(a_name) {}; diff --git a/libs/midi++2/midnam_patch.cc b/libs/midi++2/midnam_patch.cc index f149f2884b..3434db896a 100644 --- a/libs/midi++2/midnam_patch.cc +++ b/libs/midi++2/midnam_patch.cc @@ -33,7 +33,7 @@ Patch::set_state (const XMLNode& node) assert(commands); const XMLNodeList events = commands->children(); for (XMLNodeList::const_iterator i = events.begin(); i != events.end(); ++i) { - _patch_midi_commands.push_back(*(new Event(*(*i)))); + _patch_midi_commands.push_back(*(new Evoral::Event(*(*i)))); } return 0; @@ -132,13 +132,16 @@ ChannelNameSet::set_state (const XMLNode& node) } int -MIDINameDocument::set_state(const XMLNode & a_node) +MIDINameDocument::set_state(const XMLNode& a_node) { + return 0; } XMLNode& MIDINameDocument::get_state(void) { + static XMLNode nothing("<nothing>"); + return nothing; } |