source file of the GNU LilyPond music typesetter
- (C) 2002 Juergen Reuter <reuter@ipd.uka.de>
+ (c) 2002--2004 Juergen Reuter <reuter@ipd.uka.de>
*/
#include "staff-symbol-referencer.hh"
#include "pitch.hh"
#include "ambitus.hh"
-#include "molecule.hh"
+#include "stencil.hh"
#include "note-head.hh"
#include "item.hh"
#include "font-interface.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
#include "lookup.hh"
+/*
+ UGH UGH UGH
+
+ This does 3 things at one:
+
+ - acc positioning
+ - drawing accidentals
+ - drawing note heads
+
+ It confuses interpretation & formatting.
+
+ UGH.
+ --hwn.
+ */
+
/*
* TODO: note-head collision handling
*
*/
/**
- * Given a pitch and a key_signature, decide what accidentals to show.
- *
- * Possible return values:
- *
- * 0: do not show any accidental
- * 1: show pitch->alteration_ only
- * 2: show pitch->alteration_, preceded by a natural sign
+ Given a pitch and a key_signature, decide what accidentals to show.
+
+ Possible return values:
+
+ 0: do not show any accidental
+ 1: show pitch->alteration_ only
+ 2: show pitch->get_alteration, preceded by a natural sign
+
+ UGH: code duplication! See accidental-engraver.
+
*/
static int
number_accidentals (SCM key_signature, Pitch *pitch,
bool ignore_octave_b, bool force_accidental)
{
- int notename = pitch->notename_;
- int octave = pitch->octave_;
- int alteration = pitch->alteration_;
+ int notename = pitch->get_notename ();
+ int octave = pitch->get_octave ();
+ int alteration = pitch->get_alteration ();
if (force_accidental) // ignore key signature
return 1;
+
#if DEBUG_AMBITUS
scm_display (key_signature, scm_current_output_port ());
#endif
if (ignore_octave_b)
prev = ly_assoc_cdr (scm_int2num (notename), key_signature);
else
- prev = gh_assoc (gh_cons (scm_int2num (octave), scm_int2num (notename)),
+ prev = scm_assoc (scm_cons (scm_int2num (octave), scm_int2num (notename)),
key_signature);
/* should really be true unless prev == SCM_BOOL_F */
- if (gh_pair_p (prev) && gh_pair_p (ly_cdr (prev)))
+ if (ly_c_pair_p (prev) && ly_c_pair_p (ly_cdr (prev)))
{
- prev = gh_cons (ly_car (prev), ly_cadr (prev));
+ prev = scm_cons (ly_car (prev), ly_cadr (prev));
}
/* If an accidental was not found */
if (prev == SCM_BOOL_F)
- prev = gh_assoc (scm_int2num (notename), key_signature);
+ prev = scm_assoc (scm_int2num (notename), key_signature);
SCM prev_acc = (prev == SCM_BOOL_F) ? scm_int2num (0) : ly_cdr (prev);
- int sig_alteration = gh_number_p (prev_acc) ? gh_scm2int (prev_acc) : 0;
+ int sig_alteration = ly_c_number_p (prev_acc) ? ly_scm2int (prev_acc) : 0;
if (alteration == sig_alteration) // no accidental at all needed
return 0;
}
void
-add_accidentals (Item *me, Molecule *head, int num_acc,
+add_accidentals (Item *me, Stencil *head, int num_acc,
Pitch *pitch, String accidentals_style, Real yoffs)
{
if (!num_acc)
return;
- if (pitch->alteration_)
+ if (pitch->get_alteration ())
{
- Molecule accidental (Font_interface::get_default_font (me)->
+ Stencil accidental (Font_interface::get_default_font (me)->
find_by_name (String ("accidentals-") +
accidentals_style +
- to_string (pitch->alteration_)));
+ to_string (pitch->get_alteration ())));
accidental.translate_axis (yoffs, Y_AXIS);
- head->add_at_edge (X_AXIS, LEFT, accidental, 0.1);
+ head->add_at_edge (X_AXIS, LEFT, accidental, 0.1, 0);
}
if (num_acc == 2)
{
- Molecule natural (Font_interface::get_default_font (me)->
+ Stencil natural (Font_interface::get_default_font (me)->
find_by_name (String ("accidentals-") +
accidentals_style +
to_string ("0")));
natural.translate_axis (yoffs, Y_AXIS);
- head->add_at_edge (X_AXIS, LEFT, natural, 0.1);
+ head->add_at_edge (X_AXIS, LEFT, natural, 0.1, 0);
}
}
-MAKE_SCHEME_CALLBACK (Ambitus,brew_molecule,1);
+MAKE_SCHEME_CALLBACK (Ambitus,print,1);
SCM
-Ambitus::brew_molecule (SCM smob)
+Ambitus::print (SCM smob)
{
- Item *me = (Item *)unsmob_grob (smob);
- Molecule molecule = Molecule ();
+ Item *me = (Item*) unsmob_grob (smob);
+ Stencil stencil;
- SCM scm_note_head_style = me->get_grob_property ("note-head-style");
+ SCM scm_note_head_style = me->get_property ("note-head-style");
String note_head_style;
- if (gh_symbol_p (scm_note_head_style))
+ if (ly_c_symbol_p (scm_note_head_style))
{
String note_head_style =
- ly_scm2string (scm_symbol_to_string (scm_note_head_style));
+ ly_symbol2string (scm_note_head_style);
}
else
{
note_head_style = String ("noteheads-2");
}
- if (Font_interface::get_default_font (me)->find_by_name (note_head_style).empty_b ())
+ if (Font_interface::get_default_font (me)->find_by_name (note_head_style).is_empty ())
{
String message = "Ambitus: no such note head: `" + note_head_style + "'";
me->warning (_ (message.to_str0 ()));
return SCM_EOL;
}
+ /*
+ FIXME: Use positions.
+ */
int p_min, p_max;
- Pitch *pitch_min = unsmob_pitch (me->get_grob_property ("pitch-min"));
+ Pitch *pitch_min = unsmob_pitch (me->get_property ("pitch-min"));
if (!pitch_min)
{
- me->programming_error("Ambitus: pitch_min undefined; assuming 0");
+ me->programming_error ("Ambitus: pitch_min undefined; assuming 0");
p_min = 0;
}
else
{
p_min = pitch_min->steps ();
}
- Pitch *pitch_max = unsmob_pitch (me->get_grob_property ("pitch-max"));
+ Pitch *pitch_max = unsmob_pitch (me->get_property ("pitch-max"));
if (!pitch_max)
{
- me->programming_error("Ambitus: pitch_max undefined; assuming 0");
+ me->programming_error ("Ambitus: pitch_max undefined; assuming 0");
p_max = 0;
}
else
me->programming_error ("Ambitus: reverse range");
}
- SCM c0 = me->get_grob_property ("c0-position");
- if (gh_number_p (c0))
+ SCM c0 = me->get_property ("c0-position");
+ if (ly_c_number_p (c0))
{
- p_min += gh_scm2int (c0);
- p_max += gh_scm2int (c0);
+ p_min += ly_scm2int (c0);
+ p_max += ly_scm2int (c0);
}
// create heads
- Molecule head_min =
+ Stencil head_min =
Font_interface::get_default_font (me)->find_by_name (note_head_style);
head_min.translate_axis (0.5*p_min, Y_AXIS);
- Molecule head_max =
+ Stencil head_max =
Font_interface::get_default_font (me)->find_by_name (note_head_style);
head_max.translate_axis (0.5*p_max, Y_AXIS);
// join heads
- if (to_boolean (me->get_grob_property ("join-heads")) &&
+ if (to_boolean (me->get_property ("join-heads")) &&
((p_max - p_min) >= 3))
{
- Real linethickness = me->get_paper ()->get_var ("linethickness");
- Real blotdiameter = me->get_paper ()->get_var ("blotdiameter");
+ Real linethickness = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
+ Real blotdiameter = me->get_paper ()->get_dimension (ly_symbol2scm ("blotdiameter"));
Interval x_extent = 0.5 * Interval (-linethickness, +linethickness);
Interval y_extent = 0.5 * Interval (p_min + 1.35, p_max - 1.35);
Box line_box (x_extent, y_extent);
- Molecule line = Lookup::roundfilledbox (line_box, blotdiameter);
+ Stencil line = Lookup::round_filled_box (line_box, blotdiameter);
line.translate_axis (0.5 * head_min.extent (X_AXIS).length (), X_AXIS);
- molecule.add_molecule (line);
+ stencil.add_stencil (line);
}
// add ledger lines
Real right_ledger_protusion = left_ledger_protusion;
Interval l_extents = Interval (hd[LEFT] - left_ledger_protusion,
hd[RIGHT] + right_ledger_protusion);
- Molecule ledger_lines;
+ Stencil ledger_lines;
int interspaces = Staff_symbol_referencer::line_count (me) - 1;
ledger_lines =
- Note_head::brew_ledger_lines (me, p_min, interspaces, l_extents, true);
+ Note_head::brew_ledger_lines (me, p_min, interspaces, l_extents, 0,true);
ledger_lines.translate_axis (0.5 * p_min, Y_AXIS);
- molecule.add_molecule (ledger_lines);
+ stencil.add_stencil (ledger_lines);
ledger_lines =
- Note_head::brew_ledger_lines (me, p_max, interspaces, l_extents, true);
+ Note_head::brew_ledger_lines (me, p_max, interspaces, l_extents, 0, true);
ledger_lines.translate_axis (0.5 * p_max, Y_AXIS);
- molecule.add_molecule (ledger_lines);
+ stencil.add_stencil (ledger_lines);
// add accidentals
- SCM key_signature = me->get_grob_property ("key-signature");
- SCM scm_accidentals_style = me->get_grob_property ("accidentals-style");
+ SCM key_signature = me->get_property ("key-signature");
+ SCM scm_accidentals_style = me->get_property ("accidentals-style");
String accidentals_style;
- if (gh_symbol_p (scm_accidentals_style))
+ if (ly_c_symbol_p (scm_accidentals_style))
{
accidentals_style =
- ly_scm2string (scm_symbol_to_string (scm_accidentals_style));
+ ly_symbol2string (scm_accidentals_style);
}
else
{
accidentals_style = String ("");
}
+
int num_acc;
num_acc = number_accidentals (key_signature, pitch_min, true, false);
add_accidentals (me, &head_min, num_acc, pitch_min,
accidentals_style, 0.5 * p_max);
// add heads
- molecule.add_molecule (head_min);
- molecule.add_molecule (head_max);
+ stencil.add_stencil (head_min);
+ stencil.add_stencil (head_max);
- return molecule.smobbed_copy ();
+ return stencil.smobbed_copy ();
}
ADD_INTERFACE (Ambitus, "ambitus-interface",
- "An ambitus represents the pitch range of a voice.",
- "c0-position pitch-min pitch-max accidentals note-head-style join-heads");
+ "An object that represents the pitch range of a voice.",
+ "c0-position pitch-min pitch-max accidentals note-head-style accidentals-style join-heads");