Re: [frogs] chord_name_engraver - help with c++ ...

[ Thread Index | Date Index | More lilynet.net/frogs Archives ]


On 06/07/11 10:10, Wols Lists wrote:
> On 06/07/11 10:01, Jan Warchoł wrote:
>> 2011/7/6 Wols Lists <antlists@xxxxxxxxxxxxxxx>:
>>> And discovered why I was getting "cannot find property type-check" - I
>>> ran "make" in the wrong directory, so my guess that the live scheme
>>> wasn't being updated seems to have been right ... that appears to be
>>> working now.
>>>
>>> But I've now got another error.
>>>
>>> anthony@ashdown ~/gitstuff/music/Hymnal/Choruses $ lilypond
>>> HeGaveMeBeautyForAshes.ly
>>> GNU LilyPond 2.15.5
>>> Processing `HeGaveMeBeautyForAshes.ly'
>>> Parsing...
>>> Interpreting music... ERROR: Unbound variable: line_markup
>>> anthony@ashdown ~/gitstuff/music/Hymnal/Choruses $
>>>
>>> So obviously my code is creating a duff markup somewhere ...
>>
>> Hmm. I get this too.
>> Ha! I think i found it! Change line_markup to line-markup and
>> hspace_markup to hspace-markup.  Apparently naming changed.
>>
> Thanks!
> 
> I'll run all your changes. There's a fancy-formatter there too iirc?
> That'll fix all the formatting to project standard?
> 
> I'll get shot by the wife if I start working on this now, so I'll attack
> it this evening and send you a new patch :-)
> 
Fixes made. I'm happy with it now, it appears to work fine :-)

I presume I need to document it now, sort out a regression test, etc?
The code seems perfectly okay.

The only problem I'm having at the moment is with make-pitch - I want to
document a sharp or flat, and it wants to take an integer as the third
argument. Experiment isn't being that helpful at finding what that third
argument should be (-1 is returning either a double-flat or half-flat,
not sure which). The docu says "alter is a rational number of 200-cent
whole tones", but without an example I can't understand what that
actually means - the words are clear but the meaning isn't :-(

Cheers,
Wol
From 34931a23371fef1ac77c3fbd703d9f673d0fb1f0 Mon Sep 17 00:00:00 2001
From: Wol <anthony@xxxxxxxxxxxxxxx>
Date: Wed, 6 Jul 2011 18:47:14 +0100
Subject: [PATCH 2/2] Transposed guitar chords on piano score

Bug fix (double declaration of capo)
Correct naming of scheme of procedures
Run fixcc.py
---
 lily/chord-name-engraver.cc |  189 ++++++++++++++++++++-----------------------
 1 files changed, 88 insertions(+), 101 deletions(-)

diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc
index 5037825..ad4551a 100644
--- a/lily/chord-name-engraver.cc
+++ b/lily/chord-name-engraver.cc
@@ -44,14 +44,13 @@ protected:
   DECLARE_TRANSLATOR_LISTENER (note);
   DECLARE_TRANSLATOR_LISTENER (rest);
 private:
-  SCM capo_transpose( SCM, SCM) const;
-  
+  SCM capo_transpose (SCM, SCM) const;
+
   Item *chord_name_;
-  vector<Stream_event*> notes_;
- 
+  vector<Stream_event *> notes_;
+
   SCM last_chord_;
   Stream_event *rest_event_;
-  
 };
 
 void
@@ -74,7 +73,7 @@ Chord_name_engraver::Chord_name_engraver ()
 
 void
 Chord_name_engraver::process_music ()
-{ 
+{
   SCM markup;
   SCM bass = SCM_EOL;
   SCM inversion = SCM_EOL;
@@ -84,124 +83,113 @@ Chord_name_engraver::process_music ()
   SCM capo_bass = SCM_EOL;
   SCM capo_inversion = SCM_EOL;
   SCM capo_pitches = SCM_EOL;
-  
+
   bool capo = false;
 
   if (rest_event_)
     {
       SCM no_chord_markup = get_property ("noChordSymbol");
       if (!Text_interface::is_markup (no_chord_markup))
-        return;
+	return;
       markup = no_chord_markup;
     }
   else
-    {  
+    {
       if (!notes_.size ())
-        return;
+	return;
 
       // This is set by "\set ChordNames.CapoPitch = #(ly:make-pitch 0 1 1)" in the lily source file
       // declare properties in define-context-properties.scm
 
-      SCM capo_pitch = get_property ( "capoPitch" );
-      bool capo = false;
-      if ( !(capo_pitch == SCM_EOL) )
-      {
-        Pitch *cp = unsmob_pitch (capo_pitch);
-        capo = (Pitch::compare ( *cp, Pitch() ) != 0);
-      }
-      
+      SCM capo_pitch = get_property ("capoPitch");
+      if (! (capo_pitch == SCM_EOL))
+	{
+	  Pitch *cp = unsmob_pitch (capo_pitch);
+	  capo = (Pitch::compare (*cp, Pitch ()) != 0);
+	}
+
       Stream_event *inversion_event = 0;
       for (vsize i = 0; i < notes_.size (); i++)
-      {
-        Stream_event *n = notes_[i];
-        SCM p = n->get_property ("pitch");
-        if (!unsmob_pitch (p))
-          continue;
-
-        if (n->get_property ("inversion") == SCM_BOOL_T)
-        {
-          inversion_event = n;
-          inversion = p;
-          if (capo)
-          {
-            capo_inversion = capo_transpose (p, capo_pitch);
-          }
-        }
-        else if (n->get_property ("bass") == SCM_BOOL_T)
-        {
-          bass = p;
-          if (capo)
-          {
-            capo_bass = capo_transpose (p, capo_pitch);
-          }
-        }
-        else
-        {
-          pitches = scm_cons (p, pitches);
-          if (capo)
-          {
-            capo_pitches = scm_cons (capo_transpose (p, capo_pitch), capo_pitches);
-          }
-        }
-      }
+	{
+	  Stream_event *n = notes_[i];
+	  SCM p = n->get_property ("pitch");
+	  if (!unsmob_pitch (p))
+	    continue;
+
+	  if (n->get_property ("inversion") == SCM_BOOL_T)
+	    {
+	      inversion_event = n;
+	      inversion = p;
+	      if (capo)
+		capo_inversion = capo_transpose (p, capo_pitch);
+	    }
+	  else if (n->get_property ("bass") == SCM_BOOL_T)
+	    {
+	      bass = p;
+	      if (capo)
+		capo_bass = capo_transpose (p, capo_pitch);
+	    }
+	  else
+	    {
+	      pitches = scm_cons (p, pitches);
+	      if (capo)
+		capo_pitches = scm_cons (capo_transpose (p, capo_pitch), capo_pitches);
+	    }
+	}
 
       if (inversion_event)
-      {
-        SCM oct = inversion_event->get_property ("octavation");
-        if (scm_is_number (oct))
-        {
-          Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
-          int octavation = scm_to_int (oct);
-          Pitch orig = p->transposed (Pitch (-octavation, 0, 0));
-
-          pitches = scm_cons (orig.smobbed_copy (), pitches);
-        }
-        else
-          programming_error ("inversion does not have original pitch");
-      }
+	{
+	  SCM oct = inversion_event->get_property ("octavation");
+	  if (scm_is_number (oct))
+	    {
+	      Pitch *p = unsmob_pitch (inversion_event->get_property ("pitch"));
+	      int octavation = scm_to_int (oct);
+	      Pitch orig = p->transposed (Pitch (-octavation, 0, 0));
+
+	      pitches = scm_cons (orig.smobbed_copy (), pitches);
+	    }
+	  else
+	    programming_error ("inversion does not have original pitch");
+	}
 
       pitches = scm_sort_list (pitches, Pitch::less_p_proc);
       if (capo)
-      {
-        capo_pitches = scm_sort_list (capo_pitches, Pitch::less_p_proc);
-      }
-      
+	capo_pitches = scm_sort_list (capo_pitches, Pitch::less_p_proc);
+
       SCM name_proc = get_property ("chordNameFunction");
       markup = scm_call_4 (name_proc, pitches, bass, inversion,
-          context ()->self_scm ());
+			   context ()->self_scm ());
       if (capo)
-      {
-        capo_markup = scm_call_4 ( name_proc, capo_pitches, capo_bass, capo_inversion,
-                                   context ()->self_scm ());
-      }
+	capo_markup = scm_call_4 (name_proc, capo_pitches, capo_bass, capo_inversion,
+				  context ()->self_scm ());
     }
   /*
     Ugh.
   */
   SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
 
-  chord_name_ = make_item ("ChordName", 
-      rest_event_ ? rest_event_->self_scm () : notes_[0]->self_scm ());
-  if (!capo) {
+  chord_name_ = make_item ("ChordName",
+			   rest_event_ ? rest_event_->self_scm () : notes_[0]->self_scm ());
+  if (!capo)
     chord_name_->set_property ("text", markup);
-  } else {
-    SCM capovertical = get_property ("capoVertical");
-    SCM paren_proc = ly_lily_module_constant ("parenthesize-markup");
-    SCM line_proc = ly_lily_module_constant ("line_markup");
-    SCM hspace_proc = ly_lily_module_constant ("hspace_markup");
-    
-    SCM final_markup = scm_list_n (line_proc,
-                                   scm_list_3 (markup,
-                                               scm_list_2 (hspace_proc,
-                                                           scm_from_int(1)),
-                                               scm_list_2 (paren_proc, capo_markup)),
-                                   SCM_UNDEFINED);
-    
-    chord_name_->set_property ("text", final_markup);
-  }
-  
-  
-  SCM chord_changes = get_property("chordChanges");
+  else
+    {
+      SCM capovertical = get_property ("capoVertical");
+      SCM paren_proc = ly_lily_module_constant ("parenthesize-markup");
+      SCM line_proc = ly_lily_module_constant ("line-markup");
+      SCM hspace_proc = ly_lily_module_constant ("hspace-markup");
+
+      SCM final_markup = scm_list_n (line_proc,
+				     scm_list_3 (markup,
+						 scm_list_2 (hspace_proc,
+							     scm_from_int (1)),
+						 scm_list_2 (paren_proc, capo_markup)),
+				     SCM_UNDEFINED);
+
+      chord_name_->set_property ("text", final_markup);
+    }
+
+  SCM chord_changes = get_property ("chordChanges");
   if (to_boolean (chord_changes) && scm_is_pair (last_chord_)
       && ly_is_equal (chord_as_scm, last_chord_))
     chord_name_->set_property ("begin-of-line-visible", SCM_BOOL_T);
@@ -214,7 +202,7 @@ Chord_name_engraver::capo_transpose (SCM scm_pitch, SCM capo_pitch) const
 {
   Pitch *s_p = unsmob_pitch (scm_pitch);
   Pitch *c_p = unsmob_pitch (capo_pitch);
-  Pitch orig = s_p->transposed ( *c_p);
+  Pitch orig = s_p->transposed (*c_p);
   return orig.smobbed_copy ();
 }
 
@@ -229,9 +217,9 @@ IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver, rest);
 void
 Chord_name_engraver::listen_rest (Stream_event *ev)
 {
-  ASSIGN_EVENT_ONCE(rest_event_, ev);
+  ASSIGN_EVENT_ONCE (rest_event_, ev);
 }
-  
+
 void
 Chord_name_engraver::stop_translation_timestep ()
 {
@@ -252,8 +240,8 @@ ADD_TRANSLATOR (Chord_name_engraver,
 		"ChordName ",
 
 		/* read */
-                "capoPitch "
-                "capoVertical "
+		"capoPitch "
+		"capoVertical "
 		"chordChanges "
 		"chordNameExceptions "
 		"chordNameFunction "
@@ -261,8 +249,7 @@ ADD_TRANSLATOR (Chord_name_engraver,
 		"chordRootNamer "
 		"chordNameExceptions "
 		"majorSevenSymbol "
-                "noChordSymbol ",
+		"noChordSymbol ",
 
 		/* write */
-		""
-		);
+		"");
-- 
1.7.3.4



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/