]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add N.C. entry to ChordNames context.
authorCarl Sorensen <c_sorensen@byu.edu>
Sun, 10 May 2009 00:30:31 +0000 (18:30 -0600)
committerCarl Sorensen <c_sorensen@byu.edu>
Thu, 14 May 2009 15:41:29 +0000 (09:41 -0600)
Adding a rest to the music passed to a ChordNames context will
now create an N.C. ChordName.  N.C. ChordNames behave just like
regular ChordNames with respect to chordChanges.

Documentation/user/chords.itely
input/regression/chordnames-nochord.ly [new file with mode: 0644]
lily/chord-name-engraver.cc
ly/engraver-init.ly
scm/define-context-properties.scm

index 5b5422b6f6f582ac236d1180100fa37ea1538879..9e548efc6283520e0b391cdb1a68875e46ddd4e3 100644 (file)
@@ -454,6 +454,30 @@ of the mode of entry, unless there are inversions or added bass notes:
 >>
 @end lilypond
 
+@cindex no chord symbol
+@cindex N.C. symbol
+@cindex indicating No Chord in ChordNames
+
+Rests passed to a @code{ChordNames} context will cause the
+@code{noChordSymbol} markup to be displayed.
+
+@lilypond[verbatim, quote, relative=1]
+<<
+  \new ChordNames \chordmode {
+    c1
+    r1
+    g1
+    c1
+  }
+  \new Score \chordmode {
+    c1
+    r1
+    g1
+    c1
+  }
+>>
+@end lilypond
+
 @funindex{\chords}
 
 @code{\chords @{ ... @}} is a shortcut notation for
diff --git a/input/regression/chordnames-nochord.ly b/input/regression/chordnames-nochord.ly
new file mode 100644 (file)
index 0000000..6512421
--- /dev/null
@@ -0,0 +1,30 @@
+\version "2.13.1"
+
+\header {
+  texidoc = "Rests in music passed to ChordNames context display noChordSymbol.
+noChordSymbol is treated like a ChordName with respect to chordChanges.
+"
+}
+
+myChords = \chordmode {
+  c1 r1 r1 \break
+  r1 g1 c1 \break
+}
+
+\score {
+  <<
+    \new ChordNames { 
+      \myChords 
+      \set chordChanges = ##t
+      \myChords
+    }
+    \new FretBoards { 
+      \myChords 
+      \myChords
+    }
+    \new Staff { 
+      \myChords 
+      \myChords
+    }
+  >>
+}
index f8858998a1d963669bc18d37f1ccc3d0aa8b6d43..288e29348076fea42f9f7a6526c274f903c168f5 100644 (file)
@@ -16,6 +16,7 @@
 #include "pitch.hh"
 #include "protected-scm.hh"
 #include "stream-event.hh"
+#include "text-interface.hh"
 #include "warn.hh"
 
 #include "translator.icc"
@@ -29,11 +30,13 @@ protected:
   virtual void finalize ();
   virtual void derived_mark () const;
   DECLARE_TRANSLATOR_LISTENER (note);
+  DECLARE_TRANSLATOR_LISTENER (rest);
 private:
   Item *chord_name_;
   vector<Stream_event*> notes_;
-
   SCM last_chord_;
+  Stream_event *rest_event_;
 };
 
 void
@@ -51,68 +54,80 @@ Chord_name_engraver::Chord_name_engraver ()
 {
   chord_name_ = 0;
   last_chord_ = SCM_EOL;
+  rest_event_ = 0;
 }
 
 void
 Chord_name_engraver::process_music ()
