]> git.donarmstrong.com Git - lilypond.git/blob - lily/new-chord-name-engraver.cc
* scm/chords-ignatzek.scm: new file.
[lilypond.git] / lily / new-chord-name-engraver.cc
1 /*
2   chord-name-engraver.cc -- implement New_chord_name_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "engraver.hh"
10 #include "chord-name.hh"
11 #include "chord.hh"
12 #include "event.hh"
13 #include "paper-def.hh"
14 #include "font-interface.hh"
15 #include "paper-def.hh"
16 #include "main.hh"
17 #include "dimensions.hh"
18 #include "item.hh"
19 #include "pitch.hh"
20 #include "protected-scm.hh"
21 #include "translator-group.hh"
22
23 class New_chord_name_engraver : public Engraver 
24 {
25   TRANSLATOR_DECLARATIONS( New_chord_name_engraver);
26 protected:
27   virtual void stop_translation_timestep ();
28   virtual void process_music ();
29   virtual bool try_music (Music *);
30
31 private:
32   void add_note (Music *);
33   
34   Item* chord_name_;
35   Link_array<Music> notes_;
36   
37   Protected_scm last_chord_;
38 };
39
40
41
42 New_chord_name_engraver::New_chord_name_engraver ()
43 {
44   chord_name_ = 0;
45   last_chord_ = SCM_EOL;
46 }
47
48 void
49 New_chord_name_engraver::add_note (Music * n)
50 {
51   notes_.push (n);
52 }
53
54 void
55 New_chord_name_engraver::process_music ()
56 {
57   if (!notes_.size() )
58     return;
59   
60   SCM bass = SCM_EOL;
61   SCM inversion = SCM_EOL;
62   SCM pitches = SCM_EOL;
63
64   for (int i =0 ; i < notes_.size (); i++)
65     {
66       Music *n = notes_[i];
67       SCM p = n->get_mus_property ("pitch");;
68       if (n->get_mus_property ("inversion") == SCM_BOOL_T)
69         inversion = p;
70       else if (n->get_mus_property ("bass") == SCM_BOOL_T)
71         bass = p;
72       else
73         pitches = gh_cons (p, pitches);
74     }
75
76   pitches = scm_sort_list (pitches, Pitch::less_p_proc);
77
78   SCM name_proc = get_property ("chordNameFunction");
79   SCM markup = scm_call_4 (name_proc, pitches, bass, inversion,
80                            daddy_trans_->self_scm());
81
82   /*
83     Ugh. 
84    */
85   SCM chord_as_scm = gh_cons (pitches, gh_cons (bass, inversion));
86   
87   chord_name_ = new Item (get_property ("ChordName"));
88   chord_name_->set_grob_property("text", markup);
89   announce_grob(chord_name_, SCM_EOL);
90   SCM s = get_property ("chordChanges");
91   if (to_boolean (s) && gh_pair_p (last_chord_) 
92       && gh_equal_p (chord_as_scm, last_chord_))
93     chord_name_->set_grob_property ("begin-of-line-visible", SCM_BOOL_T);
94
95   last_chord_ = chord_as_scm;
96 }
97
98 bool
99 New_chord_name_engraver::try_music (Music* m)
100 {
101   /*
102     hmm. Should check? 
103    */
104   if (m->is_mus_type ("note-event"))
105     {
106       add_note (m);
107       return true;
108     }
109   return false;
110 }
111
112 void
113 New_chord_name_engraver::stop_translation_timestep ()
114 {
115   if (chord_name_)
116     {
117       typeset_grob (chord_name_);
118     }
119   chord_name_ = 0;
120   notes_.clear ();
121 }
122
123 ENTER_DESCRIPTION(New_chord_name_engraver,
124 /* descr */       "Catch note-events "
125 "and generate the appropriate chordname.",
126 /* creats*/       "ChordName",
127 /* accepts */     "note-event",
128 /* acks  */      "",
129 /* reads */       "chordChanges chordNameExceptions chordNameFunction",
130 /* write */       "");