~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmid/player/midiout.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  midiout.h   - class midiOut which handles the /dev/sequencer device
 
2
    Copyright (C) 1997,98  Antonio Larrosa Jimenez
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 
 
18
    Send comments and bug fixes to antlarr@arrakis.es
 
19
    or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
 
20
 
 
21
***************************************************************************/
 
22
#ifndef _MIDIOUT_H
 
23
#define _MIDIOUT_H
 
24
 
 
25
#include <stdio.h>
 
26
#include "dattypes.h"
 
27
#include "midimapper.h"
 
28
#include "../version.h"
 
29
 
 
30
#define N_CHANNELS 16
 
31
#define N_CTL    256
 
32
 
 
33
/**
 
34
 * External MIDI port output class . This class is used to send midi
 
35
 * events to external midi devices. 
 
36
 *
 
37
 * MidiOut is inherited by other MIDI devices classes
 
38
 * (like @ref SynthOut or @ref FMOut) to support a common API.
 
39
 *
 
40
 * In general, you don't want to use MidiOut directly, but within a 
 
41
 * @ref DeviceManager object, which is the preferred way to generate music.
 
42
 *
 
43
 * If you want to add support for other devices (I don't think
 
44
 * there are any) you just have to create a class that inherits from MidiOut
 
45
 * and create one object of your new class in @ref DeviceManager::initManager.
 
46
 *
 
47
 * @short Sends MIDI events to external MIDI devices 
 
48
 * @author Antonio Larrosa <larrosa@kde.org>
 
49
 */
 
50
class MidiOut
 
