lilypond-1.3.145
[lilypond.git] / midi2ly / midi-parser.cc
blobed9c5a49e3c0cf719ad2182ebd3a20cf87442e63
1 /*
2 midi-parser.cc -- implement Midi_parser[_info]
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include <assert.h>
10 #include "string-convert.hh"
11 #include "source-file.hh"
12 #include "midi2ly-global.hh"
13 #include "midi-parser.hh"
15 Midi_parser_info::Midi_parser_info ()
17 division_1_i_ = 0;
18 format_i_ = 0;
19 tracks_i_ = 0;
20 errorlevel_i_ = 0;
21 byte_L_ = 0;
22 end_byte_L_ = 0;
23 score_l_ = 0;
26 Midi_parser::Midi_parser ()
28 info_l_ = 0;
31 int
32 Midi_parser::exit (String str)
34 error (str);
35 ::exit (1);
36 return 0;
39 void
40 Midi_parser::error (String str)
42 ::message (message (str));
45 int
46 Midi_parser::get_i (int n)
48 assert (n <= (int)sizeof(int));
49 return String_convert::bin2_i (get_str (n));
52 unsigned
53 Midi_parser::get_u (int n)
55 assert (n <= (int)sizeof(int));
56 return String_convert::bin2_u (get_str (n));
59 String
60 Midi_parser::get_str (int n)
62 assert (n >= 0);
63 if (!n)
64 warning (_ ("zero length string encountered"));
66 Byte const* p = forward_byte_L (n);
67 return String (p, n);
70 int
71 Midi_parser::get_var_i ()
73 int var_i = 0;
75 while (1)
77 Byte byte = next_byte ();
78 var_i <<= 7;
79 var_i += byte & 0x7f;
80 if (!(byte & 0x80))
81 return var_i;
83 exit ("get_var_i:");
84 return 0;
87 String
88 Midi_parser::message (String str)
90 return String ("midi2ly: ")
91 + info_l_->source_l_->name_str () + ": "
92 + String_convert::i2dec_str (info_l_->source_l_->line_i ((char const*)info_l_->byte_L_), 0, 0) + ": "
93 + str + "\n"
94 + info_l_->source_l_->error_str ((char const*)info_l_->byte_L_);
97 void
98 Midi_parser::warning (String str)
100 ::message (message (String (_ ("warning: ")) + str));