2 page-turn-engraver.cc -- implement Page_turn_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2006 Joe Neeman <joeneeman@gmail.com>
12 #include "duration.hh"
14 #include "international.hh"
18 class Page_turn_engraver : public Engraver
23 Rational repeat_begin_rest_length_;
25 Real penalty (Rational rest_len);
28 DECLARE_ACKNOWLEDGER (note_head);
31 TRANSLATOR_DECLARATIONS (Page_turn_engraver);
32 void stop_translation_timestep ();
35 Page_turn_engraver::Page_turn_engraver ()
37 repeat_begin_ = Moment (-1);
38 repeat_begin_rest_length_ = 0;
44 Page_turn_engraver::penalty (Rational rest_len)
46 Rational min_turn = robust_scm2moment (get_property ("minPageTurnLength"), Moment (1)).main_part_;
48 return (rest_len < min_turn) ? infinity_f : 0;
52 Page_turn_engraver::acknowledge_note_head (Grob_info gi)
54 SCM dur_log_scm = gi.grob ()->get_property ("duration-log");
55 if (!scm_is_number (dur_log_scm))
58 int dur_log = scm_to_int (dur_log_scm);
59 int dot_count = robust_scm2int (gi.grob ()->get_property ("dot-count"), 0);
61 if (rest_begin_ < now_mom ())
63 Real pen = penalty ((now_mom () - rest_begin_).main_part_);
66 SCM val = scm_cons (rest_begin_.smobbed_copy (), scm_from_double (pen));
67 context ()->get_score_context ()->set_property ("allowPageTurn", val);
71 if (rest_begin_ <= repeat_begin_)
72 repeat_begin_rest_length_ = (now_mom () - repeat_begin_).main_part_;
73 note_end_ = now_mom () + Moment (Duration (dur_log, dot_count).get_length ());
77 Page_turn_engraver::stop_translation_timestep ()
79 /* C&P from Repeat_acknowledge_engraver */
80 SCM cs = get_property ("repeatCommands");
84 for (; scm_is_pair (cs); cs = scm_cdr (cs))
86 SCM command = scm_car (cs);
87 if (command == ly_symbol2scm ("start-repeat"))
89 else if (command == ly_symbol2scm ("end-repeat"))
93 if (end && repeat_begin_.main_part_ >= Moment (0))
95 Real pen = penalty ((now_mom () - rest_begin_).main_part_ + repeat_begin_rest_length_);
96 Moment *m = unsmob_moment (get_property ("minimumRepeatLengthForPageTurn"));
97 if (m && *m > (now_mom () - repeat_begin_))
101 SCM val = scm_cons (repeat_begin_.smobbed_copy (), scm_from_double (pen));
102 context ()->get_score_context ()->set_property ("revokePageTurns", val);
104 repeat_begin_ = Moment (-1);
108 repeat_begin_ = now_mom ();
109 repeat_begin_rest_length_ = 0;
111 rest_begin_ = note_end_;
114 #include "translator.icc"
116 ADD_ACKNOWLEDGER (Page_turn_engraver, note_head);
117 ADD_TRANSLATOR (Page_turn_engraver,
118 /* doc */ "Decide where page turns are allowed to go",