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_PARSER_H 00035 #define _JDKMIDI_PARSER_H 00036 00037 #include "jdkmidi/midi.h" 00038 #include "jdkmidi/msg.h" 00039 #include "jdkmidi/sysex.h" 00040 00041 namespace jdkmidi 00042 { 00043 00044 class MIDIParser 00045 { 00046 public: 00047 MIDIParser( ushort max_sysex_size=384 ); 00048 virtual ~MIDIParser(); 00049 00050 void Clear() 00051 { 00052 state=FIND_STATUS; 00053 } 00054 00055 virtual bool Parse( uchar b, MIDIMessage *msg ); 00056 00057 MIDISystemExclusive *GetSystemExclusive() const { return sysex; } 00058 00059 protected: 00060 00061 // 00062 // The states used for parsing messages. 00063 // 00064 00065 enum State 00066 { 00067 FIND_STATUS, // ignore data bytes 00068 FIRST_OF_ONE, // read first data byte of a one data byte msg 00069 FIRST_OF_TWO, // read first data byte of two data byte msg 00070 SECOND_OF_TWO, // read second data byte of two data byte msg 00071 FIRST_OF_ONE_NORUN, // read one byte message, do not allow 00072 // running status (for MTC) 00073 SYSEX_DATA // read sysex data byte 00074 }; 00075 00076 MIDIMessage tmp_msg; 00077 MIDISystemExclusive *sysex; 00078 State state; 00079 00080 bool ParseSystemByte( uchar b, MIDIMessage *msg ); 00081 bool ParseDataByte( uchar b, MIDIMessage *msg ); 00082 void ParseStatusByte( uchar b ); 00083 }; 00084 00085 00086 } 00087 00088 #endif 00089 00090