DeviceManager Class Reference
MIDI Device Manager class . Manages all MIDI devices and redirects MIDI events to each one as configured. More...
#include <deviceman.h>
Public Member Functions | |
DeviceManager (int def=-1) | |
Constructor. | |
~DeviceManager (void) | |
Destructor. | |
int | initManager (void) |
Initializes the MIDI Device Manager object. | |
int | checkInit (void) |
Checks if the device manager has been initialized (with ), and in case it wasn't, initializes it. | |
MidiOut * | chntodev (int chn) |
Obsolete. | |
MidiOut * | deviceForChannel (int chn) |
It's possible to send different MIDI channels to different MIDI devices, so that you can for example send channel 1 to an external synthesizer, channel 2 to a FM device and channel 10 to an AWE synth. | |
int | deviceNumberForChannel (int chn) |
Returns the device number associated with a given channel. | |
void | setDeviceNumberForChannel (int chn, int dev) |
Sets the device number associated with a given channel. | |
int | ok (void) |
int | usingAlsa (void) |
Returns true if it's running ALSA and false if OSS is being run. | |
void | openDev (void) |
Open the devices. | |
void | closeDev (void) |
Closes the devices, and /dev/sequencer. | |
void | initDev (void) |
Calls MidiOut::initDev() in turn in each of the available devices. | |
void | noteOn (uchar chn, uchar note, uchar vel) |
Sends a Note On MIDI event. | |
void | noteOff (uchar chn, uchar note, uchar vel) |
Sends a Note Off MIDI event. | |
void | keyPressure (uchar chn, uchar note, uchar vel) |
Sends a Key Pressure (or Aftertouch) MIDI event. | |
void | chnPatchChange (uchar chn, uchar patch) |
Changes the patch (instrument) on a MIDI channel. | |
void | chnPressure (uchar chn, uchar vel) |
Changes the Pressure (Aftertouch) on a MIDI channel. | |
void | chnPitchBender (uchar chn, uchar lsb, uchar msb) |
Changes the Pitch Bender value on a MIDI channel. | |
void | chnController (uchar chn, uchar ctl, uchar v) |
Sends a Controller event to a MIDI channel. | |
void | sysEx (uchar *data, ulong size) |
Sends a SYStem EXclusive message to the default MIDI device (usually, external MIDI synths, as most internal synths do not support sysex messages). | |
void | wait (double ms) |
Sets the number of milliseconds at which the next event will be sent. | |
void | tmrSetTempo (int v) |
Sets the tempo which will be used to convert between ticks and milliseconds. | |
void | tmrStart (long int tpcn) |
Starts the timer. | |
void | tmrStop (void) |
Stops the timer. | |
void | tmrContinue (void) |
Continue the stopped timer . | |
void | allNotesOff (void) |
Sends an all notes off event. | |
void | sync (bool f=0) |
Synchronizes with the MIDI buffer. | |
void | setVolumePercentage (int i) |
Changes the "master" volume of the played events by altering next volume controller events. | |
int | defaultDevice (void) |
Returns the device to which the MIDI events will be sent. | |
void | setDefaultDevice (int i) |
Sets the device to send the MIDI events to. | |
int | setPatchesToUse (int *patchesused) |
Loads the patches you're going to use . | |
const char * | midiMapFilename (void) |
Returns the filename where the Midi Mapper was loaded from, or "" if no MIDI Mapper is in use. | |
void | setMidiMap (MidiMapper *map) |
Sets a MidiMapper object to use. | |
int | rate (void) |
Returns the SNDCTL_SEQ_CTRLRATE ioctl value. | |
int | midiPorts (void) |
Returns the number of MIDI ports available on the system. | |
int | synthDevices (void) |
Returns the number of internal synthesizers available on the system. | |
const char * | name (int i) |
Returns the name of the i-th device . | |
const char * | type (int i) |
Returns the type of device the i-th device is , in a user-friendly string . | |
Protected Member Functions | |
void | seqbuf_dump (void) |
void | seqbuf_clean (void) |
void | checkAlsa (void) |
Protected Attributes | |
MidiOut ** | device |
midi_info * | midiinfo |
synth_info * | synthinfo |
int | chn2dev [16] |
int | n_synths |
int | n_midi |
int | n_total |
int | m_rate |
double | convertrate |
int | timerstarted |
double | lastwaittime |
MidiMapper * | mapper_tmp |
int | initialized |
int | seqfd |
int | default_dev |
int | _ok |
bool | alsa |
Detailed Description
MIDI Device Manager class . Manages all MIDI devices and redirects MIDI events to each one as configured.This class is the one you should use to send MIDI events to any device, as it creates and manages the *Out classes.
This class is usually used by creating a DeviceManager object, then call openDev() and initDev() . Then, use numberOfMidiPorts(), numberOfSynthDevices(), name() and type() to choose which device to play MIDI events to and then use defaultDevice() to set the MIDI device to play.
- Version:
- 0.9.5 17/01/2000
- Author:
- Antonio Larrosa Jimenez <larrosa@kde.org>
Definition at line 46 of file deviceman.h.
Constructor & Destructor Documentation
|
Constructor. It just initializes internal variables, before playing any music, you should call initManager(), setMidiMap() (optional), openDev(), initDev(), setPatchesToUse() (not required, unless you're playing to a GUS device, which must load the patches), tmrStart(), and finally, play the music. Definition at line 106 of file deviceman.cc. References KGlobal::_instance, QString::find(), QString::isEmpty(), QString::mid(), KConfigBase::readBoolEntry(), KConfigBase::readNumEntry(), KConfigBase::readPathEntry(), and KConfigBase::setGroup(). |
|
Destructor. It closes the device (calling closeDev() ) if it wasn't closed before. Definition at line 151 of file deviceman.cc. References closeDev(). |
Member Function Documentation
|
Initializes the MIDI Device Manager object. The /dev/sequencer and/or /dev/snd/seq files are opened, available devices are analyzed and *Out objects are created. Then, the device files are closed.
Definition at line 201 of file deviceman.cc. References KStdAccel::close(), name(), KStdAccel::open(), and setMidiMap(). Referenced by checkInit(). |
|
Checks if the device manager has been initialized (with ), and in case it wasn't, initializes it.
Definition at line 174 of file deviceman.cc. References initManager(). Referenced by name(), openDev(), setPatchesToUse(), and type(). |
|
Obsolete. Please use deviceForChannel() instead. Definition at line 205 of file deviceman.h. References deviceForChannel(). Referenced by chnController(), chnPatchChange(), chnPitchBender(), chnPressure(), keyPressure(), noteOff(), and noteOn(). |
|
It's possible to send different MIDI channels to different MIDI devices, so that you can for example send channel 1 to an external synthesizer, channel 2 to a FM device and channel 10 to an AWE synth.
Definition at line 216 of file deviceman.h. Referenced by chntodev(). |
|
Returns the device number associated with a given channel.
Definition at line 222 of file deviceman.h. |
|
Sets the device number associated with a given channel.
Definition at line 819 of file deviceman.cc. |
|
Definition at line 167 of file deviceman.cc. Referenced by MidiPlayer::play(). |
|
Returns true if it's running ALSA and false if OSS is being run.
Definition at line 238 of file deviceman.h. |
|
Open the devices. It first initializes the manager it that wasn't done yet (you should do it yourself, to be able to choose the MIDI output device, as it will be set to an external synth by default, if available). Then /dev/sequencer is opened and the MIDI devices are opened (calling MidiOut::openDev() ).
Definition at line 396 of file deviceman.cc. References checkInit(), MidiOut::closeDev(), MidiOut::ok(), KStdAccel::open(), and MidiOut::openDev(). Referenced by MidiPlayer::play(). |
|
Closes the devices, and /dev/sequencer.
Definition at line 447 of file deviceman.cc. References KStdAccel::close(), MidiOut::closeDev(), and tmrStop(). Referenced by MidiPlayer::play(), and ~DeviceManager(). |
|
Calls MidiOut::initDev() in turn in each of the available devices.
Definition at line 480 of file deviceman.cc. References MidiOut::initDev(). Referenced by MidiPlayer::play(). |
|
Sends a Note On MIDI event.
Definition at line 494 of file deviceman.cc. References chntodev(), and MidiOut::noteOn(). Referenced by MidiPlayer::play(). |
|
Sends a Note Off MIDI event. This is equivalent to send a Note On event with a vel value of 0.
Definition at line 499 of file deviceman.cc. References chntodev(), and MidiOut::noteOff(). Referenced by MidiPlayer::play(). |
|
Sends a Key Pressure (or Aftertouch) MIDI event. This event changes the pressure over a key after this key has been played.
Definition at line 504 of file deviceman.cc. References chntodev(), and MidiOut::keyPressure(). Referenced by MidiPlayer::play(). |
|
Changes the patch (instrument) on a MIDI channel.
Definition at line 509 of file deviceman.cc. References MidiOut::chnPatchChange(), and chntodev(). Referenced by MidiPlayer::play(), and MidiStatus::sendData(). |
|
Changes the Pressure (Aftertouch) on a MIDI channel. Keep in mind that some synthesizers don't like this events, and it's better not to send it.
Definition at line 514 of file deviceman.cc. References MidiOut::chnPressure(), and chntodev(). Referenced by MidiPlayer::play(), and MidiStatus::sendData(). |
|
Changes the Pitch Bender value on a MIDI channel. This bends the tone of each note played on this channel.
Definition at line 519 of file deviceman.cc. References MidiOut::chnPitchBender(), and chntodev(). Referenced by MidiPlayer::play(), and MidiStatus::sendData(). |
|
Sends a Controller event to a MIDI channel. This can be used for example to change the volume, set a XG patch, etc. Look for any General Midi resource page on the net for more information about the available controller events.
For example, to set the tremolo value to a maximum on the MIDI channel number one, you should pass 1 to
Definition at line 524 of file deviceman.cc. References MidiOut::chnController(), and chntodev(). Referenced by MidiPlayer::play(), and MidiStatus::sendData(). |
|
Sends a SYStem EXclusive message to the default MIDI device (usually, external MIDI synths, as most internal synths do not support sysex messages).
Definition at line 529 of file deviceman.cc. References MidiOut::sysex(). |
|
Sets the number of milliseconds at which the next event will be sent. This way, you can schedule notes and events to send to the MIDI device.
Definition at line 535 of file deviceman.cc. Referenced by MidiPlayer::play(). |
|
Sets the tempo which will be used to convert between ticks and milliseconds.
Definition at line 551 of file deviceman.cc. Referenced by MidiPlayer::play(), and MidiStatus::sendData(). |
|
Starts the timer. You must call tmrStart before using wait() Definition at line 563 of file deviceman.cc. Referenced by MidiPlayer::play(). |
|
Stops the timer. This will be called by closeDev() before closing the device Definition at line 589 of file deviceman.cc. Referenced by closeDev(), and MidiPlayer::play(). |
|
Continue the stopped timer . It is the same than starting a new timer, but without resetting it. Definition at line 610 of file deviceman.cc. |
|
Sends an all notes off event.
Definition at line 824 of file deviceman.cc. References MidiOut::allNotesOff(). Referenced by MidiPlayer::play(). |
|
Synchronizes with the MIDI buffer. Midi events are put into a buffer, along with timer delays (see wait() ). sync returns when the buffer is empty.
Definition at line 630 of file deviceman.cc. Referenced by MidiPlayer::play(), and MidiStatus::sendData(). |
|
Changes the "master" volume of the played events by altering next volume controller events.
The parameter
Keep in mind that as most MIDI files already play music at near the maximum volume, an Definition at line 808 of file deviceman.cc. References MidiOut::setVolumePercentage(). Referenced by MidiPlayer::play(). |
|
Returns the device to which the MIDI events will be sent. Returns -1 if there's no available device.
Definition at line 764 of file deviceman.cc. |
|
Sets the device to send the MIDI events to. By using midiPorts(), synthDevices(), name() and type(), you should choose which device to use (note that they are numbered with midi ports being first and synth devices next)
Definition at line 769 of file deviceman.cc. |
|
Loads the patches you're going to use . This has effect only for GUS cards, although, if you use this function when defaultDevice() is not a GUS device, it will be ignored. The parameter is an int [256] array, which contain the following: The first 0..127 integers, are the number of times each General MIDI patch will be used, and -1 when the corresponding patch won't be used. The 128..255 integers are the number of times each drum voice (each note on the drum channel) will be used, and -1 when the corresponding percussion won't be used. This is done this way so that if the user has very little memory on his GUS card, and not all patches will be loaded, they are at least reordered, so that it first loads the one you're going to use most. In case you don't worry about such users, or you don't know "a priori" the number of notes you're going to play, you can just use 1 for each patch you want to load and -1 in the rest.
Definition at line 794 of file deviceman.cc. References checkInit(), and GUSOut::setPatchesToUse(). Referenced by MidiPlayer::play(). |
|
Returns the filename where the Midi Mapper was loaded from, or "" if no MIDI Mapper is in use.
Definition at line 776 of file deviceman.cc. |
|
Sets a MidiMapper object to use. This object should already have loaded the configuration. See the description of MidiMapper for more information.
Definition at line 784 of file deviceman.cc. Referenced by initManager(). |
|
Returns the SNDCTL_SEQ_CTRLRATE ioctl value.
Definition at line 491 of file deviceman.h. |
|
Returns the number of MIDI ports available on the system. It's common that users have MIDI ports available, but there are no external synthesizers connected to these ports, so sending MIDI events to these ports will not produce any music in this case.
Definition at line 502 of file deviceman.h. Referenced by MidiPlayer::play(). |
|
Returns the number of internal synthesizers available on the system. Some of these devices will need special configuration, for example, to load sound patches.
Definition at line 513 of file deviceman.h. Referenced by MidiPlayer::play(). |
|
Returns the name of the In case the DeviceManager wasn't yet initialized ( see checkInit() ), the return value is NULL, and in case the parameter has a value out of the valid range ( 0 to midiPorts() + synthDevices() ) it returns an empty string. Definition at line 716 of file deviceman.cc. References checkInit(), and MidiOut::deviceName(). Referenced by initManager(). |
|
Returns the type of device the For example, "External Midi Port" for midi ports, "FM" for FM synthesizers, "GUS" for Gravis Ultrasound devices, etc. Definition at line 734 of file deviceman.cc. References checkInit(). |
The documentation for this class was generated from the following files: