]> git.donarmstrong.com Git - lilypond.git/blob - mi2mu/main.cc
f447a181dbc21fbd1a3e868df4b5388a016a8391
[lilypond.git] / mi2mu / main.cc
1 //
2 // main.cc -- implement silly main() entry point
3 // should have Root class.
4 //
5 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6
7 #include "mi2mu.hh"
8 #include "path.hh"
9
10 Sources source;
11 Sources* source_l_g = &source;
12
13 Verbose level_ver = NORMAL_ver;
14
15 // ugh, another global
16 String
17 find_file( String str )
18 {
19     return str;
20 }
21
22 void
23 usage()
24 {
25     tor( NORMAL_ver ) <<
26         "Usage: mi2mu [options] midi-file\n"
27         "Translate midi-file to mudela\n"
28         "\n"
29         "Options:\n"
30         "  -b, --no-quantify      write exact durations, e.g.: a4*385/384\n"
31         "  -d, --debug            print lots of debugging stuff\n"
32         "  -h, --help             this help\n"
33         "  -I, --include=DIR      add DIR to search path\n"
34         "  -n, --no-silly         assume no plets or double dots, smallest is 32\n"
35         "  -o, --output=FILE      set FILE as default output\n"
36         "  -p, --no-plets         assume no plets\n"
37         "  -q, --quiet            be quiet\n"
38         "  -s, --smallest=N       assume no shorter (reciprocal) durations than N\n"
39         "  -v, --verbose          be verbose\n"
40         "  -w, --warranty         show warranty and copyright\n"
41         "  -x, --no-double-dots   assume no double dotted notes\n"
42         ;
43 }
44
45 void
46 identify()
47 {
48         tor( NORMAL_ver ) << mi2mu_version_str() << endl;
49 }
50     
51 void 
52 notice()
53 {
54     tor( NORMAL_ver ) <<
55         "\n"
56         "Mi2mu, translate midi to mudela.\n"
57         "Copyright (C) 1997 by\n"
58         "  Jan Nieuwenhuizen <jan@digicash.com>\n"
59         "  Han-Wen Nienhuys <hanwen@stack.nl>\n"
60         "\n"
61         "    This program is free software; you can redistribute it and/or\n"
62         "modify it under the terms of the GNU General Public License version 2\n"
63         "as published by the Free Software Foundation.\n"
64         "\n"
65         "    This program is distributed in the hope that it will be useful,\n"
66         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
67         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
68         "General Public License for more details.\n"
69         "\n"
70         "    You should have received a copy (refer to the file COPYING) of the\n"
71         "GNU General Public License along with this program; if not, write to\n"
72         "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
73         "USA.\n";
74 }
75
76 int
77 main( int argc_i, char* argv_sz_a[] )
78 {
79         Long_option_init long_option_init_a[] = {
80                 {0, "no-quantify", 'b'},
81                 {0, "debug", 'd'},
82                 {0, "help", 'h'},
83                 {0, "no-silly", 'n'},
84                 {1, "output", 'o'},
85                 {0, "no-plets", 'p'},
86                 {0, "quiet", 'q'},
87                 {1, "smallest", 's'},
88                 {0, "verbose", 'v'},
89                 {0, "warranty", 'w'},
90                 {0, "no-double-dots", 'x'},
91                 {0,0,0}
92         };
93         Getopt_long getopt_long( argc_i, argv_sz_a, long_option_init_a );
94
95         String output_str;
96         while ( Long_option_init* long_option_init_p = getopt_long() )
97                 switch ( long_option_init_p->shortname ) {
98                 case 'b':
99                         Duration_convert::no_quantify_b_s = true;
100                         break;
101                 case 'd':
102                         level_ver = DEBUG_ver;
103                         break;
104                 case 'h':
105                         identify();
106                         usage();
107                         exit( 0 );
108                         break;
109 //              case 'I':
110 //                      path->push( getopt_long.optarg );
111 //                      break;
112                 case 'n':
113                         Duration_convert::no_double_dots_b_s = true;
114                         Duration_convert::no_triplets_b_s = true;
115                         Duration_convert::no_smaller_than_i_s = 32;
116                         break;
117                 case 'o':
118                         output_str = getopt_long.optarg;
119                         break;
120                 case 'p':
121                         Duration_convert::no_triplets_b_s = true;
122                         break;
123                 case 'q':
124                         level_ver = QUIET_ver;
125                         break;
126                 case 's': {
127                                 int i = String_convert::dec2_i( getopt_long.optarg );
128                                 if ( !i ) {
129                                         identify();
130                                         usage();
131                                         exit( 2 ); //usage
132                                 }
133                                 Duration_convert::no_smaller_than_i_s = i;
134                         }
135                         break;
136                 case 'v':
137                         level_ver = VERBOSE_ver;
138                         break;
139                 case 'w':
140                         identify();
141                         notice();
142                         exit( 0 );
143                         break;
144                 case 'x':
145                         Duration_convert::no_double_dots_b_s = true;
146                         break;
147                 default:
148                         assert( 0 );
149                         break;
150                 }
151   
152         // flag -q must be checked first
153         identify();
154
155         char* arg_sz = 0;
156         while ( ( arg_sz = getopt_long.get_next_arg() ) ) {
157                 My_midi_parser midi_parser( arg_sz, & source );
158                 midi_parser_l_g = &midi_parser;
159
160                 int error_i = midi_parser.parse();
161                 if ( error_i )
162                         return error_i;
163                 if ( !output_str.length_i() ) {
164                     String d, dir, base, ext;
165
166                     split_path(arg_sz, d, dir, base, ext);
167                     
168                     output_str = base + ext + ".ly";
169                 }
170                 error_i = midi_parser.output_mudela( output_str );
171                 if ( error_i )
172                         return error_i;
173                 midi_parser_l_g = 0;
174         }
175         return 0;
176 }