2 // main.cc -- implement silly main() entry point
3 // should have Root class.
5 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
8 #include "string-convert.hh"
11 #include "duration-convert.hh"
14 #include "mi2mu-global.hh"
15 #include "midi-score-parser.hh"
16 #include "mudela-item.hh"
17 #include "mudela-score.hh"
21 String filename_str_g
;
24 Mudela_score
* mudela_score_l_g
= 0;
28 static File_path path
;
30 Verbose level_ver
= NORMAL_ver
;
32 /// just to make sure print_rat is linked in
33 static void (*rat_printer
)(Moment
const&);
39 "Usage: mi2mu [options] midi-file\n"
40 "Translate midi-file to mudela\n"
43 " -b, --no-quantify write exact durations, e.g.: a4*385/384\n"
44 " -d, --debug print lots of debugging stuff\n"
45 " -h, --help this help\n"
46 " -I, --include=DIR add DIR to search path\n"
47 " -k, --key=ACC[:MINOR] set key: ACC +sharps/-flats; :1 minor\n"
48 " -n, --no-silly assume no plets or double dots, smallest is 32\n"
49 " -o, --output=FILE set FILE as default output\n"
50 " -p, --no-plets assume no plets\n"
51 " -q, --quiet be quiet\n"
52 " -s, --smallest=N assume no shorter (reciprocal) durations than N\n"
53 " -v, --verbose be verbose\n"
54 " -w, --warranty show warranty and copyright\n"
55 " -x, --no-double-dots assume no double dotted notes\n"
62 LOGOUT(NORMAL_ver
) << mi2mu_version_str() << endl
;
70 "Mi2mu, translate midi to mudela.\n"
71 "Copyright (C) 1997 by\n"
72 " Jan Nieuwenhuizen <jan@digicash.com>\n"
73 " Han-Wen Nienhuys <hanwen@stack.nl>\n"
75 " This program is free software; you can redistribute it and/or\n"
76 "modify it under the terms of the GNU General Public License version 2\n"
77 "as published by the Free Software Foundation.\n"
79 " This program is distributed in the hope that it will be useful,\n"
80 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
81 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
82 "General Public License for more details.\n"
84 " You should have received a copy (refer to the file COPYING) of the\n"
85 "GNU General Public License along with this program; if not, write to\n"
86 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
91 main (int argc_i
, char* argv_sz_a
[])
93 Mudela_key
key (0, 0);
94 rat_printer
= print_rat
;
96 Long_option_init long_option_init_a
[] =
98 {0, "no-quantify", 'b'},
102 {0, "no-silly", 'n'},
104 {0, "no-plets", 'p'},
106 {1, "smallest", 's'},
108 {0, "warranty", 'w'},
109 {0, "no-double-dots", 'x'},
112 Getopt_long
getopt_long (argc_i
, argv_sz_a
, long_option_init_a
);
115 while (Long_option_init
const* long_option_init_p
= getopt_long())
116 switch (long_option_init_p
->shortname
)
119 Duration_convert::no_quantify_b_s
= true;
122 level_ver
= DEBUG_ver
;
130 // path->push (getopt_long.optional_argument_ch_C_);
134 String str
= getopt_long
.optional_argument_ch_C_
;
135 int i
= str
.index_i (':');
136 i
= (i
>=0 ? i
: str
.length_i ());
137 key
.accidentals_i_
= String_convert::dec2_i (str
.left_str (i
));
138 key
.minor_i_
= (int)(bool)String_convert::dec2_i (str
.mid_str (i
,1));
142 Duration_convert::no_double_dots_b_s
= true;
143 Duration_convert::no_triplets_b_s
= true;
144 Duration_convert::no_smaller_than_i_s
= 5;
147 output_str
= getopt_long
.optional_argument_ch_C_
;
150 Duration_convert::no_triplets_b_s
= true;
153 level_ver
= QUIET_ver
;
157 int i
= String_convert::dec2_i (getopt_long
.optional_argument_ch_C_
);
164 Duration_convert::no_smaller_than_i_s
=
165 Duration_convert::i2_type(i
);
169 level_ver
= VERBOSE_ver
;
177 Duration_convert::no_double_dots_b_s
= true;
184 // flag -q must be checked first
188 source
.set_binary (true);
189 source
.set_path (&path
);
191 char const* arg_sz
= 0;
192 while ( (arg_sz
= getopt_long
.get_next_arg ()))
194 filename_str_g
= arg_sz
;
195 Midi_score_parser midi_parser
;
196 Mudela_score
* score_p
= midi_parser
.parse (arg_sz
, &source
);
201 if (!score_p
->mudela_key_l_
)
202 score_p
->mudela_key_l_
= &key
;
203 mudela_score_l_g
= score_p
;
206 if (!output_str
.length_i ())
208 String d
, dir
, base
, ext
;
209 split_path (arg_sz
, d
, dir
, base
, ext
);
210 output_str
= base
+ ext
+ ".ly";
213 score_p
->output (output_str
);