2 Copyright (C) 1998-99 Paul Barton-Davis
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __libmidi_port_h__
21 #define __libmidi_port_h__
25 #include <sigc++/sigc++.h>
27 #include <midi++/types.h>
28 #include <midi++/parser.h>
35 class Port : public sigc::trackable {
52 virtual int write (byte *msg, size_t msglen) = 0;
53 virtual int read (byte *buf, size_t max) = 0;
55 /* slowdown i/o to a loop of single byte emissions
56 interspersed with a busy loop of 10000 * this value.
58 This may be ignored by a particular instance
59 of this virtual class. See FD_MidiPort for an
60 example of where it used.
63 void set_slowdown (size_t n) { slowdown = n; }
65 /* select(2)/poll(2)-based I/O */
67 virtual int selectable() const = 0;
69 //void selector_read_callback (Select::Selectable *, Select::Condition);
71 static void xforms_read_callback (int cond, int fd, void *ptr);
72 static void gtk_read_callback (void *ptr, int fd, int cond);
74 static void write_callback (byte *msg, unsigned int len, void *);
76 Channel *channel (channel_t chn) {
77 return _channel[chn&0x7F];
80 Parser *input() { return input_parser; }
81 Parser *output() { return output_parser; }
83 void iostat (int *written, int *read,
84 const size_t **in_counts,
85 const size_t **out_counts) {
87 *written = bytes_written;
90 *in_counts = input_parser->message_counts();
95 *out_counts = output_parser->message_counts();
101 int midimsg (byte *msg, size_t len) {
102 return !(write (msg, len) == (int) len);
105 int three_byte_msg (byte a, byte b, byte c) {
112 return !(write (msg, 3) == 3);
117 const char *device () const { return _devname.c_str(); }
118 const char *name () const { return _tagname.c_str(); }
119 Type type () const { return _type; }
120 int mode () const { return _mode; }
121 bool ok () const { return _ok; }
122 size_t number () const { return _number; }
127 std::string _devname;
128 std::string _tagname;
131 Channel *_channel[16];
132 sigc::connection thru_connection;
133 unsigned int bytes_written;
134 unsigned int bytes_read;
135 Parser *input_parser;
136 Parser *output_parser;
140 static size_t nports;
145 #endif // __libmidi_port_h__