int
Stem::min_head_i()const
{
- int m = 1000;
- for (int i =0; i < head_l_arr_.size(); i++)
+ int m = 1000;
+ for (int i =0; i < head_l_arr_.size(); i++)
m = m <? head_l_arr_[i]->position_i_;
- return m;
+ return m;
}
int
Stem::max_head_i() const
{
- int m = -1000;
- for (int i =0; i < head_l_arr_.size(); i++)
+ int m = -1000;
+ for (int i =0; i < head_l_arr_.size(); i++)
m = m >? head_l_arr_[i]->position_i_;
- return m;
-
+ return m;
+
}
Stem::Stem (int c)
{
- beams_left_i_ = 0;
- beams_right_i_ = 0;
+ beams_left_i_ = 0;
+ beams_right_i_ = 0;
- stem_bottom_f_ = stem_top_f_ = 0;
- flag_i_ = 4;
- dir_i_ =0;
- staff_size_i_ = c;
+ stem_bottom_f_ = stem_top_f_ = 0;
+ flag_i_ = 4;
+ dir_i_ =0;
+ staff_size_i_ = c;
- print_flag_b_=true;
- stem_xoffset_f_ =0;
+ print_flag_b_=true;
+ stem_xoffset_f_ =0;
}
Stem::do_print() const
{
#ifndef NPRINT
- DOUT << "flag "<< flag_i_ << " print_flag_b_ " << print_flag_b_;
+ DOUT << "flag "<< flag_i_ << " print_flag_b_ " << print_flag_b_;
#endif
}
Real
Stem::stem_length_f()const
{
- return stem_top_f_-stem_bottom_f_ ;
+ return stem_top_f_-stem_bottom_f_ ;
}
Real
Stem::stem_start_f()const
{
- return (dir_i_ < 0)? stem_top_f_ : stem_bottom_f_;
+ return (dir_i_ < 0)? stem_top_f_ : stem_bottom_f_;
}
Real
Stem::stem_end_f() const
{
- return (dir_i_ < 0)? stem_bottom_f_ : stem_top_f_;
+ return (dir_i_ < 0)? stem_bottom_f_ : stem_top_f_;
}
void
Stem::set_stemend (Real se)
{
- // todo: margins
- if (! ((dir_i_ > 0 && se >= max_head_i()) ||
+ // todo: margins
+ if (! ((dir_i_ > 0 && se >= max_head_i()) ||
(se <= min_head_i() && dir_i_ <0)) )
warning ("Weird stem size; check for narrow beams");
- stem_top_f_ = (dir_i_ < 0) ? max_head_i() : se;
- stem_bottom_f_ = (dir_i_ < 0) ? se : min_head_i();
+ stem_top_f_ = (dir_i_ < 0) ? max_head_i() : se;
+ stem_bottom_f_ = (dir_i_ < 0) ? se : min_head_i();
}
void
Stem::add (Note_head *n)
{
- n->add_dependency (this);
- if (n->rest_b_) {
+ n->add_dependency (this);
+ if (n->rest_b_)
+ {
rest_l_arr_.push (n);
- } else if (n->balltype_i_ == 1) {
+ }
+ else if (n->balltype_i_ == 0)
+ {
whole_l_arr_.push (n);
return;
- } else{
+ }
+ else
+ {
head_l_arr_.push (n);
}
}
bool
Stem::invisible_b()const
{
- return !head_l_arr_.size();
+ return !head_l_arr_.size();
}
// if dir_i_ is set we return fake values.
int
Stem::get_center_distance_from_top()
{
- if (dir_i_)
+ if (dir_i_)
return (dir_i_ > 0) ? 0 : 1;
- int staff_center = staff_size_i_ / 2;
- int max = max_head_i() - staff_center;
- return max >? 0;
+ int staff_center = staff_size_i_ / 2;
+ int max = max_head_i() - staff_center;
+ return max >? 0;
}
// if dir_i_ is set we return fake values.
int
Stem::get_center_distance_from_bottom()
{
- if (dir_i_)
+ if (dir_i_)
return (dir_i_ > 0) ? 1 : 0;
- int staff_center = staff_size_i_ / 2;
- int min = staff_center - min_head_i();
- return min >? 0;
+ int staff_center = staff_size_i_ / 2;
+ int min = staff_center - min_head_i();
+ return min >? 0;
}
int
Stem::get_default_dir()
{
- if (dir_i_)
+ if (dir_i_)
return dir_i_;
- return (get_center_distance_from_top() >=
+ return (get_center_distance_from_top() >=
get_center_distance_from_bottom()) ? -1 : 1;
}
void
Stem::set_default_dir()
{
- dir_i_ = get_default_dir();
+ dir_i_ = get_default_dir();
}
void
Stem::set_default_stemlen()
{
- if (!dir_i_)
+ if (!dir_i_)
set_default_dir();
-
- // ugh... how about non 5-line staffs?
- if ((max_head_i() < -2 && dir_i_ == 1)
- ||(min_head_i() > staff_size_i_ && dir_i_ == -1)){
+
+ // ugh... how about non 5-line staffs?
+ if ((max_head_i() < -2 && dir_i_ == 1)
+ ||(min_head_i() > staff_size_i_ && dir_i_ == -1))
+ {
set_stemend (staff_size_i_ /2 -1);
- } else {
+ }
+ else
+ {
set_stemend ((dir_i_ > 0) ? max_head_i() + STEMLEN :
min_head_i() - STEMLEN);
void
Stem::set_default_extents()
{
- if (!stem_length_f())
+ if (!stem_length_f())
set_default_stemlen();
- set_stemend ((dir_i_< 0) ?
+ set_stemend ((dir_i_< 0) ?
max_head_i()-stem_length_f (): min_head_i () +stem_length_f ());
- if (dir_i_ > 0){
+ if (dir_i_ > 0){
stem_xoffset_f_ = paper()->note_width ()-paper ()->rule_thickness ();
- } else
+ }
+ else
stem_xoffset_f_ = 0;
}
void
Stem::set_noteheads()
{
- if (!head_l_arr_.size())
+ if (!head_l_arr_.size())
return;
- head_l_arr_.sort (Note_head::compare);
- if (dir_i_ < 0)
+ head_l_arr_.sort (Note_head::compare);
+ if (dir_i_ < 0)
head_l_arr_.reverse();
-
- head_l_arr_[0]->extremal_i_ = -1;
- head_l_arr_.top()->extremal_i_ = 1;
- int parity=1;
- int lastpos = head_l_arr_[0]->position_i_;
- for (int i=1; i < head_l_arr_.size(); i ++) {
+
+ head_l_arr_[0]->extremal_i_ = -1;
+ head_l_arr_.top()->extremal_i_ = 1;
+ int parity=1;
+ int lastpos = head_l_arr_[0]->position_i_;
+ for (int i=1; i < head_l_arr_.size(); i ++)
+ {
int dy =abs (lastpos- head_l_arr_[i]->position_i_);
- if (dy <= 1) {
+ if (dy <= 1)
+ {
if (parity)
head_l_arr_[i]->x_dir_i_ = (stem_xoffset_f_>0) ? 1:-1;
parity = !parity;
- } else
+ }
+ else
parity = 0;
lastpos = head_l_arr_[i]->position_i_;
}
void
Stem::do_pre_processing()
{
- if (stem_bottom_f_== stem_top_f_)
+ if (stem_bottom_f_== stem_top_f_)
set_default_extents();
- set_noteheads();
- flag_i_ = dir_i_*abs (flag_i_);
- transparent_b_ = invisible_b();
- empty_b_ = invisible_b();
+ set_noteheads();
+ flag_i_ = dir_i_*abs (flag_i_);
+ transparent_b_ = invisible_b();
+ empty_b_ = invisible_b();
}
Interval
Stem::do_width()const
{
- if (!print_flag_b_ || abs (flag_i_) <= 4)
+ if (!print_flag_b_ || abs (flag_i_) <= 4)
return Interval (0,0); // TODO!
- Paper_def*p= paper();
- Interval r (p->lookup_l()->flag (flag_i_).dim.x ());
- r+= stem_xoffset_f_;
- return r;
+ Paper_def*p= paper();
+ Interval r (p->lookup_l()->flag (flag_i_).dim.x ());
+ r+= stem_xoffset_f_;
+ return r;
}
Molecule*
Stem::brew_molecule_p()const
{
- Molecule *out =0;
-
- Real bot = stem_bottom_f_;
- Real top = stem_top_f_;
-
- assert (bot!=top);
+ Molecule *out =0;
+
+ Real bot = stem_bottom_f_;
+ Real top = stem_top_f_;
+
+ assert (bot!=top);
- Paper_def *p =paper();
+ Paper_def *p =paper();
- Real dy = p->internote_f();
- Symbol ss =p->lookup_l()->stem (bot*dy,top*dy);
+ Real dy = p->internote_f();
+ Symbol ss =p->lookup_l()->stem (bot*dy,top*dy);
- out = new Molecule (Atom (ss));
+ out = new Molecule (Atom (ss));
- if (print_flag_b_&&abs (flag_i_) > 4){
+ if (print_flag_b_&&abs (flag_i_) > 4)
+ {
Symbol fl = p->lookup_l()->flag (flag_i_);
Molecule m (fl);
if (flag_i_ < -4){
out->add_bottom (m);
- } else if (flag_i_ > 4) {
+ }
+ else if (flag_i_ > 4)
+ {
out->add_top (m);
- } else
+ }
+ else
assert (false);
}
- out->translate (stem_xoffset_f_, X_AXIS);
- return out;
+ out->translate (stem_xoffset_f_, X_AXIS);
+ return out;
}
Real
Stem::hpos_f()const
{
- return Item::hpos_f() + stem_xoffset_f_;
+ return Item::hpos_f() + stem_xoffset_f_;
}
void
Stem::do_substitute_dependency (Score_elem*o,Score_elem*n)
{
- Item * o_l = o->item();
- Item * n_l = n? n->item():0;
- whole_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
- head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
- rest_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
+ Item * o_l = o->item();
+ Item * n_l = n? n->item():0;
+ whole_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
+ head_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
+ rest_l_arr_.substitute ((Note_head*)o_l, (Note_head*)n_l);
}
void
usage()
{
- LOGOUT(NORMAL_ver) <<
+ LOGOUT(NORMAL_ver) <<
"Usage: mi2mu [options] midi-file\n"
- "Translate midi-file to mudela\n"
- "\n"
- "Options:\n"
- " -b, --no-quantify write exact durations, e.g.: a4*385/384\n"
- " -d, --debug print lots of debugging stuff\n"
- " -h, --help this help\n"
- " -I, --include=DIR add DIR to search path\n"
- " -n, --no-silly assume no plets or double dots, smallest is 32\n"
- " -o, --output=FILE set FILE as default output\n"
- " -p, --no-plets assume no plets\n"
- " -q, --quiet be quiet\n"
- " -s, --smallest=N assume no shorter (reciprocal) durations than N\n"
- " -v, --verbose be verbose\n"
- " -w, --warranty show warranty and copyright\n"
- " -x, --no-double-dots assume no double dotted notes\n"
- ;
+ "Translate midi-file to mudela\n"
+ "\n"
+ "Options:\n"
+ " -b, --no-quantify write exact durations, e.g.: a4*385/384\n"
+ " -d, --debug print lots of debugging stuff\n"
+ " -h, --help this help\n"
+ " -I, --include=DIR add DIR to search path\n"
+ " -n, --no-silly assume no plets or double dots, smallest is 32\n"
+ " -o, --output=FILE set FILE as default output\n"
+ " -p, --no-plets assume no plets\n"
+ " -q, --quiet be quiet\n"
+ " -s, --smallest=N assume no shorter (reciprocal) durations than N\n"
+ " -v, --verbose be verbose\n"
+ " -w, --warranty show warranty and copyright\n"
+ " -x, --no-double-dots assume no double dotted notes\n"
+ ;
}
void
identify()
{
- LOGOUT(NORMAL_ver) << mi2mu_version_str() << endl;
+ LOGOUT(NORMAL_ver) << mi2mu_version_str() << endl;
}
-
+
void
notice()
{
- LOGOUT(NORMAL_ver) <<
- "\n"
- "Mi2mu, translate midi to mudela.\n"
- "Copyright (C) 1997 by\n"
- " Jan Nieuwenhuizen <jan@digicash.com>\n"
- " Han-Wen Nienhuys <hanwen@stack.nl>\n"
- "\n"
- " This program is free software; you can redistribute it and/or\n"
- "modify it under the terms of the GNU General Public License version 2\n"
- "as published by the Free Software Foundation.\n"
- "\n"
- " This program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
- "General Public License for more details.\n"
- "\n"
- " You should have received a copy (refer to the file COPYING) of the\n"
- "GNU General Public License along with this program; if not, write to\n"
- "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
- "USA.\n";
+ LOGOUT(NORMAL_ver) <<
+ "\n"
+ "Mi2mu, translate midi to mudela.\n"
+ "Copyright (C) 1997 by\n"
+ " Jan Nieuwenhuizen <jan@digicash.com>\n"
+ " Han-Wen Nienhuys <hanwen@stack.nl>\n"
+ "\n"
+ " This program is free software; you can redistribute it and/or\n"
+ "modify it under the terms of the GNU General Public License version 2\n"
+ "as published by the Free Software Foundation.\n"
+ "\n"
+ " This program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
+ "General Public License for more details.\n"
+ "\n"
+ " You should have received a copy (refer to the file COPYING) of the\n"
+ "GNU General Public License along with this program; if not, write to\n"
+ "the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,\n"
+ "USA.\n";
}
int
main (int argc_i, char* argv_sz_a[])
{
- rat_printer = print_rat;
+ rat_printer = print_rat;
- Long_option_init long_option_init_a[] = {
+ Long_option_init long_option_init_a[] =
+ {
{0, "no-quantify", 'b'},
{0, "debug", 'd'},
{0, "help", 'h'},
{0, "warranty", 'w'},
{0, "no-double-dots", 'x'},
{0,0,0}
- };
- Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a);
+ };
+ Getopt_long getopt_long (argc_i, argv_sz_a, long_option_init_a);
- String output_str;
- while (Long_option_init const* long_option_init_p = getopt_long())
- switch (long_option_init_p->shortname) {
+ String output_str;
+ while (Long_option_init const* long_option_init_p = getopt_long())
+ switch (long_option_init_p->shortname)
+ {
case 'b':
Duration_convert::no_quantify_b_s = true;
break;
case 'n':
Duration_convert::no_double_dots_b_s = true;
Duration_convert::no_triplets_b_s = true;
- Duration_convert::no_smaller_than_i_s = 32;
+ Duration_convert::no_smaller_than_i_s = 5;
break;
case 'o':
output_str = getopt_long.optional_argument_ch_C_;
case 'q':
level_ver = QUIET_ver;
break;
- case 's': {
+ case 's':
+ {
int i = String_convert::dec2_i (getopt_long.optional_argument_ch_C_);
- if (!i) {
+ if (!i)
+ {
identify();
usage();
exit (2); //usage
- }
- Duration_convert::no_smaller_than_i_s = i;
- }
+ }
+ Duration_convert::no_smaller_than_i_s =
+ Duration_convert::i2_type(i);
+ }
break;
case 'v':
level_ver = VERBOSE_ver;
default:
assert (0);
break;
- }
+ }
- // flag -q must be checked first
- identify();
+ // flag -q must be checked first
+ identify();
- path.add ("");
- source_l_g->set_path (&path);
+ path.add ("");
+ source_l_g->set_path (&path);
- char const* arg_sz = 0;
- while ( (arg_sz = getopt_long.get_next_arg())) {
+ char const* arg_sz = 0;
+ while ( (arg_sz = getopt_long.get_next_arg()))
+ {
My_midi_parser midi_parser (arg_sz, & source);
midi_parser_l_g = &midi_parser;
if (error_i)
return error_i;
- if (!output_str.length_i()) {
+ if (!output_str.length_i())
+ {
String d, dir, base, ext;
split_path (arg_sz, d, dir, base, ext);
output_str = base + ext + ".ly";
- }
+ }
assert (midi_parser.mudela_score_p_);
midi_parser.mudela_score_p_->process();
midi_parser_l_g = 0;
}
- return 0;
+ return 0;
}