28 #include "libtdemid.h"
32 #include <sys/types.h>
36 #include "deviceman.h"
38 #include "midimapper.h"
42 int KMidSimpleAPI::kMidInit(
void)
45 if ( kMid.midi == 0L )
return 1;
46 kMid.midi->initManager();
47 if (!kMid.midi->ok())
return 1;
50 if (kMid.pctlsmID==-1)
return 1;
52 if (kMid.pctl==NULL)
return 1;
54 kMid.player=
new MidiPlayer(kMid.midi,kMid.pctl);
55 if ( kMid.player == 0L )
61 kMid.player->setParseSong(
false);
66 kMid.pctl->ratioTempo=1.0;
67 kMid.pctl->tempo=500000;
68 kMid.pctl->volumepercentage=100;
69 for (
int i=0;i<16;i++)
71 kMid.pctl->forcepgm[i]=0;
78 int KMidSimpleAPI::kMidLoad(
const char *filename)
80 if (kMidDevices()==0)
return 0;
81 return kMid.player->loadSong(filename);
84 int KMidSimpleAPI::kMidPlay(
int loop)
86 if (kMidDevices()==0)
return 4;
87 if (!kMid.player->isSongLoaded())
return 1;
88 if (kMid.pctl->playing==1)
return 2;
89 if (kMid.midi->checkInit()==-1)
return 3;
92 kMid.pctl->finished=0;
94 kMid.pctl->SPEVplayed=0;
95 kMid.pctl->SPEVprocessed=0;
96 kMid.pctl->millisecsPlayed=0;
97 if ((kMid.pid=fork())==0)
104 if (kMid.pctl->error)
return 5;
105 kMid.pctl->message=0;
106 kMid.pctl->playing=0;
107 kMid.pctl->finished=0;
109 kMid.pctl->SPEVplayed=0;
110 kMid.pctl->SPEVprocessed=0;
111 kMid.pctl->millisecsPlayed=0;
116 if (kMid.pctl->error)
return 5;
123 int KMidSimpleAPI::kMidStop(
void)
125 if (kMidDevices()==0)
return 4;
126 if (kMid.pctl->playing==0)
return 1;
129 kill(kMid.pid,SIGTERM);
130 waitpid(kMid.pid, NULL, 0);
134 kMid.pctl->playing=0;
138 void KMidSimpleAPI::kMidDestruct(
void)
145 shmdt((
char *)kMid.pctl);
146 shmctl(kMid.pctlsmID, IPC_RMID, 0L);
149 int KMidSimpleAPI::kMidIsPlaying(
void)
151 return kMid.pctl->playing;
154 int KMidSimpleAPI::kMidDevices(
void)
156 return kMid.midi->midiPorts()+kMid.midi->synthDevices();
159 const char * KMidSimpleAPI::kMidName(
int i)
161 return kMid.midi->name(i);
164 const char * KMidSimpleAPI::kMidType(
int i)
166 return kMid.midi->type(i);
169 void KMidSimpleAPI::kMidSetDevice(
int i)
171 kMid.midi->setDefaultDevice(i);
174 void KMidSimpleAPI::kMidSetMidiMapper(
const char *mapfilename)
176 if (kMidDevices()==0)
return;
178 if ((kMid.map->ok() == 0L)||(!kMid.map->ok()))
return;
179 kMid.midi->setMidiMap(kMid.map);
182 const char *KMidSimpleAPI::kMidVersion(
void)
187 const char *KMidSimpleAPI::kMidCopyright(
void)
189 return "LibKMid 0.9.5 (C)1997-2000 Antonio Larrosa Jimenez <larrosa@kde.org>.Malaga(es)";
201 return KMidSimpleAPI::kMidInit();
204 int kMidLoad(
const char *filename)
206 return KMidSimpleAPI::kMidLoad(filename);
211 return KMidSimpleAPI::kMidPlay();
216 return KMidSimpleAPI::kMidStop();
219 void kMidDestruct(
void)
221 KMidSimpleAPI::kMidDestruct();
224 int kMidIsPlaying(
void)
226 return KMidSimpleAPI::kMidIsPlaying();
229 int kMidDevices(
void)
231 return KMidSimpleAPI::kMidDevices();
234 const char *kMidName(
int i)
236 return KMidSimpleAPI::kMidName(i);
239 const char *kMidType(
int i)
241 return KMidSimpleAPI::kMidType(i);
244 void kMidSetDevice(
int i)
246 KMidSimpleAPI::kMidSetDevice(i);
249 void kMidSetMidiMapper(
const char *mapfilename)
251 KMidSimpleAPI::kMidSetMidiMapper(mapfilename);
254 const char *kMidVersion(
void)
256 return KMidSimpleAPI::kMidVersion();
259 const char *kMidCopyright(
void)
261 return KMidSimpleAPI::kMidCopyright();
MIDI Device Manager class .
A Midi Mapper class which defines the way MIDI events are translated (or "mapped") to different ones.
MIDI file player routines .
PlayerController is a struct that is used by the MidiPlayer object to tell other parts of the applica...