2 music.cc -- implement Music
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "input-smob.hh"
11 #include "music-list.hh"
14 #include "ly-smobs.icc"
17 ly_deep_mus_copy (SCM m
)
21 SCM ss
= unsmob_music (m
)->clone ()->self_scm ();
22 scm_unprotect_object (ss
);
25 else if (gh_pair_p (m
))
27 return gh_cons (ly_deep_mus_copy (gh_car (m
)), ly_deep_mus_copy (gh_cdr (m
)));
36 immutable_property_alist_
= SCM_EOL
;
37 mutable_property_alist_
= SCM_EOL
;
41 Music::Music (Music
const &m
)
43 immutable_property_alist_
= m
.immutable_property_alist_
;
44 SCM c
=ly_deep_mus_copy (m
.mutable_property_alist_
);
45 mutable_property_alist_
= c
;
49 set_spot (*m
.origin ());
55 immutable_property_alist_
= l
;
56 mutable_property_alist_
= SCM_EOL
;
62 Music::mark_smob (SCM m
)
64 Music
* mus
= (Music
*)SCM_CELL_WORD_1 (m
);
65 scm_gc_mark (mus
->immutable_property_alist_
);
66 scm_gc_mark (mus
->mutable_property_alist_
);
71 Music::compress (Moment
)
78 Music::length_mom () const
80 SCM l
= get_mus_property ("length");
81 if (unsmob_moment (l
))
82 return *unsmob_moment (l
);
83 else if (gh_procedure_p (l
))
85 SCM res
= gh_call1 (l
, self_scm ());
86 return *unsmob_moment (res
);
93 print_alist (SCM a
, SCM port
)
95 for (SCM s
= a
; gh_pair_p (s
); s
= gh_cdr (s
))
97 scm_display (gh_caar (s
), port
);
98 scm_puts (" = ", port
);
99 scm_write (gh_cdar (s
), port
);
100 scm_puts ("\n", port
);
105 Music::print_smob (SCM s
, SCM p
, scm_print_state
*)
107 scm_puts ("#<Music ", p
);
108 Music
* m
= unsmob_music (s
);
109 scm_puts (classname (m
),p
);
111 print_alist (m
->mutable_property_alist_
, p
);
112 print_alist (m
->immutable_property_alist_
, p
);
119 Music::to_relative_octave (Pitch m
)
126 Music::transpose (Pitch
)
130 IMPLEMENT_TYPE_P (Music
, "music?");
131 IMPLEMENT_UNSMOB (Music
,music
);
132 IMPLEMENT_SMOBS (Music
);
133 IMPLEMENT_DEFAULT_EQUAL_P (Music
);
135 /****************************/
138 Music::get_mus_property (const char *nm
) const
140 SCM sym
= ly_symbol2scm (nm
);
141 return get_mus_property (sym
);
145 Music::get_mus_property (SCM sym
) const
147 SCM s
= scm_sloppy_assq (sym
, mutable_property_alist_
);
151 s
= scm_sloppy_assq (sym
, immutable_property_alist_
);
152 return (s
== SCM_BOOL_F
) ? SCM_EOL
: gh_cdr (s
);
156 Remove the value associated with KEY, and return it. The result is
157 that a next call will yield SCM_EOL (and not the underlying
161 Music::remove_mus_property (const char* key
)
163 SCM val
= get_mus_property (key
);
165 set_mus_property (key
, SCM_EOL
);
170 Music::set_mus_property (const char* k
, SCM v
)
172 SCM s
= ly_symbol2scm (k
);
173 set_mus_property (s
, v
);
177 Music::set_immutable_mus_property (const char*k
, SCM v
)
179 SCM s
= ly_symbol2scm (k
);
180 set_immutable_mus_property (s
, v
);
184 Music::set_immutable_mus_property (SCM s
, SCM v
)
186 immutable_property_alist_
= gh_cons (gh_cons (s
,v
), mutable_property_alist_
);
187 mutable_property_alist_
= scm_assq_remove_x (mutable_property_alist_
, s
);
190 Music::set_mus_property (SCM s
, SCM v
)
192 mutable_property_alist_
= scm_assq_set_x (mutable_property_alist_
, s
, v
);
198 Music::set_spot (Input ip
)
200 set_mus_property ("origin", make_input (ip
));
206 Music::origin () const
208 Input
*ip
= unsmob_input (get_mus_property ("origin"));
209 return ip
? ip
: & dummy_input_global
;
222 ly_get_mus_property (SCM mus
, SCM sym
)
224 Music
* sc
= unsmob_music (mus
);
228 return sc
->get_mus_property (sym
);
232 warning (_ ("ly_get_mus_property (): Not a Music"));
233 scm_write (mus
, scm_current_error_port ());
240 ly_set_mus_property (SCM mus
, SCM sym
, SCM val
)
242 Music
* sc
= unsmob_music (mus
);
244 if (!gh_symbol_p (sym
))
246 warning (_ ("ly_set_mus_property (): Not a symbol"));
247 scm_write (mus
, scm_current_error_port ());
249 return SCM_UNSPECIFIED
;
254 sc
->set_mus_property (sym
, val
);
258 warning (_ ("ly_set_mus_property (): not of type Music"));
259 scm_write (mus
, scm_current_error_port ());
262 return SCM_UNSPECIFIED
;
266 // to do property args
268 ly_make_music (SCM type
)
270 if (!gh_string_p (type
))
272 warning (_ ("ly_make_music (): Not a string"));
273 scm_write (type
, scm_current_error_port ());
275 return SCM_UNSPECIFIED
;
279 SCM s
= get_music (ly_scm2string (type
))->self_scm ();
280 scm_unprotect_object (s
);
286 ly_music_name (SCM mus
)
288 Music
* m
= unsmob_music (mus
);
292 warning (_ ("ly_music_name (): Not a music expression"));
293 scm_write (mus
, scm_current_error_port ());
297 return ly_str02scm (nm
);
303 scm_make_gsubr ("ly-get-mus-property", 2, 0, 0, (Scheme_function_unknown
)ly_get_mus_property
);
304 scm_make_gsubr ("ly-set-mus-property", 3, 0, 0, (Scheme_function_unknown
)ly_set_mus_property
);
305 scm_make_gsubr ("ly-make-music", 1, 0, 0, (Scheme_function_unknown
)ly_make_music
);
306 scm_make_gsubr ("ly-music-name", 1, 0, 0, (Scheme_function_unknown
)ly_music_name
);
308 ADD_SCM_INIT_FUNC (musicscm
,init_functions
);