midistat.cc Source File (libkmid Library)

| # libkmid Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# midistat.cc

    00001 /**************************************************************************
    00002
    00003     midistat.cc - class MidiStatus, change it internally and then send it.
    00004     This file is part of LibKMid 0.9.5
    00005     Copyright (C) 1997,98,99,2000  Antonio Larrosa Jimenez
    00006     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
    00007
    00008     This library is free software; you can redistribute it and/or
    00009     modify it under the terms of the GNU Library General Public
    00010     License as published by the Free Software Foundation; either
    00011     version 2 of the License, or (at your option) any later version.
    00012
    00013     This library is distributed in the hope that it will be useful,
    00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016     Library General Public License for more details.
    00017
    00018     You should have received a copy of the GNU Library General Public License
    00019     along with this library; see the file COPYING.LIB.  If not, write to
    00020     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021     Boston, MA 02111-1307, USA.
    00022
    00023     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
    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 //    void noteOn       ( uchar chn, uchar note, uchar vel );
    00059 //    void noteOff      ( uchar chn, uchar note, uchar vel );
    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        for (int i=0;i<256;i++)
    00110        midi->chnController(chn,i,chn_controller[chn][i]);
    00111      */
    00112   }
    00113   midi->tmrSetTempo(tempo);
    00114   midi->sync();
    00115 }

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:29 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001