1
#ifndef INCLUDED_MIDIIO_H
2
#define INCLUDED_MIDIIO_H
6
#include "dynamic-object.h"
9
* Virtual base for all MIDI I/O classes.
15
* - configuration (setting and getting configuration parameters)
17
* - functionality (control and runtime information)
19
* - runtime information
21
* - constructors and destructors
23
* @author Kai Vehmanen
25
class MIDI_IO : public DYNAMIC_OBJECT<std::string> {
29
/** @name Public type definitions and constants */
39
* Object is opened for input. If opening a file,
44
* Object is opened for output. If opening a file and
45
* and output exists, it is first truncated.
49
* Object is opened for both reading and writing. If
50
* opening a file, a new file is created if needed.
51
* When switching from read to write or vica versa,
52
* position should be reset before using the device.
54
enum Io_mode { io_read = 1, io_write = 2, io_readwrite = 4 };
60
/** @name Constructors and destructors */
63
virtual MIDI_IO* clone(void) const = 0;
64
virtual MIDI_IO* new_expr(void) const = 0;
65
virtual ~MIDI_IO(void);
66
MIDI_IO(const std::string& name = "unknown",
71
/** @name Attribute functions */
74
virtual int supported_io_modes(void) const;
75
virtual bool supports_nonblocking_mode(void) const;
79
/** @name Configuration
81
* For setting and getting configuration parameters.
85
int io_mode(void) const;
86
const std::string& label(void) const;
88
void io_mode(int mode);
89
void label(const std::string& id_label);
90
void toggle_nonblocking_mode(bool value);
92
virtual std::string parameter_names(void) const { return("label"); }
93
virtual void set_parameter(int param, std::string value);
94
virtual std::string get_parameter(int param) const;
98
/** @name Main functionality */
104
* Low-level routine for reading MIDI bytes. Number of read bytes
105
* is returned. This must be implemented by all subclasses.
107
virtual long int read_bytes(void* target_buffer, long int bytes) = 0;
110
* Low-level routine for writing MIDI bytes. Number of bytes written
111
* is returned. This must be implemented by all subclasses.
113
virtual long int write_bytes(void* target_buffer, long int bytes) = 0;
116
* Opens the MIDI object (possibly in exclusive mode).
117
* This routine is meant for opening files and devices,
118
* loading libraries, etc.
121
* readable() == true || writable() == true
123
virtual void open(void) = 0;
126
* Closes the MIDI object. After calling this routine,
127
* all resources (ie. soundcard) must be freed
128
* (they can be used by other processes).
134
virtual void close(void) = 0;
138
/** @name Runtime information */
142
* Returns a file descriptor id suitable for poll() and
143
* select() system calls. If polling is not supported,
144
* returns value of '-1'.
146
virtual int poll_descriptor(void) const { return(-1); }
149
* Has device been opened (with open())?
151
bool is_open(void) const { return(open_rep); }
154
* Whether all data has been processed? If opened in mode 'io_read',
155
* this means that end of stream has been reached. If opened in
156
* 'io_write' or 'io_readwrite' modes, finished status usually
157
* means that an error has occured (no space left, etc). After
158
* finished() has returned 'true', further calls to read()
159
* and/or write() won't process any data.
161
virtual bool finished(void) const = 0;
163
virtual bool nonblocking_mode(void) const;
164
virtual bool readable(void) const;
165
virtual bool writable(void) const;
171
void toggle_open_state(bool value);
176
std::string id_label_rep;
178
bool nonblocking_rep;