| 1 | /* |
|---|
| 2 | * libjdkmidi-2004 C++ Class Library for MIDI |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. |
|---|
| 5 | * www.jdkoftinoff.com |
|---|
| 6 | * jeffk@jdkoftinoff.com |
|---|
| 7 | * |
|---|
| 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** |
|---|
| 9 | * |
|---|
| 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | * it under the terms of the GNU General Public License as published by |
|---|
| 12 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | * (at your option) any later version. |
|---|
| 14 | * |
|---|
| 15 | * This program is distributed in the hope that it will be useful, |
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | * GNU General Public License for more details. |
|---|
| 19 | * |
|---|
| 20 | * You should have received a copy of the GNU General Public License |
|---|
| 21 | * along with this program; if not, write to the Free Software |
|---|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | */ |
|---|
| 24 | /* |
|---|
| 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. |
|---|
| 26 | ** |
|---|
| 27 | ** All rights reserved. |
|---|
| 28 | ** |
|---|
| 29 | ** No one may duplicate this source code in any form for any reason |
|---|
| 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. |
|---|
| 31 | ** |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | #ifndef JDKMIDI_PARSER_H |
|---|
| 35 | #define JDKMIDI_PARSER_H |
|---|
| 36 | |
|---|
| 37 | #include "jdkmidi/midi.h" |
|---|
| 38 | #include "jdkmidi/msg.h" |
|---|
| 39 | #include "jdkmidi/sysex.h" |
|---|
| 40 | |
|---|
| 41 | namespace jdkmidi |
|---|
| 42 | { |
|---|
| 43 | |
|---|
| 44 | class MIDIParser |
|---|
| 45 | { |
|---|
| 46 | public: |
|---|
| 47 | MIDIParser ( ushort max_sysex_size=384 ); |
|---|
| 48 | virtual ~MIDIParser(); |
|---|
| 49 | |
|---|
| 50 | void Clear() |
|---|
| 51 | { |
|---|
| 52 | state=FIND_STATUS; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | virtual bool Parse ( uchar b, MIDIMessage *msg ); |
|---|
| 56 | |
|---|
| 57 | MIDISystemExclusive *GetSystemExclusive() const |
|---|
| 58 | { |
|---|
| 59 | return sysex; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | protected: |
|---|
| 63 | |
|---|
| 64 | // |
|---|
| 65 | // The states used for parsing messages. |
|---|
| 66 | // |
|---|
| 67 | |
|---|
| 68 | enum State |
|---|
| 69 | { |
|---|
| 70 | FIND_STATUS, // ignore data bytes |
|---|
| 71 | FIRST_OF_ONE, // read first data byte of a one data byte msg |
|---|
| 72 | FIRST_OF_TWO, // read first data byte of two data byte msg |
|---|
| 73 | SECOND_OF_TWO, // read second data byte of two data byte msg |
|---|
| 74 | FIRST_OF_ONE_NORUN, // read one byte message, do not allow |
|---|
| 75 | // running status (for MTC) |
|---|
| 76 | SYSEX_DATA // read sysex data byte |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | MIDIMessage tmp_msg; |
|---|
| 80 | MIDISystemExclusive *sysex; |
|---|
| 81 | State state; |
|---|
| 82 | |
|---|
| 83 | bool ParseSystemByte ( uchar b, MIDIMessage *msg ); |
|---|
| 84 | bool ParseDataByte ( uchar b, MIDIMessage *msg ); |
|---|
| 85 | void ParseStatusByte ( uchar b ); |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | #endif |
|---|
| 92 | |
|---|