1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_MmlParser.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_MML_PARSER_H_
19 #define NW_SND_MML_PARSER_H_
20 
21 #include <nw/snd/snd_SequenceTrack.h>
22 
23 namespace nw {
24 namespace snd {
25 namespace internal {
26 namespace driver {
27 
28 class MmlSequenceTrack;
29 class SequenceSoundPlayer;
30 
31 /* ========================================================================
32         class definition
33    ======================================================================== */
34 
35 class MmlParser
36 {
37 public:
38     static const int PAN_CENTER = 64;
39     static const int SURROUND_PAN_CENTER = 64;
40     static const int CALL_STACK_DEPTH   = 3;
41     static const int TEMPO_MIN = 0;
42     static const int TEMPO_MAX = 1023;
43 
44 private:
45     enum SeqArgType
46     {
47         SEQ_ARG_NONE,
48         SEQ_ARG_U8,
49         SEQ_ARG_S16,
50         SEQ_ARG_VMIDI,
51         SEQ_ARG_RANDOM,
52         SEQ_ARG_VARIABLE
53     };
54 
55 public:
56     SequenceTrack::ParseResult Parse(
57         MmlSequenceTrack* track,
58         bool doNoteOn
59     ) const;
60 
61     static u32 ParseAllocTrack( const void* baseAddress, u32 seqOffset, u32* allocTrack );
62 
EnablePrintVar(bool enble)63     static void EnablePrintVar( bool enble ) { mPrintVarEnabledFlag = enble; }
IsEnabledPrintVar()64     static bool IsEnabledPrintVar() { return mPrintVarEnabledFlag; }
65 
66 protected:
67     virtual void CommandProc(
68         MmlSequenceTrack* track,
69         u32 command,
70         s32 commandArg1,
71         s32 commandArg2
72     ) const;
73 
74     virtual void NoteOnCommandProc(
75         MmlSequenceTrack* track,
76         int key,
77         int velocity,
78         s32 length,
79         bool tieFlag
80     ) const;
81 
82 private:
83     static bool mPrintVarEnabledFlag;
84 
ReadByte(const u8 ** ptr)85     u8   ReadByte( const u8** ptr ) const { return *(*ptr)++; }
UnreadByte(const u8 ** ptr)86     void UnreadByte( const u8** ptr ) const { --(*ptr); }
87     u16  Read16( const u8** ptr ) const;
88     u32  Read24( const u8** ptr ) const;
89     s32  ReadVar( const u8** ptr ) const;
90     s32  ReadArg( const u8** ptr, SequenceSoundPlayer* player, SequenceTrack* track, SeqArgType argType ) const;
91     vs16* GetVariablePtr( SequenceSoundPlayer* player, SequenceTrack* track, int varNo ) const;
92 };
93 
94 } // namespace nw::snd::internal::driver
95 } // namespace nw::snd::internal
96 } // namespace nw::snd
97 } // namespace nw
98 
99 
100 #endif /* NW_SND_MML_PARSER_H_ */
101 
102