2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 1998-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
#ifndef __libmidi_port_base_h__
|
|
|
|
#define __libmidi_port_base_h__
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
2013-07-11 12:58:44 -04:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/xml++.h"
|
2013-07-25 02:45:24 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2010-07-05 20:16:36 -04:00
|
|
|
#include "pbd/crossthread.h"
|
2013-07-13 08:26:54 -04:00
|
|
|
#endif
|
2010-07-05 20:16:36 -04:00
|
|
|
#include "pbd/signals.h"
|
|
|
|
#include "pbd/ringbuffer.h"
|
|
|
|
|
2013-10-17 10:27:04 -04:00
|
|
|
#include "midi++/libmidi_visibility.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "midi++/types.h"
|
|
|
|
#include "midi++/parser.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
namespace MIDI {
|
|
|
|
|
|
|
|
class Channel;
|
|
|
|
class PortRequest;
|
|
|
|
|
2013-10-17 10:27:04 -04:00
|
|
|
class LIBMIDIPP_API Port {
|
2008-06-02 17:41:35 -04:00
|
|
|
public:
|
2012-04-23 22:28:51 -04:00
|
|
|
enum Flags {
|
2014-04-10 08:52:21 -04:00
|
|
|
IsInput = 0x1, /* MUST MATCH JACK's JackPortIsInput */
|
|
|
|
IsOutput = 0x2, /* MUST MATCH JACK's JackPortIsOutput */
|
2012-04-23 22:28:51 -04:00
|
|
|
};
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Port (std::string const &, Flags);
|
|
|
|
Port (const XMLNode&);
|
|
|
|
virtual ~Port ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-05-27 12:49:51 -04:00
|
|
|
virtual XMLNode& get_state () const;
|
|
|
|
virtual void set_state (const XMLNode&);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
/** Write a message to port.
|
|
|
|
* @param msg Raw MIDI message to send
|
|
|
|
* @param msglen Size of @a msg
|
2017-09-18 12:39:17 -04:00
|
|
|
* @param timestamp Time stamp in samples of this message (relative to cycle start)
|
2012-04-23 22:28:51 -04:00
|
|
|
* @return number of bytes successfully written
|
|
|
|
*/
|
2012-04-30 11:54:13 -04:00
|
|
|
virtual int write (const byte *msg, size_t msglen, timestamp_t timestamp) = 0;
|
2012-04-23 22:28:51 -04:00
|
|
|
|
|
|
|
/** Read raw bytes from a port.
|
|
|
|
* @param buf memory to store read data in
|
|
|
|
* @param bufsize size of @a buf
|
|
|
|
* @return number of bytes successfully read, negative if error
|
|
|
|
*/
|
|
|
|
virtual int read (byte *buf, size_t bufsize) = 0;
|
|
|
|
|
|
|
|
/** block until the output FIFO used by non-process threads
|
|
|
|
* is empty, checking every @a check_interval_usecs usecs
|
|
|
|
* for current status. Not to be called by a thread that
|
2015-10-04 14:51:05 -04:00
|
|
|
* executes any part of a JACK process callback (will
|
2012-04-23 22:28:51 -04:00
|
|
|
* simply return immediately in that situation).
|
|
|
|
*/
|
2016-02-01 13:26:30 -05:00
|
|
|
virtual void drain (int /* check_interval_usecs */, int /* total_usecs_to_wait */) {}
|
2012-04-23 22:28:51 -04:00
|
|
|
|
|
|
|
/** Write a message to port.
|
|
|
|
* @return true on success.
|
|
|
|
* FIXME: describe semantics here
|
|
|
|
*/
|
|
|
|
int midimsg (byte *msg, size_t len, timestamp_t timestamp) {
|
|
|
|
return !(write (msg, len, timestamp) == (int) len);
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2012-04-23 22:28:51 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
virtual void parse (samplecnt_t timestamp) = 0;
|
2012-04-23 22:28:51 -04:00
|
|
|
|
|
|
|
bool clock (timestamp_t timestamp);
|
|
|
|
|
|
|
|
/* select(2)/poll(2)-based I/O */
|
|
|
|
|
|
|
|
/** Get the file descriptor for port.
|
2015-10-04 14:51:05 -04:00
|
|
|
* @return File descriptor, or -1 if not selectable.
|
2012-04-23 22:28:51 -04:00
|
|
|
*/
|
|
|
|
virtual int selectable () const = 0;
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
Channel *channel (channel_t chn) {
|
2012-04-23 22:28:51 -04:00
|
|
|
return _channel[chn&0x7F];
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Parser* parser () {
|
|
|
|
return _parser;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
const char *name () const { return _tagname.c_str(); }
|
|
|
|
bool ok () const { return _ok; }
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
virtual bool centrally_parsed() const;
|
|
|
|
void set_centrally_parsed (bool yn) { _centrally_parsed = yn; }
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
bool receives_input () const {
|
|
|
|
return _flags == IsInput;
|
|
|
|
}
|
2010-07-05 11:41:05 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
bool sends_output () const {
|
|
|
|
return _flags == IsOutput;
|
|
|
|
}
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
struct Descriptor {
|
|
|
|
std::string tag;
|
|
|
|
Flags flags;
|
2010-07-08 18:55:20 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
Descriptor (const XMLNode&);
|
|
|
|
XMLNode& get_state();
|
|
|
|
};
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
static std::string state_node_name;
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
protected:
|
|
|
|
bool _ok;
|
|
|
|
std::string _tagname;
|
|
|
|
Channel* _channel[16];
|
|
|
|
Parser* _parser;
|
|
|
|
Flags _flags;
|
|
|
|
bool _centrally_parsed;
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
void init (std::string const &, Flags);
|
2012-04-23 22:28:51 -04:00
|
|
|
};
|
2010-07-05 20:16:36 -04:00
|
|
|
|
2013-10-17 10:27:04 -04:00
|
|
|
struct LIBMIDIPP_API PortSet {
|
2012-04-23 22:28:51 -04:00
|
|
|
PortSet (std::string str) : owner (str) { }
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
std::string owner;
|
|
|
|
std::list<XMLNode> ports;
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
std::ostream & operator << (std::ostream& os, const Port& port);
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
} // namespace MIDI
|
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
#endif // __libmidi_port_base_h__
|