#include "item.hh"
#include "spanner.hh"
#include "context.hh"
+#include "duration.hh"
+
+#include "translator.icc"
+
class Auto_beam_engraver : public Engraver
{
TRANSLATOR_DECLARATIONS (Auto_beam_engraver);
protected:
- virtual void stop_translation_timestep ();
- virtual void start_translation_timestep ();
- virtual void process_music ();
+ void stop_translation_timestep ();
+ void start_translation_timestep ();
+ void process_music ();
virtual bool try_music (Music *);
virtual void finalize ();
- virtual void acknowledge_grob (Grob_info);
- virtual void process_acknowledged_grobs ();
+
+ DECLARE_ACKNOWLEDGER(rest);
+ DECLARE_ACKNOWLEDGER(beam);
+ DECLARE_ACKNOWLEDGER(bar_line);
+ DECLARE_ACKNOWLEDGER(stem);
+
+ void process_acknowledged ();
private:
bool test_moment (Direction, Moment);
SCM beam_settings_; // ugh. should protect ?
Beaming_info_list *finished_grouping_;
+
+ void check_bar_property ();
};
+
+void
+Auto_beam_engraver::check_bar_property ()
+{
+ /* Duplicated from process_music (), since
+ Repeat_acknowledge_engraver::process_music () may also set whichBar. */
+
+ Moment now = now_mom ();
+ if (scm_is_string (get_property ("whichBar"))
+ && beam_start_moment_ < now)
+ {
+ consider_end (shortest_mom_);
+ junk_beam ();
+ }
+}
+
void
Auto_beam_engraver::process_music ()
{
Auto_beam_engraver::Auto_beam_engraver ()
{
forbid_ = 0;
-process_acknowledged_count_ = 0;
+ process_acknowledged_count_ = 0;
stems_ = 0;
shortest_mom_ = Moment (Rational (1, 8));
finished_beam_ = 0;
if (to_boolean (get_property ("skipTypesetting")))
return 0;
+ for (int i = 0; i < stems_->size (); i++)
+ if (Stem::get_beam ((*stems_)[i]))
+ return 0;
+
Spanner *beam = new Spanner (beam_settings_, context ()->get_grob_key ("Beam"));
for (int i = 0; i < stems_->size (); i++)
{
- /*
- watch out for stem tremolos and abbreviation beams
- */
- if (Stem::get_beam ((*stems_)[i]))
- {
- scm_gc_unprotect_object (beam->self_scm ());
- return 0;
- }
Beam::add_stem (beam, (*stems_)[i]);
}
junk_beam ();
}
+
+
+
void
-Auto_beam_engraver::acknowledge_grob (Grob_info info)
+Auto_beam_engraver::acknowledge_beam (Grob_info info)
{
- /* Duplicated from process_music (), since
- Repeat_acknowledge_engraver::process_music () may also set whichBar. */
-
- Moment now = now_mom ();
- if (scm_is_string (get_property ("whichBar"))
- && beam_start_moment_ < now)
+ (void)info;
+ check_bar_property ();
+ if (stems_)
{
- consider_end (shortest_mom_);
- junk_beam ();
+ end_beam ();
}
+}
+
+void
+Auto_beam_engraver::acknowledge_bar_line (Grob_info info)
+{
+ (void)info;
+ check_bar_property ();
+ if (stems_)
+ end_beam ();
+}
+void
+Auto_beam_engraver::acknowledge_rest (Grob_info info)
+{
+ (void)info;
+ check_bar_property ();
if (stems_)
+ end_beam ();
+}
+
+void
+Auto_beam_engraver::acknowledge_stem (Grob_info info)
+{
+ check_bar_property ();
+ Item *stem = dynamic_cast<Item *> (info.grob ());
+ Music *m = info.music_cause ();
+ if (!m->is_mus_type ("rhythmic-event"))
{
- if (Beam::has_interface (info.grob ()))
- {
- end_beam ();
- }
- else if (Bar_line::has_interface (info.grob ()))
- {
- end_beam ();
- }
- else if (Rest::has_interface (info.grob ()))
- {
- end_beam ();
- }
+ programming_error ("stem must have rhythmic structure");
+ return;
}
- if (Stem::has_interface (info.grob ()))
+ /*
+ Don't (start) auto-beam over empty stems; skips or rests
+ */
+ if (!Stem::head_count (stem))
{
- Item *stem = dynamic_cast<Item *> (info.grob ());
- Music *m = info.music_cause ();
- if (!m->is_mus_type ("rhythmic-event"))
- {
- programming_error ("stem must have rhythmic structure");
- return;
- }
-
- /*
- Don't (start) auto-beam over empty stems; skips or rests
- */
- if (!Stem::head_count (stem))
- {
- if (stems_)
- end_beam ();
- return;
- }
-
- if (Stem::get_beam (stem))
- {
- if (stems_)
- junk_beam ();
- return;
- }
-
- int durlog = unsmob_duration (m->get_property ("duration"))->duration_log ();
-
- if (durlog <= 2)
- {
- if (stems_)
- end_beam ();
- return;
- }
+ if (stems_)
+ end_beam ();
+ return;
+ }
- /*
- ignore grace notes.
- */
- if (bool (beam_start_location_.grace_part_) != bool (now.grace_part_))
- return;
+ if (Stem::get_beam (stem))
+ {
+ if (stems_)
+ junk_beam ();
+ return;
+ }
- Moment dur = unsmob_duration (m->get_property ("duration"))->get_length ();
- /* FIXME:
+ int durlog = unsmob_duration (m->get_property ("duration"))->duration_log ();
- This comment has been here since long:
+ if (durlog <= 2)
+ {
+ if (stems_)
+ end_beam ();
+ return;
+ }
- if shortest duration would change
- consider ending and beginning beam first.
+ /*
+ ignore grace notes.
+ */
+ Moment now = now_mom ();
+ if (bool (beam_start_location_.grace_part_) != bool (now.grace_part_))
+ return;
- but the code didn't match: */
-#if 1
- consider_end (dur);
- consider_begin (dur);
+ Moment dur = unsmob_duration (m->get_property ("duration"))->get_length ();
- if (dur < shortest_mom_)
- shortest_mom_ = dur;
-#else
- /* I very much suspect that we wanted: */
+ consider_end (dur);
+ consider_begin (dur);
- consider_end (shortest_mom_);
- if (dur < shortest_mom_)
- {
- shortest_mom_ = dur;
- consider_end (shortest_mom_);
- }
- consider_begin (shortest_mom_);
-#endif
+ if (dur < shortest_mom_)
+ shortest_mom_ = dur;
- if (!stems_)
- return;
+ if (!stems_)
+ return;
- grouping_->add_stem (now - beam_start_moment_ + beam_start_location_,
- durlog - 2);
- stems_->push (stem);
- last_add_mom_ = now;
- extend_mom_ = max (extend_mom_, now) + m->get_length ();
- }
+ grouping_->add_stem (now - beam_start_moment_ + beam_start_location_,
+ durlog - 2);
+ stems_->push (stem);
+ last_add_mom_ = now;
+ extend_mom_ = max (extend_mom_, now) + m->get_length ();
}
void
-Auto_beam_engraver::process_acknowledged_grobs ()
+Auto_beam_engraver::process_acknowledged ()
{
if (extend_mom_ > now_mom ())
return ;
process_acknowledged_count_++;
}
+ADD_ACKNOWLEDGER(Auto_beam_engraver,stem);
+ADD_ACKNOWLEDGER(Auto_beam_engraver,bar_line);
+ADD_ACKNOWLEDGER(Auto_beam_engraver,beam);
+ADD_ACKNOWLEDGER(Auto_beam_engraver,rest);
ADD_TRANSLATOR (Auto_beam_engraver,
/* descr */ "Generate beams based on measure characteristics and observed "
"Stems. Uses beatLength, measureLength and measurePosition to decide "
"@code{stemRightBeamCount}. ",
/* creats*/ "Beam",
/* accepts */ "beam-forbid-event",
- /* acks */ "stem-interface rest-interface beam-interface bar-line-interface",
/* reads */ "autoBeaming autoBeamSettings beatLength subdivideBeams",
/* write */ "");