-{
-  if (!notes_.size ())
-    return;
-
+{ 
+  SCM markup;
   SCM bass = SCM_EOL;
   SCM inversion = SCM_EOL;
   SCM pitches = SCM_EOL;
 
-  Stream_event *inversion_event = 0;
-  for (vsize i = 0; i < notes_.size (); i++)
+  if (rest_event_)
     {
-      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;
-       }
-      else if (n->get_property ("bass") == SCM_BOOL_T)
-       bass = p;
-      else
-       pitches = scm_cons (p, pitches);
+      SCM no_chord_markup = get_property ("noChordSymbol");
+      if (!Text_interface::is_markup (no_chord_markup))
+        return;
+      markup = no_chord_markup;
     }
-
-  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");
+  else
+    {  
+      if (!notes_.size ())
+        return;
+
+      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;
+        }
+        else if (n->get_property ("bass") == SCM_BOOL_T)
+          bass = p;
+        else
+          pitches = scm_cons (p, 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");
+      }
+
+      pitches = scm_sort_list (pitches, Pitch::less_p_proc);
+
+      SCM name_proc = get_property ("chordNameFunction");
+      markup = scm_call_4 (name_proc, pitches, bass, inversion,
+          context ()->self_scm ());
     }
-
-  pitches = scm_sort_list (pitches, Pitch::less_p_proc);
-
-  SCM name_proc = get_property ("chordNameFunction");
-  SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
-                          context ()->self_scm ());
-
   /*
     Ugh.
   */
   SCM chord_as_scm = scm_cons (pitches, scm_cons (bass, inversion));
 
-  chord_name_ = make_item ("ChordName", notes_[0]->self_scm ());
+  chord_name_ = make_item ("ChordName", 
+      rest_event_ ? rest_event_->self_scm () : notes_[0]->self_scm ());
   chord_name_->set_property ("text", markup);
 
-  SCM s = get_property ("chordChanges");
-  if (to_boolean (s) && scm_is_pair (last_chord_)
+  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);
 
@@ -126,11 +141,19 @@ Chord_name_engraver::listen_note (Stream_event *ev)
   notes_.push_back (ev);
 }
 
+IMPLEMENT_TRANSLATOR_LISTENER (Chord_name_engraver, rest);
+void
+Chord_name_engraver::listen_rest (Stream_event *ev)
+{
+  ASSIGN_EVENT_ONCE(rest_event_, ev);
+}
+  
 void
 Chord_name_engraver::stop_translation_timestep ()
 {
   chord_name_ = 0;
   notes_.clear ();
+  rest_event_ = 0;
 }
 
 /*
@@ -139,7 +162,7 @@ Chord_name_engraver::stop_translation_timestep ()
 */
 ADD_TRANSLATOR (Chord_name_engraver,
                /* doc */
-               "Catch note events and generate the appropriate chordname.",
+               "Catch note and rest events and generate the appropriate chordname.",
 
                /* create */
                "ChordName ",
@@ -151,7 +174,8 @@ ADD_TRANSLATOR (Chord_name_engraver,
                "chordNoteNamer "
                "chordRootNamer "
                "chordNameExceptions "
-               "majorSevenSymbol ",
+               "majorSevenSymbol "
+                "noChordSymbol ",
 
                /* write */
                ""
index 9aae417aa8bf04819ea86c02a72990bd4d3977ee..ba7b18b218946e30284c14a30b8b91dd55f72ce7 100644 (file)
@@ -561,7 +561,7 @@ automatically when an output definition (a @code{\score} or
   chordPrefixSpacer = #0
   chordNameExceptionsFull = #fullJazzExceptions
   chordNameExceptionsPartial = #partialJazzExceptions
-  
+  noChordSymbol = #(make-simple-markup "N.C.")
 
   bassStaffProperties = #'((assign clefGlyph "clefs.F")
   (assign clefPosition 2)
index 1012c8685568a32a833db3fb6f713f11c216c501..3b18e94df45aabcd5fdb6907e479287cd63fa9d8 100644 (file)
@@ -332,6 +332,8 @@ page turn to be allowed.")
 repeated section for a page turn to be allowed within that section.")
 
 
+     (noChordSymbol ,markup? "Markup to be displayed for rests in a
+ChordNames context.")
      (noteToFretFunction ,procedure? "How to produce a fret diagram.
 Parameters: A list of note events and a list of tabstring events.")