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