2 event.cc -- implement Event
4 source file of the GNU LilyPond music typesetter
6 (c) 1996--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 Event::get_length () const
16 Duration *d = unsmob_duration (get_mus_property ("duration"));
22 return d->get_length ();
26 Event::compress (Moment m)
28 Duration *d = unsmob_duration (get_mus_property ("duration"));
30 set_mus_property ("duration", d ->compressed (m.main_part_).smobbed_copy ());
34 Event::transpose (Pitch delta)
36 Pitch *p = unsmob_pitch (get_mus_property ("pitch"));
43 if (abs (np.alteration_) > 2)
45 warning (_f ("Transposition by %s makes accidental larger than two",
49 set_mus_property ("pitch", np.smobbed_copy ());
53 Event::to_relative_octave (Pitch last)
55 Pitch *old_pit = unsmob_pitch (get_mus_property ("pitch"));
58 Pitch new_pit = *old_pit;
59 new_pit.to_relative_octave (last);
60 set_mus_property ("pitch", new_pit.smobbed_copy ());
73 LY_DEFINE(music_duration_length, "music-duration-length", 1, 0,0,
75 "Extract the duration field from @var{mus}, and return the length.")
77 Music* m = unsmob_music(mus);
78 SCM_ASSERT_TYPE(m, mus, SCM_ARG1, __FUNCTION__, "Music");
80 Duration *d = unsmob_duration (m->get_mus_property ("duration"));
89 programming_error("Music has no duration");
90 return l.smobbed_copy();
95 LY_DEFINE(music_duration_compress, "music-duration-compress", 2, 0,0,
96 (SCM mus, SCM factor),
97 "Extract the duration field from @var{mus}, and compress it.")
99 Music* m = unsmob_music(mus);
100 Moment * f = unsmob_moment (factor);
101 SCM_ASSERT_TYPE(m, mus, SCM_ARG1, __FUNCTION__, "Music");
102 SCM_ASSERT_TYPE(f, factor, SCM_ARG2, __FUNCTION__, "Moment");
104 Duration *d = unsmob_duration (m->get_mus_property ("duration"));
106 m->set_mus_property ("duration", d->compressed (f->main_part_).smobbed_copy());
107 return SCM_UNSPECIFIED;
113 This is hairy, since the scale in a key-change event may contain
116 LY_DEFINE(transpose_key_alist,"transpose-key-alist",
117 2, 0,0, (SCM l, SCM pitch),
118 "Make a new key alist of @var{l} transposed by pitch @var{pitch}")
120 SCM newlist = SCM_EOL;
121 Pitch *p = unsmob_pitch (pitch);
123 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
125 SCM key = ly_caar (s);
126 SCM alter = ly_cdar (s);
129 Pitch orig (gh_scm2int (ly_car (key)),
130 gh_scm2int (ly_cdr (key)),
135 SCM key = gh_cons (scm_int2num (orig.get_octave ()),
136 scm_int2num (orig.notename_));
138 newlist = gh_cons (gh_cons (key, scm_int2num (orig.alteration_)),
141 else if (gh_number_p (key))
143 Pitch orig (0, gh_scm2int (key), gh_scm2int (alter));
146 key =scm_int2num (orig.notename_);
147 alter = scm_int2num (orig.alteration_);
148 newlist = gh_cons (gh_cons (key, alter), newlist);
151 return scm_reverse_x (newlist, SCM_EOL);
155 Key_change_req::transpose (Pitch p)
157 SCM pa = get_mus_property ("pitch-alist");
159 set_mus_property ("pitch-alist", transpose_key_alist (pa, p.smobbed_copy()));
164 alist_equal_p (SCM a, SCM b)
167 gh_pair_p (s); s = ly_cdr (s))
169 SCM key = ly_caar (s);
170 SCM val = ly_cdar (s);
171 SCM l = scm_assoc (key, b);
174 || !gh_equal_p ( ly_cdr (l), val))
182 Key_change_req::do_equal_b (Event const * m )const
184 Key_change_req const * kc =dynamic_cast<Key_change_req const*> (m);
188 return alist_equal_p (get_mus_property ("pitch-alist"),
189 kc->get_mus_property ("pitch-alist"));
192 ADD_MUSIC (Key_change_req);