]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.3.16
authorfred <fred>
Tue, 26 Mar 2002 22:44:40 +0000 (22:44 +0000)
committerfred <fred>
Tue, 26 Mar 2002 22:44:40 +0000 (22:44 +0000)
input/test/banter-chords.ly
input/test/knee-mult.ly [new file with mode: 0644]
lily/chord-name-engraver.cc
lily/chord-name.cc
lily/include/chord-name.hh
lily/include/lily-guile.icc [new file with mode: 0644]
scm/chord-names.scm

index 77ef6e5f063d34f0a5597c161683590f76c638aa..4fce5022c5dbd8ca7bc997e18db4b41623222fa4 100644 (file)
@@ -16,14 +16,14 @@ TestedFeatures =     "Banter named chords";
 % when this file has been parsed...
 
 % {
-#(set! pitch-names-alist
+#(set! note-names-alist
       (append 
       '(
        ; use these for German naming
        ((6 . 0) . ("H" ""))
        ((6 . -1) . ("B" ("feta-1" . "\12")))
        )
-      pitch-names-alist))
+      note-names-alist))
 
 #(set! chord-names-alist
       (append 
diff --git a/input/test/knee-mult.ly b/input/test/knee-mult.ly
new file mode 100644 (file)
index 0000000..98eb914
--- /dev/null
@@ -0,0 +1,24 @@
+\score{
+       \context PianoStaff <
+       \context Staff=one \notes\relative c'{
+               s1
+       }
+       \context Staff=two \notes\relative c'{
+               \clef bass;
+% no knee
+               \stemup [c8 \translator Staff=one \stemdown g'16 f]
+               s8
+               s2
+       }
+       >
+       \paper{
+               \translator{
+                       \GrandStaffContext
+                       minVerticalAlign = 2.8*\staffheight;
+                       maxVerticalAlign = 2.8*\staffheight;
+               }
+               linewidth=-1.;
+       }
+}
+
+\version "1.3.5"; 
index fcc6031cbb2224fe5acfa882fcf38674e8fbbca0..e5e31c38f5ddaad8138b21a91a6f5226e13d9087 100644 (file)
@@ -15,6 +15,7 @@
 #include "main.hh"
 #include "dimensions.hh"
 #include "text-item.hh"
+#include "lily-guile.icc"
 
 ADD_THIS_TRANSLATOR (Chord_name_engraver);
 
@@ -72,8 +73,21 @@ Chord_name_engraver::do_process_requests ()
   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));
 }
 
index b190520b74ca5fb41117b5de16e025267ba15509..f994dd34527405a7edf9bfce51da9827a01007c0 100644 (file)
 #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:
@@ -56,21 +50,21 @@ Chord_name::ly_text2molecule (SCM scm) const
     {
       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)
     {
@@ -113,17 +107,26 @@ diff_pitch (Musical_pitch tonic, Musical_pitch  p)
   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));
@@ -145,7 +148,7 @@ Chord_name::banter (Array<Musical_pitch> pitch_arr, Chord_mol* name_p) const
     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
@@ -214,10 +217,16 @@ Chord_name::banter (Array<Musical_pitch> pitch_arr, Chord_mol* name_p) const
     }
 }
 
+/*
+  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);
@@ -230,17 +239,17 @@ Chord_name::do_brew_molecule_p () const
     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);
        }
       /*
@@ -248,22 +257,27 @@ Chord_name::do_brew_molecule_p () const
        */
       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);
     }
 
index 008944569478c8a904bc3fd9e8ec82ab951c9de5..dc49f205c23f6ce26d891de2c3a94902a5559580 100644 (file)
@@ -23,6 +23,12 @@ public:
   Molecule bass_mol;
 };
 
+/**
+   elt_properties:
+   pitches: list of musical-pitch
+   inversion(optional): musical-pitch
+   bass(optional): musical-pitch
+ */
 class Chord_name : public Item
 {
 public:
@@ -33,14 +39,6 @@ public:
   bool user_chord_name (Array<Musical_pitch> pitch_arr, Chord_mol* name_p) const;
   void banter (Array<Musical_pitch> pitch_arr, Chord_mol* name_p) const;
 
-  Chord_name (Chord const& c);
-
-  /*
-    ugh. Junkme, I must be elt property.
-   */
-  
-  Chord chord_;
-
 protected:
   virtual Molecule* do_brew_molecule_p () const;
 };
diff --git a/lily/include/lily-guile.icc b/lily/include/lily-guile.icc
new file mode 100644 (file)
index 0000000..9fb611a
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+  lily-guile.icc -- implement guile templates
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1999 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#ifndef LILY_GUILE_ICC
+#define LILY_GUILE_ICC
+
+#include "lily-guile.hh"
+
+template<class T>SCM
+array_to_scm (Array<T> arr)
+{
+  SCM list = SCM_EOL;
+  for (int i = arr.size (); i--;)
+    list =  gh_cons (to_scm (arr[i]), list);
+  return list;
+}
+
+/*
+  Silly templates
+  Array<T> scm_to_array (SCM s)
+
+  check scm?
+ */
+template<class T>void
+scm_to_array (SCM s, Array<T>* arr)
+{
+  arr->clear ();
+  for (; gh_pair_p (s); s= gh_cdr (s))
+    {
+      T t;
+      scm_to (gh_car (s), &t);
+      arr->push (t);
+    }
+}
+
+#endif /* LILY_GUILE_ICC */
index 3329c144d618defc29d9491a9e19f750feab373b..a5a428d649affda0a3e5c768f5e2554e0474bafb 100644 (file)
@@ -1,11 +1,11 @@
-;; 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))))
 
@@ -47,9 +50,7 @@
       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))))