Ardour  8.7-14-g57a6773833
midi++2/midi++/port.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
4  * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef __libmidi_port_base_h__
23 #define __libmidi_port_base_h__
24 
25 #include <string>
26 #include <iostream>
27 
28 #include <pthread.h>
29 
30 #include "pbd/xml++.h"
31 #ifndef PLATFORM_WINDOWS
32 #include "pbd/crossthread.h"
33 #endif
34 #include "pbd/signals.h"
35 #include "pbd/ringbuffer.h"
36 
38 #include "midi++/types.h"
39 #include "midi++/parser.h"
40 
41 namespace MIDI {
42 
43 class Channel;
44 class PortRequest;
45 
47  public:
48  enum Flags {
49  IsInput = 0x1, /* MUST MATCH JACK's JackPortIsInput */
50  IsOutput = 0x2, /* MUST MATCH JACK's JackPortIsOutput */
51  };
52 
53  Port (std::string const &, Flags);
54  Port (const XMLNode&);
55  virtual ~Port ();
56 
57  virtual XMLNode& get_state () const;
58  virtual void set_state (const XMLNode&);
59 
66  virtual int write (const byte *msg, size_t msglen, timestamp_t timestamp) = 0;
67 
73  virtual int read (byte *buf, size_t bufsize) = 0;
74 
81  virtual void drain (int /* check_interval_usecs */, int /* total_usecs_to_wait */) {}
82 
87  int midimsg (byte *msg, size_t len, timestamp_t timestamp) {
88  return !(write (msg, len, timestamp) == (int) len);
89  }
90 
91  virtual void parse (samplecnt_t timestamp) = 0;
92 
93  bool clock (timestamp_t timestamp);
94 
95  /* select(2)/poll(2)-based I/O */
96 
100  virtual int selectable () const = 0;
101 
103  return _channel[chn&0x7F];
104  }
105 
107  return _parser;
108  }
109 
110  const char *name () const { return _tagname.c_str(); }
111  bool ok () const { return _ok; }
112 
113  virtual bool centrally_parsed() const;
114  void set_centrally_parsed (bool yn) { _centrally_parsed = yn; }
115 
116  bool receives_input () const {
117  return _flags == IsInput;
118  }
119 
120  bool sends_output () const {
121  return _flags == IsOutput;
122  }
123 
124  struct Descriptor {
125  std::string tag;
127 
128  Descriptor (const XMLNode&);
129  XMLNode& get_state() const;
130  };
131 
132  static std::string state_node_name;
133 
134  protected:
135  bool _ok;
136  std::string _tagname;
137  Channel* _channel[16];
141 
142  void init (std::string const &, Flags);
143 };
144 
146  PortSet (std::string str) : owner (str) { }
147 
148  std::string owner;
149  std::list<XMLNode> ports;
150 };
151 
152 std::ostream & operator << (std::ostream& os, const Port& port);
153 
154 } // namespace MIDI
155 
156 #endif // __libmidi_port_base_h__
virtual bool centrally_parsed() const
virtual void parse(samplecnt_t timestamp)=0
virtual int read(byte *buf, size_t bufsize)=0
Channel * channel(channel_t chn)
bool receives_input() const
void init(std::string const &, Flags)
Parser * parser()
Port(const XMLNode &)
virtual XMLNode & get_state() const
bool ok() const
int midimsg(byte *msg, size_t len, timestamp_t timestamp)
const char * name() const
std::string _tagname
virtual void drain(int, int)
virtual void set_state(const XMLNode &)
Port(std::string const &, Flags)
bool clock(timestamp_t timestamp)
virtual int write(const byte *msg, size_t msglen, timestamp_t timestamp)=0
bool sends_output() const
virtual int selectable() const =0
virtual ~Port()
static std::string state_node_name
void set_centrally_parsed(bool yn)
Definition: xml++.h:114
#define LIBMIDIPP_API
int64_t samplecnt_t
std::ostream & operator<<(std::ostream &os, const Port &port)
uint32_t timestamp_t
PortSet(std::string str)
std::list< XMLNode > ports
Descriptor(const XMLNode &)
XMLNode & get_state() const