midistat.cc00001
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 #include "midistat.h"
00027 #include "deviceman.h"
00028 #include "sndcard.h"
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 extern int MT32toGM[128];
00035
00036 MidiStatus::MidiStatus()
00037 {
00038 int i;
00039 tempo=1000000;
00040 for (int chn=0;chn<16;chn++)
00041 {
00042 chn_patch[chn]=0;
00043 chn_bender[chn]=0x4000;
00044 chn_pressure[chn]=127;
00045 for (i=0;i<256;i++)
00046 chn_controller[chn][i]=0;
00047 chn_controller[chn][CTL_MAIN_VOLUME]=127;
00048 chn_controller[chn][11]=127;
00049 chn_controller[chn][0x4a]=127;
00050 chn_lastisvolumeev[chn]=1;
00051 }
00052 }
00053
00054 MidiStatus::~MidiStatus()
00055 {
00056 }
00057
00058
00059
00060
00061 void MidiStatus::chnPatchChange ( uchar chn, uchar patch )
00062 {
00063 chn_patch[chn]=patch;
00064 }
00065
00066 void MidiStatus::chnPressure ( uchar chn, uchar vel )
00067 {
00068 chn_pressure[chn]=vel;
00069 }
00070
00071 void MidiStatus::chnPitchBender ( uchar chn, uchar lsb, uchar msb )
00072 {
00073 chn_bender[chn]=((int)msb<<8|lsb);
00074 }
00075
00076 void MidiStatus::chnController ( uchar chn, uchar ctl , uchar v )
00077 {
00078 if (ctl==7) chn_lastisvolumeev[chn]=1;
00079 else if (ctl==11) chn_lastisvolumeev[chn]=0;
00080
00081 chn_controller[chn][ctl]=v;
00082 }
00083
00084 void MidiStatus::tmrSetTempo(int v)
00085 {
00086 tempo=v;
00087 }
00088
00089 void MidiStatus::sendData(DeviceManager *midi,int gm)
00090 {
00091 for (int chn=0;chn<16;chn++)
00092 {
00093 #ifdef MIDISTATDEBUG
00094 printf("Restoring channel %d\n",chn);
00095 #endif
00096 midi->chnPatchChange(chn,
00097 (gm==1)?(chn_patch[chn]):(MT32toGM[chn_patch[chn]]));
00098 midi->chnPitchBender(chn,chn_bender[chn]&0xFF,chn_bender[chn]>>8);
00099 midi->chnPressure(chn,chn_pressure[chn]);
00100 if (chn_lastisvolumeev[chn])
00101 {
00102 midi->chnController(chn,11,chn_controller[chn][11]);
00103 midi->chnController(chn,CTL_MAIN_VOLUME,chn_controller[chn][CTL_MAIN_VOLUME]);
00104 } else {
00105 midi->chnController(chn,CTL_MAIN_VOLUME,chn_controller[chn][CTL_MAIN_VOLUME]);
00106 midi->chnController(chn,11,chn_controller[chn][11]);
00107 }
00108
00109
00110
00111
00112 }
00113 midi->tmrSetTempo(tempo);
00114 midi->sync();
00115 }
|