]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/include/midi-parser.hh
patch::: 0.1.9.jcn2: pats
[lilypond.git] / mi2mu / include / midi-parser.hh
1 /*
2   midi-parser.hh -- declare Midi_parser
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
7 */
8
9
10 #ifndef MIDI_PARSER_HH
11 #define MIDI_PARSER_HH
12
13 // must, gcc 2.7.2{,.1} hits ico on midi-track-parser.cc:134 (@Midi_note)
14 #define INLINES
15
16 #ifdef INLINES
17
18 #define next_byte() (inline_next_byte (__FUNCTION__))
19 #define peek_byte() (inline_peek_byte (__FUNCTION__))
20 #define forward_byte_L(n) (inline_forward_byte_L (__FUNCTION__, n))
21
22 #else
23
24 #define next_byte()\
25   ((info_l_->byte_L_ < info_l_->end_byte_L_ ?\
26     *info_l_->byte_L_++\
27    : (Byte const)exit (__FUNCTION__": unexpected EOF")));
28
29 #define peek_byte()\
30   ((info_l_->byte_L_ < info_l_->end_byte_L_ ?\
31     *info_l_->byte_L_\
32   : (Byte const)exit (__FUNCTION__": unexpected EOF")));
33
34 #define forward_byte_L(n) (inline_forward_byte_L (__FUNCTION__, n))
35
36 #endif
37
38 #include "proto.hh"
39 #include "moment.hh"
40
41 struct Midi_parser_info
42 {
43   Midi_parser_info();
44   int division_1_i_;
45   int format_i_;
46   int tracks_i_;
47   int errorlevel_i_;
48   Byte const* byte_L_;
49   Byte const* end_byte_L_;
50   Source_file* source_l_;
51   Moment bar_mom_;
52 };
53
54 #include "string.hh"
55
56 class Midi_parser
57 {
58 public:
59   Midi_parser ();
60
61   Midi_parser_info* info_l_;
62
63 protected:
64 //  Byte const* inline_forward_byte_L (int n)
65   Byte const* inline_forward_byte_L (char const* fun, int n)
66   {
67     if (info_l_->byte_L_ + n < info_l_->end_byte_L_ )
68       {
69       Byte const* p = info_l_->byte_L_;
70       info_l_->byte_L_ += n;
71       return p;
72     }
73 //    exit (__FUNCTION__": unexpected EOF");
74     exit (String (fun) + ": unexpected EOF");
75     return 0;
76   }
77
78 #ifdef INLINES
79 //  Byte inline_next_byte () 
80   Byte inline_next_byte (char const* fun) 
81     {
82       if (info_l_->byte_L_ < info_l_->end_byte_L_)
83          return *info_l_->byte_L_++;
84 //    exit (__FUNCTION__": unexpected EOF");
85       exit (String (fun) + ": unexpected EOF");
86       return 0;
87     }
88
89 //  Byte inline_peek_byte ()
90   Byte inline_peek_byte (char const* fun)
91     {
92       if (info_l_->byte_L_ < info_l_->end_byte_L_)
93         return *info_l_->byte_L_;
94 //      exit (__FUNCTION__": unexpected EOF");
95       exit (String (fun) + ": unexpected EOF");
96       return 0;
97     }
98 #endif
99
100   int get_i (int);
101   String get_str (int);
102   unsigned get_u (int);
103   int get_var_i ();
104   int exit (String);
105   void error (String);
106   String message (String);
107   void warning (String);
108 };
109
110 #endif // MIDI_PARSER_HH