2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 1998-2015 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2015 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/xml++.h"
|
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/failed_constructor.h"
|
2010-07-05 20:16:36 -04:00
|
|
|
#include "pbd/convert.h"
|
|
|
|
#include "pbd/strsplit.h"
|
2012-02-06 10:05:18 -05:00
|
|
|
#include "pbd/stacktrace.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/types.h"
|
|
|
|
#include "midi++/port.h"
|
|
|
|
#include "midi++/channel.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace MIDI;
|
|
|
|
using namespace std;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
string Port::state_node_name = "MIDI-port";
|
|
|
|
|
|
|
|
Port::Port (string const & name, Flags flags)
|
|
|
|
: _flags (flags)
|
|
|
|
, _centrally_parsed (true)
|
2010-07-06 20:40:58 -04:00
|
|
|
{
|
2010-07-07 21:00:46 -04:00
|
|
|
init (name, flags);
|
2010-07-06 20:40:58 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Port::Port (const XMLNode& node)
|
|
|
|
: _centrally_parsed (true)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-23 12:23:48 -04:00
|
|
|
Descriptor desc (node);
|
2012-04-23 22:28:51 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
init (desc.tag, desc.flags);
|
2012-04-23 22:28:51 -04:00
|
|
|
|
|
|
|
/* derived class must call ::set_state() */
|
2010-07-06 20:40:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-07 21:00:46 -04:00
|
|
|
Port::init (string const & name, Flags flags)
|
2010-07-06 20:40:58 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
_ok = false; /* derived class must set to true if constructor
|
|
|
|
succeeds.
|
|
|
|
*/
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
_parser = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
_tagname = name;
|
|
|
|
_flags = flags;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
_parser = new Parser ();
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
_channel[i] = new Channel (i, *this);
|
|
|
|
_channel[i]->connect_signals ();
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Port::~Port ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
delete _channel[i];
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2015-09-12 14:05:25 -04:00
|
|
|
|
|
|
|
delete _parser;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
/** Send a clock tick message.
|
|
|
|
* \return true on success.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
Port::clock (timestamp_t timestamp)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
static byte clockmsg = 0xf8;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
if (sends_output()) {
|
2012-04-23 22:28:51 -04:00
|
|
|
return midimsg (&clockmsg, 1, timestamp);
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
return false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
std::ostream & MIDI::operator << ( std::ostream & os, const MIDI::Port & port )
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
using namespace std;
|
|
|
|
os << "MIDI::Port { ";
|
|
|
|
os << "name: " << port.name();
|
|
|
|
os << "; ";
|
|
|
|
os << "ok: " << port.ok();
|
|
|
|
os << "; ";
|
|
|
|
os << " }";
|
|
|
|
return os;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Port::Descriptor::Descriptor (const XMLNode& node)
|
2010-07-05 20:16:36 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
const XMLProperty *prop;
|
|
|
|
bool have_tag = false;
|
|
|
|
bool have_mode = false;
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
if ((prop = node.property ("tag")) != 0) {
|
|
|
|
tag = prop->value();
|
|
|
|
have_tag = true;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
if ((prop = node.property ("mode")) != 0) {
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
if (strings_equal_ignore_case (prop->value(), "output") || strings_equal_ignore_case (prop->value(), "out")) {
|
|
|
|
flags = IsOutput;
|
|
|
|
} else if (strings_equal_ignore_case (prop->value(), "input") || strings_equal_ignore_case (prop->value(), "in")) {
|
|
|
|
flags = IsInput;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
have_mode = true;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
if (!have_tag || !have_mode) {
|
|
|
|
throw failed_constructor();
|
2010-07-07 21:00:46 -04:00
|
|
|
}
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
XMLNode&
|
2008-06-02 17:41:35 -04:00
|
|
|
Port::get_state () const
|
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
XMLNode* root = new XMLNode (state_node_name);
|
2016-08-28 09:22:22 -04:00
|
|
|
root->set_property ("tag", _tagname);
|
2012-04-23 22:28:51 -04:00
|
|
|
|
|
|
|
if (_flags == IsInput) {
|
2016-08-28 09:22:22 -04:00
|
|
|
root->set_property ("mode", "input");
|
2012-04-23 22:28:51 -04:00
|
|
|
} else {
|
2016-08-28 09:22:22 -04:00
|
|
|
root->set_property ("mode", "output");
|
2012-04-23 22:28:51 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-10 15:51:35 -05:00
|
|
|
#if 0
|
|
|
|
byte device_inquiry[6];
|
|
|
|
|
|
|
|
device_inquiry[0] = 0xf0;
|
|
|
|
device_inquiry[0] = 0x7e;
|
|
|
|
device_inquiry[0] = 0x7f;
|
|
|
|
device_inquiry[0] = 0x06;
|
|
|
|
device_inquiry[0] = 0x02;
|
|
|
|
device_inquiry[0] = 0xf7;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-10 15:51:35 -05:00
|
|
|
write (device_inquiry, sizeof (device_inquiry), 0);
|
|
|
|
#endif
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
return *root;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-05 20:16:36 -04:00
|
|
|
Port::set_state (const XMLNode& node)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2010-07-05 20:16:36 -04:00
|
|
|
const XMLProperty* prop;
|
|
|
|
|
2012-04-23 12:23:48 -04:00
|
|
|
if ((prop = node.property ("tag")) == 0 || prop->value() != _tagname) {
|
|
|
|
return;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2010-07-05 20:16:36 -04:00
|
|
|
bool
|
2012-04-23 22:28:51 -04:00
|
|
|
Port::centrally_parsed() const
|
2010-07-05 20:16:36 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
return _centrally_parsed;
|
2010-07-05 20:16:36 -04:00
|
|
|
}
|