]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/midi-parser.cc
patch::: 0.1.9.jcn2: pats
[lilypond.git] / mi2mu / midi-parser.cc
1 /*
2   midi-parser.cc -- implement 
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 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 }
24
25 Midi_parser::Midi_parser ()
26 {
27   info_l_ = 0;
28 }
29
30 int
31 Midi_parser::exit (String str)
32 {
33   error (str);
34   ::exit (1);
35   return 0;
36 }
37
38 void
39 Midi_parser::error (String str)
40 {
41   ::message (message (str));
42 }
43
44 int
45 Midi_parser::get_i (int n)
46 {
47   assert (n <= (int)sizeof(int));
48   return String_convert::bin2_i (get_str (n));
49 }
50
51 unsigned
52 Midi_parser::get_u (int n)
53 {
54   assert (n <= (int)sizeof(int));
55   return String_convert::bin2_i (get_str (n));
56 }
57
58 String
59 Midi_parser::get_str (int n)
60 {
61   assert (n > 0);
62   Byte const* p = forward_byte_L (n);
63   return String (p, n);
64 }
65
66 int
67 Midi_parser::get_var_i ()
68 {
69   int var_i = 0;
70
71   while (1)
72     {
73       Byte byte = next_byte ();
74       var_i <<= 7;
75       var_i += byte & 0x7f;
76       if (!(byte & 0x80))
77         return var_i;
78     }
79   exit ("get_var_i:");
80   return 0;
81 }
82
83 String
84 Midi_parser::message (String str)
85 {
86   return String ("mi2mu: ") 
87     + info_l_->source_l_->name_str () + ": "
88     + String_convert::i2dec_str (info_l_->source_l_->line_i ((char const*)info_l_->byte_L_), 0, 0) + ": "
89     + str + "\n"
90     + info_l_->source_l_->error_str ((char const*)info_l_->byte_L_);
91 }
92
93 void
94 Midi_parser::warning (String str)
95 {
96   ::message (message (String ("warning: ") + str));
97 }