]> git.donarmstrong.com Git - lilypond.git/blob - src/midi-main.cc
5b6ecb3e2d73c4d68ea8fe599286d2b68e3eecd6
[lilypond.git] / src / midi-main.cc
1 //
2 // midi-main.cc -- implement silly main() entry point
3 // should have Root class.
4 //
5 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6
7 #include <iostream.h>
8 #include "proto.hh"
9 #include "plist.hh"
10 #include "version.hh"
11 #include "fversion.hh"
12 #include "string.hh"
13 #include "lgetopt.hh"
14 #include "source.hh"
15 #include "sourcefile.hh"
16 #include "midi-main.hh"
17 #include "moment.hh"
18 #include "midi-event.hh"
19 #include "midi-track.hh"
20 #include "my-midi-lexer.hh"
21 #include "my-midi-parser.hh"
22
23 Source source;
24 Source* source_l_g = &source;
25
26 Verbose level_ver = NORMAL_ver;
27
28 //ugh
29 char const* defined_ch_c_l = 0;
30
31 // ugh, another global
32 String
33 find_file( String str )
34 {
35     return str;
36 }
37
38 // ugh, copied from warn.cc, cannot use
39 void
40 message( String message_str, char const* context_ch_c_l )
41 {
42     String str = "m2m: ";
43     Source_file* sourcefile_l = source_l_g->sourcefile_l( context_ch_c_l );
44     if ( sourcefile_l ) {
45         str += sourcefile_l->file_line_no_str(context_ch_c_l) + String(": ");
46     }
47     str += message_str;
48     if ( sourcefile_l ) {
49         str += ":\n";
50         str += sourcefile_l->error_str( context_ch_c_l );
51     }
52 //    if ( busy_parsing() )
53 //      cerr << endl;
54     cerr << str << endl;
55 }
56
57 void
58 warning( String message_str, char const* context_ch_c_l )
59 {
60     message( "warning: " + message_str, context_ch_c_l );
61 }
62
63 void
64 error( String message_str, char const* context_ch_c_l )
65 {
66     message( message_str, context_ch_c_l );
67     // since when exits error again?
68     // i-d say: error: errorlevel |= 1; -> no output upon error
69     //          warning: recovery -> output (possibly wrong)
70     if ( midi_lexer_l_g )
71         midi_lexer_l_g->errorlevel_i_ |= 1;
72 }
73
74 void
75 help()
76 {
77     btor <<
78         "--debug, -d            be really verbose\n"
79         "--help, -h             This help\n"
80         "--include, -I          add to file search path.\n"
81         "--output, -o           set default output\n"
82         "--quiet, -q            be quiet\n"
83         "--verbose, -v          be verbose\n"
84         "--warranty, -w         show warranty & copyright\n"
85         ;
86 }
87
88 void
89 identify()
90 {
91         mtor << "This is m2m "  << VERSIONSTR << "/FlowerLib " << FVERSIONSTR
92                 << " of " << __DATE__ << " " << __TIME__ << endl;
93 }
94     
95 void 
96 notice()
97 {
98     mtor <<
99         "\n"
100         "M2m, translate midi to mudela.\n"
101         "Copyright (C) 1997 by\n"
102         "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
103 //      "Contributors\n"
104         "  Jan Nieuwenhuizen <jan@digicash.com>\n"
105 //      "  Mats Bengtsson <matsb@s3.kth.se>\n"
106         "\n"
107         "    This program is free software; you can redistribute it and/or\n"
108         "modify it under the terms of the GNU General Public License version 2\n"
109         "as published by the Free Software Foundation.\n"
110         "\n"
111         "    This program is distributed in the hope that it will be useful,\n"
112         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
113         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
114         "General Public License for more details.\n"
115         "\n"
116         "    You should have received a copy (refer to the file COPYING) of the\n"
117         "GNU General Public License along with this program; if not, write to\n"
118         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
119         "USA.\n";
120 }
121
122 int
123 main( int argc_i, char* argv_sz_a[] )
124 {
125         long_option_init long_option_init_a[] = {
126                 0, "debug", 'd',
127                 0, "help", 'h',
128 //              1, "include", 'I',
129                 1, "output", 'o',
130                 0, "quiet", 'q',
131                 0, "verbose", 'v',
132                 0, "warranty", 'w',
133                 0,0,0
134         };
135         Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a );
136         identify();
137
138         String output_str;
139         while ( long_option_init* long_option_init_p = getopt_long() )
140                 switch ( long_option_init_p->shortname ) {
141                         case 'd':
142                                 level_ver = DEBUG_ver;
143                                 break;
144                         case 'h':
145                                 help();
146                                 exit( 0 );
147                                 break;
148 //                      case 'I':
149 //                              path->push( getopt_long.optarg );
150 //                              break;
151                         case 'o':
152                                 output_str = getopt_long.optarg;
153                                 break;
154                         case 'q':
155                                 level_ver = QUIET_ver;
156                                 break;
157                         case 'v':
158                                 level_ver = VERBOSE_ver;
159                                 break;
160                         case 'w':
161                                 notice();
162                                 exit( 0 );
163                                 break;
164                         default:
165                                 assert( 0 );
166                                 break;
167                 }
168
169         char* arg_sz = 0;
170         while ( ( arg_sz = getopt_long.get_next_arg() ) ) {
171                 My_midi_parser midi_parser( arg_sz );
172                 int error_i = midi_parser.parse();
173                 if ( error_i )
174                         return error_i;
175                 error_i = midi_parser.output( output_str );
176                 if ( error_i )
177                         return error_i;
178         }
179         return 0;
180 }