1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: snd_MidiStreamParser.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_SND_MIDI_STREAM_PARSER_H_ 19 #define NW_SND_MIDI_STREAM_PARSER_H_ 20 21 namespace nw { 22 namespace snd { 23 namespace internal { 24 25 /* ======================================================================== 26 class definition 27 ======================================================================== */ 28 29 class MidiStreamParser 30 { 31 public: 32 typedef void (*MidiCallback)( u8 status, u8 data1, u8 data2, void* arg ); 33 34 MidiStreamParser(); 35 void SetCallback( MidiCallback callback, void* arg ); 36 void Parse( const void* buffer, unsigned long size ); 37 void Reset(); 38 39 private: 40 struct MidiMsgBuffer 41 { 42 const u8* ptr; 43 u32 len; 44 u32 readPos; 45 u32 donePos; 46 }; 47 48 bool ReadByte( u8* data ); 49 bool PeakByte( u8* data ); 50 void BackByte( u8 byte ); 51 void EatByte(); 52 void SetMsgBuffer( const void* buffer, u32 len ); 53 void ParseBuffer(); 54 void RestBuffer(); 55 bool SeekStatusByte(); 56 IsDataByte(u8 b)57 static bool IsDataByte( u8 b ) { return ( b & 0x80 ) ? false : true; } IsStatusByte(u8 b)58 static bool IsStatusByte( u8 b ) { return ( b & 0x80 ) ? true : false; } IsRealtimeMesg(u8 b)59 static bool IsRealtimeMesg( u8 b ) { return ( b >= 0xf8 ) ? true : false; } IsSystemResetMesg(u8 b)60 static bool IsSystemResetMesg( u8 b ) { return ( b == 0xff ) ? true : false; } 61 62 MidiCallback m_CallbackFunc; 63 void* m_pCallbackArg; 64 65 MidiMsgBuffer m_MsgBuffer; 66 MidiMsgBuffer m_RestBuffer; 67 68 u8 m_RestBuf[256]; 69 bool m_IsReset; 70 bool m_IsSysEx; 71 u8 m_RunningStatus; 72 u8 m_BackByte; 73 bool m_IsBackByteAvailable; 74 }; 75 76 } // namespace nw::snd::internal 77 } // namespace nw::snd 78 } // namespace nw 79 80 81 #endif /* NW_SND_MIDI_STREAM_PARSER_H_ */ 82 83