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 #ifndef _JDKMIDI_SYSEX_H 00035 #define _JDKMIDI_SYSEX_H 00036 00037 #include "jdkmidi/midi.h" 00038 00039 namespace jdkmidi 00040 { 00041 00042 class MIDISystemExclusive 00043 { 00044 public: 00045 MIDISystemExclusive( int size=384 ); 00046 00047 MIDISystemExclusive( const MIDISystemExclusive &e ); 00048 00049 00050 MIDISystemExclusive( 00051 unsigned char *buf_, 00052 int max_len_, 00053 int cur_len_, 00054 bool deletable_ 00055 ) 00056 { 00057 buf=buf_; 00058 max_len=max_len_; 00059 cur_len=cur_len_; 00060 chk_sum=0; 00061 deletable=deletable_; 00062 } 00063 00064 virtual ~MIDISystemExclusive(); 00065 00066 void Clear() { cur_len=0; chk_sum=0; } 00067 void ClearChecksum() { chk_sum=0; } 00068 00069 void PutSysByte( unsigned char b ) // does not add to chksum 00070 { 00071 if( cur_len<max_len ) 00072 buf[cur_len++]=b; 00073 } 00074 00075 void PutByte( unsigned char b ) 00076 { 00077 PutSysByte(b); 00078 chk_sum+=b; 00079 } 00080 00081 void PutEXC() { PutSysByte( SYSEX_START ); } 00082 void PutEOX() { PutSysByte( SYSEX_END ); } 00083 00084 // low nibble first 00085 void PutNibblizedByte( unsigned char b ) 00086 { 00087 PutByte( (unsigned char)(b&0xf) ); 00088 PutByte( (unsigned char)(b>>4) ); 00089 } 00090 00091 // high nibble first 00092 void PutNibblizedByte2( unsigned char b ) 00093 { 00094 PutByte( (unsigned char)(b>>4) ); 00095 PutByte( (unsigned char)(b&0xf) ); 00096 } 00097 00098 void PutChecksum() 00099 { 00100 PutByte( (unsigned char)(chk_sum&0x7f )); 00101 } 00102 00103 unsigned char GetChecksum() const 00104 { 00105 return (unsigned char)(chk_sum&0x7f); 00106 } 00107 00108 int GetLength() const 00109 { 00110 return cur_len; 00111 } 00112 00113 unsigned char GetData( int i) const 00114 { 00115 return buf[i]; 00116 } 00117 00118 bool IsFull() const 00119 { 00120 return cur_len>=max_len; 00121 } 00122 00123 unsigned char *GetBuf() 00124 { 00125 return buf; 00126 } 00127 00128 const unsigned char *GetBuf() const 00129 { 00130 return buf; 00131 } 00132 00133 private: 00134 00135 unsigned char *buf; 00136 int max_len; 00137 int cur_len; 00138 unsigned char chk_sum; 00139 bool deletable; 00140 }; 00141 } 00142 00143 #endif 00144 00145