2 // main.cc -- implement main () entry point
4 // copyright 1997 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "string-convert.hh"
10 #include "getopt-long.hh"
11 #include "file-path.hh"
12 #include "duration-convert.hh"
15 #include "midi2ly-global.hh"
16 #include "midi-score-parser.hh"
17 #include "mudela-item.hh"
18 #include "mudela-score.hh"
26 String filename_str_g;
29 Mudela_score* mudela_score_l_g = 0;
31 bool no_timestamps_b_g = false;
35 static File_path path;
37 Verbose level_ver = NORMAL_ver;
43 cout << midi2ly_version_str() << endl;
53 "This is free software. It is covered by the GNU General Public License,"
54 "and you are welcome to change it and/or distribute copies of it under"
55 "certain conditions. Invoke as `%s --warranty' for more information.\n",
59 cout << _f ("Copyright (c) %s by", "1996--1999");
60 cout << "Han-Wen Nienhuys <hanwen@cs.uu.nl>\n"
61 << "Jan Nieuwenhuizen <janneke@gnu.org>\n";
68 " This program is free software; you can redistribute it and/or\n"
69 "modify it under the terms of the GNU General Public License version 2\n"
70 "as published by the Free Software Foundation.\n"
72 " This program is distributed in the hope that it will be useful,\n"
73 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
74 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
75 "General Public License for more details.\n"
77 " You should have received a copy (refer to the file COPYING) of the\n"
78 "GNU General Public License along with this program; if not, write to\n"
79 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
84 Internationalisation kludge in two steps:
85 * use _i () to get entry in POT file
86 * call gettext () explicitely for actual "translation"
88 Long_option_init long_option_init_a[] =
90 {0, "no-quantify", 'b', _i ("write exact durations, e.g.: a4*385/384")},
91 {0, "debug", 'd', _i ("enable debugging output")},
92 {0, "help", 'h', _i ("this help")},
93 {_i ("ACC[:MINOR]"), "key", 'k', _i ("set key: ACC +sharps/-flats; :1 minor")},
94 {0, "no-silly", 'n', _i ("assume no tuplets or double dots, smallest is 32")},
95 {_i ("FILE"), "output", 'o', _i ("set FILE as default output")},
96 {0, "no-tuplets", 'p', _i ("assume no tuplets")},
97 {0, "quiet", 'q', _i ("be quiet")},
98 {_i ("DUR"), "smallest", 's', _i ("Set smallest duration (?)")},
99 {0, "no-timestamps", 'T', _i ("don't timestamp the output")},
100 {0, "verbose", 'v', _i ("be verbose")},
101 {0, "warranty", 'w', _i ("show warranty and copyright")},
102 {0, "no-double-dots", 'x', _i ("assume no double dotted notes")},
103 {0, "version", 'V', _i ("print version number")},
110 cout << _f ("Usage: %s [OPTION]... [FILE]", "midi2ly");
112 cout << _ ("Translate midi-file to mudela");
115 cout << _ ("Options:");
117 cout << Long_option_init::table_str (long_option_init_a) << endl;
119 cout << _("Report bugs to") << " bug-gnu-music@gnu.org" << endl;
123 main (int argc_i, char* argv_sz_a[])
127 setlocale (LC_ALL, ""); /* enable locales */
128 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in output */
129 String name (PACKAGE);
131 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
132 textdomain (name.ch_C ()) ;
135 bool key_override_b = false;
136 Mudela_key key (0, 0);
139 Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a);
142 while (Long_option_init const* long_option_init_p = getopt_long())
143 switch (long_option_init_p->shortname_ch_)
146 Duration_convert::no_quantify_b_s = true;
149 level_ver = DEBUG_ver;
156 // path->push (getopt_long.optional_argument_ch_C_);
160 String str = getopt_long.optional_argument_ch_C_;
161 int i = str.index_i (':');
162 i = (i >=0 ? i : str.length_i ());
163 key.accidentals_i_ = String_convert::dec2_i (str.left_str (i));
164 key.minor_i_ = (int)(bool)String_convert::dec2_i (str.cut_str (i + 1, str.length_i ()));
165 key_override_b = true;
169 Duration_convert::no_double_dots_b_s = true;
170 Duration_convert::no_triplets_b_s = true;
171 Duration_convert::no_smaller_than_i_s = 5;
174 output_str = getopt_long.optional_argument_ch_C_;
177 Duration_convert::no_triplets_b_s = true;
180 level_ver = QUIET_ver;
183 no_timestamps_b_g = true;
187 int i = String_convert::dec2_i (getopt_long.optional_argument_ch_C_);
194 Duration_convert::no_smaller_than_i_s =
195 Duration_convert::i2_type(i);
199 level_ver = VERBOSE_ver;
212 Duration_convert::no_double_dots_b_s = true;
219 // flag -q must be checked first
223 source.set_binary (true);
224 source.set_path (&path);
226 char const* arg_sz = 0;
227 while ( (arg_sz = getopt_long.get_next_arg ()))
229 filename_str_g = arg_sz;
230 Midi_score_parser midi_parser;
231 Mudela_score* score_p = midi_parser.parse (arg_sz, &source);
236 // if given on command line: override
237 if (key_override_b || !score_p->mudela_key_l_)
238 score_p->mudela_key_l_ = &key;
239 mudela_score_l_g = score_p;
242 if (!output_str.length_i ())
244 String d, dir, base, ext;
245 split_path (arg_sz, d, dir, base, ext);
246 output_str = base + ext + ".ly";
249 score_p->output (output_str);