~ubuntu-branches/ubuntu/jaunty/ecasound2.2/jaunty

« back to all changes in this revision

Viewing changes to libecasound/midiio.h

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2005-04-14 09:15:48 UTC
  • Revision ID: james.westby@ubuntu.com-20050414091548-o7kgb47z0tcunh0s
Tags: upstream-2.4.1
ImportĀ upstreamĀ versionĀ 2.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INCLUDED_MIDIIO_H
 
2
#define INCLUDED_MIDIIO_H
 
3
 
 
4
#include <string>
 
5
 
 
6
#include "dynamic-object.h"
 
7
 
 
8
/**
 
9
 * Virtual base for all MIDI I/O classes.
 
10
 *
 
11
 *  - type definitions
 
12
 *
 
13
 *  - attributes
 
14
 *
 
15
 *  - configuration (setting and getting configuration parameters)
 
16
 *
 
17
 *  - functionality (control and runtime information)
 
18
 *
 
19
 *  - runtime information
 
20
 *
 
21
 *  - constructors and destructors
 
22
 *
 
23
 * @author Kai Vehmanen
 
24
 */
 
25
class MIDI_IO : public DYNAMIC_OBJECT<std::string> {
 
26
 
 
27
 public:
 
28
 
 
29
  /** @name Public type definitions and constants */
 
30
  /*@{*/
 
31
 
 
32
  /**
 
33
   * Input/Output mode
 
34
   *
 
35
   * @see io_mode()
 
36
   *
 
37
   * io_read
 
38
   *
 
39
   * Object is opened for input. If opening a file, 
 
40
   * it must exist.
 
41
   *
 
42
   * io_write
 
43
   *
 
44
   * Object is opened for output. If opening a file and
 
45
   * and output exists, it is first truncated.
 
46
   * 
 
47
   * io_readwrite
 
48
   *
 
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.
 
53
   **/
 
54
  enum Io_mode { io_read = 1, io_write = 2, io_readwrite = 4 };
 
55
 
 
56
  /*@}*/
 
57
 
 
58
 public:
 
59
 
 
60
  /** @name Constructors and destructors */
 
61
  /*@{*/
 
62
 
 
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",
 
67
          int mode = io_read);
 
68
 
 
69
  /*@}*/
 
70
 
 
71
  /** @name Attribute functions */
 
72
  /*@{*/
 
73
 
 
74
  virtual int supported_io_modes(void) const;
 
75
  virtual bool supports_nonblocking_mode(void) const;
 
76
 
 
77
  /*@}*/
 
78
 
 
79
  /** @name Configuration 
 
80
   * 
 
81
   * For setting and getting configuration parameters.
 
82
   */
 
83
  /*@{*/
 
84
  
 
85
  int io_mode(void) const;
 
86
  const std::string& label(void) const;
 
87
 
 
88
  void io_mode(int mode);
 
89
  void label(const std::string& id_label);
 
90
  void toggle_nonblocking_mode(bool value);
 
91
 
 
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;
 
95
 
 
96
  /*@}*/
 
97
 
 
98
  /** @name Main functionality */
 
99
  /*@{*/
 
100
 
 
101
 public:
 
102
 
 
103
  /**
 
104
   * Low-level routine for reading MIDI bytes. Number of read bytes
 
105
   * is returned. This must be implemented by all subclasses.
 
106
   */
 
107
  virtual long int read_bytes(void* target_buffer, long int bytes) = 0;
 
108
 
 
109
  /**
 
110
   * Low-level routine for writing MIDI bytes. Number of bytes written
 
111
   * is returned. This must be implemented by all subclasses.
 
112
   */
 
113
  virtual long int write_bytes(void* target_buffer, long int bytes) = 0;
 
114
 
 
115
  /**
 
116
   * Opens the MIDI object (possibly in exclusive mode).
 
117
   * This routine is meant for opening files and devices,
 
118
   * loading libraries, etc. 
 
119
   *
 
120
   * ensure:
 
121
   *  readable() == true || writable() == true
 
122
   */
 
123
  virtual void open(void) = 0;
 
124
 
 
125
  /**
 
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).
 
129
   *
 
130
   * ensure:
 
131
   *  readable() != true
 
132
   *  writable() != true
 
133
   */
 
134
  virtual void close(void) = 0;
 
135
 
 
136
  /*@}*/
 
137
 
 
138
  /** @name Runtime information */
 
139
  /*@{*/
 
140
 
 
141
  /**
 
142
   * Returns a file descriptor id suitable for poll() and 
 
143
   * select() system calls. If polling is not supported,
 
144
   * returns value of '-1'.
 
145
   */
 
146
  virtual int poll_descriptor(void) const { return(-1); }
 
147
 
 
148
  /**
 
149
   * Has device been opened (with open())?
 
150
   */
 
151
  bool is_open(void) const { return(open_rep); }
 
152
 
 
153
  /**
 
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.
 
160
   */
 
161
  virtual bool finished(void) const = 0;
 
162
 
 
163
  virtual bool nonblocking_mode(void) const;
 
164
  virtual bool readable(void) const;
 
165
  virtual bool writable(void) const;
 
166
 
 
167
  /*@}*/
 
168
 
 
169
 protected:
 
170
 
 
171
  void toggle_open_state(bool value);
 
172
 
 
173
 private:
 
174
  
 
175
  int io_mode_rep;
 
176
  std::string id_label_rep;
 
177
 
 
178
  bool nonblocking_rep;
 
179
  bool readable_rep;
 
180
  bool writable_rep;
 
181
  bool open_rep;
 
182
};
 
183
 
 
184
#endif