#include "main.hh"
#include "dimensions.hh"
#include "text-item.hh"
+#include "lily-guile.icc"
ADD_THIS_TRANSLATOR (Chord_name_engraver);
if (gh_boolean_p (chord_inversion))
find_inversion_b = gh_scm2bool (chord_inversion);
- chord_name_p_ = new Chord_name (to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_, find_inversion_b));
-
+ chord_name_p_ = new Chord_name;
+ Chord chord = to_chord (pitch_arr_, tonic_req_, inversion_req_, bass_req_,
+ find_inversion_b);
+
+ /*
+ Hmm, why not represent complete chord as list?
+ ((tonic third fifth) (inversion bass))
+ */
+ chord_name_p_->set_elt_property ("pitches", array_to_scm (chord.pitch_arr_));
+ if (chord.inversion_b_)
+ chord_name_p_->set_elt_property ("inversion",
+ to_scm (chord.inversion_pitch_));
+ if (chord.bass_b_)
+ chord_name_p_->set_elt_property ("bass", to_scm (chord.bass_pitch_));
+
announce_element (Score_element_info (chord_name_p_, 0));
}
#include "molecule.hh"
#include "paper-def.hh"
#include "lookup.hh"
+#include "lily-guile.icc"
-SCM
-pitch2scm (Musical_pitch p)
-{
- return gh_cons (gh_int2scm (p.notename_i_), gh_int2scm (p.accidental_i_));
-}
-
-Chord_name::Chord_name (Chord const& c)
-{
- chord_ = c;
-}
+/*
+ TODO: move text lookup out of Chord_name
+ */
/*
word is roman text or styled text:
{
while (gh_cdr (scm) != SCM_EOL)
{
- mol.add_at_edge (X_AXIS, RIGHT,
- ly_word2molecule (gh_car (scm)), 0);
+ mol.add_at_edge (X_AXIS, RIGHT, ly_word2molecule (gh_car (scm)), 0);
scm = gh_cdr (scm);
}
scm = gh_car (scm);
}
- mol.add_at_edge (X_AXIS, RIGHT,
- ly_word2molecule (scm), 0);
+ mol.add_at_edge (X_AXIS, RIGHT, ly_word2molecule (scm), 0);
return mol;
}
Molecule
Chord_name::pitch2molecule (Musical_pitch p) const
{
- SCM name = scm_eval (gh_list (ly_symbol2scm ("user-pitch-name"), ly_quote_scm (pitch2scm (p)), SCM_UNDEFINED));
+ SCM name = scm_eval (gh_list (ly_symbol2scm ("user-pitch-name"),
+ ly_quote_scm (to_scm (p)),
+ SCM_UNDEFINED));
if (name != SCM_UNSPECIFIED)
{
return diff;
}
+/*
+ JUNKME
+ */
bool
Chord_name::user_chord_name (Array<Musical_pitch> pitch_arr, Chord_mol* name_p) const
{
- SCM chord = SCM_EOL;
Array<Musical_pitch> chord_type = pitch_arr;
Chord::rebuild_transpose (&chord_type, diff_pitch (pitch_arr[0], Musical_pitch (0)), false);
+#if 0
+ SCM chord = SCM_EOL;
for (int i= chord_type.size (); i--; )
- chord = gh_cons (pitch2scm (chord_type[i]), chord);
+ chord = gh_cons (to_scm (chord_type[i]), chord);
+#else
+ SCM chord = array_to_scm (chord_type);
+#endif
- SCM name = scm_eval (gh_list (ly_symbol2scm ("user-chord-name"), ly_quote_scm (chord), SCM_UNDEFINED));
+ SCM name = scm_eval (gh_list (ly_symbol2scm ("user-chord-name"),
+ ly_quote_scm (chord),
+ SCM_UNDEFINED));
if (gh_pair_p (name))
{
name_p->modifier_mol = ly_text2molecule (gh_car (name));
scale.push (Musical_pitch (i));
Musical_pitch tonic = pitch_arr[0];
- chord_.rebuild_transpose (&scale, tonic, true);
+ Chord::rebuild_transpose (&scale, tonic, true);
/*
Does chord include this step? -1 if flat
}
}
+/*
+ TODO:
+ fix silly to-and-fro scm conversions
+ */
Molecule*
Chord_name::do_brew_molecule_p () const
{
- Musical_pitch tonic = chord_.pitch_arr_[0];
+ Array<Musical_pitch> pitch_arr;
+ scm_to_array (get_elt_property ("pitches"), &pitch_arr);
+ Musical_pitch tonic = pitch_arr[0];
Chord_mol name;
name.tonic_mol = pitch2molecule (tonic);
maybe we should check all sub-lists of pitches, not
just full list and base triad?
*/
- if (!user_chord_name (chord_.pitch_arr_, &name))
+ if (!user_chord_name (pitch_arr, &name))
{
/*
else, check if user has listed base triad
use user base name and add banter for remaining part
*/
- if ((chord_.pitch_arr_.size () > 2)
- && user_chord_name (chord_.pitch_arr_.slice (0, 3), &name))
+ if ((pitch_arr.size () > 2)
+ && user_chord_name (pitch_arr.slice (0, 3), &name))
{
Array<Musical_pitch> base = Chord::base_arr (tonic);
- base.concat (chord_.pitch_arr_.slice (3, chord_.pitch_arr_.size ()));
+ base.concat (pitch_arr.slice (3, pitch_arr.size ()));
banter (base, &name);
}
/*
*/
else
{
- banter (chord_.pitch_arr_, &name);
+ banter (pitch_arr, &name);
}
}
- if (chord_.inversion_b_)
+ SCM s = get_elt_property ("inversion");
+ if (s != SCM_UNDEFINED)
{
name.inversion_mol = lookup_l ()->text ("", "/", paper_l ());
- // zucht const&
- Molecule mol = pitch2molecule (chord_.inversion_pitch_);
+ Musical_pitch p;
+ scm_to (s, &p);
+ Molecule mol = pitch2molecule (p);
name.inversion_mol.add_at_edge (X_AXIS, RIGHT, mol, 0);
}
- if (chord_.bass_b_)
+ s = get_elt_property ("bass");
+ if (s != SCM_UNDEFINED)
{
name.bass_mol = lookup_l ()->text ("", "/", paper_l ());
- Molecule mol = pitch2molecule (chord_.bass_pitch_);
+ Musical_pitch p;
+ scm_to (s, &p);
+ Molecule mol = pitch2molecule (p);
name.bass_mol.add_at_edge (X_AXIS, RIGHT, mol, 0);
}
-;; pitch: (notename . accidental)
+;; note-name: (note . accidental)
;; list: (list-of-pitches . (modifier-string . addition-subtraction-string))
;; if a complete chord is found, use name
;; if a chord's base triad is found (c e g), use name
-(define pitch-names-alist '())
-(set! pitch-names-alist
+(define note-names-alist '())
+(set! note-names-alist
(append
'(
; use these for German naming
;((0 . 1) . ("C" ("feta-1" . "\10")))
;((0 . -1) . ("C" ("feta-1" . "\12")))
)
- pitch-names-alist))
+ note-names-alist))
+(define (pitch->note-name pitch)
+ (cons (car pitch) (cadr pitch)))
+
(define (user-pitch-name pitch)
- (let ((entry (assoc pitch pitch-names-alist)))
+ (let ((entry (assoc (pitch->note-name pitch) note-names-alist)))
(if entry
(cdr entry))))
chord-names-alist))
(define (user-chord-name chord)
- ;(display chord)
- ;(newline)
- (let ((entry (assoc chord chord-names-alist)))
- (if entry
- (cdr entry))))
-
+ (let ((entry (assoc (map (lambda (x) (pitch->note-name x)) chord)
+ chord-names-alist)))
+ (if entry
+ (cdr entry))))