source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
+/*
+ ugh. Rewrite not finished yet. Still must copy atom lists.
+ */
+
+
+#include <math.h>
+
+#include "font-metric.hh"
+#include "dimensions.hh"
#include "interval.hh"
#include "string.hh"
#include "molecule.hh"
-#include "atom.hh"
-#include "debug.hh"
+#include "debug.hh"
#include "killing-cons.tcc"
-#ifdef ATOM_SMOB
-#define MOL_EOL SCM_EOL
-#define NEXT_CELL(a) SCM_CDR(a)
-#define CELLTYPE SCM
-#define UNBOX_ATOM(a) Atom::atom_l (a)
-#define BOX_ATOM(a) a->make_smob ()
-#define NEWCELL(a,b) gh_cons (a,b)
-#define UNBOX_PTR(a) SCM_CAR(a)
-#else
-#define MOL_EOL 0
-#define NEXT_CELL(a) ptr->next_
-#define CELLTYPE Cons<Atom>*
-#define UNBOX_ATOM(a) a
-#define UNBOX_PTR(a) a->car_
-#define BOX_ATOM(a) a
-#define NEWCELL(a,b) new Killing_cons<Atom>(a,b)
-#endif
Box
Molecule::extent() const
return dim_[a];
}
+Molecule::Molecule (Box b, SCM func)
+{
+ expr_ = func;
+ dim_ = b ;
+}
+
+Molecule::Molecule()
+{
+ expr_ = SCM_EOL;
+ set_empty (true);
+}
+
void
Molecule::translate (Offset o)
{
- for (CELLTYPE ptr = atom_list_; ptr != MOL_EOL; ptr = NEXT_CELL(ptr))
+ Axis a = X_AXIS;
+ while (a < NO_AXES)
{
- UNBOX_ATOM(UNBOX_PTR(ptr))->off_ += o;
+ if (abs(o[a]) > 30 CM
+ || isinf (o[a]) || isnan (o[a]))
+ {
+ programming_error ("Improbable offset for translation: setting to zero");
+ o[a] = 0.0;
+ }
+ incr (a);
}
+
+ expr_ = gh_list (ly_symbol2scm ("translate-molecule"),
+ ly_offset2scm (o),
+ expr_, SCM_UNDEFINED);
if (!empty_b ())
dim_.translate (o);
}
+
void
Molecule::translate_axis (Real x,Axis a)
{
- for (CELLTYPE ptr = atom_list_; ptr != MOL_EOL; ptr = NEXT_CELL(ptr))
- UNBOX_ATOM (UNBOX_PTR(ptr))->off_[a] += x;
+ Offset o(0,0);
+ o[a] = x;
+ translate (o);
+}
+
- if (!dim_[a].empty_b ())
- dim_[a] += x;
-}
void
Molecule::add_molecule (Molecule const &m)
{
- for (CELLTYPE ptr = m.atom_list_; ptr != MOL_EOL; ptr = NEXT_CELL(ptr))
- add_atom(UNBOX_ATOM (UNBOX_PTR(ptr)));
-
+ expr_ = gh_list (ly_symbol2scm ("combine-molecule"),
+ m.expr_,
+ expr_, SCM_UNDEFINED);
dim_.unite (m.dim_);
}
-void
-Molecule::add_atom (Atom const *al)
-{
- Atom *a = new Atom(*al);
-
- atom_list_ = NEWCELL(BOX_ATOM(a), atom_list_);
-}
-
-void
-Molecule::operator=(Molecule const & src)
-{
- if (&src == this) return;
-
-#ifndef ATOM_SMOB
- delete atom_list_;
-#endif
-
- atom_list_ = MOL_EOL;
- dim_= src.dim_;
- add_molecule (src);
-}
-
void
Molecule::set_empty (bool e)
{
}
}
-Molecule::Molecule (Molecule const &s)
-{
- atom_list_ = MOL_EOL;
- set_empty (true);
- add_molecule (s);
-}
-
-Molecule::~Molecule ()
-{
-#ifndef ATOM_SMOB
- delete atom_list_;
-#endif
-}
-
-void
-Molecule::print() const
-{
-#ifndef NPRINT
- if (! flower_dstream)
- return;
- DEBUG_OUT << "dim:";
- for (Axis i=X_AXIS; i < NO_AXES; incr (i))
- DEBUG_OUT << axis_name_str (i) << " = " << dim_[i].str ();
-#endif
-}
void
Molecule::align_to (Axis a, Direction d)
{
- if (d == CENTER)
- {
- Interval i (extent (a));
- translate_axis (-i.center (), a);
- }
- else
- {
- translate_axis (-extent (a)[d], a);
- }
-}
-
-Molecule::Molecule ()
-{
- dim_[X_AXIS].set_empty ();
- dim_[Y_AXIS].set_empty ();
- atom_list_ = MOL_EOL;
+ Interval i (extent (a));
+ Real r = (d == CENTER) ? i.center () : i[d];
+ translate_axis (-r, a);
}
bool
Molecule::empty_b () const
{
- return atom_list_ == MOL_EOL;
+ return expr_ == SCM_EOL;
+}
+
+
+SCM
+fontify_atom(Font_metric * met, SCM f)
+{
+ return gh_list (ly_symbol2scm ("fontify"),
+ ly_quote_scm (met->description ()), f, SCM_UNDEFINED);
}