1
/* midiout.h - class midiOut which handles the /dev/sequencer device
2
Copyright (C) 1997,98 Antonio Larrosa Jimenez
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.
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.
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.
18
Send comments and bug fixes to antlarr@arrakis.es
19
or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
21
***************************************************************************/
27
#include "midimapper.h"
28
#include "../version.h"
34
* External MIDI port output class . This class is used to send midi
35
* events to external midi devices.
37
* MidiOut is inherited by other MIDI devices classes
38
* (like @ref SynthOut or @ref FMOut) to support a common API.
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.
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.
47
* @short Sends MIDI events to external MIDI devices
48
* @author Antonio Larrosa <larrosa@kde.org>
52
//friend class DeviceManager;
54
// This is the /dev/sequencer file handler.
55
// Remember NOT TO CLOSE it on MidiOut, but just on DeviceManager
59
#ifdef HANDLETIMEINDEVICES
60
int ndevs; // Total number of devices
61
int nmidiports; // Total number of midi ports
69
double convertrate; // A "constant" used to convert from
70
// milliseconds to the computer rate
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];
86
void seqbuf_dump (void);
87
void seqbuf_clean(void);
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),
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.
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
108
* @param sqfd a file descriptor of /dev/sequencer
112
virtual void openDev (int sqfd);
115
* Closes the device. It basically tells the device (the file descriptor)
116
* is going to be closed.
119
virtual void closeDev ();
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.
126
virtual void initDev ();
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 :
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
138
* which are defined in midispec.h
141
int deviceType () const { return devicetype; };
144
* @return the name and type of this MIDI device.
146
const char * deviceName (void) const;
148
#ifdef HANDLETIMEINDEVICES
149
int rate (void) { return rate; };
153
* Sets a @ref MidiMapper object to be used to modify the midi events before
156
* @param map the MidiMapper to use.
159
* @see #midiMapFilename
161
void setMidiMapper ( MidiMapper *map );
164
* See @ref DeviceManager::noteOn
166
virtual void noteOn ( uchar chn, uchar note, uchar vel );
169
* See @ref DeviceManager::noteOff
171
virtual void noteOff ( uchar chn, uchar note, uchar vel );
174
* See @ref DeviceManager::keyPressure
176
virtual void keyPressure ( uchar chn, uchar note, uchar vel );
179
* See @ref DeviceManager::chnPatchChange
181
virtual void chnPatchChange ( uchar chn, uchar patch );
184
* See @ref DeviceManager::chnPressure
186
virtual void chnPressure ( uchar chn, uchar vel );
189
* See @ref DeviceManager::chnPitchBender
191
virtual void chnPitchBender ( uchar chn, uchar lsb, uchar msb );
194
* See @ref DeviceManager::chnController
196
virtual void chnController ( uchar chn, uchar ctl , uchar v );
199
* See @ref DeviceManager::sysex
201
virtual void sysex ( uchar *data,ulong size);
204
* Mutes all notes being played on a given channel.
206
virtual void channelSilence ( uchar chn );
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
215
virtual void channelMute ( uchar chn, int a );
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.
224
virtual void setVolumePercentage ( int volper )
225
{ volumepercentage = volper; };
228
* @return true if everything's ok and false if there has been any problem
231
{ if (seqfd<0) return 0;
235
#ifdef HANDLETIMEINDEVICES
236
void wait (double ticks);
237
void tmrSetTempo (int v);
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 :-)
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.
250
char *midiMapFilename ();