]> git.donarmstrong.com Git - lilypond.git/blob - lily/music.cc
release: 1.3.93
[lilypond.git] / lily / music.cc
1 /*
2   music.cc -- implement Music
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "input-smob.hh"
10 #include "music.hh"
11 #include "music-list.hh"
12 #include "debug.hh"
13 #include "musical-pitch.hh"
14 #include "ly-smobs.icc"
15
16 SCM
17 ly_deep_mus_copy (SCM m)
18 {
19   if (unsmob_music (m))
20     {
21       SCM ss =  unsmob_music (m)->clone ()->self_scm ();
22       scm_unprotect_object (ss);
23       return ss;
24     }
25   else if (gh_pair_p (m))
26     {
27       return gh_cons (ly_deep_mus_copy (gh_car (m)), ly_deep_mus_copy (gh_cdr (m)));
28     }
29   else
30     return m;
31 }
32
33
34 Music::Music (Music const &m)
35 {
36   immutable_property_alist_ = m.immutable_property_alist_;
37   SCM c =ly_deep_mus_copy (m.mutable_property_alist_);
38   mutable_property_alist_ = c;
39
40   smobify_self ();
41
42   set_spot (*m.origin ());
43 }
44
45
46 Music::Music()
47 {
48   immutable_property_alist_ = SCM_EOL;
49   mutable_property_alist_ = SCM_EOL;
50   smobify_self ();
51 }
52
53 SCM
54 Music::mark_smob (SCM m)
55 {
56   Music * mus = (Music *)SCM_CELL_WORD_1(m);
57   scm_gc_mark (mus->immutable_property_alist_);
58   scm_gc_mark (mus->mutable_property_alist_);
59   return SCM_EOL;
60 }
61
62 void    
63 Music::compress (Moment)
64 {
65 }
66
67
68
69 Moment
70 Music::length_mom () const
71 {
72   return 0;
73 }
74
75 int
76 Music::print_smob(SCM s, SCM p, scm_print_state*)
77 {
78   scm_puts ("#<Music ", p);
79   scm_puts (classname(unsmob_music (s)),p);
80   scm_puts (">",p);
81   return 1;
82 }
83
84 Musical_pitch
85 Music::to_relative_octave (Musical_pitch m)
86 {
87   return m;
88 }
89
90
91 void
92 Music::transpose (Musical_pitch )
93 {
94 }
95
96
97 IMPLEMENT_UNSMOB(Music,music);
98 IMPLEMENT_SMOBS(Music);
99 IMPLEMENT_DEFAULT_EQUAL_P(Music);
100
101 /****************************/
102
103 SCM
104 Music::get_mus_property (const char *nm) const
105 {
106   SCM sym = ly_symbol2scm (nm);
107   return get_mus_property (sym);
108 }
109
110 SCM
111 Music::get_mus_property (SCM sym) const
112 {
113   SCM s = scm_sloppy_assq(sym, mutable_property_alist_);
114   if (s != SCM_BOOL_F)
115     return gh_cdr (s);
116
117   s = scm_sloppy_assq (sym, immutable_property_alist_);
118   return (s == SCM_BOOL_F) ? SCM_EOL : gh_cdr (s); 
119 }
120
121 /*
122   Remove the value associated with KEY, and return it. The result is
123   that a next call will yield SCM_EOL (and not the underlying
124   `basic' property.
125 */
126 SCM
127 Music::remove_mus_property (const char* key)
128 {
129   SCM val = get_mus_property (key);
130   if (val != SCM_EOL)
131     set_mus_property (key, SCM_EOL);
132   return val;
133 }
134
135 void
136 Music::set_mus_property (const char* k, SCM v)
137 {
138   SCM s = ly_symbol2scm (k);
139   set_mus_property (s, v);
140 }
141
142 void
143 Music::set_immutable_mus_property (const char*k, SCM v)
144 {
145   SCM s = ly_symbol2scm (k);
146   set_immutable_mus_property (s, v);
147 }
148
149 void
150 Music::set_immutable_mus_property (SCM s, SCM v)
151 {
152   immutable_property_alist_ = gh_cons (gh_cons (s,v), mutable_property_alist_);
153   mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, s);
154 }
155 void
156 Music::set_mus_property (SCM s, SCM v)
157 {
158   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
159 }
160
161 void
162 Music::set_spot (Input ip)
163 {
164    set_mus_property ("origin", make_input (ip));
165 }
166
167
168
169 Input*
170 Music::origin () const
171 {
172   Input *ip = unsmob_input (get_mus_property ("origin"));
173   return ip ? ip : & dummy_input_global; 
174 }
175
176
177
178
179
180 Music::~Music ()
181 {
182   
183 }