lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: figured bass. [Comments wanted]


From: Han-Wen Nienhuys
Subject: Patch: figured bass. [Comments wanted]
Date: Sun, 9 Sep 2001 21:47:18 +0200

As per Jeremie's request, I tried to hack figured bass into Lily. The
implementation is kind of crude, but it more or less works:

\context FiguredBass \transpose c'' {
   <e! g >
   <f ais >
}


will put

  5        6#
  3 nat    4


on a separate line.


Now my request: I know exactly zilch of figured bass, so could those
in the know expand on my formatting functions and fine tune the looks
of the output? There is doubtlessly much to improve on it.  (and to be
completely honest, I also don't know how to use markup texts
effectively anyway). For starters, I reversed the accidentals and the
numbers in order.

Talented hackers might want to move the functionality of
Figured_bass_engraver::process_music () into a separate scheme
function, so you can debug the formatting processs more easily.

Finally, I've contemplated some kind of new syntax, maybe something
like

  \figures { [3 5!]4  [6+ 4]4 }   


but I wonder if it's needed; the chord syntax as demonstrated above is
also quite terse; as you can imagine, I'd like to keep syntax
extensions to a minimum. 


Generated by address@hidden,
>From = lilypond-1.5.9, To = lilypond-1.5.9.hwn1

usage 

    cd lilypond-source-dir; patch -E -p1 < lilypond-1.5.9.hwn1.diff

Patches do not contain automatically generated files 
or (urg) empty directories, 
i.e., you should rerun autoconf, configure

diff -urN ../lilypond-1.5.9/VERSION ./VERSION
--- ../lilypond-1.5.9/VERSION   Sat Sep  8 20:09:25 2001
+++ ./VERSION   Sat Sep  8 21:03:06 2001
@@ -2,7 +2,7 @@
 MAJOR_VERSION=1
 MINOR_VERSION=5
 PATCH_LEVEL=9
-MY_PATCH_LEVEL=
+MY_PATCH_LEVEL=hwn1
 
 # use the above to send patches: MY_PATCH_LEVEL is always empty for a
 # released version.
diff -urN ../lilypond-1.5.9/input/regression/collision-mesh.ly 
./input/regression/collision-mesh.ly
--- ../lilypond-1.5.9/input/regression/collision-mesh.ly        Sat Sep  8 
19:20:07 2001
+++ ./input/regression/collision-mesh.ly        Sat Sep  8 19:10:46 2001
@@ -7,14 +7,14 @@
   \context Staff \notes \relative c' {
      \time 3/4
      % Here's what I was trying to do:
