jdkmidi class library documentation

Copyright © 2004 J.D. Koftinoff Software, Ltd.

Released under the GNU General Public License (GPL)




Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

src/jdkmidi_matrix.cpp

Go to the documentation of this file.
00001 /*
00002  *  libjdkmidi-2004 C++ Class Library for MIDI
00003  *
00004  *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
00005  *  www.jdkoftinoff.com
00006  *  jeffk@jdkoftinoff.com
00007  *
00008  *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program 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
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 /*
00025 **  Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd.
00026 **
00027 **  All rights reserved.
00028 **
00029 **  No one may duplicate this source code in any form for any reason
00030 **  without the written permission given by J.D. Koftinoff Software, Ltd.
00031 **
00032 */
00033 
00034 
00035 #include "jdkmidi/world.h"
00036 
00037 #include "jdkmidi/matrix.h"
00038 
00039 #ifndef DEBUG_MDMATRIX
00040 # define DEBUG_MDMATRIX 0
00041 #endif
00042 
00043 #if DEBUG_MDMATRIX
00044 # undef DBG
00045 # define DBG(a) a
00046 #endif
00047 
00048 
00049 namespace jdkmidi
00050 {
00051   
00052   
00053   MIDIMatrix::MIDIMatrix()
00054   {
00055     ENTER("MIDIMatrix::MIDIMatrix()");
00056     
00057     for( int channel=0; channel<16; channel++ )
00058     {
00059       channel_count[channel]=0;
00060       hold_pedal[channel]= false;
00061       for( unsigned char note=0; note<128; note++ )
00062         note_on_count[channel][note]=0;
00063     }
00064     
00065     total_count=0;
00066   }
00067   
00068   MIDIMatrix::~MIDIMatrix()
00069   {
00070     ENTER("MIDIMatrix::~MIDIMatrix()");
00071   }
00072   
00073   
00074   void  MIDIMatrix::DecNoteCount( const MIDIMessage &, int channel, int note )
00075   {
00076     ENTER( "MIDIMatrix::DecNoteCount()" );
00077     
00078     if( note_on_count[channel][note]>0 )
00079     {
00080       --note_on_count[channel][note];
00081       --channel_count[channel];
00082       --total_count;
00083     }
00084   }
00085   
00086   void  MIDIMatrix::IncNoteCount( const MIDIMessage &, int channel, int note )
00087   {
00088     ENTER( "MIDIMatrix::IncNoteCount()" );
00089     
00090     ++note_on_count[channel][note];
00091     ++channel_count[channel];
00092     ++total_count;
00093   }
00094   
00095   void  MIDIMatrix::OtherMessage( const MIDIMessage & )
00096   {
00097     ENTER( "MIDIMatrix::OtherMessage()" );
00098     
00099   }
00100   
00101   
00102   bool  MIDIMatrix::Process( const MIDIMessage &m )
00103   {
00104     ENTER( "MIDIMatrix::Process()" );
00105     
00106     bool status=false;
00107     
00108     if( m.IsChannelMsg() )
00109     {
00110       int channel=m.GetChannel();
00111       int note=m.GetNote();
00112       
00113       if( m.IsAllNotesOff() )
00114       {
00115         ClearChannel( channel );
00116         status=true;
00117       }
00118       else
00119         if( m.IsNoteOn() )
00120         {
00121           if( m.GetVelocity()!=0 )
00122             IncNoteCount( m, channel, note );
00123           else
00124             DecNoteCount( m, channel, note );
00125           status=true;
00126         }
00127         else
00128           if( m.IsNoteOff() )
00129           {
00130             DecNoteCount( m, channel, note );
00131             status=true;
00132           }
00133           else
00134             if( m.IsControlChange() && m.GetController()==C_DAMPER )
00135             {
00136               if( m.GetControllerValue() & 0x40 )
00137               {
00138                 hold_pedal[channel]=true;
00139               }
00140               else
00141               {
00142                 hold_pedal[channel]=false;
00143               }
00144             }
00145             else
00146               OtherMessage( m );
00147     }
00148     return status;
00149   }
00150   
00151   void  MIDIMatrix::Clear()
00152   {
00153     ENTER( "MIDIMatrix::Clear()" );
00154     
00155     for( int channel=0; channel<16; ++channel )
00156     {
00157       ClearChannel( channel );
00158     }
00159     total_count=0;
00160   }
00161   
00162   void  MIDIMatrix::ClearChannel( int channel )
00163   {
00164     ENTER( "MIDIMatrix::ClearChannel()" );
00165     
00166     for( int note=0; note<128; ++note )
00167     {
00168       total_count -= note_on_count[channel][note];
00169       note_on_count[channel][note]=0;
00170     }
00171     channel_count[channel]=0;
00172     hold_pedal[channel]=0;
00173   }
00174   
00175   
00176   
00177 }