51
{
 
52
//friend class DeviceManager; 
 
53
protected:
 
54
// This is the /dev/sequencer file handler. 
 
55
// Remember NOT TO CLOSE it on MidiOut, but just on DeviceManager
 
56
    int                 seqfd; 
 
57
 
 
58
    int                 device;
 
59
#ifdef HANDLETIMEINDEVICES
 
60
    int                 ndevs; // Total number of devices
 
61
    int                 nmidiports; // Total number of midi ports
 
62
 
 
63
    double              count;
 
64
    double              lastcount;
 
65
    double              lasttime;
 
66
    double              begintime;
 
67
    
 
68
    int                 rate;
 
69
    double              convertrate; // A "constant" used to convert from
 
70
                                // milliseconds to the computer rate
 
71
#endif
 
72
  int   devicetype; 
 
73
 
 
74
  int           volumepercentage;
 
75
 
 
76
  MidiMapper    *map;
 
77
 
 
78
  uchar chnpatch [N_CHANNELS];
 
79
  int   chnbender [N_CHANNELS];
 
80
  uchar chnpressure [N_CHANNELS];
 
81
  uchar chncontroller [N_CHANNELS][N_CTL];
 
82
  int   chnmute [N_CHANNELS];
 
83
 
 
84
  int   _ok;
 
85
 
 
86
  void seqbuf_dump (void);
 
87
  void seqbuf_clean(void);
 
88
 
 
89
public:
 
90
 
 
91
/**
 
92
 * Constructor. After constructing a MidiOut device, you must open it
 
93
 * (using @ref openDev). Additionally you may want to initialize it
 
94
 * (with @ref initDev),
 
95
 */
 
96
        MidiOut(int d=0);
 
97
 
 
98
/**
 
99
 * Destructor. It doesn't matter if you close the device (@ref closeDev) before
 
100
 * you destruct the object because in other case, it will be closed here.
 
101
 */
 
102
virtual ~MidiOut();
 
103
 
 
104
/**
 
105
 * Opens the device. This is generally called from @ref DeviceManager , so you
 
106
 * shouldn't call this yourself (except if you created the MidiOut object
 
107
 * yourself.
 
108
 * @param sqfd a file descriptor of /dev/sequencer
 
109
 * @see #closeDev
 
110
 * @see #initDev
 
111
 */
 
112
  virtual void openDev  (int sqfd);
 
113
 
 
114
/**
 
115
 * Closes the device. It basically tells the device (the file descriptor)
 
116
 * is going to be closed.
 
117
 * @see openDev
 
118
 */
 
119
  virtual void closeDev ();
 
120
 
 
121
/**
 
122
 * Initializes the device sending generic standard midi events and controllers,
 
123
 * such as changing the patches of each channel to an Acoustic Piano (000),
 
124
 * setting the volume to a normal value, etc.
 
125
 */
 
126
  virtual void initDev  ();
 
127
 
 
128
/**
 
129
 * @return the device type of the object. This is to identify the 
 
130
 * inherited class that a given object is polymorphed to.
 
131
 * The returned value is one of these :
 
132
 *
 
133
 * @li KMID_EXTERNAL_MIDI if it's a @ref MidiOut object
 
134
 * @li KMID_SYNTH if it's a @ref SynthOut object (as an AWE device)
 
135
 * @li KMID_FM if it's a @ref FMOut object
 
136
 * @li KMID_GUS if it's a @ref GUSOut object
 
137
 *
 
138
 * which are defined in midispec.h
 
139
 * 
 
140
 */
 
141
  int          deviceType () const { return devicetype; };
 
142
 
 
143
/**
 
144
 * @return the name and type of this MIDI device. 
 
145
 */
 
146
  const char * deviceName (void) const;
 
147
 
 
148
#ifdef HANDLETIMEINDEVICES
 
149
  int  rate     (void) { return rate; };
 
150
#endif
 
151
 
 
152
/**
 
153
 * Sets a @ref MidiMapper object to be used to modify the midi events before
 
154
 * sending them.
 
155
 *
 
156
 * @param map the MidiMapper to use.
 
157
 *
 
158
 * @see MidiMapper
 
159
 * @see #midiMapFilename
 
160
 */
 
161
  void setMidiMapper    ( MidiMapper *map );
 
162
 
 
163
/**
 
164
 * See @ref DeviceManager::noteOn
 
165
 */
 
166
  virtual void noteOn   ( uchar chn, uchar note, uchar vel );
 
167
 
 
168
/**
 
169
 * See @ref DeviceManager::noteOff
 
170
 */
 
171
  virtual void noteOff  ( uchar chn, uchar note, uchar vel );
 
172
 
 
173
/**
 
174
 * See @ref DeviceManager::keyPressure
 
175
 */
 
176
  virtual void keyPressure      ( uchar chn, uchar note, uchar vel );
 
177
 
 
178
/**
 
179
 * See @ref DeviceManager::chnPatchChange
 
180
 */
 
181
  virtual void chnPatchChange   ( uchar chn, uchar patch );
 
182
 
 
183
/**
 
184
 * See @ref DeviceManager::chnPressure
 
185
 */
 
186
  virtual void chnPressure      ( uchar chn, uchar vel );
 
187
 
 
188
/**
 
189
 * See @ref DeviceManager::chnPitchBender
 
190
 */
 
191
  virtual void chnPitchBender   ( uchar chn, uchar lsb,  uchar msb );
 
192
 
 
193
/**
 
194
 * See @ref DeviceManager::chnController
 
195
 */
 
196
  virtual void chnController    ( uchar chn, uchar ctl , uchar v ); 
 
197
 
 
198
/**
 
199
 * See @ref DeviceManager::sysex
 
200
 */
 
201
  virtual void sysex            ( uchar *data,ulong size);
 
202
 
 
203
/**
 
204
 * Mutes all notes being played on a given channel.
 
205
 */
 
206
  virtual void channelSilence   ( uchar chn );
 
207
 
 
208
/**
 
209
 * Mute or "unmute" a given channel .
 
210
 * @param chn channel to work on
 
211
 * @param b if true, the device will ignore subsequent notes played on the chn
 
212
 * channel, and mute all notes being played on it. If b is false, the channel
 
213
 * is back to work.
 
214
 */
 
215
  virtual void channelMute      ( uchar chn, int a );
 
216
 
 
217
/**
 
218
 * Change all channel volume events multiplying it by this percentage correction
 
219
 * Instead of forcing a channel to a fixed volume, this method allows to 
 
220
 * music to fade out even when it was being played softly.
 
221
 * @param volper is an integer value, where 0 is quiet, 100 is used to send
 
222
 * an unmodified value, 200 play music twice louder than it should, etc.
 
223
 */ 
 
224
  virtual void setVolumePercentage ( int volper ) 
 
225
                        { volumepercentage = volper; };
 
226
 
 
227
/**
 
228
 * @return true if everything's ok and false if there has been any problem
 
229
 */
 
230
  int ok (void) 
 
231
    { if (seqfd<0) return 0;
 
232
        return (_ok>0);
 
233
    };
 
234
 
 
235
#ifdef HANDLETIMEINDEVICES
 
236
  void wait        (double ticks);
 
237
  void tmrSetTempo (int v);
 
238
  void tmrStart    ();
 
239
  void tmrStop     ();
 
240
  void tmrContinue ();
 
241
  void sync        (int i=0);  // if i==1 syncronizes by cleaning the buffer
 
242
                        // instead of sending it (in fact, this is what
 
243
                        // syncronizing really means :-)
 
244
#endif
 
245
 
 
246
/**
 
247
 * @return the path to the file where the current used @ref MidiMapper object
 
248
 * reads the configuration from, or an empty string if there's no MidiMapper.
 
249
 */
 
250
  char *midiMapFilename ();
 
251
 
 
252
};
 
253
 
 
254
#endif