Ardour  9.2-129-gdf5e1050bd
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 #pragma once
22 
23 #include <string>
24 #include <iostream>
25 #if defined(PLATFORM_WINDOWS)
26 #include <winsock2.h>
27 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
28 #include <netinet/in.h>
29 #include <sys/socket.h>
30 #if defined(__FreeBSD__)
31 #include <sys/_sockaddr_storage.h>
32 #endif
33 #include <arpa/inet.h>
34 #include <netinet/ip_carp.h>
35 #include <sys/types.h>
36 #include <sys/time.h>
37 #include <sys/socket.h>
38 #include <net/if.h>
39 #include <net/route.h>
40 #else
41 #include <arpa/inet.h>
42 #include <net/if.h>
43 #endif
44 
45 #include "pbd/xml++.h"
46 #include "pbd/crossthread.h"
47 #include "pbd/mutex.h"
48 #include "pbd/signals.h"
49 #include "pbd/ringbuffer.h"
50 
52 #include "midi++/types.h"
53 #include "midi++/parser.h"
54 #include "midi++/port.h"
55 
56 namespace MIDI {
57 
58 class LIBMIDIPP_API IPMIDIPort : public Port {
59  public:
60  IPMIDIPort (int base_port = lowest_ipmidi_port_default, const std::string& ifname = std::string());
61  IPMIDIPort (const XMLNode&);
63 
64  XMLNode& get_state () const;
65  void set_state (const XMLNode&);
66 
67  int write (const byte *msg, size_t msglen, timestamp_t timestamp);
68  int read (byte *buf, size_t bufsize);
69  void parse (samplecnt_t timestamp);
70  int selectable () const;
71 
72  static const int lowest_ipmidi_port_default = 21928;
73 
74 private:
75  int sockin;
76  int sockout;
77  struct sockaddr_in addrout;
79 
80  bool open_sockets (int base_port, const std::string& ifname);
81  void close_sockets ();
82 
83  void init (std::string const &, Flags);
84 };
85 
86 } // namespace MIDI
87 
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 &)
PBD::Mutex write_lock
Definition: ipmidi_port.h:78
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)
Definition: xml++.h:114
#define LIBMIDIPP_API
int64_t samplecnt_t
uint32_t timestamp_t