Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
23 
24 #include <string>
25 #include <iostream>
26 
27 #include <pthread.h>
28 
29 #include "pbd/xml++.h"
30 #ifndef PLATFORM_WINDOWS
31 #include "pbd/crossthread.h"
32 #endif
33 #include "pbd/signals.h"
34 #include "pbd/ringbuffer.h"
35 
37 #include "midi++/types.h"
38 #include "midi++/parser.h"
39 
40 namespace MIDI {
41 
42 class Channel;
43 class PortRequest;
44 
46  public:
47  enum Flags {
48  IsInput = 0x1, /* MUST MATCH JACK's JackPortIsInput */
49  IsOutput = 0x2, /* MUST MATCH JACK's JackPortIsOutput */
50  };
51 
52  Port (std::string const &, Flags);
53  Port (const XMLNode&);
54  virtual ~Port ();
55 
56  virtual XMLNode& get_state () const;
57  virtual void set_state (const XMLNode&);
58 
65  virtual int write (const byte *msg, size_t msglen, timestamp_t timestamp) = 0;
66 
72  virtual int read (byte *buf, size_t bufsize) = 0;
73 
80  virtual void drain (int /* check_interval_usecs */, int /* total_usecs_to_wait */) {}
81 
86  int midimsg (byte *msg, size_t len, timestamp_t timestamp) {
87  return !(write (msg, len, timestamp) == (int) len);
88  }
89 
90  virtual void parse (samplecnt_t timestamp) = 0;
91 
92  bool clock (timestamp_t timestamp);
93 
94  /* select(2)/poll(2)-based I/O */
95 
99  virtual int selectable () const = 0;
100 
102  return _channel[chn&0x7F];
103  }
104 
106  return _parser;
107  }
108 
109  const char *name () const { return _tagname.c_str(); }
110  bool ok () const { return _ok; }
111 
112  virtual bool centrally_parsed() const;
113  void set_centrally_parsed (bool yn) { _centrally_parsed = yn; }
114 
115  bool receives_input () const {
116  return _flags == IsInput;
117  }
118 
119  bool sends_output () const {
120  return _flags == IsOutput;
121  }
122 
123  struct Descriptor {
124  std::string tag;
126 
127  Descriptor (const XMLNode&);
128  XMLNode& get_state() const;
129  };
130 
131  static std::string state_node_name;
132 
133  protected:
134  bool _ok;
135  std::string _tagname;
136  Channel* _channel[16];
140 
141  void init (std::string const &, Flags);
142 };
143 
145  PortSet (std::string str) : owner (str) { }
146 
147  std::string owner;
148  std::list<XMLNode> ports;
149 };
150 
151 std::ostream & operator << (std::ostream& os, const Port& port);
152 
153 } // namespace MIDI
154 
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