into "namespace" class.
* lily/event.cc: remove Key_change_event.
* lily/include/transposed-music.hh (class Transposed_music): remove.
* lily/transposed-music.cc: remove
* lily/include/relative-music.hh: remove.
* lily/include/music-sequence.hh (struct Music_sequence): change
into "namespace" class.
* lily/untransposable-music.cc (Module): remove
* lily/include/un-relativable-music.hh (Module): remove
* lily/include/untransposable-music.hh (Module): remove
* lily/un-relativable-music.cc: remove file.
2005-01-16 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/include/repeated-music.hh (class Repeated_music): change
+ into "namespace" class.
+
+ * lily/event.cc: remove Key_change_event.
+
* lily/include/transposed-music.hh (class Transposed_music): remove.
* lily/transposed-music.cc: remove
void typeset_beam ();
TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
protected:
- Repeated_music * repeat_;
+ Music * repeat_;
/// moment (global time) where beam started.
Moment start_mom_;
/// location within measure where beam started.
Moment beam_start_location_;
- bool sequential_body_b_;
+ bool body_is_sequential_;
Spanner * beam_;
Spanner * finished_beam_;
Item * stem_tremolo_;
repeat_ = 0;
flags_ = 0;
stem_tremolo_ = 0;
- sequential_body_b_ = false;
+ body_is_sequential_ = false;
}
bool
Chord_tremolo_engraver::try_music (Music * m)
{
- Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
- if (rp
- && rp->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
+ if (m->is_mus_type ("repeated-music")
+ && m->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
&& !repeat_)
{
- Moment l = rp->get_length ();
- repeat_ = rp;
+ Moment l = m->get_length ();
+ repeat_ = m;
start_mom_ = now_mom ();
stop_mom_ = start_mom_ + l;
-
- sequential_body_b_ = rp->body()->is_mus_type ("sequential-music");
- int elt_count = sequential_body_b_ ? scm_ilength (rp->body()->get_property ("elements")) : 1;
+ Music *body = Repeated_music::body (m);
+ body_is_sequential_ = body->is_mus_type ("sequential-music");
+
+ int elt_count = body_is_sequential_ ? scm_ilength (body->get_property ("elements")) : 1;
- if (sequential_body_b_ && elt_count != 2)
+ if (body_is_sequential_ && elt_count != 2)
{
- rp->origin ()->warning (_f ("Chord tremolo with %d elements. Must have two elements.", elt_count));
+ m->origin ()->warning (_f ("Chord tremolo with %d elements. Must have two elements.", elt_count));
}
if (elt_count <= 0)
elt_count = 1;
Rational total_dur = l.main_part_;
- Rational note_dur = total_dur / Rational (elt_count * repeat_->repeat_count ());
+ Rational note_dur = total_dur / Rational (elt_count * Repeated_music::repeat_count (repeat_));
total_duration_flags_ = 0 >? (intlog2 (total_dur.den ()) - 2);
void
Chord_tremolo_engraver::process_music ()
{
- if (repeat_ && sequential_body_b_ && !beam_)
+ if (repeat_ && body_is_sequential_ && !beam_)
{
beam_ = make_spanner ("Beam", repeat_->self_scm ());
beam_->set_property ("chord-tremolo", SCM_BOOL_T);
}
}
else if (repeat_ &&
- flags_ && !sequential_body_b_ && Stem::has_interface (info.grob_))
+ flags_ && !body_is_sequential_ && Stem::has_interface (info.grob_))
{
stem_tremolo_ = make_item ("StemTremolo", repeat_->self_scm ());
stem_tremolo_->set_property ("flag-count",
void
Chord_tremolo_iterator::construct_children ()
{
- Repeated_music * rep = dynamic_cast<Repeated_music*> (get_music ());
+ Music *m = get_music();
+
factor_ = Moment (Rational (1, 1));
- child_iter_ = unsmob_iterator (get_iterator (rep->body ()));
+ child_iter_ = unsmob_iterator (get_iterator (Repeated_music::body (m)));
}
Chord_tremolo_iterator::Chord_tremolo_iterator ()
ADD_MUSIC (Event);
-Key_change_ev::Key_change_ev (SCM x)
- : Event (x)
-{
-}
-void
-Key_change_ev::transpose (Pitch p)
-{
- SCM pa = get_property ("pitch-alist");
- set_property ("pitch-alist", ly_transpose_key_alist (pa, p.smobbed_copy ()));
- Event::transpose (p);
-}
-ADD_MUSIC (Key_change_ev);
void
Folded_repeat_iterator::construct_children ()
{
- Repeated_music * mus = dynamic_cast<Repeated_music*> (get_music ());
- main_iter_ = unsmob_iterator (get_iterator (mus->body ()));
+ Music *mus = get_music ();
+ main_iter_ = unsmob_iterator (get_iterator (Repeated_music::body (mus)));
if (!main_iter_->ok ())
{
leave_body ();
void
Folded_repeat_iterator::leave_body ()
{
- Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
+ Music *mus = get_music ();
main_iter_->quit ();
main_iter_ = 0;
- main_length_mom_ += mus->body ()->get_length ();
+ main_length_mom_ += Repeated_music::body (mus)->get_length ();
}
void
Folded_repeat_iterator::enter_alternative ()
{
- Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
- if (mus->alternatives ())
+ Music *mus = get_music ();
+ if (scm_is_pair (Repeated_music::alternatives (mus)))
{
/*
ugh.
};
-/**
- Handle key changes.
-*/
-class Key_change_ev : public Event
-{
-public:
- Key_change_ev (SCM);
- SCM pitch_alist ();
-
-protected:
- VIRTUAL_COPY_CONSTRUCTOR (Music, Key_change_ev);
- void transpose (Pitch d);
-};
-
-SCM ly_transpose_key_alist (SCM,SCM);
static Moment minimum_start (SCM list);
};
+SCM ly_transpose_key_alist (SCM l, SCM pit);
Pitch music_list_to_relative (SCM l,Pitch p, bool ret_first);
void transpose_music_list (SCM , Pitch);
void compress_music_list (SCM, Moment);
SCM internal_get_property (SCM) const;
void internal_set_property (SCM , SCM val);
- SCM get_property_alist (bool mut) const;
+ SCM get_property_alist (bool mutble) const;
bool internal_is_music_type (SCM) const;
int duration_log () const;
DECLARE_SCHEME_CALLBACK(relative_callback,(SCM,SCM));
- virtual Pitch to_relative_octave (Pitch);
+ Pitch to_relative_octave (Pitch);
+ Pitch generic_to_relative_octave (Pitch);
String name () const;
Moment get_length () const;
Moment start_mom () const;
the first alternative is assumed to be repeated.
*/
-class Repeated_music : public Music
+class Repeated_music
{
public:
- Repeated_music (SCM);
- VIRTUAL_COPY_CONSTRUCTOR (Music, Repeated_music);
-
- Music *body () const;
- SCM alternatives () const;
+ static Music *body (Music*);
+ static SCM alternatives (Music*);
/* How often do we repeat? */
- int repeat_count () const;
+ static int repeat_count (Music*);
DECLARE_SCHEME_CALLBACK(relative_callback,(SCM,SCM));
- virtual Pitch to_relative_octave (Pitch);
-
- Moment body_get_length () const;
- Moment alternatives_get_length (bool fold) const;
- Moment alternatives_volta_get_length () const;
+ static Moment body_get_length (Music*);
+ static Moment alternatives_get_length (Music *, bool fold);
+ static Moment alternatives_volta_get_length (Music *);
DECLARE_SCHEME_CALLBACK (unfolded_music_length, (SCM));
DECLARE_SCHEME_CALLBACK (volta_music_length, (SCM));
(c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
*/
+#include "music-sequence.hh"
#include "audio-item.hh"
#include "performer.hh"
#include "warn.hh"
~Key_performer ();
protected:
- virtual bool try_music (Music* req);
+ virtual bool try_music (Music* ev);
virtual void create_audio_elements ();
virtual void stop_translation_timestep ();
private:
- Key_change_ev* key_req_;
+ Event* key_ev_;
Audio_key* audio_;
};
Key_performer::Key_performer ()
{
- key_req_ = 0;
+ key_ev_ = 0;
audio_ = 0;
}
void
Key_performer::create_audio_elements ()
{
- if (key_req_)
+ if (key_ev_)
{
- SCM pitchlist = key_req_->get_property ("pitch-alist");
+ SCM pitchlist = key_ev_->get_property ("pitch-alist");
SCM proc = ly_lily_module_constant ("alterations-in-key");
SCM acc = scm_call_1 (proc, pitchlist);
audio_ = new Audio_key (scm_to_int (acc),
SCM_BOOL_T != scm_equal_p (minor, c_pitchlist));
- Audio_element_info info (audio_, key_req_);
+ Audio_element_info info (audio_, key_ev_);
announce_element (info);
- key_req_ = 0;
+ key_ev_ = 0;
}
}
}
bool
-Key_performer::try_music (Music* req)
+Key_performer::try_music (Music* ev)
{
- if (Key_change_ev *kc = dynamic_cast <Key_change_ev *> (req))
+ if (Event *kc = dynamic_cast <Event *> (ev))
{
- if (key_req_)
+ if (key_ev_)
warning (_ ("FIXME: key change merge"));
- key_req_ = kc;
+ key_ev_ = kc;
return true;
}
}
Pitch
-Music::to_relative_octave (Pitch last)
+Music::generic_to_relative_octave (Pitch last)
{
- SCM callback = get_property ("to-relative-callback");
- if (ly_c_procedure_p (callback))
- {
- Pitch * p = unsmob_pitch (scm_call_2 (callback, self_scm(), last.smobbed_copy ()));
- return *p;
- }
-
SCM elt = get_property ("element");
Pitch *old_pit = unsmob_pitch (get_property ("pitch"));
if (old_pit)
last = new_pit;
}
-
if (Music *m = unsmob_music (elt))
last = m->to_relative_octave (last);
return last;
}
+Pitch
+Music::to_relative_octave (Pitch last)
+{
+ SCM callback = get_property ("to-relative-callback");
+ if (ly_c_procedure_p (callback))
+ {
+ Pitch * p = unsmob_pitch (scm_call_2 (callback, self_scm(), last.smobbed_copy ()));
+ return *p;
+ }
+
+ return generic_to_relative_octave (last);
+}
+
void
Music::compress (Moment factor)
{
m->transpose (delta);
transpose_music_list (get_property ("elements"), delta);
+
+ /*
+ UGH - how do this more generically?
+ */
+ SCM pa = get_property ("pitch-alist");
+ if (scm_is_pair (pa))
+ {
+ set_property ("pitch-alist", ly_transpose_key_alist (pa, delta.smobbed_copy ()));
+ }
+
}
IMPLEMENT_TYPE_P (Music, "ly:music?");
public:
TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
protected:
- Repeated_music * repeat_;
+ Music *repeat_;
/// moment (global time) where beam started.
Moment start_mom_;
bool
Percent_repeat_engraver::try_music (Music * m)
{
- Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
- if (rp
- && rp->get_property ("iterator-ctor")
+ if (m->is_mus_type ("repeated-music")
+ && m->get_property ("iterator-ctor")
== Percent_repeat_iterator::constructor_proc
&& !repeat_)
{
- body_length_ = rp->body_get_length ();
- int count = rp->repeat_count ();
+ body_length_ = Repeated_music::body_get_length (m);
+ int count = Repeated_music::repeat_count (m);
Moment now = now_mom ();
start_mom_ = now;
return false;
}
- repeat_ = rp;
+ repeat_ = m;
Global_context *global = get_global_context ();
void
Percent_repeat_iterator::construct_children ()
{
- Repeated_music * mus = dynamic_cast<Repeated_music *> (get_music ());
+ Music *mus = get_music ();
finish_mom_ = mus->get_length ();
- child_iter_ = unsmob_iterator (get_iterator (mus->body ()));
+ child_iter_ = unsmob_iterator (get_iterator (Repeated_music::body (mus)));
}
lily_1_8_compatibility_used = true;
/* last-pitch should be junked some time, when
we ditch 1.8 compat too.
-cvs-
+
When you do, B should start where A left off.
\relative { A \relative { ...} B } */
#include "scm-option.hh"
Music *
-Repeated_music::body ()const
+Repeated_music::body (Music *me)
{
- return unsmob_music (get_property ("element"));
+ return unsmob_music (me->get_property ("element"));
}
SCM
-Repeated_music::alternatives ()const
+Repeated_music::alternatives (Music *me)
{
- return get_property ("elements");
+ return me->get_property ("elements");
}
-Pitch
-Repeated_music::to_relative_octave (Pitch p)
+MAKE_SCHEME_CALLBACK(Repeated_music,relative_callback, 2);
+SCM
+Repeated_music::relative_callback (SCM music, SCM pitch)
{
+ Pitch p = *unsmob_pitch (pitch);
+ Music *me = unsmob_music (music);
if (lily_1_8_relative)
{
- if (body ())
- p = body ()->to_relative_octave (p);
+ Music *body = unsmob_music (me->get_property ("element"));
+ if (body)
+ p = body->to_relative_octave (p);
- Pitch last = p ;
- if (alternatives ())
- {
- lily_1_8_compatibility_used = true;
+ Pitch last = p ;
+ SCM alternatives = me->get_property ("elements");
- for (SCM s = alternatives (); scm_is_pair (s); s = scm_cdr (s))
- unsmob_music (scm_car (s))->to_relative_octave (p);
- }
+ for (SCM s = alternatives; scm_is_pair (s); s = scm_cdr (s))
+ {
+ lily_1_8_compatibility_used = true;
+ unsmob_music (scm_car (s))->to_relative_octave (p);
+ }
- return last;
+ return last.smobbed_copy ();
}
else
{
- return Music::to_relative_octave (p);
+ return me->generic_to_relative_octave (p).smobbed_copy ();
}
}
Moment
-Repeated_music::alternatives_get_length (bool fold) const
+Repeated_music::alternatives_get_length (Music *me, bool fold)
{
- if (!alternatives ())
+ SCM alternative_list = alternatives (me);
+ int len = scm_ilength (alternative_list);
+ if (len <= 0)
return 0;
if (fold)
- return Music_sequence::maximum_length (alternatives ());
+ return Music_sequence::maximum_length (alternative_list);
Moment m = 0;
int done = 0;
+ int count = robust_scm2int (me->get_property ("repeat-count"), 0);
- SCM p = alternatives ();
- while (scm_is_pair (p) && done < repeat_count ())
+ SCM p = alternative_list;
+ while (scm_is_pair (p) && done < count)
{
m = m + unsmob_music (scm_car (p))->get_length ();
done ++;
- if (repeat_count () - done < scm_ilength (alternatives ()))
+ if (count - done < len)
p = scm_cdr (p);
}
return m;
of volta repeats, where the alternatives are iterated just as they
were entered. */
Moment
-Repeated_music::alternatives_volta_get_length () const
+Repeated_music::alternatives_volta_get_length (Music *me)
{
- if (!alternatives ())
- return 0;
-
- Moment m;
- SCM p = alternatives ();
- while (scm_is_pair (p))
- {
- m = m + unsmob_music (scm_car (p))->get_length ();
- p = scm_cdr (p);
- }
- return m;
+ return Music_sequence::cumulative_length (alternatives (me));
}
Length of the body in THIS. Disregards REPEAT-COUNT.
*/
Moment
-Repeated_music::body_get_length () const
+Repeated_music::body_get_length (Music *me)
{
Moment m = 0;
- if (body ())
+ if (Music *body = unsmob_music (me->get_property ("element")))
{
- m = body ()->get_length ();
+ m = body->get_length ();
}
return m;
}
-int
-Repeated_music::repeat_count () const
-{
- return scm_to_int (get_property ("repeat-count"));
-}
-
MAKE_SCHEME_CALLBACK (Repeated_music,unfolded_music_length, 1);
-MAKE_SCHEME_CALLBACK (Repeated_music,folded_music_length, 1);
-MAKE_SCHEME_CALLBACK (Repeated_music,volta_music_length, 1);
SCM
Repeated_music::unfolded_music_length (SCM m)
{
- Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
-
- Moment l = Moment (r->repeat_count ()) * r->body_get_length () + r->alternatives_get_length (false);
+ Music *me = unsmob_music (m);
+
+ Moment l = Moment (repeat_count (me)) * body_get_length (me) + alternatives_get_length (me, false);
return l.smobbed_copy ();
}
+MAKE_SCHEME_CALLBACK (Repeated_music,folded_music_length, 1);
SCM
Repeated_music::folded_music_length (SCM m)
{
- Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
-
- Moment l = r->body_get_length () + r->alternatives_get_length (true);
+ Music *me = unsmob_music (m);
+
+ Moment l = body_get_length (me) + alternatives_get_length (me, true);
return l.smobbed_copy ();
}
-SCM
-Repeated_music::volta_music_length (SCM m)
+int
+Repeated_music::repeat_count (Music *me)
{
- Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
- Moment l = r->body_get_length () + r->alternatives_volta_get_length ();
- return l.smobbed_copy ();
+ return scm_to_int (me->get_property ("repeat-count"));
}
-ADD_MUSIC (Repeated_music);
-
-Repeated_music::Repeated_music (SCM x)
- : Music (x)
+MAKE_SCHEME_CALLBACK (Repeated_music,volta_music_length, 1);
+SCM
+Repeated_music::volta_music_length (SCM m)
{
+ Music *me = unsmob_music (m);
+ Moment l = body_get_length (me) + alternatives_volta_get_length (me);
+ return l.smobbed_copy ();
}
-
MAKE_SCHEME_CALLBACK (Repeated_music,minimum_start, 1);
SCM
Repeated_music::minimum_start (SCM m)
{
- Music * me = unsmob_music (m);
- Music * body = unsmob_music (me->get_property ("element"));
+ Music *me = unsmob_music (m);
+ Music *body = unsmob_music (me->get_property ("element"));
if (body)
return body->start_mom ().smobbed_copy ();
public:
TRANSLATOR_DECLARATIONS (Slash_repeat_engraver);
protected:
- Repeated_music * repeat_;
+ Music *repeat_;
/// moment (global time) where beam started.
Moment start_mom_;
bool
Slash_repeat_engraver::try_music (Music * m)
{
- Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
- if (rp
+ if (m->is_mus_type ("repeated-music")
&& !repeat_
- && rp->get_property ("iterator-ctor")
+ && m->get_property ("iterator-ctor")
== Percent_repeat_iterator::constructor_proc)
{
- body_length_ = rp->body_get_length ();
- int count = rp->repeat_count ();
+ body_length_ = Repeated_music::body_get_length (m);
+ int count = Repeated_music::repeat_count (m);
Moment now = now_mom ();
start_mom_ = now;
stop_mom_ = start_mom_ + Moment (count) * body_length_;
next_moment_ = start_mom_ + body_length_;
- SCM m = get_property ("measureLength");
- Moment meas_len;
- if (Moment *mp = unsmob_moment (m))
- meas_len = *mp;
-
+ Moment meas_len = robust_scm2moment (m->get_property ("measureLength"), Moment (0));
if (body_length_ < meas_len
&& meas_len.main_part_.mod_rat (body_length_.main_part_)
== Moment (Rational (0,0)))
{
- repeat_ = rp;
+ repeat_ = m;
}
else
return false;