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

include/jdkmidi/driver.h

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 #ifndef _JDKMIDI_DRIVER_H
00025 #define _JDKMIDI_DRIVER_H
00026 
00027 #include "jdkmidi/msg.h"
00028 #include "jdkmidi/sysex.h"
00029 #include "jdkmidi/matrix.h"
00030 #include "jdkmidi/process.h"
00031 #include "jdkmidi/queue.h"
00032 #include "jdkmidi/tick.h"
00033 
00034 namespace jdkmidi
00035 {  
00036   class MIDIDriver : public MIDITick 
00037     {
00038     public:
00039       MIDIDriver(int queue_size );
00040       virtual ~MIDIDriver();
00041       
00042       virtual void Reset();
00043       
00044       // to get the midi in queue
00045       MIDIQueue * InputQueue() 
00046         {
00047           return &in_queue;
00048         } 
00049       
00050       const MIDIQueue * InputQueue() const 
00051         {
00052           return &in_queue;
00053         } 
00054       
00055       // to get the midi out queue
00056       MIDIQueue * OutputQueue() 
00057         {
00058           return &out_queue;
00059         } 
00060       
00061       const MIDIQueue * OutputQueue() const 
00062         {
00063           return &out_queue;
00064         } 
00065       
00066       
00067       //
00068       // returns true if the output queue is not full
00069       bool CanOutputMessage() const 
00070         {
00071           return out_queue.CanPut();
00072         } 
00073       
00074       
00075       // processes message with the OutProcessor and then
00076       // puts the message in the out_queue
00077       void OutputMessage( MIDITimedBigMessage &msg ) 
00078         {
00079           if( (out_proc && out_proc->Process( &msg )) || !out_proc )
00080           {
00081             out_matrix.Process( msg );
00082             out_queue.Put( msg );
00083           }
00084         } 
00085       
00086       void SetThruEnable( bool f ) 
00087         {
00088           thru_enable = f;
00089         } 
00090       
00091       bool GetThruEnable() const 
00092         {
00093           return thru_enable;
00094         } 
00095       
00096       // to set the midi processors used for thru, out, and in
00097       void SetThruProcessor( MIDIProcessor *proc ) 
00098         {
00099           thru_proc = proc;
00100         } 
00101       
00102       void SetOutProcessor( MIDIProcessor *proc ) 
00103         {
00104           out_proc = proc;
00105         } 
00106       
00107       void SetInProcessor( MIDIProcessor *proc ) 
00108         {
00109           in_proc = proc;
00110         } 
00111       
00112       void SetTickProc( MIDITick *tick ) 
00113         {
00114           tick_proc = tick;
00115         } 
00116       
00117       // to send all notes off on selected midi chanel
00118       void AllNotesOff(int chan);
00119       
00120       // to send all notes off on all midi channels
00121       void AllNotesOff();
00122       
00123       // call handle midi in when a parsed midi message
00124       // comes in to the system. Can be called by a callback function
00125       // or by your TimeTick() function.
00126       
00127       virtual bool HardwareMsgIn( MIDITimedBigMessage &msg );
00128       
00129       // HardwareMsgOut() must be overriden by a subclass - It must
00130       // take
00131       
00132       virtual bool HardwareMsgOut( const MIDITimedBigMessage &msg ) = 0;
00133       
00134       // the time tick procedure:
00135       //  manages in/out/thru to hardware
00136       // inherited from MIDITick.
00137       //
00138       // if you need to poll midi in hardware,
00139       // you can override this method - Call MIDIDriver::TimeTick(t)
00140       // first, You may then poll the midi in
00141       // hardware, parse the bytes, form a message, and give the
00142       // resulting message to HandleMsgIn to process it and put it in
00143       // the in_queue.
00144       
00145       virtual void TimeTick( unsigned long sys_time );
00146       
00147       
00148     protected:
00149       
00150       
00151       // the in and out queues
00152       MIDIQueue in_queue;
00153       MIDIQueue out_queue;
00154       
00155       // the processors
00156       MIDIProcessor *in_proc;
00157       MIDIProcessor *out_proc;
00158       MIDIProcessor *thru_proc;
00159       
00160       bool thru_enable;
00161       
00162       // additional TimeTick procedure
00163       
00164       MIDITick *tick_proc;
00165       
00166       // to keep track of notes on going to MIDI out
00167       
00168       MIDIMatrix out_matrix;
00169     }; 
00170   
00171   
00172 }
00173 
00174 #endif