Ardour  9.0-pre0-582-g084a23a80d
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 <winsock.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 <glibmm/threads.h>
46 
47 #include "pbd/xml++.h"
48 #include "pbd/crossthread.h"
49 #include "pbd/signals.h"
50 #include "pbd/ringbuffer.h"
51 
53 #include "midi++/types.h"
54 #include "midi++/parser.h"
55 #include "midi++/port.h"
56 
57 namespace MIDI {
58 
59 class LIBMIDIPP_API IPMIDIPort : public Port {
60  public:
61  IPMIDIPort (int base_port = lowest_ipmidi_port_default, const std::string& ifname = std::string());
62  IPMIDIPort (const XMLNode&);
64 
65  XMLNode& get_state () const;
66  void set_state (const XMLNode&);
67 
68  int write (const byte *msg, size_t msglen, timestamp_t timestamp);
69  int read (byte *buf, size_t bufsize);
70  void parse (samplecnt_t timestamp);
71  int selectable () const;
72 
73  static const int lowest_ipmidi_port_default = 21928;
74 
75 private:
76  int sockin;
77  int sockout;
78  struct sockaddr_in addrout;
79  Glib::Threads::Mutex write_lock;
80 
81  bool open_sockets (int base_port, const std::string& ifname);
82  void close_sockets ();
83 
84  void init (std::string const &, Flags);
85 };
86 
87 } // namespace MIDI
88 
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:79
Definition: xml++.h:114
#define LIBMIDIPP_API
int64_t samplecnt_t
uint32_t timestamp_t