• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdemid
 

libtdemid

  • libtdemid
deviceman.cpp
1/**************************************************************************
2
3 deviceman.cpp - The device manager, that hides the use of midiOut
4 This file is part of LibKMid 0.9.5
5 Copyright (C) 1997,98,99,2000 Antonio Larrosa Jimenez
6 LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libtdemid.html
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23 $Id$
24
25 Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
26
27***************************************************************************/
28#include "deviceman.h"
29#include "midiout.h"
30#include <stdio.h>
31#include <fcntl.h>
32#include <unistd.h>
33#include <sys/ioctl.h>
34#include <errno.h>
35#include "sndcard.h"
36#include "synthout.h"
37#include "fmout.h"
38#include "gusout.h"
39#include "alsaout.h"
40#include "midimapper.h"
41#include "midispec.h"
42
43#ifdef HAVE_CONFIG_H
44#include <config.h>
45#endif
46
47#ifdef HAVE_SYS_STAT_H
48#include <sys/stat.h>
49#endif
50
51#ifdef HAVE_ALSA_ASOUNDLIB_H
52# define HAVE_ALSA_SUPPORT
53# include <alsa/asoundlib.h>
54#elif defined(HAVE_SYS_ASOUNDLIB_H)
55# define HAVE_ALSA_SUPPORT
56# include <sys/asoundlib.h>
57#else
58#ifdef HAVE_LIBASOUND2
59# define HAVE_ALSA_SUPPORT
60# include <sound/asound.h>
61# include <sound/asequencer.h>
62#elif defined(HAVE_LIBASOUND)
63# define HAVE_ALSA_SUPPORT
64# include <linux/asequencer.h>
65#endif
66#endif
67
68#if 1
69#include <kinstance.h>
70#include <tdeglobal.h>
71#include <tdeconfig.h>
72#endif
73
74//#define DEVICEMANDEBUG
75//#define GENERAL_DEBUG_MESSAGES
76
77SEQ_DEFINEBUF (4096);
78
79#define CONTROLTIMER
80
81#ifdef GENERAL_DEBUG_MESSAGES
82void DEBUGPRINTF(const char *format)
83{
84 printf(format);
85}
86
87void DEBUGPRINTF(const char *format,int i)
88{
89 printf(format,i);
90}
91
92void DEBUGPRINTF(const char *format,const char *s)
93{
94 printf(format,s);
95}
96
97#else
98
99void DEBUGPRINTF(const char *) { }
100void DEBUGPRINTF(const char *,int ) { }
101void DEBUGPRINTF(const char *,const char * ) { }
102
103#endif
104
105
106DeviceManager::DeviceManager(int def)
107{
108#if 1
109 if (def==-1)
110 {
111 TDEInstance *tmp_instance=0L;
112 if (!TDEGlobal::_instance) tmp_instance=new TDEInstance("nonKDEapp");
113 TDEConfig *config = new TDEConfig("kcmmidirc", true);
114
115 config->setGroup("Configuration");
116 default_dev=config->readNumEntry("midiDevice",0);
117 if ( default_dev < 0 )
118 default_dev=0;
119 TQString mapurl(config->readPathEntry("mapFilename"));
120 if ((config->readBoolEntry("useMidiMapper", false))&&(!mapurl.isEmpty()))
121 {
122 mapper_tmp = new MidiMapper( mapurl.mid(mapurl.find(":")+1 ).local8Bit() );
123 }
124 else
125 mapper_tmp = 0L;
126
127 delete config;
128 delete tmp_instance;
129 }
130 else
131#endif
132 {
133 default_dev = def;
134 mapper_tmp = 0L;
135 }
136
137 initialized=0;
138 _ok=1;
139 alsa=false;
140 device = 0L;
141 m_rate=0;
142 convertrate=10;
143 seqfd=-1;
144 timerstarted=0;
145 n_midi=0;
146 n_synths=0;
147 n_total=0;
148 midiinfo=0L;
149 synthinfo=0L;
150 for (int i=0;i<16;i++) chn2dev[i]=default_dev;
151}
152
153DeviceManager::~DeviceManager(void)
154{
155 closeDev();
156 if (device)
157 {
158 for (int i=0;i<n_total;i++)
159 delete device[i];
160 delete[] device;
161 device=0L;
162 }
163#ifdef HAVE_OSS_SUPPORT
164 delete[] midiinfo;
165 delete[] synthinfo;
166#endif
167}
168
169int DeviceManager::ok(void)
170{
171 int r=_ok;
172 _ok=1;
173 return r;
174}
175
176int DeviceManager::checkInit(void)
177{
178 if (initialized==0)
179 {
180 int r=initManager();
181 if (default_dev>=n_total) default_dev=0;
182 DEBUGPRINTF("check : %d\n",r);
183 return r;
184 }
185 return 0;
186}
187
188void DeviceManager::checkAlsa(void)
189{
190#ifdef HAVE_SYS_STAT_H
191 struct stat buf;
192 stat("/proc/asound", &buf);
193 if ((stat("/proc/asound", &buf) == 0 ) && (S_ISDIR(buf.st_mode)))
194 alsa=true;
195 else
196 alsa=false;
197#else
198#warning "ALSA won't be found at runtime"
199 alsa=false;
200#endif
201}
202
203int DeviceManager::initManager(void)
204{
205 checkAlsa();
206
207 if (!alsa) // We are using OSS
208 {
209#ifdef HAVE_OSS_SUPPORT
210 n_synths=0;
211 n_midi=0;
212 n_total=0;
213
214 seqfd = open("/dev/sequencer", O_WRONLY | O_NONBLOCK, 0);
215 if (seqfd==-1)
216 {
217 fprintf(stderr,"ERROR: Couldn't open /dev/sequencer to get some information\n");
218 _ok=0;
219 return -1;
220 }
221 ioctl(seqfd,SNDCTL_SEQ_NRSYNTHS,&n_synths);
222 ioctl(seqfd,SNDCTL_SEQ_NRMIDIS,&n_midi);
223 n_total=n_midi+n_synths;
224
225
226 if (n_midi==0)
227 {
228 fprintf(stderr,"ERROR: There's no midi port\n");
229 /* This could be a problem if the user don't have a synth neither,
230 but not having any of both things is unusual */
231 // _ok=0;
232 // return 1;
233 }
234
235 device=new MidiOut*[n_total];
236 midiinfo=new midi_info[n_midi];
237 synthinfo=new synth_info[n_synths];
238
239 int i;
240 for (i=0;i<n_midi;i++)
241 {
242 midiinfo[i].device=i;
243 if (ioctl(seqfd,SNDCTL_MIDI_INFO,&midiinfo[i])!=-1)
244 {
245#ifdef GENERAL_DEBUG_MESSAGES
246 printf("----\n");
247 printf("Device : %d\n",i);
248 printf("Name : %s\n",midiinfo[i].name);
249 printf("Device type : %d\n",midiinfo[i].dev_type);
250#endif
251 }
252 device[i]=new MidiOut(i);
253 }
254
255 for (i=0;i<n_synths;i++)
256 {
257 synthinfo[i].device=i;
258 if (ioctl(seqfd,SNDCTL_SYNTH_INFO,&synthinfo[i])!=-1)
259 {
260#ifdef GENERAL_DEBUG_MESSAGES
261 printf("----\n");
262 printf("Device : %d\n",i);
263 printf("Name : %s\n",synthinfo[i].name);
264 switch (synthinfo[i].synth_type)
265 {
266 case (SYNTH_TYPE_FM) : printf("FM\n");break;
267 case (SYNTH_TYPE_SAMPLE) : printf("Sample\n");break;
268 case (SYNTH_TYPE_MIDI) : printf("Midi\n");break;
269 default : printf("default type\n");break;
270 };
271 switch (synthinfo[i].synth_subtype)
272 {
273 case (FM_TYPE_ADLIB) : printf("Adlib\n");break;
274 case (FM_TYPE_OPL3) : printf("Opl3\n");break;
275 case (MIDI_TYPE_MPU401) : printf("Mpu-401\n");break;
276 case (SAMPLE_TYPE_GUS) : printf("Gus\n");break;
277 default : printf("default subtype\n");break;
278 }
279#endif
280 if (synthinfo[i].synth_type==SYNTH_TYPE_FM)
281 device[i+n_midi]=new FMOut(i,synthinfo[i].nr_voices);
282 else if ((synthinfo[i].synth_type==SYNTH_TYPE_SAMPLE)&&
283 (synthinfo[i].synth_subtype==SAMPLE_TYPE_GUS))
284 device[i+n_midi]=new GUSOut(i,synthinfo[i].nr_voices);
285 else
286 device[i+n_midi]=new SynthOut(i);
287 }
288 }
289
290 close(seqfd);
291#else // There's no OSS support and ALSA wasn't detected
292 // It must be one of those systems coolo is using :-)
293
294 n_synths=0;
295 n_midi=0;
296 n_total=0;
297 device=0L;
298 midiinfo=0L;
299 synthinfo=0L;
300
301#endif
302
303 }
304 else
305 { // We are using ALSA
306
307#ifdef HAVE_ALSA_SUPPORT
308 int client, port;
309#ifdef HAVE_LIBASOUND2
310 snd_seq_t *handle=0;
311 snd_seq_client_info_t *clienti;
312 snd_seq_client_info_malloc(&clienti);
313 snd_seq_port_info_t *porti;
314 snd_seq_port_info_malloc(&porti);
315
316 snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
317 if (!handle) { printf("handle==0\n"); return -1; };
318 snd_seq_system_info_t *info;
319 snd_seq_system_info_malloc(&info);
320 if (!info) { printf("info==0\n"); return -1; };
321 snd_seq_system_info(handle, info);
322
323 n_total=0;
324 n_midi=0;
325 n_synths=0;
326
327 device=new MidiOut*[snd_seq_system_info_get_clients(info)*snd_seq_system_info_get_ports(info)];
328 unsigned int k=SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_WRITE ;
329 for (client=0 ; client<snd_seq_system_info_get_clients(info) ; client++)
330 {
331 snd_seq_get_any_client_info(handle, client, clienti);
332 for (port=0 ; port<snd_seq_client_info_get_num_ports(clienti) ; port++)
333 {
334 snd_seq_get_any_port_info(handle, client, port, porti);
335 if (( snd_seq_port_info_get_capability(porti) & k ) == k)
336 {
337 device[n_midi]=new AlsaOut(n_midi,client, port, snd_seq_client_info_get_name(clienti), snd_seq_port_info_get_name(porti));
338 n_midi++;
339 };
340 }
341 }
342 snd_seq_client_info_free(clienti);
343 snd_seq_port_info_free(porti);
344 snd_seq_system_info_free(info);
345#else
346 snd_seq_t *handle=0;
347 snd_seq_client_info_t clienti;
348 snd_seq_port_info_t porti;
349
350 snd_seq_open(&handle, SND_SEQ_OPEN);
351 if (!handle) { printf("handle(2)==0\n"); return -1; };
352
353 snd_seq_system_info_t info;
354 info.clients=info.ports=0;
355 snd_seq_system_info(handle, &info);
356
357 n_total=0;
358 n_midi=0;
359 n_synths=0;
360
361 device=new MidiOut*[info.clients*info.ports];
362 unsigned int k=SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_WRITE ;
363 for (client=0 ; client<info.clients ; client++)
364 {
365 snd_seq_get_any_client_info(handle, client, &clienti);
366 for (port=0 ; port<clienti.num_ports ; port++)
367 {
368 snd_seq_get_any_port_info(handle, client, port, &porti);
369 if (( porti.capability & k ) == k)
370 {
371 device[n_midi]=new AlsaOut(n_midi,client, port, clienti.name, porti.name);
372 n_midi++;
373 };
374 }
375 }
376#endif
377 n_total=n_midi;
378
379 snd_seq_close(handle);
380#else
381
382 // Note: Please don't add i18n for the text below, thanks :)
383
384 fprintf(stderr,"Sorry, this KMid version was compiled without \n");
385 fprintf(stderr,"ALSA support but you're using ALSA . \n");
386 fprintf(stderr,"Please compile KMid for yourself or tell the people\n");
387 fprintf(stderr,"at your Linux distribution to compile it themselves\n");
388#endif
389 }
390
391 if (mapper_tmp!=0L) setMidiMap(mapper_tmp);
392
393 initialized=1;
394
395 return 0;
396}
397
398void DeviceManager::openDev(void)
399{
400 if (checkInit()<0)
401 {
402 DEBUGPRINTF("DeviceManager::openDev : Not initialized\n");
403 _ok = 0;
404 return;
405 }
406 _ok=1;
407
408 if (!alsa)
409 {
410#ifdef HAVE_OSS_SUPPORT
411 seqfd = open("/dev/sequencer", O_WRONLY | O_NONBLOCK, 0);
412 if (seqfd==-1)
413 {
414 fprintf(stderr,"Couldn't open the MIDI sequencer device (/dev/sequencer)\n");
415 _ok=0;
416 return;
417 }
418 _seqbufptr = 0;
419 ioctl(seqfd,SNDCTL_SEQ_RESET);
420 //ioctl(seqfd,SNDCTL_SEQ_PANIC);
421 m_rate=0;
422 int r=ioctl(seqfd,SNDCTL_SEQ_CTRLRATE,&m_rate);
423 if ((r==-1)||(m_rate<=0)) m_rate=HZ;
424
425 convertrate=1000/m_rate;
426
427#endif
428 }
429 else seqfd=0L; // ALSA
430
431// DEBUGPRINTF("Opening devices : ");
432 for (int i=0;i<n_total;i++)
433 {
434 device[i]->openDev(seqfd);
435// DEBUGPRINTF("%s ",device[i]->deviceName());
436 }
437// DEBUGPRINTF("\n");
438 for (int i=0;i<n_total;i++) if (!device[i]->ok()) _ok=0;
439 if (_ok==0)
440 {
441 for (int i=0;i<n_total;i++) device[i]->closeDev();
442// DEBUGPRINTF("DeviceMan :: ERROR : Closing devices\n");
443 return;
444 }
445
446// DEBUGPRINTF("Devices opened\n");
447}
448
449void DeviceManager::closeDev(void)
450{
451 if (alsa)
452 {
453 if (device)
454 for (int i=0;i<n_total;i++)
455 if (device[i]) device[i]->closeDev();
456
457 return;
458 }
459
460#ifdef HAVE_OSS_SUPPORT
461 if (seqfd==-1) return;
462 tmrStop();
463 if (device)
464 for (int i=0;i<n_total;i++)
465 if (device[i]) device[i]->closeDev();
466 /*
467 DEBUGPRINTF("Closing devices : ");
468 if (device!=NULL) for (int i=0;i<n_total;i++)
469 {
470 device[i]->initDev();
471 DEBUGPRINTF("%s ",device[i]->deviceName());
472
473 // device[i]->closeDev();
474 };
475 DEBUGPRINTF("\n");
476 */
477 close(seqfd);
478 seqfd=-1;
479#endif
480}
481
482void DeviceManager::initDev(void)
483{
484 if (device!=0L)
485 {
486// DEBUGPRINTF("Initializing devices :");
487 for (int i=0;i<n_total;i++)
488 {
489 device[i]->initDev();
490 DEBUGPRINTF("%s ",device[i]->deviceName());
491 }
492 DEBUGPRINTF("\n");
493 }
494}
495
496void DeviceManager::noteOn ( uchar chn, uchar note, uchar vel )
497{
498 MidiOut *midi=chntodev(chn);
499 if (midi) midi->noteOn(chn,note,vel);
500}
501void DeviceManager::noteOff ( uchar chn, uchar note, uchar vel )
502{
503 MidiOut *midi=chntodev(chn);
504 if (midi) midi->noteOff(chn,note,vel);
505}
506void DeviceManager::keyPressure ( uchar chn, uchar note, uchar vel )
507{
508 MidiOut *midi=chntodev(chn);
509 if (midi) midi->keyPressure(chn,note,vel);
510}
511void DeviceManager::chnPatchChange ( uchar chn, uchar patch )
512{
513 MidiOut *midi=chntodev(chn);
514 if (midi) midi->chnPatchChange(chn,patch);
515}
516void DeviceManager::chnPressure ( uchar chn, uchar vel )
517{
518 MidiOut *midi=chntodev(chn);
519 if (midi) midi->chnPressure(chn,vel);
520}
521void DeviceManager::chnPitchBender ( uchar chn, uchar lsb, uchar msb )
522{
523 MidiOut *midi=chntodev(chn);
524 if (midi) midi->chnPitchBender(chn,lsb,msb);
525}
526void DeviceManager::chnController ( uchar chn, uchar ctl , uchar v )
527{
528 MidiOut *midi=chntodev(chn);
529 if (midi) midi->chnController(chn,ctl,v);
530}
531void DeviceManager::sysEx ( uchar *data,ulong size)
532{
533 for (int i=0;i<n_midi;i++)
534 device[i]->sysex(data,size);
535}
536
537void DeviceManager::wait (double ticks)
538{
539#ifdef HAVE_ALSA_SUPPORT
540 if (alsa) { ((AlsaOut *)device[default_dev])->wait(ticks); return; };
541#endif
542
543#ifdef HAVE_OSS_SUPPORT
544 unsigned long int t=(unsigned long int)(ticks/convertrate);
545 if (lastwaittime==t) return;
546 lastwaittime=t;
547 SEQ_WAIT_TIME(t);
548 SEQ_DUMPBUF();
549#endif
550}
551
552//void DeviceManager::tmrSetTempo(int v)
553void DeviceManager::tmrSetTempo(int v)
554{
555#ifdef HAVE_ALSA_SUPPORT
556 if (alsa) { ((AlsaOut *)device[default_dev])->tmrSetTempo(v); return; }
557#endif
558
559#ifdef HAVE_OSS_SUPPORT
560 SEQ_SET_TEMPO(v);
561 SEQ_DUMPBUF();
562#endif
563}
564
565void DeviceManager::tmrStart(long int
566#ifdef HAVE_ALSA_SUPPORT
567tpcn /*name the argument only if it is used*/
568#endif
569)
570{
571#ifdef HAVE_ALSA_SUPPORT
572 if (alsa) { ((AlsaOut *)device[default_dev])->tmrStart(tpcn); return; }
573#endif
574
575#ifdef HAVE_OSS_SUPPORT
576#ifdef CONTROLTIMER
577 if (!timerstarted)
578 {
579 SEQ_START_TIMER();
580 SEQ_DUMPBUF();
581 timerstarted=1;
582 }
583 lastwaittime=0;
584#else
585 SEQ_START_TIMER();
586 SEQ_DUMPBUF();
587#endif
588#endif
589}
590
591void DeviceManager::tmrStop(void)
592{
593#ifdef HAVE_ALSA_SUPPORT
594 if (alsa) { ((AlsaOut *)device[default_dev])->tmrStop(); return; }
595#endif
596
597#ifdef HAVE_OSS_SUPPORT
598#ifdef CONTROLTIMER
599 if (timerstarted)
600 {
601 SEQ_STOP_TIMER();
602 SEQ_DUMPBUF();
603 timerstarted=0;
604 }
605#else
606 SEQ_STOP_TIMER();
607 SEQ_DUMPBUF();
608#endif
609#endif
610}
611
612void DeviceManager::tmrContinue(void)
613{
614#ifdef HAVE_ALSA_SUPPORT
615 if (alsa) { ((AlsaOut *)device[default_dev])->tmrContinue(); return; }
616#endif
617
618#ifdef HAVE_OSS_SUPPORT
619#ifdef CONTROLTIMER
620 if (timerstarted)
621 {
622 SEQ_CONTINUE_TIMER();
623 SEQ_DUMPBUF();
624 }
625#else
626 SEQ_CONTINUE_TIMER();
627 SEQ_DUMPBUF();
628#endif
629#endif
630}
631
632void DeviceManager::sync(bool f)
633{
634#ifdef HAVE_ALSA_SUPPORT
635 if (alsa) { ((AlsaOut *)device[default_dev])->sync(f); return ; };
636#endif
637
638#ifdef HAVE_OSS_SUPPORT
639#ifdef DEVICEMANDEBUG
640 printf("Sync %d\n",f);
641#endif
642 if (f)
643 {
644 seqbuf_clean();
645 /* If you have any problem, try removing the next 2 lines,
646 I though they would be useful here but the may have side effects */
647 ioctl(seqfd,SNDCTL_SEQ_RESET);
648 ioctl(seqfd,SNDCTL_SEQ_PANIC);
649 }
650 else
651 {
652 seqbuf_dump();
653 ioctl(seqfd, SNDCTL_SEQ_SYNC);
654 };
655#endif
656}
657
658void DeviceManager::seqbuf_dump (void)
659{
660 if (!alsa)
661 {
662#ifdef HAVE_OSS_SUPPORT
663 if (_seqbufptr)
664 {
665 int r=0;
666 unsigned char *sb=_seqbuf;
667 int w=_seqbufptr;
668 r=write (seqfd, _seqbuf, _seqbufptr);
669#ifdef DEVICEMANDEBUG
670 printf("%d == %d\n",r,w);
671 printf("%d\n",(errno==EAGAIN)? 1 : 0);
672#endif
673 while (((r == -1)&&(errno==EAGAIN))||(r != w))
674 {
675 if ((r==-1)&&(errno==EAGAIN))
676 {
677 usleep(1);
678 }
679 else if ((r>0)&&(r!=w))
680 {
681 w-=r;
682 sb+=r;
683 }
684 r=write (seqfd, sb, w);
685#ifdef DEVICEMANDEBUG
686 printf("%d == %d\n",r,w);
687 printf("%d\n",(errno==EAGAIN)? 1 : 0);
688#endif
689 }
690 }
691 /*
692 * if (_seqbufptr)
693 * if (write (seqfd, _seqbuf, _seqbufptr) == -1)
694 * {
695 * printf("Error writing to /dev/sequencer in deviceManager::seqbuf_dump\n");
696 * perror ("write /dev/sequencer in seqbuf_dump\n");
697 * exit (-1);
698 * }
699 */
700 _seqbufptr = 0;
701#endif
702 }
703}
704
705void DeviceManager::seqbuf_clean(void)
706{
707#ifdef HAVE_ALSA_SUPPORT
708 if (alsa) { ((AlsaOut *)device[default_dev])->seqbuf_clean(); return ; }
709#endif
710#ifdef HAVE_OSS_SUPPORT
711 _seqbufptr=0;
712#endif
713}
714
715
716const char *DeviceManager::name(int i)
717{
718#ifdef HAVE_OSS_SUPPORT
719 if (checkInit()<0) {_ok = 0; return NULL;}
720
721 if (alsa)
722 {
723 if (i<n_midi) return device[i]->deviceName();
724 }
725 else
726 {
727 if (i<n_midi) return midiinfo[i].name;
728 if (i<n_midi+n_synths) return synthinfo[i-n_midi].name;
729 };
730#endif
731 return (char *)"";
732}
733
734const char *DeviceManager::type(int i)
735{
736#ifdef HAVE_OSS_SUPPORT
737 if (checkInit()<0) {_ok = 0; return NULL;}
738
739 if (alsa)
740 {
741 if (i<n_midi) return "ALSA device";
742 }
743 else
744 {
745 if (i<n_midi)
746 {
747 return "External Midi Port";
748 }
749 if (i<n_midi+n_synths)
750 {
751 switch (synthinfo[i-n_midi].synth_subtype)
752 {
753 case (FM_TYPE_ADLIB) : return "Adlib";break;
754 case (FM_TYPE_OPL3) : return "FM";break;
755 case (MIDI_TYPE_MPU401) : return "MPU 401";break;
756 case (SAMPLE_TYPE_GUS) : return "GUS";break;
757 }
758 }
759 }
760#endif
761 return "";
762}
763
764int DeviceManager::defaultDevice(void)
765{
766 return default_dev;
767}
768
769void DeviceManager::setDefaultDevice(int i)
770{
771 if (i>=n_total) return;
772 default_dev=i;
773 for (int i=0;i<16;i++) chn2dev[i]=default_dev;
774}
775
776const char *DeviceManager::midiMapFilename(void)
777{
778 if (device==0L) return "";
779 if (default_dev>=n_total) return "";
780 return (device[default_dev]!=NULL) ?
781 device[default_dev]->midiMapFilename() : "";
782}
783
784void DeviceManager::setMidiMap(MidiMapper *map)
785{
786 if (map==NULL) return;
787 mapper_tmp=map;
788 if (default_dev>=n_total) {default_dev=0;return;};
789 if ((device==0L)||(device[default_dev]==NULL))
790 return;
791 device[default_dev]->setMidiMapper(map);
792}
793
794int DeviceManager::setPatchesToUse(int *patchesused)
795{
796 if (checkInit()<0) return -1;
797 if ((device==0L)||(device[default_dev]==NULL))
798 return 0;
799
800 if ((device[default_dev]->deviceType())==KMID_GUS)
801 {
802 GUSOut *gus=(GUSOut *)device[default_dev];
803 gus->setPatchesToUse(patchesused);
804 }
805 return 0;
806}
807
808void DeviceManager::setVolumePercentage(int v)
809{
810 if (device!=0L)
811 {
812 for (int i=0;i<n_total;i++)
813 {
814 device[i]->setVolumePercentage(v);
815 }
816 }
817}
818
819void DeviceManager::setDeviceNumberForChannel(int chn, int dev)
820{
821 chn2dev[chn]=dev;
822}
823
824void DeviceManager::allNotesOff(void)
825{
826 for (int i=0;i<n_midi;i++)
827 device[i]->allNotesOff();
828}
AlsaOut
Sends MIDI events to a MIDI devices using ALSA.
Definition: alsaout.h:38
DeviceManager::noteOn
void noteOn(uchar chn, uchar note, uchar vel)
Sends a Note On MIDI event.
Definition: deviceman.cpp:496
DeviceManager::checkInit
int checkInit(void)
Checks if the device manager has been initialized (with initManager), and in case it wasn't,...
Definition: deviceman.cpp:176
DeviceManager::chnPitchBender
void chnPitchBender(uchar chn, uchar lsb, uchar msb)
Changes the Pitch Bender value on a MIDI channel.
Definition: deviceman.cpp:521
DeviceManager::wait
void wait(double ms)
Sets the number of milliseconds at which the next event will be sent.
Definition: deviceman.cpp:537
DeviceManager::name
const char * name(int i)
Returns the name of the i-th device .
Definition: deviceman.cpp:716
DeviceManager::chnPatchChange
void chnPatchChange(uchar chn, uchar patch)
Changes the patch (instrument) on a MIDI channel.
Definition: deviceman.cpp:511
DeviceManager::setPatchesToUse
int setPatchesToUse(int *patchesused)
Loads the patches you're going to use .
Definition: deviceman.cpp:794
DeviceManager::setDefaultDevice
void setDefaultDevice(int i)
Sets the device to send the MIDI events to.
Definition: deviceman.cpp:769
DeviceManager::chnController
void chnController(uchar chn, uchar ctl, uchar v)
Sends a Controller event to a MIDI channel.
Definition: deviceman.cpp:526
DeviceManager::~DeviceManager
~DeviceManager(void)
Destructor.
Definition: deviceman.cpp:153
DeviceManager::initDev
void initDev(void)
Calls MidiOut::initDev() in turn in each of the available devices.
Definition: deviceman.cpp:482
DeviceManager::tmrStart
void tmrStart(long int tpcn)
Starts the timer.
Definition: deviceman.cpp:565
DeviceManager::defaultDevice
int defaultDevice(void)
Returns the device to which the MIDI events will be sent.
Definition: deviceman.cpp:764
DeviceManager::sysEx
void sysEx(uchar *data, ulong size)
Sends a SYStem EXclusive message to the default MIDI device (usually, external MIDI synths,...
Definition: deviceman.cpp:531
DeviceManager::setVolumePercentage
void setVolumePercentage(int i)
Changes the "master" volume of the played events by altering next volume controller events.
Definition: deviceman.cpp:808
DeviceManager::initManager
int initManager(void)
Initializes the MIDI Device Manager object.
Definition: deviceman.cpp:203
DeviceManager::setMidiMap
void setMidiMap(MidiMapper *map)
Sets a MidiMapper object to use.
Definition: deviceman.cpp:784
DeviceManager::type
const char * type(int i)
Returns the type of device the i-th device is , in a user-friendly string .
Definition: deviceman.cpp:734
DeviceManager::ok
int ok(void)
Definition: deviceman.cpp:169
DeviceManager::chnPressure
void chnPressure(uchar chn, uchar vel)
Changes the Pressure (Aftertouch) on a MIDI channel.
Definition: deviceman.cpp:516
DeviceManager::tmrStop
void tmrStop(void)
Stops the timer.
Definition: deviceman.cpp:591
DeviceManager::sync
void sync(bool f=0)
Synchronizes with the MIDI buffer.
Definition: deviceman.cpp:632
DeviceManager::noteOff
void noteOff(uchar chn, uchar note, uchar vel)
Sends a Note Off MIDI event.
Definition: deviceman.cpp:501
DeviceManager::DeviceManager
DeviceManager(int def=-1)
Constructor.
Definition: deviceman.cpp:106
DeviceManager::chntodev
MidiOut * chntodev(int chn)
Definition: deviceman.h:206
DeviceManager::keyPressure
void keyPressure(uchar chn, uchar note, uchar vel)
Sends a Key Pressure (or Aftertouch) MIDI event.
Definition: deviceman.cpp:506
DeviceManager::closeDev
void closeDev(void)
Closes the devices, and /dev/sequencer.
Definition: deviceman.cpp:449
DeviceManager::tmrSetTempo
void tmrSetTempo(int v)
Sets the tempo which will be used to convert between ticks and milliseconds.
Definition: deviceman.cpp:553
DeviceManager::midiMapFilename
const char * midiMapFilename(void)
Returns the filename where the Midi Mapper was loaded from, or "" if no MIDI Mapper is in use.
Definition: deviceman.cpp:776
DeviceManager::openDev
void openDev(void)
Open the devices.
Definition: deviceman.cpp:398
DeviceManager::allNotesOff
void allNotesOff(void)
Sends an all notes off event.
Definition: deviceman.cpp:824
DeviceManager::setDeviceNumberForChannel
void setDeviceNumberForChannel(int chn, int dev)
Sets the device number associated with a given channel.
Definition: deviceman.cpp:819
DeviceManager::tmrContinue
void tmrContinue(void)
Continue the stopped timer .
Definition: deviceman.cpp:612
FMOut
FM device output class .
Definition: fmout.h:44
GUSOut
Gravis Ultrasound synthesizer output class .
Definition: gusout.h:46
GUSOut::setPatchesToUse
void setPatchesToUse(int *patchesused)
See DeviceManager::setPatchesToUse() .
Definition: gusout.cpp:525
MidiMapper
A Midi Mapper class which defines the way MIDI events are translated (or "mapped") to different ones.
Definition: midimapper.h:60
MidiOut
External MIDI port output class .
Definition: midiout.h:52
MidiOut::setVolumePercentage
virtual void setVolumePercentage(int volper)
Change all channel volume events multiplying it by this percentage correction Instead of forcing a ch...
Definition: midiout.h:225
MidiOut::chnPitchBender
virtual void chnPitchBender(uchar chn, uchar lsb, uchar msb)
See DeviceManager::chnPitchBender()
Definition: midiout.cpp:166
MidiOut::deviceName
const char * deviceName(void) const
Returns the name and type of this MIDI device.
Definition: midiout.cpp:280
MidiOut::noteOn
virtual void noteOn(uchar chn, uchar note, uchar vel)
See DeviceManager::noteOn()
Definition: midiout.cpp:113
MidiOut::setMidiMapper
void setMidiMapper(MidiMapper *map)
Sets a MidiMapper object to be used to modify the midi events before sending them.
Definition: midiout.cpp:107
MidiOut::chnPatchChange
virtual void chnPatchChange(uchar chn, uchar patch)
See DeviceManager::chnPatchChange()
Definition: midiout.cpp:147
MidiOut::initDev
virtual void initDev()
Initializes the device sending generic standard midi events and controllers, such as changing the pat...
Definition: midiout.cpp:86
MidiOut::midiMapFilename
const char * midiMapFilename()
Returns the path to the file where the current used MidiMapper object reads the configuration from,...
Definition: midiout.cpp:275
MidiOut::openDev
virtual void openDev(int sqfd)
Opens the device.
Definition: midiout.cpp:63
MidiOut::closeDev
virtual void closeDev()
Closes the device.
Definition: midiout.cpp:77
MidiOut::chnPressure
virtual void chnPressure(uchar chn, uchar vel)
See DeviceManager::chnPressure()
Definition: midiout.cpp:158
MidiOut::keyPressure
virtual void keyPressure(uchar chn, uchar note, uchar vel)
See DeviceManager::keyPressure()
Definition: midiout.cpp:140
MidiOut::noteOff
virtual void noteOff(uchar chn, uchar note, uchar vel)
See DeviceManager::noteOff()
Definition: midiout.cpp:130
MidiOut::chnController
virtual void chnController(uchar chn, uchar ctl, uchar v)
See DeviceManager::chnController()
Definition: midiout.cpp:186
SynthOut
Synth (AWE) device output class .
Definition: synthout.h:45
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
TDEConfigBase::readPathEntry
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig
TDEInstance

libtdemid

Skip menu "libtdemid"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdemid

Skip menu "libtdemid"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for libtdemid by doxygen 1.9.4
This website is maintained by Timothy Pearson.