|
|
MIDI Device Manager class . 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.
MidiOut ** device | device |
[protected]
struct midi_info * midiinfo | midiinfo |
[protected]
struct synth_info * synthinfo | synthinfo |
[protected]
int chn2dev[16] | chn2dev[16] |
[protected]
int n_synths | n_synths |
[protected]
int n_midi | n_midi |
[protected]
int n_total | n_total |
[protected]
int m_rate | m_rate |
[protected]
double convertrate | convertrate |
[protected]
int timerstarted | timerstarted |
[protected]
double lastwaittime | lastwaittime |
[protected]
MidiMapper * mapper_tmp | mapper_tmp |
[protected]
int initialized | initialized |
[protected]
int seqfd | seqfd |
[protected]
int default_dev | default_dev |
[protected]
int _ok | _ok |
[protected]
bool alsa | alsa |
[protected]
void seqbuf_dump (void)
| seqbuf_dump |
[protected]
void seqbuf_clean (void)
| seqbuf_clean |
[protected]
void checkAlsa (void)
| checkAlsa |
[protected]
DeviceManager (int def=-1)
| DeviceManager |
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.
~DeviceManager (void)
| ~DeviceManager |
Destructor. It closes the device (calling closeDev() ) if it wasn't closed before.
int initManager (void)
| initManager |
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.
Returns: 0 if everything was OK, or -1 if there was an error and it couldn't be initialized (for example, because it couldn't open the /dev/sequencer file)
int checkInit (void)
| checkInit |
Checks if the device manager has been initialized (with @initManager), and in case it wasn't, initializes it.
Returns: 0 if it was (or has just been) correctly initialized, and -1 if there was an error.
MidiOut * chntodev (int chn)
| chntodev |
Obsolete. Please use deviceForChannel() instead.
MidiOut * deviceForChannel (int chn)
| deviceForChannel |
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.
Returns: the device to which MIDI events goind to channel chn
should
be sent.
int deviceNumberForChannel (int chn)
| deviceNumberForChannel |
Returns the device number associated with a given channel.
void setDeviceNumberForChannel (int chn, int dev)
| setDeviceNumberForChannel |
Sets the device number associated with a given channel.
int ok (void)
| ok |
Returns: 0 if there was a problem and 1 if everything was OK. Note that the return value is changed after you check it, so you can only check it once.
int usingAlsa (void)
| usingAlsa |
Returns true if it's running ALSA and false if OSS is being run
void openDev (void)
| openDev |
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() ).
See also: ok(), to, check, if, there, was, any, problem, closeDev(), initDev()
void closeDev (void)
| closeDev |
Closes the devices, and /dev/sequencer.
See also: openDev()
void initDev (void)
| initDev |
Calls MidiOut::initDev() in turn in each of the available devices.
See also: MidiOut::initDev()
void noteOn ( uchar chn, uchar note, uchar vel )
| noteOn |
Sends a Note On MIDI event.
Parameters:
chn | the MIDI channel (0 to 15) to play the note on. |
note | the key of the note to play (0 to 127). |
vel | the velocity of the note (0 to 127). |
See also: noteOff()
void noteOff ( uchar chn, uchar note, uchar vel )
| noteOff |
Sends a Note Off MIDI event. This is equivalent to send a Note On event with a vel value of 0.
Parameters:
chn | the MIDI channel (0 to 15) to play the note on. |
note | the key of the note to play (0 to 127). |
vel | the velocity of the note (0 to 127). |
See also: noteOn()
void keyPressure ( uchar chn, uchar note, uchar vel )
| keyPressure |
Sends a Key Pressure (or Aftertouch) MIDI event. This event changes the pressure over a key after this key has been played.
Parameters:
chn | the MIDI channel (0 to 15) where the note is being played. |
note | the key of the note (0 to 127). |
vel | the new velocity (or pressure) of the note (0 to 127). |
void chnPatchChange ( uchar chn, uchar patch )
| chnPatchChange |
Changes the patch (instrument) on a MIDI channel.
Parameters:
chn | the MIDI channel (0 to 15) . |
patch | the General Midi patch (0 to 127) to use on the channel chn. |
See also: setPatchesToUse()
void chnPressure ( uchar chn, uchar vel )
| chnPressure |
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.
Parameters:
chn | the MIDI channel (0 to 15) to change. |
vel | the velocity (0 to 127) to use on the channel chn. |
void chnPitchBender ( uchar chn, uchar lsb, uchar msb )
| chnPitchBender |
Changes the Pitch Bender value on a MIDI channel. This bends the tone of each note played on this channel.
Parameters:
chn | the MIDI channel (0 to 15) to use. |
lsb | and msb the less significant byte and the most significant
byte (0 to 127 each) of the number by which notes will be bend. a 0x4000
value means not to bend.
|
void chnController ( uchar chn, uchar ctl , uchar v )
| chnController |
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 chn
, 1 to ctl
and 127 to v
.
Parameters:
chn | the MIDI channel (0 to 15) to send the event to. |
ctl | the controller (0 to 15) to send. |
v | the value (data) of the controller. |
void sysEx ( uchar *data,ulong size)
| sysEx |
Sends a SYStem EXclusive message to the default MIDI device (usually, external MIDI synths, as most internal synths do not support sysex messages)
Parameters:
data | the array of bytes that comform the system exclusive message. Without the initial 0xF0 char, and including the final 0xF7 char (end of exclusive message) |
size | the size in bytes of the data to send |
See also: setDefaultDevice()
void wait (double ms)
| wait |
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.
See also: tmrStart()
void tmrSetTempo (int v)
| tmrSetTempo |
Sets the tempo which will be used to convert between ticks and milliseconds.
void tmrStart (long int tpcn)
| tmrStart |
Starts the timer. You must call tmrStart before using wait()
void tmrStop (void)
| tmrStop |
Stops the timer. This will be called by closeDev() before closing the device
void tmrContinue (void)
| tmrContinue |
Continue the stopped timer . It is the same than starting a new timer, but without resetting it.
void allNotesOff (void)
| allNotesOff |
Sends an all notes off event
void sync (bool f=0)
| sync |
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.
Parameters:
f | if false, it syncronizes by waiting for the buffer to be sent. If true, it forces the synchronization by clearing the buffer inmediately. The "force" method is, of course, not recommended, except in rare situations. |
void setVolumePercentage (int i)
| setVolumePercentage |
Changes the "master" volume of the played events by altering next volume
controller events. The parameter i
should be in the range of 0
(nothing is heard) to 150 (music is played at a 150% of the original
volume).
Keep in mind that as most MIDI files already play music at near the
maximum volume, an i
value greater than 100 is very probably ignored
most of the times.
int defaultDevice (void)
| defaultDevice |
Returns the device to which the MIDI events will be sent. Returns -1 if there's no available device.
See also: setDefaultDevice()
void setDefaultDevice (int i)
| setDefaultDevice |
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)
See also: defaultDevice()
int setPatchesToUse (int *patchesused)
| setPatchesToUse |
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.
Returns: 0 if ok, and -1 if there wasn't enough memory to load the patches in the card's memory.
See also: GUSOut::setPatchesToUse(), GUSOut::loadPatch()
const char * midiMapFilename (void)
| midiMapFilename |
Returns the filename where the Midi Mapper was loaded from, or "" if no MIDI Mapper is in use.
See also: setMidiMap()
void setMidiMap (MidiMapper *map)
| setMidiMap |
Sets a MidiMapper object to use. This object should already have loaded the configuration. See the description of MidiMapper for more information.
See also: MidiMapper::MidiMapper(), midiMapFilename()
int rate (void)
| rate |
Returns the SNDCTL_SEQ_CTRLRATE ioctl value
int midiPorts (void)
| midiPorts |
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.
See also: synthDevices(), setDefaultDevice()
int synthDevices (void)
| synthDevices |
Returns the number of internal synthesizers available on the system. Some of these devices will need special configuration, for example, to load sound patches.
See also: midiPorts(), setDefaultDevice(), setPatchesToUse()
const char * name (int i)
| name |
Returns the name of the i
-th device . 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.
const char * type (int i)
| type |
Returns the type of device the i
-th device is , in a user-friendly
string . For example, "External Midi Port" for midi ports, "FM" for FM
synthesizers, "GUS" for Gravis Ultrasound devices, etc.