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_driver.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/driver.h"
00026 
00027 namespace jdkmidi
00028 {
00029   
00030   
00031   MIDIDriver::MIDIDriver( int queue_size ) 
00032     :   
00033     in_queue(queue_size),
00034     out_queue(queue_size),
00035     in_proc(0),
00036     out_proc(0),
00037     thru_proc(0),
00038     thru_enable(false),
00039     tick_proc(0)
00040   {
00041     
00042   } 
00043   
00044   MIDIDriver::~MIDIDriver() 
00045   {
00046     
00047   } 
00048   
00049   void MIDIDriver::Reset()
00050   {
00051     in_queue.Clear();
00052     out_queue.Clear();
00053     out_matrix.Clear();
00054   }
00055   
00056   void MIDIDriver::AllNotesOff( int chan ) 
00057   {
00058     MIDITimedBigMessage msg;
00059     
00060     // send a note off for every note on in the out_matrix
00061     
00062     if( out_matrix.GetChannelCount(chan)>0 )
00063     {
00064       for( int note=0; note<128; ++note )
00065       {
00066         while( out_matrix.GetNoteCount(chan,note)>0 )
00067         {
00068           // make a note off with note on msg, velocity 0
00069           msg.SetNoteOn( (unsigned char)chan,
00070                          (unsigned char)note, 0 );
00071           
00072           OutputMessage( msg );
00073         }
00074       }
00075     }
00076     
00077     msg.SetControlChange(chan,C_DAMPER,0 );
00078     OutputMessage( msg );
00079     
00080     msg.SetAllNotesOff( (unsigned char)chan );
00081     OutputMessage( msg );
00082     
00083   } 
00084   
00085   void MIDIDriver::AllNotesOff() 
00086   {
00087     for( int i=0; i<16; ++i )
00088     {
00089       AllNotesOff(i);
00090     }
00091   } 
00092   
00093   bool MIDIDriver::HardwareMsgIn( MIDITimedBigMessage &msg ) 
00094   {
00095     // put input midi messages thru the in processor
00096     
00097     if( in_proc )
00098     {
00099       if( in_proc->Process( &msg )==false )
00100       {
00101         // message was deleted, so ignore it.
00102         return true;
00103       }
00104     }
00105     
00106     // stick input into in queue
00107     
00108     if( in_queue.CanPut() )
00109     {
00110       in_queue.Put( msg );
00111     }
00112     else
00113     {
00114       return false;
00115     }
00116     
00117     
00118     // now stick it through the THRU processor
00119     
00120     if( thru_proc )
00121     {
00122       if( thru_proc->Process( &msg )==false )
00123       {
00124         // message was deleted, so ignore it.
00125         return true;
00126       }
00127     }
00128     
00129     
00130     if( thru_enable )
00131     {
00132       // stick this message into the out queue so the tick procedure
00133       // will play it out asap
00134       
00135       if( out_queue.CanPut() )
00136       {
00137         out_queue.Put( msg );
00138       }
00139       else
00140       {
00141         return false;
00142       }
00143     }
00144     
00145     return true;
00146   } 
00147   
00148   void MIDIDriver::TimeTick( unsigned long sys_time ) 
00149   {
00150     // run the additional tick procedure if we need to
00151     if( tick_proc )
00152     {
00153       tick_proc->TimeTick( sys_time );
00154     }   
00155     
00156     // feed as many midi messages from out_queu to the hardware out port
00157     // as we can
00158     
00159     while( out_queue.CanGet() )
00160     {
00161       // use the Peek() function to avoid allocating memory for
00162       // a duplicate sysex
00163       
00164       if( HardwareMsgOut( *(out_queue.Peek() ) )==true )
00165       {
00166         // ok, got and sent a message - update our out_queue now
00167         out_queue.Next();
00168       }
00169       else
00170       {
00171         // cant send any more, stop now.
00172         break;
00173       }
00174       
00175     }
00176     
00177   } 
00178   
00179 }