2 Copyright (C) 1998 Paul Barton-Davis
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 $Id: port.cc 11871 2012-04-10 16:27:01Z paul $
25 #include <jack/jack.h>
26 #include <jack/midiport.h>
28 #include "pbd/xml++.h"
29 #include "pbd/error.h"
30 #include "pbd/failed_constructor.h"
31 #include "pbd/convert.h"
32 #include "pbd/strsplit.h"
33 #include "pbd/stacktrace.h"
35 #include "midi++/types.h"
36 #include "midi++/port.h"
37 #include "midi++/channel.h"
43 string Port::state_node_name = "MIDI-port";
45 Port::Port (string const & name, Flags flags)
47 , _centrally_parsed (true)
52 Port::Port (const XMLNode& node)
53 : _centrally_parsed (true)
55 Descriptor desc (node);
57 init (desc.tag, desc.flags);
59 /* derived class must call ::set_state() */
63 Port::init (string const & name, Flags flags)
65 _ok = false; /* derived class must set to true if constructor
74 _parser = new Parser (*this);
76 for (int i = 0; i < 16; i++) {
77 _channel[i] = new Channel (i, *this);
78 _channel[i]->connect_signals ();
84 for (int i = 0; i < 16; i++) {
89 /** Send a clock tick message.
90 * \return true on success.
93 Port::clock (timestamp_t timestamp)
95 static byte clockmsg = 0xf8;
98 return midimsg (&clockmsg, 1, timestamp);
104 std::ostream & MIDI::operator << ( std::ostream & os, const MIDI::Port & port )
107 os << "MIDI::Port { ";
108 os << "name: " << port.name();
110 os << "ok: " << port.ok();
116 Port::Descriptor::Descriptor (const XMLNode& node)
118 const XMLProperty *prop;
119 bool have_tag = false;
120 bool have_mode = false;
122 if ((prop = node.property ("tag")) != 0) {
127 if ((prop = node.property ("mode")) != 0) {
129 if (strings_equal_ignore_case (prop->value(), "output") || strings_equal_ignore_case (prop->value(), "out")) {
131 } else if (strings_equal_ignore_case (prop->value(), "input") || strings_equal_ignore_case (prop->value(), "in")) {
138 if (!have_tag || !have_mode) {
139 throw failed_constructor();
144 Port::get_state () const
146 XMLNode* root = new XMLNode (state_node_name);
147 root->add_property ("tag", _tagname);
149 if (_flags == IsInput) {
150 root->add_property ("mode", "input");
152 root->add_property ("mode", "output");
156 byte device_inquiry[6];
158 device_inquiry[0] = 0xf0;
159 device_inquiry[0] = 0x7e;
160 device_inquiry[0] = 0x7f;
161 device_inquiry[0] = 0x06;
162 device_inquiry[0] = 0x02;
163 device_inquiry[0] = 0xf7;
165 write (device_inquiry, sizeof (device_inquiry), 0);
172 Port::set_state (const XMLNode& node)
174 const XMLProperty* prop;
176 if ((prop = node.property ("tag")) == 0 || prop->value() != _tagname) {
182 Port::centrally_parsed() const
184 return _centrally_parsed;