Source Code (Use browser search to find items of interest.)
Class Index
kmid'MidiMapper (./kdemultimedia/kmid/player/midimapper.h:35)
class MidiMapper
{
private:
int _ok;
uchar channelmap[16];
Keymap *channelKeymap[16]; // pointer to the keymap to use for a channel
// this is to make it faster
// The index is with the real channel (already mapped)
int channelPatchForced[16]; // if -1 the channel doesn't have
// a forced patch, else indicates the patch to
// force in a channel
uchar patchmap[128];
Keymap *patchKeymap[128]; // Same as channelKeymap
Keymap *keymaps; // Real linked list of keymaps used around the program
char *_filename;
// Stores the name of the file from which the map was loaded
int mapExpressionToVolumeEvents;
// Simulate expression events with volume events
int mapPitchBender; // Use or not use the next variable
int pitchBenderRatio;
// Indicates the ratio between the standard and the synth's pitch
// bender engine. The number sent to the synth is multiplied by this
// and dividied by 4096. Thus if PitchBenderRatio is 4096, the synth's
// pitch bender works as the standard one
void getValue(char *s,char *v);
void removeSpaces(char *s);
int countWords(char *s);
void getWord(char *t,char *s,int w);
// get from s the word in position w and store it in t
void deallocateMaps(void);
Keymap *createKeymap(char *name,uchar use_same_note=0,uchar note=0);
void readPatchmap(FILE *fh);
void readKeymap(FILE *fh,char *first_line);
void readChannelmap(FILE *fh);
void readOptions(FILE *fh);
void addKeymap(Keymap *newkm);
Keymap *keymap(char *n);
public:
MidiMapper(const char *name);
~MidiMapper();
void loadFile(const char *name);
int ok(void) { return _ok; };
uchar channel(uchar chn) { return channelmap[chn];};
uchar patch(uchar chn,uchar pgm);
uchar key(uchar chn,uchar pgm, uchar note);
void pitchBender(uchar chn,uchar &lsb,uchar &msb);
void controller(uchar chn,uchar &ctl,uchar &v);
char *filename(void);
};
kmid'MidiMapper::MidiMapper() (./kdemultimedia/kmid/player/midimapper.cc:30)
MidiMapper::MidiMapper(const char *name)
{
_ok=1;
keymaps=NULL;
_filename=NULL;
mapPitchBender=0;
mapExpressionToVolumeEvents=0;
if ((name==NULL)||(name[0]==0))
{
deallocateMaps();
int i;
for (i=0;i<16;i++)
{
channelmap[i]=i;
channelPatchForced[i]=-1;
}
for (i=0;i<128;i++) patchmap[i]=i;
}
else
loadFile(name);
}
kmid'MidiMapper::~MidiMapper() (./kdemultimedia/kmid/player/midimapper.cc:52)
MidiMapper::~MidiMapper()
{
if (_filename!=NULL) delete _filename;
deallocateMaps();
}
kmid'MidiMapper::deallocateMaps() (./kdemultimedia/kmid/player/midimapper.cc:58)
void MidiMapper::deallocateMaps(void)
{
int i;
for (i=0;i<16;i++) channelKeymap[i]=NULL;
for (i=0;i<128;i++) patchKeymap[i]=NULL;
Keymap *km;
while (keymaps!=NULL)
{
km=keymaps->next;
delete keymaps;
keymaps=km;
}
}
kmid'MidiMapper::getValue() (./kdemultimedia/kmid/player/midimapper.cc:72)
void MidiMapper::getValue(char *s,char *v)
{
char *c=s;
while ((*c!=0)&&(*c!='=')) c++;
if (c==0) v[0]=0;
else
{
c++;
while (*c!=0)
{
*v=*c;
c++;v++;
}
*v=0;
}
}
kmid'MidiMapper::removeSpaces() (./kdemultimedia/kmid/player/midimapper.cc:89)
void MidiMapper::removeSpaces(char *s)
{
char *a=s;
while ((*a!=0)&&(*a==' ')) a++;
if (*a==0) {*s=0;return;};
while (*a!=0)
{
while ((*a!=0)&&(*a!=' ')&&(*a!=10)&&(*a!=13))
{
*s=*a;
s++;
a++;
}
while ((*a!=0)&&((*a==' ')||(*a==10)||(*a==13))) a++;
*s=' ';s++;
if (*a==0) {*s=0;return;};
}
*s=0;
}
kmid'MidiMapper::countWords() (./kdemultimedia/kmid/player/midimapper.cc:110)
int MidiMapper::countWords(char *s)
{
int c=0;
while (*s!=0)
{
if (*s==' ') c++;
s++;
}
return c;
}
kmid'MidiMapper::getWord() (./kdemultimedia/kmid/player/midimapper.cc:121)
void MidiMapper::getWord(char *t,char *s,int w)
{
int i=0;
*t=0;
while ((*s!=0)&&(i<w))
{
if (*s==' ') i++;
s++;
}
while ((*s!=0)&&(*s!=' ')&&(*s!=10)&&(*s!=13))
{
*t=*s;
t++;s++;
}
*t=0;
}
kmid'MidiMapper::loadFile() (./kdemultimedia/kmid/player/midimapper.cc:139)
void MidiMapper::loadFile(const char *name)
{
_ok=1;
FILE *fh = fopen(name,"rt");
if ( fh == NULL ) { _ok = -1; return; };
char s[101];
s[0] = 0;
if ( _filename != NULL ) delete _filename;
_filename = new char[ strlen(name)+1 ];
strcpy(_filename,name);
#ifdef MIDIMAPPERDEBUG
printf("Loading mapper ...\n");
#endif
while (!feof(fh))
{
s[0]=0;
while ((!feof(fh))&&((s[0]==0)||(s[0]=='#'))) fgets(s,100,fh);
if (strncmp(s,"DEFINE",6)==0)
{
if (strncmp(&s[7],"PATCHMAP",8)==0) readPatchmap(fh);
else
if (strncmp(&s[7],"KEYMAP",6)==0) readKeymap(fh,s);
else
if (strncmp(&s[7],"CHANNELMAP",10)==0) readChannelmap(fh);
else
{
printf("ERROR: Unknown DEFINE line in map file\n");
_ok=0;
}
if (_ok==0)
{
printf("The midi map file will be ignored\n");
fclose(fh);
return;
}
}
else if (strncmp(s,"OPTIONS",7)==0) readOptions(fh);
}
fclose(fh);
}
kmid'MidiMapper::createKeymap() (./kdemultimedia/kmid/player/midimapper.cc:180)
Keymap *MidiMapper::createKeymap(char *name,uchar use_same_note,uchar note)
{
Keymap *km=new Keymap;
strcpy(km->name,name);
int i;
if (use_same_note==1)
{
for (i=0;i<128;i++)
km->key[i]=note;
}
else
{
for (i=0;i<128;i++)
km->key[i]=i;
}
addKeymap(km);
return km;
}
kmid'MidiMapper::addKeymap() (./kdemultimedia/kmid/player/midimapper.cc:199)
void MidiMapper::addKeymap(Keymap *newkm)
{
Keymap *km=keymaps;
if (keymaps==NULL)
{
keymaps=newkm;
newkm->next=NULL;
return;
}
while (km->next!=NULL) km=km->next;
km->next=newkm;
newkm->next=NULL;
return;
}
kmid'MidiMapper::keymap() (./kdemultimedia/kmid/player/midimapper.cc:214)
Keymap *MidiMapper::keymap(char *n)
{
Keymap *km=keymaps;
while ((km!=NULL)&&(strcmp(km->name,n)!=0)) km=km->next;
return km;
}
kmid'MidiMapper::readOptions() (./kdemultimedia/kmid/player/midimapper.cc:221)
void MidiMapper::readOptions(FILE *fh)
{
#ifdef MIDIMAPPERDEBUG
printf("Loading Options ... \n");
#endif
char s[101];
char v[101];
char t[101];
int fin=0;
mapPitchBender=0;
while (!fin)
{
s[0]=0;
while ((s[0]==0)||(s[0]=='#')) fgets(s,100,fh);
if (strncmp(s,"PitchBenderRatio",16)==0)
{
getValue(s,v);
removeSpaces(v);
getWord(t,v,0);
mapPitchBender=1;
pitchBenderRatio=atoi(t);
}
else if (strncmp(s,"MapExpressionToVolumeEvents",27)==0) mapExpressionToVolumeEvents=1;
else if (strncmp(s,"END",3)==0)
{
fin=1;
}
else
{
printf("ERROR: Invalid option in OPTIONS section of map file : (%s)\n",s);
_ok=0;
return;
}
}
}
kmid'MidiMapper::readPatchmap() (./kdemultimedia/kmid/player/midimapper.cc:257)
void MidiMapper::readPatchmap(FILE *fh)
{
char s[101];
char v[101];
char t[101];
char name[101];
int i=0;
int j,w;
#ifdef MIDIMAPPERDEBUG
printf("Loading Patch map ... \n");
#endif
while (i<128)
{
s[0]=0;
while ((s[0]==0)||(s[0]=='#')) fgets(s,100,fh);
getValue(s,v);
removeSpaces(v);
w=countWords(v);
j=0;
patchKeymap[i]=NULL;
patchmap[i]=i;
while (j<w)
{
getWord(t,v,j);
if (strcmp(t,"AllKeysTo")==0)
{
j++;
if (j>=w)
{
printf("ERROR: Invalid option in PATCHMAP section of map file\n");
_ok=0;
return;
}
getWord(t,v,j);
sprintf(name,"AllKeysTo%s",t);
patchKeymap[i]=createKeymap(name,1,atoi(t));
}
else
{
patchmap[i]=atoi(t);
}
j++;
}
i++;
}
s[0]=0;
while ((s[0]==0)||(s[0]=='#')||(s[0]==10)||(s[0]==13)) fgets(s,100,fh);
if (strncmp(s,"END",3)!=0)
{
printf("ERROR: End of section not found in map file\n");
_ok=0;
return;
}
}
kmid'MidiMapper::readKeymap() (./kdemultimedia/kmid/player/midimapper.cc:312)
void MidiMapper::readKeymap(FILE *fh,char *first_line)
{
char s[101];
char v[101];
#ifdef MIDIMAPPERDEBUG
printf("Loading Key map ... %s",first_line);
#endif
removeSpaces(first_line);
getWord(v,first_line,2);
Keymap *km=new Keymap;
strcpy(km->name,v);
int i=0;
while (i<128)
{
s[0]=0;
while ((s[0]==0)||(s[0]=='#')) fgets(s,100,fh);
getValue(s,v);
removeSpaces(v);
km->key[i]=atoi(v);
i++;
}
s[0]=0;
while ((s[0]==0)||(s[0]=='#')||(s[0]==10)||(s[0]==13)) fgets(s,100,fh);
if (strncmp(s,"END",3)!=0)
{
printf("ERROR: End of section not found in map file\n");
_ok=0;
return;
}
addKeymap(km);
}
kmid'MidiMapper::readChannelmap() (./kdemultimedia/kmid/player/midimapper.cc:344)
void MidiMapper::readChannelmap(FILE *fh)
{
char s[101];
char v[101];
char t[101];
int i=0;
int w,j;
#ifdef MIDIMAPPERDEBUG
printf("Loading Channel map ... \n");
#endif
while (i<16)
{
s[0]=0;
while ((s[0]==0)||(s[0]=='#')) fgets(s,100,fh);
getValue(s,v);
removeSpaces(v);
w=countWords(v);
j=0;
channelKeymap[i]=NULL;
channelPatchForced[i]=-1;
channelmap[i]=i;
while (j<w)
{
getWord(t,v,j);
if (strcmp(t,"Keymap")==0)
{
j++;
if (j>=w)
{
printf("ERROR: Invalid option in CHANNELMAP section of map file\n");
_ok=0;
return;
}
getWord(t,v,j);
channelKeymap[i]=keymap(t);
}
else if (strcmp(t,"ForcePatch")==0)
{
j++;
if (j>=w)
{
printf("ERROR: Invalid option in CHANNELMAP section of map file\n");
_ok=0;
return;
}
getWord(t,v,j);
channelPatchForced[i]=atoi(t);
}
else
{
channelmap[i]=atoi(t);
}
j++;
}
i++;
}
s[0]=0;
while ((s[0]==0)||(s[0]=='#')||(s[0]==10)||(s[0]==13)) fgets(s,100,fh);
if (strncmp(s,"END",3)!=0)
{
printf("END of section not found in map file\n");
_ok=0;
return;
}
}
kmid'MidiMapper::filename() (./kdemultimedia/kmid/player/midimapper.cc:411)
char *MidiMapper::filename(void)
{
return (_filename!=NULL)? _filename : (char *)"";
}
kmid'MidiMapper::key() (./kdemultimedia/kmid/player/midimapper.cc:416)
uchar MidiMapper::key(uchar chn,uchar pgm, uchar note)
{
uchar notemapped=note;
if (patchKeymap[pgm]!=NULL) notemapped=patchKeymap[pgm]->key[note];
if (channelKeymap[chn]!=NULL) notemapped=channelKeymap[chn]->key[note];
return notemapped;
}
kmid'MidiMapper::patch() (./kdemultimedia/kmid/player/midimapper.cc:424)
uchar MidiMapper::patch(uchar chn,uchar pgm)
{
return (channelPatchForced[chn] == -1) ?
patchmap[pgm] : (uchar)channelPatchForced[chn] ;
}
kmid'MidiMapper::pitchBender() (./kdemultimedia/kmid/player/midimapper.cc:430)
void MidiMapper::pitchBender(uchar ,uchar &lsb,uchar &msb)
{
if (mapPitchBender)
{
short pbs=((short)msb<<7) | (lsb & 0x7F);
pbs=pbs-0x2000;
short pbs2=(((long)pbs*pitchBenderRatio)/4096);
#ifdef MIDIMAPPERDEBUG
printf("Pitch Bender (%d): %d -> %d \n",chn,pbs,pbs2);
#endif
pbs2=pbs2+0x2000;
lsb=pbs2 & 0x7F;
msb=(pbs2 >> 7)&0x7F;
}
}
kmid'MidiMapper::controller() (./kdemultimedia/kmid/player/midimapper.cc:446)
void MidiMapper::controller(uchar ,uchar &ctl, uchar &)
{
if ((mapExpressionToVolumeEvents)&&(ctl==11)) ctl=7;
}