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 "synthout.h"
00029 #include <unistd.h>
00030 #include <fcntl.h>
00031 #include <stdio.h>
00032 #include "sndcard.h"
00033 #include <sys/ioctl.h>
00034 #include <errno.h>
00035 #include <string.h>
00036 #include <sys/param.h>
00037 #include "awe_sup.h"
00038 #include "midispec.h"
00039 
00040 #ifdef HAVE_CONFIG_H
00041 #include <config.h>
00042 #endif
00043 
00044 SEQ_USE_EXTBUF();
00045 
00046 SynthOut::SynthOut(int d)
00047 {
00048   seqfd = -1;
00049   devicetype=KMID_SYNTH;
00050   device= d;
00051   _ok=1;
00052 }
00053 
00054 SynthOut::~SynthOut()
00055 {
00056   closeDev();
00057 }
00058 
00059 void SynthOut::openDev (int sqfd)
00060 {
00061   _ok=1;
00062   seqfd = sqfd;
00063   if (seqfd==-1)
00064   {
00065     printfdebug("ERROR: Could not open /dev/sequencer\n");
00066     return;
00067   }
00068 #ifdef HAVE_OSS_SUPPORT
00069   
00070 
00071 
00072 
00073 
00074 #ifdef SYNTHOUTDEBUG
00075   printfdebug("Number of synth devices : %d\n",ndevs);
00076   printfdebug("Number of midi ports : %d\n",nmidiports);
00077   printfdebug("Rate : %d\n",m_rate);
00078 #endif
00079 
00080 #ifdef HAVE_AWE32
00081 
00082   struct synth_info info;
00083 
00084   
00085 
00086   info.device = device;
00087 
00088   if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1)
00089     printfdebug(" ioctl  SNDCTL_SYNTH_INFO FAILED \n");
00090 
00091   if (info.synth_type == SYNTH_TYPE_SAMPLE
00092       && info.synth_subtype == SAMPLE_TYPE_AWE32)
00093   {
00094 
00095     
00096     AWE_SET_CHANNEL_MODE(device,1);
00097 #ifdef SYNTHOUTDEBUG
00098     printfdebug(" Found AWE32 dev=%d \n",device);
00099 #endif
00100   }
00101 #endif // HAVE_AWE32
00102 #endif // HAVE_OSS_SUPPORT
00103 
00104 }
00105 
00106 void SynthOut::closeDev (void)
00107 {
00108   if (!ok()) return;
00109   
00110   seqfd=-1;
00111 }
00112 
00113 void SynthOut::initDev (void)
00114 {
00115 #ifdef HAVE_OSS_SUPPORT
00116   int chn;
00117   if (!ok()) return;
00118   uchar gm_reset[5]={0x7e, 0x7f, 0x09, 0x01, 0xf7};
00119   sysex(gm_reset, sizeof(gm_reset));
00120   for (chn=0;chn<16;chn++)
00121   {
00122     chnmute[chn]=0;
00123     chnPatchChange(chn,0);
00124     chnPressure(chn,127);
00125     chnPitchBender(chn, 0x00, 0x40);
00126     chnController(chn, CTL_MAIN_VOLUME,127);
00127     chnController(chn, CTL_EXT_EFF_DEPTH, 0);
00128     chnController(chn, CTL_CHORUS_DEPTH, 0);
00129     chnController(chn, 0x4a, 127);
00130   }
00131 #endif
00132 }
00133 
00134 void SynthOut::noteOn  (uchar chn, uchar note, uchar vel)
00135 {
00136   if (vel==0)
00137   {
00138     noteOff(chn,note,vel);
00139   }
00140   else
00141   {
00142     SEQ_START_NOTE(device, map->channel(chn),
00143     map->key(chn,chnpatch[chn],note),
00144     vel);
00145   }
00146 #ifdef SYNTHOUTDEBUG
00147   printfdebug("Note ON >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
00148 #endif
00149 }
00150 
00151 void SynthOut::noteOff (uchar chn, uchar note, uchar)
00152 {
00153   SEQ_STOP_NOTE(device, map->channel(chn),
00154       map->key(chn,chnpatch[chn],note), 0);
00155 #ifdef SYNTHOUTDEBUG
00156   printfdebug("Note OFF >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
00157 #endif
00158 }
00159 
00160 void SynthOut::keyPressure (uchar chn, uchar note, uchar vel)
00161 {
00162   SEQ_KEY_PRESSURE(device, map->channel(chn), map->key(chn,chnpatch[chn],note),vel);
00163 }
00164 
00165 void SynthOut::chnPatchChange (uchar chn, uchar patch)
00166 {
00167   SEQ_SET_PATCH(device,map->channel(chn),map->patch(chn,patch));
00168   chnpatch[chn]=patch;
00169 }
00170 
00171 void SynthOut::chnPressure (uchar chn, uchar vel)
00172 {
00173   SEQ_CHN_PRESSURE(device, map->channel(chn) , vel);
00174   chnpressure[chn]=vel;
00175 }
00176 
00177 void SynthOut::chnPitchBender(uchar chn,uchar lsb, uchar msb)
00178 {
00179   chnbender[chn]=((int)msb<<7) | (lsb & 0x7F);
00180   SEQ_BENDER(device, map->channel(chn), chnbender[chn]);
00181 }
00182 
00183 void SynthOut::chnController (uchar chn, uchar ctl, uchar v)
00184 {
00185   if ((ctl==11)||(ctl==7))
00186   {
00187     v=(v*volumepercentage)/100;
00188     if (v>127) v=127;
00189   }
00190 
00191   SEQ_CONTROL(device, map->channel(chn), ctl, v);
00192   chncontroller[chn][ctl]=v;
00193 }
00194 
00195 void SynthOut::sysex(uchar *, ulong )
00196 {
00197   
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 }