source file of the GNU LilyPond music typesetter
- (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include "beaming.hh"
-#include "auto-beam-engraver.hh"
#include "musical-request.hh"
-#include "bar.hh"
#include "beam.hh"
-#include "rest.hh"
#include "stem.hh"
#include "debug.hh"
-#include "timing-engraver.hh"
#include "engraver-group-engraver.hh"
+#include "bar.hh"
+#include "rest.hh"
+#include "engraver.hh"
+#include "item.hh"
+#include "spanner.hh"
+
+/*
+ TODO: figure what to do in grace?
+ */
+class Auto_beam_engraver : public Engraver
+{
+public:
+ Auto_beam_engraver ();
+ VIRTUAL_COPY_CONS (Translator);
+
+protected:
+ virtual bool do_try_music (Music*);
+ virtual void do_pre_move_processing ();
+ virtual void do_post_move_processing ();
+ virtual void do_removal_processing ();
+ virtual void acknowledge_element (Score_element_info);
+ virtual void do_process_music ();
+ virtual void process_acknowledged ();
+private:
+ void begin_beam ();
+ void consider_end_and_begin (Moment test_mom);
+ Spanner* create_beam_p ();
+ void end_beam ();
+ void junk_beam ();
+ bool same_grace_state_b (Score_element* e);
+ void typeset_beam ();
+
+ Moment shortest_mom_;
+ Spanner *finished_beam_p_;
+ Link_array<Item>* stem_l_arr_p_;
+
+ Moment last_add_mom_;
+ Moment extend_mom_;
+ Moment beam_start_moment_;
+ Moment beam_start_location_;
+
+ // We act as if beam were created, and start a grouping anyway.
+ Beaming_info_list*grouping_p_;
+ Beaming_info_list*finished_grouping_p_;
+};
ADD_THIS_TRANSLATOR (Auto_beam_engraver);
finished_beam_p_ = 0;
finished_grouping_p_ = 0;
grouping_p_ = 0;
- timer_l_ =0;
-}
-
-void
-Auto_beam_engraver::do_creation_processing ()
-{
- Translator * t = daddy_grav_l ()->get_simple_translator ("Timing_engraver");
- timer_l_ = dynamic_cast<Timing_engraver*> (t);
}
bool
}
void
-Auto_beam_engraver::do_process_requests ()
+Auto_beam_engraver::do_process_music ()
{
consider_end_and_begin (shortest_mom_);
}
void
Auto_beam_engraver::consider_end_and_begin (Moment test_mom)
{
- if (!timer_l_)
- return;
-
- int num;
- int den;
- timer_l_->get_time_signature (&num, &den);
-
- String time_str = String ("time") + to_str (num) + "_" + to_str (den);
+ SCM wild = gh_list (ly_symbol2scm ("*"), ly_symbol2scm ("*"), SCM_UNDEFINED);
+ SCM b = gh_list (ly_symbol2scm ("begin"), SCM_UNDEFINED);
+ SCM e = gh_list (ly_symbol2scm ("end"), SCM_UNDEFINED);
- String type_str;
- if (test_mom.num () != 1)
- type_str = to_str (test_mom.num ());
- if (test_mom.den () != 1)
- type_str = type_str + "_" + to_str (test_mom.den ());
+ Moment one_beat = *unsmob_moment( get_property ("beatLength"));
+ int num = *unsmob_moment (get_property("measureLength")) / one_beat;
+ int den = one_beat.den_i ();
+ SCM time = gh_list (gh_int2scm (num), gh_int2scm (den), SCM_UNDEFINED);
- /*
- URG
-
- FIXME: SHOULD USE ALIST
-
- */
+ SCM type = gh_list (gh_int2scm (test_mom.num_i ()),
+ gh_int2scm (test_mom.den_i ()), SCM_UNDEFINED);
+ SCM settings = get_property ("autoBeamSettings");
+
/*
Determine end moment for auto beaming (and begin, mostly 0==anywhere)
In order of increasing priority:
- i. every beat <den>
- ii. time<num>_<den>beamAutoEnd
- iii. time<num>_<den>beamAutoEnd<type>
- iv. beamAutoEnd
- v. beamAutoEnd<type>
+ i. every beat
+ ii. end * <num> <den>
+ iii. end <type> <num> <den>
+
+ iv. end * * *
+ v. end <type> * *
Rationale:
iv. generic override
v. override for specific duration type
- The user overrides should be required for common cases.
- */
+ */
+
/*
first guess: begin beam at any position
*/
/*
first guess: end beam at end of beat
*/
- SCM one (get_property ("beatLength", 0));
+ SCM one (get_property ("beatLength"));
Moment end_mom;
- if (SMOB_IS_TYPE_B(Moment, one))
- end_mom = *SMOB_TO_TYPE (Moment, one);
+ if (unsmob_moment (one))
+ end_mom = *unsmob_moment (one);
/*
second guess: property generic time exception
*/
- SCM begin = get_property (time_str + "beamAutoBegin", 0);
- if (SMOB_IS_TYPE_B(Moment, begin))
- begin_mom = * SMOB_TO_TYPE(Moment, begin);
+ SCM begin = gh_assoc (gh_append3 (b, wild, time), settings);
+
+ if (begin != SCM_BOOL_F && unsmob_moment (gh_cdr (begin)))
+ begin_mom = * unsmob_moment (gh_cdr (begin));
- SCM end = get_property (time_str + "beamAutoEnd", 0);
- if (SMOB_IS_TYPE_B (Moment, end))
- end_mom = * SMOB_TO_TYPE(Moment,end);
+ SCM end = gh_assoc (gh_append3 (e, wild, time), settings);
+ if (end != SCM_BOOL_F && unsmob_moment (gh_cdr (end)))
+ end_mom = * unsmob_moment (gh_cdr (end));
/*
third guess: property time exception, specific for duration type
*/
- if (type_str.length_i ())
- {
- SCM end_mult = get_property (time_str + "beamAutoEnd" + type_str, 0);
- if (SMOB_IS_TYPE_B (Moment, end_mult))
- end_mom = * SMOB_TO_TYPE (Moment,end_mult);
-
- SCM begin_mult = get_property (time_str + "beamAutoBegin" + type_str, 0);
- if (SMOB_IS_TYPE_B (Moment, begin_mult))
- begin_mom = * SMOB_TO_TYPE (Moment,begin_mult);
- }
+ SCM begin_mult = gh_assoc (gh_append3 (b, type, time), settings);
+ if (begin_mult != SCM_BOOL_F && unsmob_moment (gh_cdr (begin_mult)))
+ begin_mom = * unsmob_moment (gh_cdr (begin_mult));
+
+ SCM end_mult = gh_assoc (gh_append3 (e, type, time), settings);
+ if (end_mult != SCM_BOOL_F && unsmob_moment (gh_cdr (end_mult)))
+ end_mom = * unsmob_moment (gh_cdr (end_mult));
/*
fourth guess [user override]: property plain generic
*/
- begin = get_property ("beamAutoBegin", 0);
- if (SMOB_IS_TYPE_B(Moment, begin))
- begin_mom = * SMOB_TO_TYPE(Moment, begin);
+ begin = gh_assoc (gh_append3 (b, wild, wild), settings);
+ if (begin != SCM_BOOL_F && unsmob_moment (gh_cdr (begin)))
+ begin_mom = * unsmob_moment (gh_cdr (begin));
-
-
- end = get_property ("beamAutoEnd", 0);
- if (SMOB_IS_TYPE_B (Moment, end))
- end_mom = * SMOB_TO_TYPE (Moment,end);
+ end = gh_assoc (gh_append3 (e, wild, wild), settings);
+ if (end != SCM_BOOL_F && unsmob_moment (gh_cdr (end)))
+ end_mom = * unsmob_moment (gh_cdr (end));
/*
fifth guess [user override]: property plain, specific for duration type
*/
- if (type_str.length_i ())
- {
- SCM end_mult = get_property (String ("beamAutoEnd") + type_str, 0);
- if (SMOB_IS_TYPE_B (Moment, end_mult))
- end_mom = * SMOB_TO_TYPE (Moment,end_mult);
-
- SCM begin_mult = get_property (String ("beamAutoBegin") + type_str, 0);
- if (SMOB_IS_TYPE_B (Moment, begin_mult))
- begin_mom = * SMOB_TO_TYPE (Moment,begin_mult);
- }
+ begin_mult = gh_assoc (gh_append3 (b, type, wild), settings);
+ if (begin_mult != SCM_BOOL_F && unsmob_moment (gh_cdr (begin_mult)))
+ begin_mom = * unsmob_moment (gh_cdr (begin_mult));
+
+ end_mult = gh_assoc (gh_append3 (e, type, wild), settings);
+ if (end_mult != SCM_BOOL_F && unsmob_moment (gh_cdr (end_mult)))
+ end_mom = * unsmob_moment (gh_cdr (end_mult));
Rational r;
if (end_mom)
- r = timer_l_->measure_position ().mod_rat (end_mom);
+ r = unsmob_moment (get_property ("measurePosition"))->mod_rat (end_mom);
else
r = Moment (1);
/*
Allow already started autobeam to end
*/
- SCM on = get_property ("noAutoBeaming", 0);
+ SCM on = get_property ("noAutoBeaming");
if (to_boolean (on))
return;
if (begin_mom)
- r = timer_l_->measure_position ().mod_rat (begin_mom);
+ r = unsmob_moment (get_property ("measurePosition"))->mod_rat (begin_mom);
if (!stem_l_arr_p_ && (!begin_mom || !r))
begin_beam ();
}
Auto_beam_engraver::begin_beam ()
{
assert (!stem_l_arr_p_);
- stem_l_arr_p_ = new Array<Stem*>;
+ stem_l_arr_p_ = new Link_array<Item>;
assert (!grouping_p_);
grouping_p_ = new Beaming_info_list;
beam_start_moment_ = now_mom ();
- beam_start_location_ = timer_l_->measure_position ();
+ beam_start_location_ = *unsmob_moment (get_property ("measurePosition"));
}
-Beam*
+Spanner*
Auto_beam_engraver::create_beam_p ()
{
- Beam* beam_p = new Beam;
+ Spanner* beam_p = new Spanner (get_property ("Beam"));
+ Beam::set_interface (beam_p);
for (int i = 0; i < stem_l_arr_p_->size (); i++)
{
/*
watch out for stem tremolos and abbreviation beams
*/
- if ((*stem_l_arr_p_)[i]->beam_l ())
+ if (Stem::beam_l ((*stem_l_arr_p_)[i]))
{
return 0;
}
- beam_p->add_stem ((*stem_l_arr_p_)[i]);
+ Beam::add_stem (beam_p,(*stem_l_arr_p_)[i]);
}
- announce_element (Score_element_info (beam_p, 0));
+ announce_element (beam_p, 0);
return beam_p;
}
if (finished_beam_p_)
{
finished_grouping_p_->beamify ();
- finished_beam_p_->set_beaming (finished_grouping_p_);
+ Beam::set_beaming (finished_beam_p_, finished_grouping_p_);
typeset_element (finished_beam_p_);
finished_beam_p_ = 0;
Auto_beam_engraver::same_grace_state_b (Score_element* e)
{
bool gr = e->get_elt_property ("grace") == SCM_BOOL_T;
- SCM wg =get_property ("weAreGraceContext",0);
+ SCM wg =get_property ("weAreGraceContext");
return (to_boolean (wg)) == gr;
}
void
Auto_beam_engraver::acknowledge_element (Score_element_info info)
{
- if (!same_grace_state_b (info.elem_l_) || !timer_l_)
+ if (!same_grace_state_b (info.elem_l_))
return;
if (stem_l_arr_p_)
{
- if (Beam *b = dynamic_cast<Beam *> (info.elem_l_))
+ if (Beam::has_interface (info.elem_l_))
{
end_beam ();
}
- else if (Bar *b = dynamic_cast<Bar *> (info.elem_l_))
+ else if (Bar::has_interface (info.elem_l_))
{
end_beam ();
}
- else if (Rest* rest_l = dynamic_cast<Rest *> (info.elem_l_))
+ else if (Rest::has_interface (info.elem_l_))
{
end_beam ();
}
}
- if (Stem* stem_l = dynamic_cast<Stem *> (info.elem_l_))
+ if (Stem::has_interface (info.elem_l_))
{
+ Item* stem_l = dynamic_cast<Item *> (info.elem_l_);
+
Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (info.req_l_);
if (!rhythmic_req)
{
/*
Don't (start) auto-beam over empty stems; skips or rests
*/
- if (!stem_l->heads_i ())
+ if (!Stem::heads_i (stem_l))
{
if (stem_l_arr_p_)
end_beam ();
return;
}
- if (stem_l->beam_l ())
+ if (Stem::beam_l (stem_l))
{
if (stem_l_arr_p_)
junk_beam ();
}
}
}
-