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