From ead2bc50eefa1caf1f375488e11f93ee504dbaf2 Mon Sep 17 00:00:00 2001 From: Carl Sorensen Date: Sat, 9 May 2009 18:30:31 -0600 Subject: [PATCH] Add N.C. entry to ChordNames context. 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 | 24 +++++ input/regression/chordnames-nochord.ly | 30 +++++++ lily/chord-name-engraver.cc | 118 +++++++++++++++---------- ly/engraver-init.ly | 2 +- scm/define-context-properties.scm | 2 + 5 files changed, 128 insertions(+), 48 deletions(-) create mode 100644 input/regression/chordnames-nochord.ly diff --git a/Documentation/user/chords.itely b/Documentation/user/chords.itely index 5b5422b6f6..9e548efc62 100644 --- a/Documentation/user/chords.itely +++ b/Documentation/user/chords.itely @@ -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 index 0000000000..6512421f2c --- /dev/null +++ b/input/regression/chordnames-nochord.ly @@ -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 + } + >> +} diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc index f8858998a1..288e293480 100644 --- a/lily/chord-name-engraver.cc +++ b/lily/chord-name-engraver.cc @@ -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 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 */ "" diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 9aae417aa8..ba7b18b218 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -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) diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index 1012c86855..3b18e94df4 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -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.") -- 2.39.5