]> git.donarmstrong.com Git - lilypond.git/blob - midi2ly/include/midi-parser.hh
patch::: 1.5.18.moh1: [PATCH] 1.4 Lyric alignment
[lilypond.git] / midi2ly / 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--1998 Jan Nieuwenhuizen <janneke@gnu.org>
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 "flower-proto.hh"
39 #include "rational.hh"
40 #include "midi2ly-proto.hh"
41
42 struct Midi_parser_info
43 {
44   Midi_parser_info();
45   int division_1_i_;
46   int format_i_;
47   int tracks_i_;
48   int errorlevel_i_;
49   Byte const* byte_L_;
50   Byte const* end_byte_L_;
51   Source_file* source_l_;
52   Lilypond_score* score_l_;
53   Rational bar_mom_;
54 };
55
56 #include "string.hh"
57
58 class Midi_parser
59 {
60 public:
61   Midi_parser ();
62
63   Midi_parser_info* info_l_;
64
65 protected:
66   Byte const* inline_forward_byte_L (char const* fun, int n)
67   {
68     if (info_l_->byte_L_ + n < info_l_->end_byte_L_ )
69       {
70       Byte const* p = info_l_->byte_L_;
71       info_l_->byte_L_ += n;
72       return p;
73     }
74     exit (String (fun) + ": unexpected EOF");
75     return 0;
76   }
77
78 #ifdef INLINES
79   Byte inline_next_byte (char const* fun) 
80     {
81       if (info_l_->byte_L_ < info_l_->end_byte_L_)
82          return *info_l_->byte_L_++;
83       exit (String (fun) + ": unexpected EOF");
84       return 0;
85     }
86
87   Byte inline_peek_byte (char const* fun)
88     {
89       if (info_l_->byte_L_ < info_l_->end_byte_L_)
90         return *info_l_->byte_L_;
91       exit (String (fun) + ": unexpected EOF");
92       return 0;
93     }
94 #endif
95
96   int get_i (int);
97   String get_str (int);
98   unsigned get_u (int);
99   int get_var_i ();
100   int exit (String);
101   void error (String);
102   String message (String);
103   void warning (String);
104 };
105
106 #endif // MIDI_PARSER_HH