-     < \context Voice  = VI {\stemDown <g4 b g'> 
-     r4 r4 }
-       \context Voice=VII {\stemUp d'2.} >
-
+     < \context Voice  = VI {\stemDown <g4 b g'>
+       <g b d>
+       }
+       \context Voice=VII {\stemUp d'4 <a c>   } >
      % Or:
 
-     <\context Voice = VI {\stemUp <g4 b g'>  r r}
-       \context Voice= VII {\stemDown d'2.} >
+     <\context Voice = VI {\stemUp <g4 b g'> }
+       \context Voice= VII {\stemDown d'4} >
   }
 }
 
diff -urN ../lilypond-1.5.9/input/test/figured-bass.ly 
./input/test/figured-bass.ly
--- ../lilypond-1.5.9/input/test/figured-bass.ly        Mon Apr 16 23:42:19 2001
+++ ./input/test/figured-bass.ly        Sun Sep  9 21:41:19 2001
@@ -1,27 +1,16 @@
-\version "1.3.146"
-% Example of figured bass, using text scripts.
-% (An alternative is to use a lyrics line if you want the figures
-% aligned vertically.)
-
-
-
-% Scheme macros for accidentals. Note how they can be combined
-% with other strings, for example in: d^#`(columns ,sharp "4")
-
-#(define sharp '((raise . 0.2) (music (named "accidentals-1"))))
-#(define natural '((raise . 0.2) (music (named "accidentals-0"))))
-#(define flat '((raise . 0.2) (music (named "accidentals--1"))))
-
-
-\score{
-  \notes \relative c'{
-    \clef bass
-
-      c^"5" d^#natural g,^"7 6" [a8 e] |
-      fis4^"7 6" [g8 d] e4^"7 6" [f?8 c] |
-      [d^#sharp d b g][c^"7" c^"5" a^"6" f] |
-      [bes^"7" bes^"5" g^"6" e] a4^#sharp d^"6" ~ |
-      d^#`(columns ,sharp "4") c^"6" d e^#sharp |
-  }
+\header {
+texidoc = "test figured bass"
 }
 
+\score { \notes  <
+\context FiguredBass \transpose c'' {
+   <e! g >
+   <f ais > 
+ }
+ \context Voice {
+   c 
+   g 
+  }
+ 
+>
+ }
diff -urN ../lilypond-1.5.9/lily/figured-bass-engraver.cc 
./lily/figured-bass-engraver.cc
--- ../lilypond-1.5.9/lily/figured-bass-engraver.cc     Thu Jan  1 01:00:00 1970
+++ ./lily/figured-bass-engraver.cc     Sun Sep  9 21:41:59 2001
@@ -0,0 +1,91 @@
+#include "engraver.hh"
+#include "text-item.hh"
+#include "musical-request.hh"
+#include "item.hh"
+
+class Figured_bass_engraver : public Engraver
+{
+public:
+  VIRTUAL_COPY_CONS(Translator);
+  Figured_bass_engraver();
+
+protected:
+  Link_array<Note_req> figures_;
+
+  Grob * figure_;
+  
+  virtual bool try_music (Music*);
+  virtual void stop_translation_timestep ();
+  virtual void process_music ();
+};
+
+
+Figured_bass_engraver::Figured_bass_engraver()
+{
+  figure_ = 0;
+}
+
+void
+Figured_bass_engraver::stop_translation_timestep ()
+{
+  if (figure_)
+    {
+      typeset_grob (figure_);
+      figure_ =00;
+    }
+
+  figures_.clear ();
+}
+
+bool
+Figured_bass_engraver::try_music (Music*m)
+{
+  if (Note_req* n = dynamic_cast<Note_req*> (m))
+    {
+      figures_.push (n);
+      return true;
+    }
+  return false;
+}
+
+void
+Figured_bass_engraver::process_music ()
+{
+  if (figures_.size ())
+    {
+      figure_ = new Item (get_property ("BassFigure"));
+      announce_grob (figure_, figures_[0]); // todo
+      SCM flist = SCM_EOL;
+      for (int i = 0; i < figures_.size (); i++)
+       {
+         Note_req * n = figures_[i];
+         Pitch *p = unsmob_pitch (n->get_mus_property ("pitch"));
+         
+         String fstr = to_str (p->steps ()+ 1);
+         
+         SCM one_fig = ly_str02scm(fstr.ch_C ());
+
+         if (p->alteration_i_ || to_boolean (n->get_mus_property 
("force-accidental") ))
+           {
+             SCM alter = scm_assoc (gh_int2scm (p->alteration_i_),
+                                    figure_->get_grob_property 
("accidental-alist"));
+             if (gh_pair_p (alter))
+               {
+                 one_fig = gh_list (ly_symbol2scm ("columns"),
+                                    one_fig,
+                                    gh_cdr(alter),
+                                    SCM_UNDEFINED);
+               }
+           }
+         
+         flist = gh_cons (one_fig, flist);
+       }
+
+      flist = gh_cons (ly_symbol2scm ("lines"), flist);
+
+      figure_-> set_grob_property ("text", flist);
+    }
+}
+
+  
+ADD_THIS_TRANSLATOR(Figured_bass_engraver);
diff -urN ../lilypond-1.5.9/ly/engraver-init.ly ./ly/engraver-init.ly
--- ../lilypond-1.5.9/ly/engraver-init.ly       Fri Aug 10 14:56:43 2001
+++ ./ly/engraver-init.ly       Sun Sep  9 21:23:19 2001
@@ -221,6 +221,7 @@
        \accepts "InnerChoirStaff"
        \accepts "ChoirStaff"
        \accepts "InnerStaffGroup"
+       \accepts "FiguredBass"
 }
 
 
@@ -334,6 +335,7 @@
        \consists "Bar_number_engraver"
        \consists "Span_arpeggio_engraver"
 
+       \accepts "FiguredBass"  
        \accepts "Staff"
        \accepts "StaffContainer"
        \accepts "StaffGroup"
@@ -412,4 +414,11 @@
 % retain for compatibility reasons (FIXME: convert-ly)
 GraceContext = \translator {
        \type "Engraver_group_engraver"
+}
+
+FiguredBassContext = \translator {
+       \type "Engraver_group_engraver"
+       \name FiguredBass 
+       \consists "Figured_bass_engraver"       
+       \consistsend "Axis_group_engraver"
 }
diff -urN ../lilypond-1.5.9/ly/params-init.ly ./ly/params-init.ly
--- ../lilypond-1.5.9/ly/params-init.ly Fri Aug 10 14:56:43 2001
+++ ./ly/params-init.ly Sun Sep  9 21:22:06 2001
@@ -41,7 +41,7 @@
 \translator { \PianoStaffContext}
 \translator { \LyricsVoiceContext }
 \translator { \StaffContainerContext }
-
+\translator { \FiguredBassContext }
 
 
 
diff -urN ../lilypond-1.5.9/scm/grob-description.scm ./scm/grob-description.scm
--- ../lilypond-1.5.9/scm/grob-description.scm  Wed Aug 22 23:23:14 2001
+++ ./scm/grob-description.scm  Sun Sep  9 21:39:40 2001
@@ -8,6 +8,16 @@
 ; distances are given in stafflinethickness (thicknesses) and
 ; staffspace (distances)
 
+(define default-alteration-alist
+  '(
+    (0 . ((raise . 0.5) (music "accidentals-0")))
+    (-1 . ((raise . 0.5) (music "accidentals--1")))
+    (-2 . ((raise . 0.5) (music "accidentals--2")))
+    (1 . ((raise . 0.5) (music  "accidentals-1")))
+    (2 . ((raise . 0.5) (music "accidentals-2")))
+    ))
+
+
 (define all-grob-descriptions
   `(
     (Accidentals . (
@@ -66,6 +76,15 @@
                        text-interface  font-interface break-aligned-interface))
        ))
 
+       (BassFigure . (
+                      (molecule-callback . ,Text_item::brew_molecule)
+                      (Y-offset-callbacks . 
(,Side_position_interface::aligned_on_self))
+                      (direction . 0)
+                      (accidental-alist . ,default-alteration-alist)
+                      (font-family . number)
+                      (font-relative-size . -1)
+                      (meta . ,(grob-description "BassFigure" text-interface 
font-interface ))
+       ))
        (Beam . (
                 ;; todo: clean this up a bit: the list is getting
                 ;; rather long.


-- 

Han-Wen Nienhuys   |   address@hidden    | http://www.cs.uu.nl/~hanwen/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]