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;
42 cout << _f ("Usage: %s [OPTION]... [FILE]", "midi2ly");
44 cout << _ ("Translate midi-file to mudela");
47 cout << _ ("Options:");
50 " -b, --no-quantify write exact durations, e.g.: a4*385/384\n"
53 " -D, --debug enable debugging output\n"
56 " -h, --help this help\n"
59 " -I, --include=DIR add DIR to search path\n"
62 " -k, --key=ACC[:MINOR] set key: ACC +sharps/-flats; :1 minor\n"
65 " -n, --no-silly assume no tuplets or double dots, smallest is 32\n"
68 " -o, --output=FILE set FILE as default output\n"
71 " -p, --no-tuplets assume no tuplets\n"
74 " -q, --quiet be quiet\n"
77 " -T, --no-timestamps don't timestamp the output\n"
80 " -s, --smallest=N assume no shorter (reciprocal) durations than N\n"
83 " -v, --verbose be verbose\n"
86 " -w, --warranty show warranty and copyright\n"
89 " -x, --no-double-dots assume no double dotted notes\n"
97 LOGOUT(NORMAL_ver) << midi2ly_version_str() << endl;
103 LOGOUT(NORMAL_ver) << '\n';
104 LOGOUT(NORMAL_ver) << _ ("Midi2ly, translate midi to mudela");
105 LOGOUT(NORMAL_ver) << '\n';
106 LOGOUT(NORMAL_ver) << _f ("Copyright (c) %s by", "1997, 1998");
107 LOGOUT(NORMAL_ver) << '\n';
108 LOGOUT(NORMAL_ver) << " " + _ ("Han-Wen Nienhuys <hanwen@cs.uu.nl>") + "\n";
109 LOGOUT(NORMAL_ver) << " " + _ ("Jan Nieuwenhuizen <janneke@gnu.org>") + "\n";
110 LOGOUT(NORMAL_ver) << '\n';
111 LOGOUT(NORMAL_ver) << _ (
112 " This program is free software; you can redistribute it and/or\n"
113 "modify it under the terms of the GNU General Public License version 2\n"
114 "as published by the Free Software Foundation.\n"
116 " This program is distributed in the hope that it will be useful,\n"
117 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
118 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
119 "General Public License for more details.\n"
121 " You should have received a copy (refer to the file COPYING) of the\n"
122 "GNU General Public License along with this program; if not, write to\n"
123 "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
128 main (int argc_i, char* argv_sz_a[])
132 setlocale (LC_ALL, ""); /* enable locales */
133 setlocale (LC_NUMERIC, "C"); /* musn't have comma's in output */
134 String name (PACKAGE);
136 bindtextdomain (name.ch_C (), DIR_LOCALEDIR);
137 textdomain (name.ch_C ()) ;
140 bool key_override_b = false;
141 Mudela_key key (0, 0);
143 Long_option_init long_option_init_a[] =
145 {0, "no-quantify", 'b'},
149 {0, "no-silly", 'n'},
151 {0, "no-tuplets", 'p'},
153 {1, "smallest", 's'},
154 {0, "no-timestamps", 'T'},
156 {0, "warranty", 'w'},
157 {0, "no-double-dots", 'x'},
160 Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a);
163 while (Long_option_init const* long_option_init_p = getopt_long())
164 switch (long_option_init_p->shortname)
167 Duration_convert::no_quantify_b_s = true;
170 level_ver = DEBUG_ver;
178 // path->push (getopt_long.optional_argument_ch_C_);
182 String str = getopt_long.optional_argument_ch_C_;
183 int i = str.index_i (':');
184 i = (i >=0 ? i : str.length_i ());
185 key.accidentals_i_ = String_convert::dec2_i (str.left_str (i));
186 key.minor_i_ = (int)(bool)String_convert::dec2_i (str.cut_str (i + 1, str.length_i ()));
187 key_override_b = true;
191 Duration_convert::no_double_dots_b_s = true;
192 Duration_convert::no_triplets_b_s = true;
193 Duration_convert::no_smaller_than_i_s = 5;
196 output_str = getopt_long.optional_argument_ch_C_;
199 Duration_convert::no_triplets_b_s = true;
202 level_ver = QUIET_ver;
205 no_timestamps_b_g = true;
209 int i = String_convert::dec2_i (getopt_long.optional_argument_ch_C_);
216 Duration_convert::no_smaller_than_i_s =
217 Duration_convert::i2_type(i);
221 level_ver = VERBOSE_ver;
229 Duration_convert::no_double_dots_b_s = true;
236 // flag -q must be checked first
240 source.set_binary (true);
241 source.set_path (&path);
243 char const* arg_sz = 0;
244 while ( (arg_sz = getopt_long.get_next_arg ()))
246 filename_str_g = arg_sz;
247 Midi_score_parser midi_parser;
248 Mudela_score* score_p = midi_parser.parse (arg_sz, &source);
253 // if given on command line: override
254 if (key_override_b || !score_p->mudela_key_l_)
255 score_p->mudela_key_l_ = &key;
256 mudela_score_l_g = score_p;
259 if (!output_str.length_i ())
261 String d, dir, base, ext;
262 split_path (arg_sz, d, dir, base, ext);
263 output_str = base + ext + ".ly";
266 score_p->output (output_str);