#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 ();
+ PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
+ PRECOMPUTED_VIRTUAL void start_translation_timestep ();
+ PRECOMPUTED_VIRTUAL 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);
+
+ PRECOMPUTED_VIRTUAL void process_acknowledged ();
private:
bool test_moment (Direction, Moment);
Spanner *finished_beam_;
Link_array<Item> *stems_;
- int count_;
+ int process_acknowledged_count_;
Moment last_add_mom_;
/*
Projected ending of the beam we're working on.
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;
- count_ = 0;
+process_acknowledged_count_ = 0;
stems_ = 0;
shortest_mom_ = Moment (Rational (1, 8));
finished_beam_ = 0;
Auto_beam_engraver::test_moment (Direction dir, Moment test)
{
return scm_call_3 (get_property ("autoBeamCheck"),
- self_scm (),
+ context ()->self_scm (),
scm_from_int (dir),
test.smobbed_copy ())
!= SCM_BOOL_F;
void
Auto_beam_engraver::start_translation_timestep ()
{
- count_ = 0;
+ process_acknowledged_count_ = 0;
/*
don't beam over skips
*/
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. */
- if (scm_is_string (get_property ("whichBar"))
- && beam_start_moment_ < now_mom ())
+ check_bar_property ();
+ if (stems_)
{
- consider_end (shortest_mom_);
- junk_beam ();
+ end_beam ();
}
+}
+
+void
+Auto_beam_engraver::acknowledge_bar_line (Grob_info info)
+{
+ check_bar_property ();
+ if (stems_)
+ end_beam ();
+}
+void
+Auto_beam_engraver::acknowledge_rest (Grob_info 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;
- }
-
- /*
- ignore grace notes.
- */
- if (bool (beam_start_location_.grace_part_) != bool (now_mom ().grace_part_))
- return;
+ if (stems_)
+ end_beam ();
+ return;
+ }
- Moment dur = unsmob_duration (m->get_property ("duration"))->get_length ();
- /* FIXME:
+ if (Stem::get_beam (stem))
+ {
+ if (stems_)
+ junk_beam ();
+ return;
+ }
- This comment has been here since long:
+ int durlog = unsmob_duration (m->get_property ("duration"))->duration_log ();
- if shortest duration would change
- consider ending and beginning beam first.
+ if (durlog <= 2)
+ {
+ if (stems_)
+ end_beam ();
+ return;
+ }
- but the code didn't match: */
-#if 1
- consider_end (dur);
- consider_begin (dur);
+ /*
+ ignore grace notes.
+ */
+ Moment now = now_mom ();
+ if (bool (beam_start_location_.grace_part_) != bool (now.grace_part_))
+ return;
- if (dur < shortest_mom_)
- shortest_mom_ = dur;
-#else
- /* I very much suspect that we wanted: */
+ Moment dur = unsmob_duration (m->get_property ("duration"))->get_length ();
- consider_end (shortest_mom_);
- if (dur < shortest_mom_)
- {
- shortest_mom_ = dur;
- consider_end (shortest_mom_);
- }
- consider_begin (shortest_mom_);
-#endif
+ consider_end (dur);
+ consider_begin (dur);
- if (!stems_)
- return;
+ if (dur < shortest_mom_)
+ shortest_mom_ = dur;
- Moment now = now_mom ();
+ if (!stems_)
+ return;
- grouping_->add_stem (now - beam_start_moment_ + beam_start_location_,
- durlog - 2);
- stems_->push (stem);
- last_add_mom_ = now;
- extend_mom_ = (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 (!count_)
+ if (extend_mom_ > now_mom ())
+ return ;
+
+ if (!process_acknowledged_count_)
{
consider_end (shortest_mom_);
consider_begin (shortest_mom_);
}
- else if (count_ > 1)
+ else if (process_acknowledged_count_ > 1)
{
if (stems_)
{
}
}
- count_++;
+ 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",
+ /* acks */ "",
/* reads */ "autoBeaming autoBeamSettings beatLength subdivideBeams",
/* write */ "");