00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "deviceman.h"
00029 #include "midiout.h"
00030 #include <stdio.h>
00031 #include <fcntl.h>
00032 #include <unistd.h>
00033 #include <sys/ioctl.h>
00034 #include <errno.h>
00035 #include "sndcard.h"
00036 #include "synthout.h"
00037 #include "fmout.h"
00038 #include "gusout.h"
00039 #include "alsaout.h"
00040 #include "midimapper.h"
00041 #include "midispec.h"
00042
00043 #ifdef HAVE_CONFIG_H
00044 #include <config.h>
00045 #endif
00046
00047 #ifdef HAVE_SYS_STAT_H
00048 #include <sys/stat.h>
00049 #endif
00050
00051 #ifdef HAVE_ALSA_ASOUNDLIB_H
00052 # define HAVE_ALSA_SUPPORT
00053 # include <alsa/asoundlib.h>
00054 #elif defined(HAVE_SYS_ASOUNDLIB_H)
00055 # define HAVE_ALSA_SUPPORT
00056 # include <sys/asoundlib.h>
00057 #else
00058 #ifdef HAVE_LIBASOUND2
00059 # define HAVE_ALSA_SUPPORT
00060 # include <sound/asound.h>
00061 # include <sound/asequencer.h>
00062 #elif defined(HAVE_LIBASOUND)
00063 # define HAVE_ALSA_SUPPORT
00064 # include <linux/asequencer.h>
00065 #endif
00066 #endif
00067
00068 #if 1
00069 #include <kinstance.h>
00070 #include <kglobal.h>
00071 #include <kconfig.h>
00072 #endif
00073
00074
00075
00076
00077 SEQ_DEFINEBUF (4096);
00078
00079 #define CONTROLTIMER
00080
00081 #ifdef GENERAL_DEBUG_MESSAGES
00082 void DEBUGPRINTF(const char *format)
00083 {
00084 printf(format);
00085 }
00086
00087 void DEBUGPRINTF(const char *format,int i)
00088 {
00089 printf(format,i);
00090 }
00091
00092 void DEBUGPRINTF(const char *format,const char *s)
00093 {
00094 printf(format,s);
00095 }
00096
00097 #else
00098
00099 void DEBUGPRINTF(const char *) { }
00100 void DEBUGPRINTF(const char *,int ) { }
00101 void DEBUGPRINTF(const char *,const char * ) { }
00102
00103 #endif
00104
00105
00106 DeviceManager::DeviceManager(int def)
00107 {
00108 #if 1
00109 if (def==-1)
00110 {
00111 KInstance *tmp_instance=0L;
00112 if (!KGlobal::_instance) tmp_instance=new KInstance("nonKDEapp");
00113 KConfig *config = new KConfig("kcmmidirc", true);
00114
00115 config->setGroup("Configuration");
00116 default_dev=config->readNumEntry("midiDevice",0);
00117 if ( default_dev < 0 )
00118 default_dev=0;
00119 QString mapurl(config->readPathEntry("mapFilename"));
00120 if ((config->readBoolEntry("useMidiMapper", false))&&(!mapurl.isEmpty()))
00121 {
00122 mapper_tmp = new MidiMapper( mapurl.mid(mapurl.find(":")+1 ).local8Bit() );
00123 }
00124 else
00125 mapper_tmp = 0L;
00126
00127 delete config;
00128 delete tmp_instance;
00129 }
00130 else
00131 #endif
00132 {
00133 default_dev = def;
00134 mapper_tmp = 0L;
00135 }
00136
00137 initialized=0;
00138 _ok=1;
00139 alsa=false;
00140 device = 0L;
00141 m_rate=0;
00142 convertrate=10;
00143 seqfd=-1;
00144 timerstarted=0;
00145 n_midi=0;
00146 n_synths=0;
00147 n_total=0;
00148 midiinfo=0L;
00149 synthinfo=0L;
00150 for (int i=0;i<16;i++) chn2dev[i]=default_dev;
00151 }
00152
00153 DeviceManager::~DeviceManager(void)
00154 {
00155 closeDev();
00156 if (device)
00157 {
00158 for (int i=0;i<n_total;i++)
00159 delete device[i];
00160 delete[] device;
00161 device=0L;
00162 }
00163 #ifdef HAVE_OSS_SUPPORT
00164 delete[] midiinfo;
00165 delete[] synthinfo;
00166 #endif
00167 }
00168
00169 int DeviceManager::ok(void)
00170 {
00171 int r=_ok;
00172 _ok=1;
00173 return r;
00174 }
00175
00176 int DeviceManager::checkInit(void)
00177 {
00178 if (initialized==0)
00179 {
00180 int r=initManager();
00181 if (default_dev>=n_total) default_dev=0;
00182 DEBUGPRINTF("check : %d\n",r);
00183 return r;
00184 }
00185 return 0;
00186 }
00187
00188 void DeviceManager::checkAlsa(void)
00189 {
00190 #ifdef HAVE_SYS_STAT_H
00191 struct stat buf;
00192 stat("/proc/asound", &buf);
00193 if ((stat("/proc/asound", &buf) == 0 ) && (S_ISDIR(buf.st_mode)))
00194 alsa=true;
00195 else
00196 alsa=false;
00197 #else
00198 #warning "ALSA won't be found at runtime"
00199 alsa=false;
00200 #endif
00201 }
00202
00203 int DeviceManager::initManager(void)
00204 {
00205 checkAlsa();
00206
00207 if (!alsa)
00208 {
00209 #ifdef HAVE_OSS_SUPPORT
00210 n_synths=0;
00211 n_midi=0;
00212 n_total=0;
00213
00214 seqfd = open("/dev/sequencer", O_WRONLY | O_NONBLOCK, 0);
00215 if (seqfd==-1)
00216 {
00217 fprintf(stderr,"ERROR: Couldn't open /dev/sequencer to get some information\n");
00218 _ok=0;
00219 return -1;
00220 }
00221 ioctl(seqfd,SNDCTL_SEQ_NRSYNTHS,&n_synths);
00222 ioctl(seqfd,SNDCTL_SEQ_NRMIDIS,&n_midi);
00223 n_total=n_midi+n_synths;
00224
00225
00226 if (n_midi==0)
00227 {
00228 fprintf(stderr,"ERROR: There's no midi port\n");
00229
00230
00231
00232
00233 }
00234
00235 device=new MidiOut*[n_total];
00236 midiinfo=new midi_info[n_midi];
00237 synthinfo=new synth_info[n_synths];
00238
00239 int i;
00240 for (i=0;i<n_midi;i++)
00241 {
00242 midiinfo[i].device=i;
00243 if (ioctl(seqfd,SNDCTL_MIDI_INFO,&midiinfo[i])!=-1)
00244 {
00245 #ifdef GENERAL_DEBUG_MESSAGES
00246 printf("----\n");
00247 printf("Device : %d\n",i);
00248 printf("Name : %s\n",midiinfo[i].name);
00249 printf("Device type : %d\n",midiinfo[i].dev_type);
00250 #endif
00251 }
00252 device[i]=new MidiOut(i);
00253 }
00254
00255 for (i=0;i<n_synths;i++)
00256 {
00257 synthinfo[i].device=i;
00258 if (ioctl(seqfd,SNDCTL_SYNTH_INFO,&synthinfo[i])!=-1)
00259 {
00260 #ifdef GENERAL_DEBUG_MESSAGES
00261 printf("----\n");
00262 printf("Device : %d\n",i);
00263 printf("Name : %s\n",synthinfo[i].name);
00264 switch (synthinfo[i].synth_type)
00265 {
00266 case (SYNTH_TYPE_FM) : printf("FM\n");break;
00267 case (SYNTH_TYPE_SAMPLE) : printf("Sample\n");break;
00268 case (SYNTH_TYPE_MIDI) : printf("Midi\n");break;
00269 default : printf("default type\n");break;
00270 };
00271 switch (synthinfo[i].synth_subtype)
00272 {
00273 case (FM_TYPE_ADLIB) : printf("Adlib\n");break;
00274 case (FM_TYPE_OPL3) : printf("Opl3\n");break;
00275 case (MIDI_TYPE_MPU401) : printf("Mpu-401\n");break;
00276 case (SAMPLE_TYPE_GUS) : printf("Gus\n");break;
00277 default : printf("default subtype\n");break;
00278 }
00279 #endif
00280 if (synthinfo[i].synth_type==SYNTH_TYPE_FM)
00281 device[i+n_midi]=new FMOut(i,synthinfo[i].nr_voices);
00282 else if ((synthinfo[i].synth_type==SYNTH_TYPE_SAMPLE)&&
00283 (synthinfo[i].synth_subtype==SAMPLE_TYPE_GUS))
00284 device[i+n_midi]=new GUSOut(i,synthinfo[i].nr_voices);
00285 else
00286 device[i+n_midi]=new SynthOut(i);
00287 }
00288 }
00289
00290 close(seqfd);
00291 #else // There's no OSS support and ALSA wasn't detected
00292
00293
00294 n_synths=0;
00295 n_midi=0;
00296 n_total=0;
00297 device=0L;
00298 midiinfo=0L;
00299 synthinfo=0L;
00300
00301 #endif
00302
00303 }
00304 else
00305 {
00306
00307 #ifdef HAVE_ALSA_SUPPORT
00308 int client, port;
00309 #ifdef HAVE_LIBASOUND2
00310 snd_seq_t *handle=0;
00311 snd_seq_client_info_t *clienti;
00312 snd_seq_client_info_malloc(&clienti);
00313 snd_seq_port_info_t *porti;
00314 snd_seq_port_info_malloc(&porti);
00315
00316 snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
00317 if (!handle) { printf("handle==0\n"); return -1; };
00318 snd_seq_system_info_t *info;
00319 snd_seq_system_info_malloc(&info);
00320 if (!info) { printf("info==0\n"); return -1; };
00321 snd_seq_system_info(handle, info);
00322
00323 n_total=0;
00324 n_midi=0;
00325 n_synths=0;
00326
00327 device=new MidiOut*[snd_seq_system_info_get_clients(info)*snd_seq_system_info_get_ports(info)];
00328 unsigned int k=SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_WRITE ;
00329 for (client=0 ; client<snd_seq_system_info_get_clients(info) ; client++)
00330 {
00331 snd_seq_get_any_client_info(handle, client, clienti);
00332 for (port=0 ; port<snd_seq_client_info_get_num_ports(clienti) ; port++)
00333 {
00334 snd_seq_get_any_port_info(handle, client, port, porti);
00335 if (( snd_seq_port_info_get_capability(porti) & k ) == k)
00336 {
00337 device[n_midi]=new AlsaOut(n_midi,client, port, snd_seq_client_info_get_name(clienti), snd_seq_port_info_get_name(porti));
00338 n_midi++;
00339 };
00340 }
00341 }
00342 snd_seq_client_info_free(clienti);
00343 snd_seq_port_info_free(porti);
00344 snd_seq_system_info_free(info);
00345 #else
00346 snd_seq_t *handle=0;
00347 snd_seq_client_info_t clienti;
00348 snd_seq_port_info_t porti;
00349
00350 snd_seq_open(&handle, SND_SEQ_OPEN);
00351 if (!handle) { printf("handle(2)==0\n"); return -1; };
00352
00353 snd_seq_system_info_t info;
00354 info.clients=info.ports=0;
00355 snd_seq_system_info(handle, &info);
00356
00357 n_total=0;
00358 n_midi=0;
00359 n_synths=0;
00360
00361 device=new MidiOut*[info.clients*info.ports];
00362 unsigned int k=SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_WRITE ;
00363 for (client=0 ; client<info.clients ; client++)
00364 {
00365 snd_seq_get_any_client_info(handle, client, &clienti);
00366 for (port=0 ; port<clienti.num_ports ; port++)
00367 {
00368 snd_seq_get_any_port_info(handle, client, port, &porti);
00369 if (( porti.capability & k ) == k)
00370 {
00371 device[n_midi]=new AlsaOut(n_midi,client, port, clienti.name, porti.name);
00372 n_midi++;
00373 };
00374 }
00375 }
00376 #endif
00377 n_total=n_midi;
00378
00379 snd_seq_close(handle);
00380 #else
00381
00382
00383
00384 fprintf(stderr,"Sorry, this KMid version was compiled without \n");
00385 fprintf(stderr,"ALSA support but you're using ALSA . \n");
00386 fprintf(stderr,"Please compile KMid for yourself or tell the people\n");
00387 fprintf(stderr,"at your Linux distribution to compile it themselves\n");
00388 #endif
00389 }
00390
00391 if (mapper_tmp!=0L) setMidiMap(mapper_tmp);
00392
00393 initialized=1;
00394
00395 return 0;
00396 }
00397
00398 void DeviceManager::openDev(void)
00399 {
00400 if (checkInit()<0)
00401 {
00402 DEBUGPRINTF("DeviceManager::openDev : Not initialized\n");
00403 _ok = 0;
00404 return;
00405 }
00406 _ok=1;
00407
00408 if (!alsa)
00409 {
00410 #ifdef HAVE_OSS_SUPPORT
00411 seqfd = open("/dev/sequencer", O_WRONLY | O_NONBLOCK, 0);
00412 if (seqfd==-1)
00413 {
00414 fprintf(stderr,"Couldn't open the MIDI sequencer device (/dev/sequencer)\n");
00415 _ok=0;
00416 return;
00417 }
00418 _seqbufptr = 0;
00419 ioctl(seqfd,SNDCTL_SEQ_RESET);
00420
00421 m_rate=0;
00422 int r=ioctl(seqfd,SNDCTL_SEQ_CTRLRATE,&m_rate);
00423 if ((r==-1)||(m_rate<=0)) m_rate=HZ;
00424
00425 convertrate=1000/m_rate;
00426
00427 #endif
00428 }
00429 else seqfd=0L;
00430
00431
00432 for (int i=0;i<n_total;i++)
00433 {
00434 device[i]->openDev(seqfd);
00435
00436 }
00437
00438 for (int i=0;i<n_total;i++) if (!device[i]->ok()) _ok=0;
00439 if (_ok==0)
00440 {
00441 for (int i=0;i<n_total;i++) device[i]->closeDev();
00442
00443 return;
00444 }
00445
00446
00447 }
00448
00449 void DeviceManager::closeDev(void)
00450 {
00451 if (alsa)
00452 {
00453 if (device)
00454 for (int i=0;i<n_total;i++)
00455 if (device[i]) device[i]->closeDev();
00456
00457 return;
00458 }
00459
00460 #ifdef HAVE_OSS_SUPPORT
00461 if (seqfd==-1) return;
00462 tmrStop();
00463 if (device)
00464 for (int i=0;i<n_total;i++)
00465 if (device[i]) device[i]->closeDev();
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 close(seqfd);
00478 seqfd=-1;
00479 #endif
00480 }
00481
00482 void DeviceManager::initDev(void)
00483 {
00484 if (device!=0L)
00485 {
00486
00487 for (int i=0;i<n_total;i++)
00488 {
00489 device[i]->initDev();
00490 DEBUGPRINTF("%s ",device[i]->deviceName());
00491 }
00492 DEBUGPRINTF("\n");
00493 }
00494 }
00495
00496 void DeviceManager::noteOn ( uchar chn, uchar note, uchar vel )
00497 {
00498 MidiOut *midi=chntodev(chn);
00499 if (midi) midi->noteOn(chn,note,vel);
00500 }
00501 void DeviceManager::noteOff ( uchar chn, uchar note, uchar vel )
00502 {
00503 MidiOut *midi=chntodev(chn);
00504 if (midi) midi->noteOff(chn,note,vel);
00505 }
00506 void DeviceManager::keyPressure ( uchar chn, uchar note, uchar vel )
00507 {
00508 MidiOut *midi=chntodev(chn);
00509 if (midi) midi->keyPressure(chn,note,vel);
00510 }
00511 void DeviceManager::chnPatchChange ( uchar chn, uchar patch )
00512 {
00513 MidiOut *midi=chntodev(chn);
00514 if (midi) midi->chnPatchChange(chn,patch);
00515 }
00516 void DeviceManager::chnPressure ( uchar chn, uchar vel )
00517 {
00518 MidiOut *midi=chntodev(chn);
00519 if (midi) midi->chnPressure(chn,vel);
00520 }
00521 void DeviceManager::chnPitchBender ( uchar chn, uchar lsb, uchar msb )
00522 {
00523 MidiOut *midi=chntodev(chn);
00524 if (midi) midi->chnPitchBender(chn,lsb,msb);
00525 }
00526 void DeviceManager::chnController ( uchar chn, uchar ctl , uchar v )
00527 {
00528 MidiOut *midi=chntodev(chn);
00529 if (midi) midi->chnController(chn,ctl,v);
00530 }
00531 void DeviceManager::sysEx ( uchar *data,ulong size)
00532 {
00533 for (int i=0;i<n_midi;i++)
00534 device[i]->sysex(data,size);
00535 }
00536
00537 void DeviceManager::wait (double ticks)
00538 {
00539 #ifdef HAVE_ALSA_SUPPORT
00540 if (alsa) { ((AlsaOut *)device[default_dev])->wait(ticks); return; };
00541 #endif
00542
00543 #ifdef HAVE_OSS_SUPPORT
00544 unsigned long int t=(unsigned long int)(ticks/convertrate);
00545 if (lastwaittime==t) return;
00546 lastwaittime=t;
00547 SEQ_WAIT_TIME(t);
00548 SEQ_DUMPBUF();
00549 #endif
00550 }
00551
00552
00553 void DeviceManager::tmrSetTempo(int v)
00554 {
00555 #ifdef HAVE_ALSA_SUPPORT
00556 if (alsa) { ((AlsaOut *)device[default_dev])->tmrSetTempo(v); return; }
00557 #endif
00558
00559 #ifdef HAVE_OSS_SUPPORT
00560 SEQ_SET_TEMPO(v);
00561 SEQ_DUMPBUF();
00562 #endif
00563 }
00564
00565 void DeviceManager::tmrStart(long int
00566 #ifdef HAVE_ALSA_SUPPORT
00567 tpcn
00568 #endif
00569 )
00570 {
00571 #ifdef HAVE_ALSA_SUPPORT
00572 if (alsa) { ((AlsaOut *)device[default_dev])->tmrStart(tpcn); return; }
00573 #endif
00574
00575 #ifdef HAVE_OSS_SUPPORT
00576 #ifdef CONTROLTIMER
00577 if (!timerstarted)
00578 {
00579 SEQ_START_TIMER();
00580 SEQ_DUMPBUF();
00581 timerstarted=1;
00582 }
00583 lastwaittime=0;
00584 #else
00585 SEQ_START_TIMER();
00586 SEQ_DUMPBUF();
00587 #endif
00588 #endif
00589 }
00590
00591 void DeviceManager::tmrStop(void)
00592 {
00593 #ifdef HAVE_ALSA_SUPPORT
00594 if (alsa) { ((AlsaOut *)device[default_dev])->tmrStop(); return; }
00595 #endif
00596
00597 #ifdef HAVE_OSS_SUPPORT
00598 #ifdef CONTROLTIMER
00599 if (timerstarted)
00600 {
00601 SEQ_STOP_TIMER();
00602 SEQ_DUMPBUF();
00603 timerstarted=0;
00604 }
00605 #else
00606 SEQ_STOP_TIMER();
00607 SEQ_DUMPBUF();
00608 #endif
00609 #endif
00610 }
00611
00612 void DeviceManager::tmrContinue(void)
00613 {
00614 #ifdef HAVE_ALSA_SUPPORT
00615 if (alsa) { ((AlsaOut *)device[default_dev])->tmrContinue(); return; }
00616 #endif
00617
00618 #ifdef HAVE_OSS_SUPPORT
00619 #ifdef CONTROLTIMER
00620 if (timerstarted)
00621 {
00622 SEQ_CONTINUE_TIMER();
00623 SEQ_DUMPBUF();
00624 }
00625 #else
00626 SEQ_CONTINUE_TIMER();
00627 SEQ_DUMPBUF();
00628 #endif
00629 #endif
00630 }
00631
00632 void DeviceManager::sync(bool f)
00633 {
00634 #ifdef HAVE_ALSA_SUPPORT
00635 if (alsa) { ((AlsaOut *)device[default_dev])->sync(f); return ; };
00636 #endif
00637
00638 #ifdef HAVE_OSS_SUPPORT
00639 #ifdef DEVICEMANDEBUG
00640 printf("Sync %d\n",f);
00641 #endif
00642 if (f)
00643 {
00644 seqbuf_clean();
00645
00646
00647 ioctl(seqfd,SNDCTL_SEQ_RESET);
00648 ioctl(seqfd,SNDCTL_SEQ_PANIC);
00649 }
00650 else
00651 {
00652 seqbuf_dump();
00653 ioctl(seqfd, SNDCTL_SEQ_SYNC);
00654 };
00655 #endif
00656 }
00657
00658 void DeviceManager::seqbuf_dump (void)
00659 {
00660 if (!alsa)
00661 {
00662 #ifdef HAVE_OSS_SUPPORT
00663 if (_seqbufptr)
00664 {
00665 int r=0;
00666 unsigned char *sb=_seqbuf;
00667 int w=_seqbufptr;
00668 r=write (seqfd, _seqbuf, _seqbufptr);
00669 #ifdef DEVICEMANDEBUG
00670 printf("%d == %d\n",r,w);
00671 printf("%d\n",(errno==EAGAIN)? 1 : 0);
00672 #endif
00673 while (((r == -1)&&(errno==EAGAIN))||(r != w))
00674 {
00675 if ((r==-1)&&(errno==EAGAIN))
00676 {
00677 usleep(1);
00678 }
00679 else if ((r>0)&&(r!=w))
00680 {
00681 w-=r;
00682 sb+=r;
00683 }
00684 r=write (seqfd, sb, w);
00685 #ifdef DEVICEMANDEBUG
00686 printf("%d == %d\n",r,w);
00687 printf("%d\n",(errno==EAGAIN)? 1 : 0);
00688 #endif
00689 }
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 _seqbufptr = 0;
00701 #endif
00702 }
00703 }
00704
00705 void DeviceManager::seqbuf_clean(void)
00706 {
00707 #ifdef HAVE_ALSA_SUPPORT
00708 if (alsa)
00709 ((AlsaOut *)device[default_dev])->seqbuf_clean();
00710 else
00711 #endif
00712 #ifdef HAVE_OSS_SUPPORT
00713 _seqbufptr=0;
00714 #endif
00715 }
00716
00717
00718 const char *DeviceManager::name(int i)
00719 {
00720 #ifdef HAVE_OSS_SUPPORT
00721 if (checkInit()<0) {_ok = 0; return NULL;}
00722
00723 if (alsa)
00724 {
00725 if (i<n_midi) return device[i]->deviceName();
00726 }
00727 else
00728 {
00729 if (i<n_midi) return midiinfo[i].name;
00730 if (i<n_midi+n_synths) return synthinfo[i-n_midi].name;
00731 };
00732 #endif
00733 return (char *)"";
00734 }
00735
00736 const char *DeviceManager::type(int i)
00737 {
00738 #ifdef HAVE_OSS_SUPPORT
00739 if (checkInit()<0) {_ok = 0; return NULL;}
00740
00741 if (alsa)
00742 {
00743 if (i<n_midi) return "ALSA device";
00744 }
00745 else
00746 {
00747 if (i<n_midi)
00748 {
00749 return "External Midi Port";
00750 }
00751 if (i<n_midi+n_synths)
00752 {
00753 switch (synthinfo[i-n_midi].synth_subtype)
00754 {
00755 case (FM_TYPE_ADLIB) : return "Adlib";break;
00756 case (FM_TYPE_OPL3) : return "FM";break;
00757 case (MIDI_TYPE_MPU401) : return "MPU 401";break;
00758 case (SAMPLE_TYPE_GUS) : return "GUS";break;
00759 }
00760 }
00761 }
00762 #endif
00763 return "";
00764 }
00765
00766 int DeviceManager::defaultDevice(void)
00767 {
00768 return default_dev;
00769 }
00770
00771 void DeviceManager::setDefaultDevice(int i)
00772 {
00773 if (i>=n_total) return;
00774 default_dev=i;
00775 for (int i=0;i<16;i++) chn2dev[i]=default_dev;
00776 }
00777
00778 const char *DeviceManager::midiMapFilename(void)
00779 {
00780 if (device==0L) return "";
00781 if (default_dev>=n_total) return "";
00782 return (device[default_dev]!=NULL) ?
00783 device[default_dev]->midiMapFilename() : "";
00784 }
00785
00786 void DeviceManager::setMidiMap(MidiMapper *map)
00787 {
00788 if (map==NULL) return;
00789 mapper_tmp=map;
00790 if (default_dev>=n_total) {default_dev=0;return;};
00791 if ((device==0L)||(device[default_dev]==NULL))
00792 return;
00793 device[default_dev]->setMidiMapper(map);
00794 }
00795
00796 int DeviceManager::setPatchesToUse(int *patchesused)
00797 {
00798 if (checkInit()<0) return -1;
00799 if ((device==0L)||(device[default_dev]==NULL))
00800 return 0;
00801
00802 if ((device[default_dev]->deviceType())==KMID_GUS)
00803 {
00804 GUSOut *gus=(GUSOut *)device[default_dev];
00805 gus->setPatchesToUse(patchesused);
00806 }
00807 return 0;
00808 }
00809
00810 void DeviceManager::setVolumePercentage(int v)
00811 {
00812 if (device!=0L)
00813 {
00814 for (int i=0;i<n_total;i++)
00815 {
00816 device[i]->setVolumePercentage(v);
00817 }
00818 }
00819 }
00820
00821 void DeviceManager::setDeviceNumberForChannel(int chn, int dev)
00822 {
00823 chn2dev[chn]=dev;
00824 }
00825
00826 void DeviceManager::allNotesOff(void)
00827 {
00828 for (int i=0;i<n_midi;i++)
00829 device[i]->allNotesOff();
00830 }