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_process.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 #include "jdkmidi/world.h"
00025 #include "jdkmidi/process.h"
00026 
00027 namespace jdkmidi
00028 {
00029   
00030   
00031   MIDIProcessor::MIDIProcessor()
00032   {
00033   }
00034   
00035   MIDIProcessor::~MIDIProcessor()
00036   {
00037   }
00038   
00039   
00040   
00041   
00042   MIDIMultiProcessor::MIDIMultiProcessor( int num ) 
00043     :
00044     processors( new MIDIProcessor *[num] ),
00045     num_processors( num )
00046   {   
00047     for( int i=0; i<num_processors; ++i )
00048     {
00049       processors[i] = 0;
00050     }
00051   }
00052   
00053   MIDIMultiProcessor::~MIDIMultiProcessor()
00054   {
00055     delete [] processors;
00056   }
00057   
00058   
00059   
00060   bool MIDIMultiProcessor::Process( MIDITimedBigMessage *msg )
00061   {
00062     for( int i=0; i<num_processors; ++i )
00063     {
00064       if( processors[i] )
00065       {
00066         if( processors[i]->Process( msg )==false )
00067         {
00068           return false;
00069         }     
00070       }
00071       
00072     } 
00073     
00074     return true;
00075   }
00076   
00077   
00078   
00079   
00080   
00081   MIDIProcessorTransposer::MIDIProcessorTransposer()
00082   {
00083     for( int i=0; i<16; ++i )
00084     {
00085       trans_amount[i] = 0;
00086     }
00087     
00088   }
00089   
00090   MIDIProcessorTransposer::~MIDIProcessorTransposer()
00091   {
00092   }
00093   
00094   
00095   void MIDIProcessorTransposer::SetAllTranspose( int val )
00096   {
00097     for( int chan=0; chan<16; ++chan )
00098     {
00099       trans_amount[chan]=val;
00100     }
00101   } 
00102 
00103   bool MIDIProcessorTransposer::Process( MIDITimedBigMessage *msg )
00104   {
00105     if( msg->IsChannelMsg() )
00106     {   
00107       if( msg->IsNoteOn() || msg->IsNoteOff() || msg->IsPolyPressure() )
00108       {
00109         int trans = trans_amount[ msg->GetChannel() ];
00110         
00111         int new_note = ((int)msg->GetNote())+trans;
00112         
00113         if( trans>127 || trans<0 )
00114         {
00115           // delete event if out of range
00116           return false;
00117         }     
00118         else
00119         {
00120           // set new note number
00121           msg->SetNote( (unsigned char)new_note );
00122         }
00123         
00124       }
00125     }
00126     
00127     return true;
00128   }
00129   
00130   
00131   
00132   
00133   
00134   MIDIProcessorRechannelizer::MIDIProcessorRechannelizer()
00135   {
00136     for( int i=0; i<16; ++i )
00137     {
00138       rechan_map[i] = i;
00139     }
00140     
00141   }
00142   
00143   MIDIProcessorRechannelizer::~MIDIProcessorRechannelizer()
00144   {
00145   }
00146   
00147   
00148   void MIDIProcessorRechannelizer::SetAllRechan( int dest_chan )
00149   {
00150     for( int i=0; i<16; ++i )
00151     {
00152       rechan_map[i] = dest_chan;
00153     }
00154   }
00155   
00156   bool MIDIProcessorRechannelizer::Process( MIDITimedBigMessage *msg )
00157   {
00158     if( msg->IsChannelMsg() )
00159     {   
00160       int new_chan = rechan_map[ msg->GetChannel() ];
00161       
00162       if( new_chan==-1 )
00163       {
00164         // this channel is to be deleted! return false
00165         return false;
00166       }
00167       
00168       msg->SetChannel( (unsigned char)new_chan );
00169     }
00170     
00171     return true;
00172   }
00173   
00174   
00175   
00176   
00177   
00178 }