]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/midi-parser.cc
ad8e020d263c98c42edb39e9806cfdf15f190346
[lilypond.git] / mi2mu / midi-parser.cc
1 /*
2   midi-parser.cc -- implement Midi_parser[_info]
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Jan Nieuwenhuizen <jan@digicash.com>
7 */
8
9 #include <assert.h>
10 #include "string-convert.hh"
11 #include "source-file.hh"
12 #include "mi2mu-global.hh"
13 #include "midi-parser.hh"
14
15 Midi_parser_info::Midi_parser_info ()
16 {
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;
24 }
25
26 Midi_parser::Midi_parser ()
27 {
28   info_l_ = 0;
29 }
30
31 int
32 Midi_parser::exit (String str)
33 {
34   error (str);
35   ::exit (1);
36   return 0;
37 }
38
39 void
40 Midi_parser::error (String str)
41 {
42   ::message (message (str));
43 }
44
45 int
46 Midi_parser::get_i (int n)
47 {
48   assert (n <= (int)sizeof(int));
49   return String_convert::bin2_i (get_str (n));
50 }
51
52 unsigned
53 Midi_parser::get_u (int n)
54 {
55   assert (n <= (int)sizeof(int));
56   return String_convert::bin2_i (get_str (n));
57 }
58
59 String
60 Midi_parser::get_str (int n)
61 {
62   assert (n >= 0);
63   if (!n)
64     warning (_("Zero length string encountered"));
65
66   Byte const* p = forward_byte_L (n);
67   return String (p, n);
68 }
69
70 int
71 Midi_parser::get_var_i ()
72 {
73   int var_i = 0;
74
75   while (1)
76     {
77       Byte byte = next_byte ();
78       var_i <<= 7;
79       var_i += byte & 0x7f;
80       if (!(byte & 0x80))
81         return var_i;
82     }
83   exit ("get_var_i:");
84   return 0;
85 }
86
87 String
88 Midi_parser::message (String str)
89 {
90   return String ("mi2mu: ")
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_);
95 }
96
97 void
98 Midi_parser::warning (String str)
99 {
100   ::message (message (String (_("warning: ")) + str));
101 }