Ardour  8.7-15-gadf511264b
ipmidi_port.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2013-2016 Robin Gareus <robin@gareus.org>
4  * Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __libmidi_ipmidi_port_h__
22 #define __libmidi_ipmidi_port_h__
23 
24 #include <string>
25 #include <iostream>
26 #if defined(PLATFORM_WINDOWS)
27 #include <winsock.h>
28 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
29 #include <netinet/in.h>
30 #include <sys/socket.h>
31 #if defined(__FreeBSD__)
32 #include <sys/_sockaddr_storage.h>
33 #endif
34 #include <arpa/inet.h>
35 #include <netinet/ip_carp.h>
36 #include <sys/types.h>
37 #include <sys/time.h>
38 #include <sys/socket.h>
39 #include <net/if.h>
40 #include <net/route.h>
41 #else
42 #include <arpa/inet.h>
43 #include <net/if.h>
44 #endif
45 
46 #include <glibmm/threads.h>
47 
48 #include "pbd/xml++.h"
49 #include "pbd/crossthread.h"
50 #include "pbd/signals.h"
51 #include "pbd/ringbuffer.h"
52 
54 #include "midi++/types.h"
55 #include "midi++/parser.h"
56 #include "midi++/port.h"
57 
58 namespace MIDI {
59 
60 class LIBMIDIPP_API IPMIDIPort : public Port {
61  public:
62  IPMIDIPort (int base_port = lowest_ipmidi_port_default, const std::string& ifname = std::string());
63  IPMIDIPort (const XMLNode&);
65 
66  XMLNode& get_state () const;
67  void set_state (const XMLNode&);
68 
69  int write (const byte *msg, size_t msglen, timestamp_t timestamp);
70  int read (byte *buf, size_t bufsize);
71  void parse (samplecnt_t timestamp);
72  int selectable () const;
73 
74  static const int lowest_ipmidi_port_default = 21928;
75 
76 private:
77  int sockin;
78  int sockout;
79  struct sockaddr_in addrout;
80  Glib::Threads::Mutex write_lock;
81 
82  bool open_sockets (int base_port, const std::string& ifname);
83  void close_sockets ();
84 
85  void init (std::string const &, Flags);
86 };
87 
88 } // namespace MIDI
89 
90 #endif // __libmidi_ipmidi_port_h__
XMLNode & get_state() const
void set_state(const XMLNode &)
void init(std::string const &, Flags)
int selectable() const
void parse(samplecnt_t timestamp)
IPMIDIPort(const XMLNode &)
IPMIDIPort(int base_port=lowest_ipmidi_port_default, const std::string &ifname=std::string())
int write(const byte *msg, size_t msglen, timestamp_t timestamp)
int read(byte *buf, size_t bufsize)
bool open_sockets(int base_port, const std::string &ifname)
Glib::Threads::Mutex write_lock
Definition: ipmidi_port.h:80
Definition: xml++.h:114
#define LIBMIDIPP_API
int64_t samplecnt_t
uint32_t timestamp_t