2 // main.cc -- implement silly main () entry point
3 // should have Root class.
5 // 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;
36 static File_path path;
38 Verbose level_ver = NORMAL_ver;
43 cout << _f ("Usage: %s [OPTION]... [FILE]", "midi2ly");
45 cout << _ ("Translate midi-file to mudela");
48 cout << _ ("Options:");
51 " -b, --no-quantify write exact durations, e.g.: a4*385/384\n"
54 " -D, --debug enable debugging output\n"
57 " -h, --help this help\n"
60 " -I, --include=DIR add DIR to search path\n"
63 " -k, --key=ACC[:MINOR] set key: ACC +sharps/-flats; :1 minor\n"
66 " -n, --no-silly assume no plets or double dots, smallest is 32\n"
69 " -o, --output=FILE set FILE as default output\n"
72 " -p, --no-plets assume no plets\n"
75 " -q, --quiet be quiet\n"
78 " -T, --no-timestamps don't timestamp the output\n"
81 " -s, --smallest=N assume no shorter (reciprocal) durations than N\n"
84 " -v, --verbose be verbose\n"
87 " -w, --warranty show warranty and copyright\n"
90 " -x, --no-double-dots assume no double dotted notes\n"
98 LOGOUT(NORMAL_ver) << midi2ly_version_str() << endl;
104 LOGOUT(NORMAL_ver) << '\n';
105 LOGOUT(NORMAL_ver) << _ ("Midi2ly, translate midi to mudela");
106 LOGOUT(NORMAL_ver) << '\n';
107 LOGOUT(NORMAL_ver) << _f ("Copyright (c) %s by", "1997, 1998");
108 LOGOUT(NORMAL_ver) << '\n';
109 LOGOUT(NORMAL_ver) << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
110 LOGOUT(NORMAL_ver) << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
111 LOGOUT(NORMAL_ver) << '\n';
112 LOGOUT(NORMAL_ver) << _ (
113 " This program is free software; you can redistribute it and/or\n"
114 "modify it under the terms of the GNU General Public License version 2\n"
115 "as published by the Free Software Foundation.\n"
117 " This program is distributed in the hope that it will be useful,\n"
118 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
119 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
120 "General Public License for more details.\n"
122 " You should have received a copy (refer to the file COPYING) of the\n"
123 "GNU General Public License along with this program; if not, write to\n"
124 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
129 main (int argc_i, char* argv_sz_a[])
133 setlocale (LC_ALL, ""); /* enable locales */
134 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in output */
135 String name (PACKAGE);
137 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
138 textdomain (name.ch_C ()) ;
141 bool key_override_b = false;
142 Mudela_key key (0, 0);
144 Long_option_init long_option_init_a[] =
146 {0, "no-quantify", 'b'},
150 {0, "no-silly", 'n'},
152 {0, "no-plets", 'p'},
154 {1, "smallest", 's'},
155 {0, "no-timestamps", 'T'},
157 {0, "warranty", 'w'},
158 {0, "no-double-dots", 'x'},
161 Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a);
164 while (Long_option_init const* long_option_init_p = getopt_long())
165 switch (long_option_init_p->shortname)
168 Duration_convert::no_quantify_b_s = true;
171 level_ver = DEBUG_ver;
179 // path->push (getopt_long.optional_argument_ch_C_);
183 String str = getopt_long.optional_argument_ch_C_;
184 int i = str.index_i (':');
185 i = (i >=0 ? i : str.length_i ());
186 key.accidentals_i_ = String_convert::dec2_i (str.left_str (i));
187 key.minor_i_ = (int)(bool)String_convert::dec2_i (str.cut_str (i + 1, str.length_i ()));
188 key_override_b = true;
192 Duration_convert::no_double_dots_b_s = true;
193 Duration_convert::no_triplets_b_s = true;
194 Duration_convert::no_smaller_than_i_s = 5;
197 output_str = getopt_long.optional_argument_ch_C_;
200 Duration_convert::no_triplets_b_s = true;
203 level_ver = QUIET_ver;
206 no_timestamps_b_g = true;
210 int i = String_convert::dec2_i (getopt_long.optional_argument_ch_C_);
217 Duration_convert::no_smaller_than_i_s =
218 Duration_convert::i2_type(i);
222 level_ver = VERBOSE_ver;
230 Duration_convert::no_double_dots_b_s = true;
237 // flag -q must be checked first
241 source.set_binary (true);
242 source.set_path (&path);
244 char const* arg_sz = 0;
245 while ( (arg_sz = getopt_long.get_next_arg ()))
247 filename_str_g = arg_sz;
248 Midi_score_parser midi_parser;
249 Mudela_score* score_p = midi_parser.parse (arg_sz, &source);
254 // if given on command line: override
255 if (key_override_b || !score_p->mudela_key_l_)
256 score_p->mudela_key_l_ = &key;
257 mudela_score_l_g = score_p;
260 if (!output_str.length_i ())
262 String d, dir, base, ext;
263 split_path (arg_sz, d, dir, base, ext);
264 output_str = base + ext + ".ly";
267 score_p->output (output_str);