lilypond-devel
[Top][All Lists]
Advanced

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

print transposed guitar chords on piano sheets (issue4626094)


From: lemniskata . bernoullego
Subject: print transposed guitar chords on piano sheets (issue4626094)
Date: Tue, 05 Jul 2011 22:04:49 +0000

Reviewers: antlists_youngman.org.uk, carl.d.sorensen_gmail.com,

Message:
Modify chord-name-engraver to print transposed guitar chords on piano
sheets
Add associated properties capoPitch and capoVertical to
define-context-properties

Description:
print transposed guitar chords on pia

Please review this at http://codereview.appspot.com/4626094/

Affected files:
  M lily/chord-name-engraver.cc
  M scm/define-context-properties.scm


Index: lily/chord-name-engraver.cc
diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc
index d0ced5a395f836e99fe57970185e26793b52612f..5037825ca0149eb08d9e0150f0b45bc43334bf2e 100644
--- a/lily/chord-name-engraver.cc
+++ b/lily/chord-name-engraver.cc
@@ -2,6 +2,7 @@
   This file is part of LilyPond, the GNU music typesetter.

   Copyright (C) 1998--2011 Jan Nieuwenhuizen <address@hidden>
+  Copyright (C) 2011 Anthony Youngman <address@hidden>

   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -43,11 +44,14 @@ protected:
   DECLARE_TRANSLATOR_LISTENER (note);
   DECLARE_TRANSLATOR_LISTENER (rest);
 private:
+  SCM capo_transpose( SCM, SCM) const;
+
   Item *chord_name_;
   vector<Stream_event*> notes_;

   SCM last_chord_;
   Stream_event *rest_event_;
+
 };

 void
@@ -76,6 +80,13 @@ Chord_name_engraver::process_music ()
   SCM inversion = SCM_EOL;
   SCM pitches = SCM_EOL;

+  SCM capo_markup;
+  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");
@@ -88,6 +99,17 @@ Chord_name_engraver::process_music ()
       if (!notes_.size ())
         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);
+      }
+
       Stream_event *inversion_event = 0;
       for (vsize i = 0; i < notes_.size (); i++)
       {
@@ -100,11 +122,27 @@ Chord_name_engraver::process_music ()
         {
           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)
@@ -123,10 +161,19 @@ Chord_name_engraver::process_music ()
       }

       pitches = scm_sort_list (pitches, Pitch::less_p_proc);
-
+      if (capo)
+      {
+        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 ());
+      if (capo)
+      {
+ capo_markup = scm_call_4 ( name_proc, capo_pitches, capo_bass, capo_inversion,
+                                   context ()->self_scm ());
+      }
     }
   /*
     Ugh.
@@ -135,8 +182,25 @@ Chord_name_engraver::process_music ()

   chord_name_ = make_item ("ChordName",
       rest_event_ ? rest_event_->self_scm () : notes_[0]->self_scm ());
-  chord_name_->set_property ("text", markup);
-
+  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");
   if (to_boolean (chord_changes) && scm_is_pair (last_chord_)
       && ly_is_equal (chord_as_scm, last_chord_))
@@ -145,6 +209,15 @@ Chord_name_engraver::process_music ()
   last_chord_ = chord_as_scm;
 }

+SCM
+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);
+  return orig.smobbed_copy ();
+}
+
 IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver, note);
 void
 Chord_name_engraver::listen_note (Stream_event *ev)
@@ -179,6 +252,8 @@ ADD_TRANSLATOR (Chord_name_engraver,
                "ChordName ",

                /* read */
+                "capoPitch "
+                "capoVertical "
                "chordChanges "
                "chordNameExceptions "
                "chordNameFunction "
Index: scm/define-context-properties.scm
diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index dab5211f14372444171626f23fb0ef3120175ee8..d17f72fa2c687b7dc5aff148e8d7c906a9b48c25 100644
--- a/scm/define-context-properties.scm
+++ b/scm/define-context-properties.scm
@@ -135,6 +135,8 @@ that normally end on beats.")
      (beatStructure ,list? "List of @code{baseMoment}s that are combined
 to make beats.")

+ (capoPitch ,ly:pitch? "The pitch to transpose chords down by when using the capo.") + (capoVertical ,boolean? "Whether to display actual and transposed pitches above each other or not.")
      (chordChanges ,boolean? "Only show changes in chords scheme?")
      (chordNameExceptions ,list? "An alist of chord exceptions.
 Contains @code{(@var{chord} . @var{markup})} entries.")





reply via email to

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