Ardour  8.12
MIDIXML.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 David Robillard <d@drobilla.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef EVORAL_MIDI_XML_HPP
20 #define EVORAL_MIDI_XML_HPP
21 
22 #include "evoral/Event.h"
23 #include "pbd/xml++.h"
24 
25 namespace Evoral {
26 namespace MIDIXML {
27 
28 template<typename Time>
29 bool
31 {
32  if (node.name() == "ControlChange") {
34  ev.set_cc_number(atoi(node.property("Control")->value().c_str()));
35  ev.set_cc_value(atoi(node.property("Value")->value().c_str()));
36  return true;
37  } else if (node.name() == "ProgramChange") {
39  ev.set_pgm_number(atoi(node.property("Number")->value().c_str()));
40  return true;
41  }
42 
43  return false;
44 }
45 
46 template<typename Time>
47 std::shared_ptr<XMLNode>
49 {
50  XMLNode* result = 0;
51 
52  switch (ev.type()) {
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()));
58  break;
59 
61  result = new XMLNode("ProgramChange");
62  result->add_property("Channel", long(ev.channel()));
63  result->add_property("Number", long(ev.pgm_number()));
64  break;
65 
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()));
71  break;
72 
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()));
78  break;
79 
80  case MIDI_CMD_BENDER:
81  result = new XMLNode("PitchBendChange");
82  result->add_property("Channel", long(ev.channel()));
83  result->add_property("Value", long(ev.pitch_bender_value()));
84  break;
85 
86  default:
87  return std::shared_ptr<XMLNode>();
88  }
89 
90  return std::shared_ptr<XMLNode>(result);
91 }
92 
93 } // namespace MIDIXML
94 } // namespace Evoral
95 
96 #endif // EVORAL_MIDI_XML_HPP
uint8_t note() const
Definition: Event.h:164
uint8_t type() const
Definition: Event.h:145
uint8_t cc_number() const
Definition: Event.h:169
uint8_t channel() const
Definition: Event.h:146
uint8_t cc_value() const
Definition: Event.h:170
uint8_t pgm_number() const
Definition: Event.h:171
void set_pgm_number(uint8_t num)
Definition: Event.h:182
void set_cc_value(uint8_t val)
Definition: Event.h:181
void set_type(uint8_t type)
Definition: Event.h:177
uint16_t pitch_bender_value() const
Definition: Event.h:174
uint8_t velocity() const
Definition: Event.h:165
void set_cc_number(uint8_t num)
Definition: Event.h:180
Definition: xml++.h:114
const std::string & name() const
Definition: xml++.h:126
XMLProperty const * property(const char *) const
const std::string & value() const
Definition: xml++.h:58
#define MIDI_CMD_NOTE_ON
Definition: midi_events.h:107
#define MIDI_CMD_BENDER
Definition: midi_events.h:112
#define MIDI_CMD_PGM_CHANGE
Definition: midi_events.h:110
#define MIDI_CMD_CONTROL
Definition: midi_events.h:109
#define MIDI_CMD_NOTE_OFF
Definition: midi_events.h:106
std::shared_ptr< XMLNode > midi_to_xml(const Evoral::Event< Time > &ev)
Definition: MIDIXML.h:48
bool xml_to_midi(const XMLNode &node, Evoral::Event< Time > &ev)
Definition: MIDIXML.h:30
Definition: editor.h:87
int atoi(const std::string &)