Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'DeviceManager (./kdelibs/libkmid/deviceman.h:46)
class DeviceManager
{
protected:
/**
* @internal
* The midi devices objects
*/
MidiOut **device;
/**
* @internal
* Midi info
*/
struct midi_info *midiinfo;
/**
* @internal
* Synth info
*/
struct synth_info *synthinfo;
/**
* @internal
* Stores the device thru which a channel will be sent
*/
int chn2dev[16];
/**
* @internal
* Number of synths devices
*/
int n_synths;
/**
* @internal
* Number of midi ports
*/
int n_midi;
/**
* @internal
* n_midi + n_synths
*/
int n_total;
#ifndef HANDLETIMEINDEVICES
/**
* @internal
*/
int rate;
/**
* @internal
* A "constant" used to convert from milliseconds to the computer rate.
*/
double convertrate;
#endif
/**
* @internal
* Newest kernels don't want me to stop a timer that hasn't been started :-)
*/
int timerstarted;
/**
* @internal
* Last time waited for in wait(double)
*/
double lastwaittime;
/**
* @internal
* Keeps a pointer to the mapper so that if devices weren't initialized when
* first called setMidiMap then, when they get initialized, they use the
* proper mapper
*/
MidiMapper *mapper_tmp;
int initialized;
/**
* @internal
* The real file handler for /dev/sequencer, that is opened and closed.
*/
int seqfd;
/**
* @internal
* The device to which timer events will be sent
*/
int default_dev;
/**
* @internal
*/
int _ok;
/**
* @internal
* True if the user is running ALSA. False if (s)he's using OSS
*/
bool alsa;
/**
* @internal
*/
void seqbuf_dump (void);
/**
* @internal
*/
void seqbuf_clean (void);
/**
* @internal
*/
void checkAlsa (void);
public:
/**
* Constructor. It just initializes internal variables, before playing any
* music, you should call @ref #initManager(), @ref #setMidiMap()
* (optional), @ref #openDev(), @ref #initDev(), @ref #setPatchesToUse()
* (not required, unless you're playing to a GUS device, which must load
* the patches), @ref #tmrStart(), and finally, play the music.
*/
DeviceManager(int def=-1);
/**
* Destructor. It closes the device (calling @ref #closeDev() ) if it wasn't
* closed before.
*/
~DeviceManager(void);
/**
* 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.
*
* @return 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 initManager(void);
/**
* Checks if the device manager has been initialized (with @initManager),
* and in case it wasn't, initializes it.
*
* @return 0 if it was (or has just been) correctly initialized, and -1 if
* there was an error.
*/
int checkInit(void);
/**
* 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.
*
* @return the device to which MIDI events goind to channel @p chn should
* be sent.
*/
MidiOut *chntodev(int chn)
{ return (device!=0L) ? device[chn2dev[chn]] : 0L ; };
/**
* @return 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 ok(void);
/**
* Returns true if it's running ALSA and false if OSS is being run
*/
int usingAlsa(void) { return alsa; };
// The following funtion are here to emulate a midi, so that the
// DeviceManager sends the events to the appropiate devices.
/**
* 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 @ref MidiOut::openDev() ).
* @see #ok() to check if there was any problem
* @see #closeDev()
* @see #initDev()
*/
void openDev (void);
/**
* Closes the devices, and /dev/sequencer.
*
* @see #openDev()
*/
void closeDev (void);
/**
* Calls @ref MidiOut::initDev() in turn in each of the available devices.
*
* @see MidiOut::initDev()
*/
void initDev (void);
/**
* Sends a Note On MIDI event.
*
* @param chn the MIDI channel (0 to 15) to play the note on.
* @param note the key of the note to play (0 to 127).
* @param vel the velocity of the note (0 to 127).
*
* @see #noteOff()
*/
void noteOn ( uchar chn, uchar note, uchar vel );
/**
* Sends a Note Off MIDI event. This is equivalent to send a Note On event
* with a vel value of 0.
*
* @param chn the MIDI channel (0 to 15) to play the note on.
* @param note the key of the note to play (0 to 127).
* @param vel the velocity of the note (0 to 127).
*
* @see #noteOn()
*/
void noteOff ( uchar chn, uchar note, uchar vel );
/**
* Sends a Key Pressure (or Aftertouch) MIDI event.
* This event changes the pressure over a key after this key has been played.
*
* @param chn the MIDI channel (0 to 15) where the note is being played.
* @param note the key of the note (0 to 127).
* @param vel the new velocity (or pressure) of the note (0 to 127).
*/
void keyPressure ( uchar chn, uchar note, uchar vel );
/**
* Changes the patch (instrument) on a MIDI channel.
*
* @see setPatchesToUse()
*
* @param chn the MIDI channel (0 to 15) .
* @param patch the General Midi patch (0 to 127) to use on the channel chn.
*/
void chnPatchChange ( uchar chn, uchar patch );
/**
* 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.
*
* @param chn the MIDI channel (0 to 15) to change.
* @param vel the velocity (0 to 127) to use on the channel chn.
*/
void chnPressure ( uchar chn, uchar vel );
/**
* Changes the Pitch Bender value on a MIDI channel. This bends the tone of
* each note played on this channel.
*
* @param chn the MIDI channel (0 to 15) to use.
* @param lsb and @p 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 chnPitchBender ( uchar chn, uchar lsb, uchar msb );
/**
* 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 @p chn, 1 to @p ctl and 127 to @p v.
*
* @param chn the MIDI channel (0 to 15) to send the event to.
* @param ctl the controller (0 to 15) to send.
* @param v the value (data) of the controller.
*/
void chnController ( uchar chn, uchar ctl , uchar v );
/**
* Sends a SYStem EXclusive message to the default MIDI device (usually,
* external MIDI synths, as most internal synths do not support sysex
* messages)
*
* @param 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)
* @param size the size in bytes of the data to send
*
* @see setDefaultDevice()
*/
void sysEx ( uchar *data,ulong size);
/**
* 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 tmrStart()
*/
void wait (double ms);
/**
* Sets the tempo which will be used to convert between ticks and
* milliseconds.
*/
void tmrSetTempo(int v);
/**
* Starts the timer. You must call tmrStart before using @ref #wait()
*/
void tmrStart(long int tpcn);
/**
* Stops the timer. This will be called by @ref #closeDev() before closing
* the device
*/
void tmrStop(void);
/**
* Continue the stopped timer . It is the same than starting a new timer, but
* without resetting it.
*/
void tmrContinue(void);
/**
* Synchronizes with the MIDI buffer. Midi events are put into a buffer,
* along with timer delays (see @ref #wait() ). sync returns when the buffer
* is empty.
*
* @param 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 sync(bool f=0);
/**
* Changes the "master" volume of the played events by altering next volume
* controller events. The parameter @p 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 @p i value greater than 100 is very probably ignored
* most of the times.
*/
void setVolumePercentage(int i);
/**
* Returns the device to which the MIDI events will be sent.
* Returns -1 if there's no available device.
*
* @see #setDefaultDevice()
*/
int defaultDevice(void);
/**
* Sets the device to send the MIDI events to.
*
* By using @ref #midiPorts(), @ref #synthDevices(), @ref #name() and
* @ref #type(), you should choose which device to use (note that they are
* numbered with midi ports being first and synth devices next)
*
* @see #defaultDevice()
*/
void setDefaultDevice(int i);
/**
* Loads the patches you're going to use . This has effect only for GUS
* cards, although, if you use this function when @ref 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.
*
* @see GUSOut::setPatchesToUse()
* @see GUSOut::loadPatch()
*
* @return 0 if ok, and -1 if there wasn't enough memory to load the patches
* in the card's memory.
*/
int setPatchesToUse(int *patchesused);
/**
* Returns the filename where the Midi Mapper was loaded from, or "" if no
* MIDI Mapper is in use.
*
* @see #setMidiMap()
*/
char *midiMapFilename(void);
/**
* Sets a @ref MidiMapper object to use. This object should already have
* loaded the configuration. See the description of @ref MidiMapper for
* more information.
*
* @see MidiMapper::MidiMapper()
* @see #midiMapFilename()
*/
void setMidiMap(MidiMapper *map);
/**
* 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 #synthDevices()
* @see #setDefaultDevice()
*/
int midiPorts(void) { return n_midi; };
/**
* 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 #midiPorts()
* @see #setDefaultDevice()
* @see #setPatchesToUse()
*/
int synthDevices(void) { return n_synths; };
/**
* Returns the name of the @p i-th device . In case the DeviceManager wasn't
* yet initialized ( see @ref #checkInit() ), the return value is NULL, and
* in case the parameter has a value out of the valid range ( 0 to
* @ref midiPorts() + @ref synthDevices() ) it returns an empty string.
*/
const char *name(int i);
/**
* Returns the type of device the @p 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.
*/
const char *type(int i);
private:
class DeviceManagerPrivate;
DeviceManagerPrivate *d;
};
kdelibs'DeviceManager::DeviceManager() (./kdelibs/libkmid/deviceman.cc:93)
DeviceManager::DeviceManager(int def)
{
#if 1
if (def==-1)
{
KInstance *tmp_instance=0L;
if (!KGlobal::_instance) tmp_instance=new KInstance("nonKDEapp");
KConfig *config = new KConfig("kcmmidirc", true);
config->setGroup("Configuration");
default_dev=config->readNumEntry("midiDevice",0);
QString mapurl(config->readEntry("mapFilename",""));
if ((config->readBoolEntry("useMidiMapper", false))&&(!mapurl.isEmpty()))
{
mapper_tmp = new MidiMapper( mapurl.mid(mapurl.find(":")+1 ).local8Bit() );
}
else
mapper_tmp = 0L;
delete config;
delete tmp_instance;
}
else
#endif
{
default_dev = def;
mapper_tmp = 0L;
}
initialized=0;
_ok=1;
alsa=false;
device = 0L;
#ifdef HANDLETIMEINDEVICES
rate=100;
convertrate=10;
#endif
seqfd=-1;
timerstarted=0;
for (int i=0;i<16;i++) chn2dev[i]=default_dev;
}
kdelibs'DeviceManager::~DeviceManager() (./kdelibs/libkmid/deviceman.cc:135)
DeviceManager::~DeviceManager(void)
{
closeDev();
if (device!=0L)
{
for (int i=0;i<n_midi;i++)
delete device[i];
delete device;
device=0L;
}
}
kdelibs'DeviceManager::ok() (./kdelibs/libkmid/deviceman.cc:147)
int DeviceManager::ok(void)
{
int r=_ok;
_ok=1;
return r;
}
kdelibs'DeviceManager::checkInit() (./kdelibs/libkmid/deviceman.cc:154)
int DeviceManager::checkInit(void)
{
if (initialized==0)
{
int r=initManager();
if (default_dev>=n_total) default_dev=0;
DEBUGPRINTF("check : %d\n",r);
return r;
}
return 0;
}
kdelibs'DeviceManager::checkAlsa() (./kdelibs/libkmid/deviceman.cc:166)
void DeviceManager::checkAlsa(void)
{
#ifdef HAVE_SYS_STAT_H
struct stat buf;
stat("/proc/asound", &buf);
if ((stat("/proc/asound", &buf) == 0 ) && (S_ISDIR(buf.st_mode)))
alsa=true;
else
alsa=false;
#else
#warning "ALSA won't be found at runtime"
alsa=false;
#endif
}
kdelibs'DeviceManager::initManager() (./kdelibs/libkmid/deviceman.cc:181)
int DeviceManager::initManager(void)
{
checkAlsa();
if (!alsa) // We are using OSS
{
#ifdef HAVE_OSS_SUPPORT
seqfd = open("/dev/sequencer", O_WRONLY | O_NONBLOCK, 0);
if (seqfd==-1)
{
printf("ERROR: Couldn't open /dev/sequencer to get some information\n");
_ok=0;
return -1;
};
n_synths=0;
n_midi=0;
ioctl(seqfd,SNDCTL_SEQ_NRSYNTHS,&n_synths);
ioctl(seqfd,SNDCTL_SEQ_NRMIDIS,&n_midi);
n_total=n_midi+n_synths;
if (n_midi==0)
{
printf("ERROR: There's no midi port\n");
/* This could be a problem if the user don't have a synth neither,
but not having any of both things is unusual */
// _ok=0;
// return 1;
}
device=new MidiOut*[n_total];
midiinfo=new midi_info[n_midi];
synthinfo=new synth_info[n_synths];
int i;
for (i=0;i<n_midi;i++)
{
midiinfo[i].device=i;
if (ioctl(seqfd,SNDCTL_MIDI_INFO,&midiinfo[i])!=-1)
{
#ifdef GENERAL_DEBUG_MESSAGES
printf("----\n");
printf("Device : %d\n",i);
printf("Name : %s\n",midiinfo[i].name);
printf("Device type : %d\n",midiinfo[i].dev_type);
#endif
}
device[i]=new MidiOut(i);
}
for (i=0;i<n_synths;i++)
{
synthinfo[i].device=i;
if (ioctl(seqfd,SNDCTL_SYNTH_INFO,&synthinfo[i])!=-1)
{
#ifdef GENERAL_DEBUG_MESSAGES
printf("----\n");
printf("Device : %d\n",i);
printf("Name : %s\n",synthinfo[i].name);
switch (synthinfo[i].synth_type)
{
case (SYNTH_TYPE_FM) : printf("FM\n");break;
case (SYNTH_TYPE_SAMPLE) : printf("Sample\n");break;
case (SYNTH_TYPE_MIDI) : printf("Midi\n");break;
default : printf("default type\n");break;
};
switch (synthinfo[i].synth_subtype)
{
case (FM_TYPE_ADLIB) : printf("Adlib\n");break;
case (FM_TYPE_OPL3) : printf("Opl3\n");break;
case (MIDI_TYPE_MPU401) : printf("Mpu-401\n");break;
case (SAMPLE_TYPE_GUS) : printf("Gus\n");break;
default : printf("default subtype\n");break;
}
#endif
if (synthinfo[i].synth_type==SYNTH_TYPE_FM)
device[i+n_midi]=new FMOut(i,synthinfo[i].nr_voices);
else if ((synthinfo[i].synth_type==SYNTH_TYPE_SAMPLE)&&
(synthinfo[i].synth_subtype==SAMPLE_TYPE_GUS))
device[i+n_midi]=new GUSOut(i,synthinfo[i].nr_voices);
else
device[i+n_midi]=new SynthOut(i);
}
}
close(seqfd);
#else // There's no OSS support and ALSA wasn't detected
// It must be one of those systems coolo is using :-)
n_synths=0;
n_midi=0;
n_total=0;
device=0L;
midiinfo=0L;
synthinfo=0L;
#endif
}
else
{ // We are using ALSA
#ifdef HAVE_ALSA_SUPPORT
snd_seq_client_info_t clienti;
snd_seq_port_info_t porti;
int client;
int port;
snd_seq_t *handle;
snd_seq_open(&handle, SND_SEQ_OPEN);
snd_seq_system_info_t info;
snd_seq_system_info(handle, &info);
n_total=0;
n_midi=0;
n_synths=0;
device=new MidiOut*[info.clients*info.ports];
unsigned int k=SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_WRITE ;
for (client=0 ; client<info.clients ; client++)
{
snd_seq_get_any_client_info(handle, client, &clienti);
for (port=0 ; port<clienti.num_ports ; port++)
{
snd_seq_get_any_port_info(handle, client, port, &porti);
if (( porti.capability & k ) == k)
{
device[n_midi]=new AlsaOut(n_midi,client, port, clienti.name, porti.name);
n_midi++;
};
}
}
n_total=n_midi;
snd_seq_close(handle);
#else
// Note: Please don't add i18n for the text below, thanks :)
fprintf(stderr,"Sorry, this KMid version was compiled without \n");
fprintf(stderr,"ALSA support but you're using ALSA . \n");
fprintf(stderr,"Please compile KMid for yourself or tell the people\n");
fprintf(stderr,"at your Linux distribution to compile it themselves\n");
#endif
}
if (mapper_tmp!=0L) setMidiMap(mapper_tmp);
initialized=1;
return 0;
}
kdelibs'DeviceManager::openDev() (./kdelibs/libkmid/deviceman.cc:335)
void DeviceManager::openDev(void)
{
if (checkInit()<0)
{
DEBUGPRINTF("DeviceManager::openDev : Not initialized\n");
_ok = 0;
return;
}
_ok=1;
if (!alsa)
{
#ifdef HAVE_OSS_SUPPORT
seqfd = open("/dev/sequencer", O_WRONLY | O_NONBLOCK, 0);
if (seqfd==-1)
{
printf("Couldn't open the /dev/sequencer device\n");
_ok=0;
return;
}
_seqbufptr = 0;
ioctl(seqfd,SNDCTL_SEQ_RESET);
//ioctl(seqfd,SNDCTL_SEQ_PANIC);
#ifndef HANDLETIMEINDEVICES
rate=0;
int r=ioctl(seqfd,SNDCTL_SEQ_CTRLRATE,&rate);
if ((r==-1)||(rate<=0)) rate=HZ;
convertrate=1000/rate;
#endif
#endif
}
else seqfd=0L; // ALSA
DEBUGPRINTF("Opening devices : ");
for (int i=0;i<n_total;i++)
{
device[i]->openDev(seqfd);
DEBUGPRINTF("%s ",device[i]->deviceName());
}
DEBUGPRINTF("\n");
for (int i=0;i<n_total;i++) if (!device[i]->ok()) _ok=0;
if (_ok==0)
{
for (int i=0;i<n_total;i++) device[i]->closeDev();
DEBUGPRINTF("DeviceMan :: ERROR : Closing devices\n");
return;
}
DEBUGPRINTF("Devices opened\n");
}
kdelibs'DeviceManager::closeDev() (./kdelibs/libkmid/deviceman.cc:388)
void DeviceManager::closeDev(void)
{
if (alsa)
{
if (device!=NULL) for (int i=0;i<n_total;i++)
device[i]->closeDev();
return;
}
#ifdef HAVE_OSS_SUPPORT
if (seqfd==-1) return;
#ifndef HANDLETIMEINDEVICES
tmrStop();
#endif
/*
DEBUGPRINTF("Closing devices : ");
if (device!=NULL) for (int i=0;i<n_total;i++)
{
device[i]->initDev();
DEBUGPRINTF("%s ",device[i]->deviceName());
// device[i]->closeDev();
};
DEBUGPRINTF("\n");
*/
close(seqfd);
seqfd=-1;
#endif
}
kdelibs'DeviceManager::initDev() (./kdelibs/libkmid/deviceman.cc:418)
void DeviceManager::initDev(void)
{
if (device!=0L)
{
DEBUGPRINTF("Initializing devices :");
for (int i=0;i<n_total;i++)
{
device[i]->initDev();
DEBUGPRINTF("%s ",device[i]->deviceName());
}
DEBUGPRINTF("\n");
}
}
kdelibs'DeviceManager::noteOn() (./kdelibs/libkmid/deviceman.cc:432)
void DeviceManager::noteOn ( uchar chn, uchar note, uchar vel )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->noteOn(chn,note,vel);
}
kdelibs'DeviceManager::noteOff() (./kdelibs/libkmid/deviceman.cc:437)
void DeviceManager::noteOff ( uchar chn, uchar note, uchar vel )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->noteOff(chn,note,vel);
}
kdelibs'DeviceManager::keyPressure() (./kdelibs/libkmid/deviceman.cc:442)
void DeviceManager::keyPressure ( uchar chn, uchar note, uchar vel )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->keyPressure(chn,note,vel);
}
kdelibs'DeviceManager::chnPatchChange() (./kdelibs/libkmid/deviceman.cc:447)
void DeviceManager::chnPatchChange ( uchar chn, uchar patch )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->chnPatchChange(chn,patch);
}
kdelibs'DeviceManager::chnPressure() (./kdelibs/libkmid/deviceman.cc:452)
void DeviceManager::chnPressure ( uchar chn, uchar vel )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->chnPressure(chn,vel);
}
kdelibs'DeviceManager::chnPitchBender() (./kdelibs/libkmid/deviceman.cc:457)
void DeviceManager::chnPitchBender ( uchar chn, uchar lsb, uchar msb )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->chnPitchBender(chn,lsb,msb);
}
kdelibs'DeviceManager::chnController() (./kdelibs/libkmid/deviceman.cc:462)
void DeviceManager::chnController ( uchar chn, uchar ctl , uchar v )
{
MidiOut *midi=chntodev(chn);
if (midi) midi->chnController(chn,ctl,v);
}
kdelibs'DeviceManager::sysEx() (./kdelibs/libkmid/deviceman.cc:467)
void DeviceManager::sysEx ( uchar *data,ulong size)
{
for (int i=0;i<n_midi;i++)
device[i]->sysex(data,size);
}
kdelibs'DeviceManager::wait() (./kdelibs/libkmid/deviceman.cc:473)
void DeviceManager::wait (double ticks)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa) { ((AlsaOut *)device[default_dev])->wait(ticks); return; };
#endif
#ifdef HAVE_OSS_SUPPORT
unsigned long int t=(unsigned long int)(ticks/convertrate);
if (lastwaittime==t) return;
lastwaittime=t;
#ifdef HANDLETIMEINDEVICES
device[default_dev]->wait(ticks);
#else
//printf("%ld\n",t);
SEQ_WAIT_TIME(t);
SEQ_DUMPBUF();
#endif
#endif
}
//void DeviceManager::tmrSetTempo(int v)
kdelibs'DeviceManager::tmrSetTempo() (./kdelibs/libkmid/deviceman.cc:494)
void DeviceManager::tmrSetTempo(int v)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa) { ((AlsaOut *)device[default_dev])->tmrSetTempo(v); return; }
#endif
#ifdef HAVE_OSS_SUPPORT
SEQ_SET_TEMPO(v);
SEQ_DUMPBUF();
#endif
}
kdelibs'DeviceManager::tmrStart() (./kdelibs/libkmid/deviceman.cc:506)
void DeviceManager::tmrStart(long int
#ifdef HAVE_ALSA_SUPPORT
tpcn /*name the argument only if it is used*/
#endif
)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa) { ((AlsaOut *)device[default_dev])->tmrStart(tpcn); return; }
#endif
#ifdef HAVE_OSS_SUPPORT
#ifdef HANDLETIMEINDEVICES
device[default_dev]->tmrStart();
#else
#ifdef CONTROLTIMER
if (!timerstarted)
{
SEQ_START_TIMER();
SEQ_DUMPBUF();
timerstarted=1;
}
lastwaittime=0;
#else
SEQ_START_TIMER();
SEQ_DUMPBUF();
#endif
#endif
#endif
}
kdelibs'DeviceManager::tmrStop() (./kdelibs/libkmid/deviceman.cc:536)
void DeviceManager::tmrStop(void)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa) { ((AlsaOut *)device[default_dev])->tmrStop(); return; }
#endif
#ifdef HAVE_OSS_SUPPORT
#ifdef HANDLETIMEINDEVICES
device[default_dev]->tmrStop();
#else
#ifdef CONTROLTIMER
if (timerstarted)
{
SEQ_STOP_TIMER();
SEQ_DUMPBUF();
timerstarted=0;
}
#else
SEQ_STOP_TIMER();
SEQ_DUMPBUF();
#endif
#endif
#endif
}
kdelibs'DeviceManager::tmrContinue() (./kdelibs/libkmid/deviceman.cc:561)
void DeviceManager::tmrContinue(void)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa) { ((AlsaOut *)device[default_dev])->tmrContinue(); return; }
#endif
#ifdef HAVE_OSS_SUPPORT
#ifdef HANDLETIMEINDEVICES
device[default_dev]->tmrContinue();
#else
#ifdef CONTROLTIMER
if (timerstarted)
{
SEQ_CONTINUE_TIMER();
SEQ_DUMPBUF();
}
#else
SEQ_CONTINUE_TIMER();
SEQ_DUMPBUF();
#endif
#endif
#endif
}
kdelibs'DeviceManager::sync() (./kdelibs/libkmid/deviceman.cc:585)
void DeviceManager::sync(bool f)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa) { ((AlsaOut *)device[default_dev])->sync(f); return ; };
#endif
#ifdef HAVE_OSS_SUPPORT
#ifdef HANDLETIMEINDEVICES
device[default_dev]->sync(f);
#else
#ifdef DEVICEMANDEBUG
printf("Sync %d\n",f);
#endif
if (f)
{
seqbuf_clean();
/* If you have any problem, try removing the next 2 lines,
I though they would be useful here but the may have side effects */
ioctl(seqfd,SNDCTL_SEQ_RESET);
ioctl(seqfd,SNDCTL_SEQ_PANIC);
}
else
{
seqbuf_dump();
ioctl(seqfd, SNDCTL_SEQ_SYNC);
};
#endif
#endif
}
kdelibs'DeviceManager::seqbuf_dump() (./kdelibs/libkmid/deviceman.cc:615)
void DeviceManager::seqbuf_dump (void)
{
if (!alsa)
{
#ifdef HAVE_OSS_SUPPORT
if (_seqbufptr)
{
int r=0;
unsigned char *sb=_seqbuf;
int w=_seqbufptr;
r=write (seqfd, _seqbuf, _seqbufptr);
#ifdef DEVICEMANDEBUG
printf("%d == %d\n",r,w);
printf("%d\n",(errno==EAGAIN)? 1 : 0);
#endif
while (((r == -1)&&(errno==EAGAIN))||(r != w))
{
if ((r==-1)&&(errno==EAGAIN))
{
usleep(1);
}
else if ((r>0)&&(r!=w))
{
w-=r;
sb+=r;
}
r=write (seqfd, sb, w);
#ifdef DEVICEMANDEBUG
printf("%d == %d\n",r,w);
printf("%d\n",(errno==EAGAIN)? 1 : 0);
#endif
}
}
/*
* if (_seqbufptr)
* if (write (seqfd, _seqbuf, _seqbufptr) == -1)
* {
* printf("Error writing to /dev/sequencer in deviceManager::seqbuf_dump\n");
* perror ("write /dev/sequencer in seqbuf_dump\n");
* exit (-1);
* }
*/
_seqbufptr = 0;
#endif
}
}
kdelibs'DeviceManager::seqbuf_clean() (./kdelibs/libkmid/deviceman.cc:662)
void DeviceManager::seqbuf_clean(void)
{
#ifdef HAVE_ALSA_SUPPORT
if (alsa)
((AlsaOut *)device[default_dev])->seqbuf_clean();
else
#endif
#ifdef HAVE_OSS_SUPPORT
_seqbufptr=0;
#endif
}
kdelibs'DeviceManager::name() (./kdelibs/libkmid/deviceman.cc:675)
const char *DeviceManager::name(int i)
{
#ifdef HAVE_OSS_SUPPORT
if (checkInit()<0) {_ok = 0; return NULL;}
if (alsa)
{
if (i<n_midi) return device[i]->deviceName();
}
else
{
if (i<n_midi) return midiinfo[i].name;
if (i<n_midi+n_synths) return synthinfo[i-n_midi].name;
};
#endif
return (char *)"";
}
kdelibs'DeviceManager::type() (./kdelibs/libkmid/deviceman.cc:693)
const char *DeviceManager::type(int i)
{
#ifdef HAVE_OSS_SUPPORT
if (checkInit()<0) {_ok = 0; return NULL;}
if (alsa)
{
if (i<n_midi) return "ALSA device";
}
else
{
if (i<n_midi)
{
return "External Midi Port";
}
if (i<n_midi+n_synths)
{
switch (synthinfo[i-n_midi].synth_subtype)
{
case (FM_TYPE_ADLIB) : return "Adlib";break;
case (FM_TYPE_OPL3) : return "FM";break;
case (MIDI_TYPE_MPU401) : return "MPU 401";break;
case (SAMPLE_TYPE_GUS) : return "GUS";break;
}
}
}
#endif
return "";
}
kdelibs'DeviceManager::defaultDevice() (./kdelibs/libkmid/deviceman.cc:723)
int DeviceManager::defaultDevice(void)
{
return default_dev;
}
kdelibs'DeviceManager::setDefaultDevice() (./kdelibs/libkmid/deviceman.cc:728)
void DeviceManager::setDefaultDevice(int i)
{
if (i>=n_total) return;
default_dev=i;
for (int i=0;i<16;i++) chn2dev[i]=default_dev;
}
kdelibs'DeviceManager::midiMapFilename() (./kdelibs/libkmid/deviceman.cc:735)
char *DeviceManager::midiMapFilename(void)
{
if (device==0L) return (char *)"";
return (device[default_dev]!=NULL) ?
device[default_dev]->midiMapFilename() : (char *)"";
}
kdelibs'DeviceManager::setMidiMap() (./kdelibs/libkmid/deviceman.cc:742)
void DeviceManager::setMidiMap(MidiMapper *map)
{
if (map==NULL) return;
mapper_tmp=map;
if (default_dev>=n_total) {default_dev=0;return;};
if ((device==0L)||(device[default_dev]==NULL))
return;
device[default_dev]->setMidiMapper(map);
}
kdelibs'DeviceManager::setPatchesToUse() (./kdelibs/libkmid/deviceman.cc:752)
int DeviceManager::setPatchesToUse(int *patchesused)
{
if (checkInit()<0) return -1;
if ((device==0L)||(device[default_dev]==NULL))
return 0;
if ((device[default_dev]->deviceType())==KMID_GUS)
{
GUSOut *gus=(GUSOut *)device[default_dev];
gus->setPatchesToUse(patchesused);
}
return 0;
}
kdelibs'DeviceManager::setVolumePercentage() (./kdelibs/libkmid/deviceman.cc:766)
void DeviceManager::setVolumePercentage(int v)
{
if (device!=0L)
{
for (int i=0;i<n_total;i++)
{
device[i]->setVolumePercentage(v);
}
}
}