1 /* This file is part of Evoral.
2 * Copyright (C) 2008 David Robillard <http://drobilla.net>
3 * Copyright (C) 2000-2008 Paul Davis
5 * Evoral is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
10 * Evoral is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "evoral/Beats.hpp"
21 #include "evoral/MIDIEvent.hpp"
22 #ifdef EVORAL_MIDI_XML
23 #include "pbd/xml++.h"
30 #ifdef EVORAL_MIDI_XML
32 template<typename Time>
33 MIDIEvent<Time>::MIDIEvent(const XMLNode& event)
36 string name = event.name();
38 if (name == "ControlChange") {
39 this->_buf = (uint8_t*) ::malloc(3);
40 this->_owns_buf = true;
41 set_type(MIDI_CMD_CONTROL);
43 set_cc_number(atoi(event.property("Control")->value().c_str()));
44 set_cc_value (atoi(event.property("Value")->value().c_str()));
45 } else if (name == "ProgramChange") {
46 this->_buf = (uint8_t*) ::malloc(2);
47 this->_owns_buf = true;
48 set_type(MIDI_CMD_PGM_CHANGE);
50 set_pgm_number(atoi(event.property("Number")->value().c_str()));
55 template<typename Time>
56 boost::shared_ptr<XMLNode>
57 MIDIEvent<Time>::to_xml() const
62 case MIDI_CMD_CONTROL:
63 result = new XMLNode("ControlChange");
64 result->add_property("Channel", long(channel()));
65 result->add_property("Control", long(cc_number()));
66 result->add_property("Value", long(cc_value()));
69 case MIDI_CMD_PGM_CHANGE:
70 result = new XMLNode("ProgramChange");
71 result->add_property("Channel", long(channel()));
72 result->add_property("Number", long(pgm_number()));
75 case MIDI_CMD_NOTE_ON:
76 result = new XMLNode("NoteOn");
77 result->add_property("Channel", long(channel()));
78 result->add_property("Note", long(note()));
79 result->add_property("Velocity", long(velocity()));
82 case MIDI_CMD_NOTE_OFF:
83 result = new XMLNode("NoteOff");
84 result->add_property("Channel", long(channel()));
85 result->add_property("Note", long(note()));
86 result->add_property("Velocity", long(velocity()));
90 result = new XMLNode("PitchBendChange");
91 result->add_property("Channel", long(channel()));
92 result->add_property("Value", long(pitch_bender_value()));
96 // The implementation is continued as needed
97 result = new XMLNode("NotImplemented");
101 return boost::shared_ptr<XMLNode>(result);
104 #endif // EVORAL_MIDI_XML
106 template class MIDIEvent<Evoral::Beats>;
108 } // namespace Evoral