# libkmid Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# synthout.cc

    00001 /**************************************************************************
    00002
    00003     synthout.cc   - class synthOut which handles the /dev/sequencer device
    00004                         for synths (as AWE32)
    00005     This file is part of LibKMid 0.9.5
    00006     Copyright (C) 1997,98  Antonio Larrosa Jimenez and P.J.Leonard
    00007                   1999,2000 Antonio Larrosa Jimenez
    00008     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
    00009
    00010     This library is free software; you can redistribute it and/or
    00011     modify it under the terms of the GNU Library General Public
    00012     License as published by the Free Software Foundation; either
    00013     version 2 of the License, or (at your option) any later version.
    00014
    00015     This library is distributed in the hope that it will be useful,
    00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018     Library General Public License for more details.
    00019
    00020     You should have received a copy of the GNU Library General Public License
    00021     along with this library; see the file COPYING.LIB.  If not, write to
    00022     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00023     Boston, MA 02111-1307, USA.
    00024
    00025     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
    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      int i=1;
    00071      ioctl(seqfd,SNDCTL_SEQ_THRESHOLD,i);
    00072      printfdebug("Threshold : %d\n",i);
    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   // Should really collect the possible devices and let the user choose ?
    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     // Enable layered patches ....
    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   //if (seqfd>=0) close(seqfd);
    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   // AWE32 doesn't respond to sysex (AFAIK)
    00198 /*
    00199 #ifndef HAVE_AWE32
    00200   ulong i=0;
    00201   SEQ_MIDIOUT(device, MIDI_SYSTEM_PREFIX);
    00202   while (i<size)
    00203   {
    00204     SEQ_MIDIOUT(device, *data);
    00205     data++;
    00206     i++;
    00207   };
    00208   printfdebug("sysex\n");
    00209 #endif
    00210 */
    00211 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:28:30 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001