1 /* This file is part of Evoral.
2 * Copyright (C) 2008-2016 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
19 #ifndef EVORAL_MIDI_XML_HPP
20 #define EVORAL_MIDI_XML_HPP
22 #include "evoral/Event.hpp"
23 #include "pbd/xml++.h"
28 template<typename Time>
30 xml_to_midi(const XMLNode& node, Evoral::Event<Time>& ev)
32 if (node.name() == "ControlChange") {
33 ev.set_type(MIDI_CMD_CONTROL);
34 ev.set_cc_number(atoi(node.property("Control")->value().c_str()));
35 ev.set_cc_value(atoi(node.property("Value")->value().c_str()));
37 } else if (node.name() == "ProgramChange") {
38 ev.set_type(MIDI_CMD_PGM_CHANGE);
39 ev.set_pgm_number(atoi(node.property("Number")->value().c_str()));
46 template<typename Time>
47 boost::shared_ptr<XMLNode>
48 midi_to_xml(const Evoral::Event<Time>& ev)
53 case MIDI_CMD_CONTROL:
54 result = new XMLNode("ControlChange");
55 result->add_property("Channel", long(ev.channel()));
56 result->add_property("Control", long(ev.cc_number()));
57 result->add_property("Value", long(ev.cc_value()));
60 case MIDI_CMD_PGM_CHANGE:
61 result = new XMLNode("ProgramChange");
62 result->add_property("Channel", long(ev.channel()));
63 result->add_property("Number", long(ev.pgm_number()));
66 case MIDI_CMD_NOTE_ON:
67 result = new XMLNode("NoteOn");
68 result->add_property("Channel", long(ev.channel()));
69 result->add_property("Note", long(ev.note()));
70 result->add_property("Velocity", long(ev.velocity()));
73 case MIDI_CMD_NOTE_OFF:
74 result = new XMLNode("NoteOff");
75 result->add_property("Channel", long(ev.channel()));
76 result->add_property("Note", long(ev.note()));
77 result->add_property("Velocity", long(ev.velocity()));
81 result = new XMLNode("PitchBendChange");
82 result->add_property("Channel", long(ev.channel()));
83 result->add_property("Value", long(ev.pitch_bender_value()));
87 return boost::shared_ptr<XMLNode>();
90 return boost::shared_ptr<XMLNode>(result);
93 } // namespace MIDIXML
96 #endif // EVORAL_MIDI_XML_HPP