2 // main.cc -- implement main () entry point
4 // copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "string-convert.hh"
11 #include "getopt-long.hh"
12 #include "file-path.hh"
13 #include "duration-convert.hh"
16 #include "midi2ly-global.hh"
17 #include "midi-score-parser.hh"
18 #include "mudela-item.hh"
19 #include "mudela-score.hh"
27 String filename_str_g;
30 Mudela_score* mudela_score_l_g = 0;
32 bool no_timestamps_b_g = false;
33 bool no_rests_b_g = false;
37 static File_path path;
39 Verbose level_ver = NORMAL_ver;
45 cout << midi2ly_version_str() << endl;
55 "This is free software. It is covered by the GNU General Public License,\n"
56 "and you are welcome to change it and/or distribute copies of it under\n"
57 "certain conditions. Invoke as `%s --warranty' for more information.\n",
61 cout << _f ("Copyright (c) %s by", "1996--2000");
62 cout << "Han-Wen Nienhuys <hanwen@cs.uu.nl>\n"
63 << "Jan Nieuwenhuizen <janneke@gnu.org>\n";
70 " This program is free software; you can redistribute it and/or\n"
71 "modify it under the terms of the GNU General Public License version 2\n"
72 "as published by the Free Software Foundation.\n"
74 " This program is distributed in the hope that it will be useful,\n"
75 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
76 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
77 "General Public License for more details.\n"
79 " You should have received a copy (refer to the file COPYING) of the\n"
80 "GNU General Public License along with this program; if not, write to\n"
81 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
86 Internationalisation kludge in two steps:
87 * use _i () to get entry in POT file
88 * call gettext () explicitely for actual "translation"
90 Long_option_init long_option_init_a[] =
92 {0, "no-quantify", 'b', _i ("write exact durations, e.g.: a4*385/384")},
93 {0, "debug", 'd', _i ("enable debugging output")},
94 {0, "help", 'h', _i ("this help")},
95 {_i ("ACC[:MINOR]"), "key", 'k', _i ("set key: ACC +sharps/-flats; :1 minor")},
96 {0, "no-silly", 'n', _i ("don't output tuplets, double dots or rests, smallest is 32")},
97 {_i ("FILE"), "output", 'o', _i ("set FILE as default output")},
98 {0, "no-tuplets", 'p', _i ("don't output tuplets")},
99 {0, "quiet", 'q', _i ("be quiet")},
100 {0, "no-rests", 'r', _i ("don't output rests or skips")},
101 {_i ("DUR"), "smallest", 's', _i ("set smallest duration")},
102 {0, "no-timestamps", 'T', _i ("don't timestamp the output")},
103 {0, "version", 'V', _i ("print version number")},
104 {0, "verbose", 'v', _i ("be verbose")},
105 {0, "warranty", 'w', _i ("show warranty and copyright")},
106 {0, "no-double-dots", 'x', _i ("assume no double dotted notes")},
113 cout << _f ("Usage: %s [OPTION]... [FILE]", "midi2ly");
115 cout << _ ("Translate MIDI-file to mudela");
118 cout << _ ("Options:");
120 cout << Long_option_init::table_str (long_option_init_a) << endl;
122 cout << _f ("Report bugs to %s", "bug-gnu-music@gnu.org") << endl;
128 LOGOUT (VERBOSE_ver) << "\n";
129 LOGOUT (VERBOSE_ver) << _f ("no_double_dots: %d\n",
130 Duration_convert::no_double_dots_b_s);
131 LOGOUT (VERBOSE_ver) << _f ("no_rests: %d\n",
133 LOGOUT (VERBOSE_ver) << _f ("no_quantify_b_s: %d\n",
134 Duration_convert::no_quantify_b_s);
135 LOGOUT (VERBOSE_ver) << _f ("no_smaller_than: %d (1/%d)\n",
136 Duration_convert::no_smaller_than_i_s,
137 Duration_convert::type2_i (Duration_convert::no_smaller_than_i_s));
138 LOGOUT (VERBOSE_ver) << _f ("no_tuplets: %d\n",
139 Duration_convert::no_tuplets_b_s);
143 main (int argc_i, char* argv_sz_a[])
147 setlocale (LC_ALL, ""); /* enable locales */
148 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in output */
149 String name (PACKAGE);
151 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
152 textdomain (name.ch_C ()) ;
155 bool key_override_b = false;
156 Mudela_key key (0, 0);
159 Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a);
162 while (Long_option_init const* long_option_init_p = getopt_long())
163 switch (long_option_init_p->shortname_ch_)
166 Duration_convert::no_quantify_b_s = true;
169 level_ver = DEBUG_ver;
176 // path->push (getopt_long.optional_argument_ch_C_);
180 String str = getopt_long.optional_argument_ch_C_;
181 int i = str.index_i (':');
182 i = (i >=0 ? i : str.length_i ());
183 key.accidentals_i_ = String_convert::dec2_i (str.left_str (i));
184 key.minor_i_ = (int)(bool)String_convert::dec2_i (str.cut_str (i + 1, str.length_i ()));
185 key_override_b = true;
189 Duration_convert::no_double_dots_b_s = true;
190 Duration_convert::no_tuplets_b_s = true;
191 Duration_convert::no_smaller_than_i_s = 5;
195 output_str = getopt_long.optional_argument_ch_C_;
198 Duration_convert::no_tuplets_b_s = true;
201 level_ver = QUIET_ver;
207 no_timestamps_b_g = true;
211 int i = String_convert::dec2_i (getopt_long.optional_argument_ch_C_);
218 Duration_convert::no_smaller_than_i_s =
219 Duration_convert::i2_type(i);
223 level_ver = VERBOSE_ver;
236 Duration_convert::no_double_dots_b_s = true;
243 // flag -q must be checked first
247 source.set_binary (true);
248 source.set_path (&path);
250 char const* arg_sz = 0;
251 while ( (arg_sz = getopt_long.get_next_arg ()))
254 filename_str_g = arg_sz;
255 Midi_score_parser midi_parser;
256 Mudela_score* score_p = midi_parser.parse (arg_sz, &source);
261 // if given on command line: override
262 if (key_override_b || !score_p->mudela_key_l_)
263 score_p->mudela_key_l_ = &key;
264 mudela_score_l_g = score_p;
267 if (!output_str.length_i ())
269 String d, dir, base, ext;
270 split_path (arg_sz, d, dir, base, ext);
271 output_str = base + ext + ".ly";
274 score_p->output (output_str);