]> git.donarmstrong.com Git - lilypond.git/blob - lily/fretboard-engraver.cc
LSR: update.
[lilypond.git] / lily / fretboard-engraver.cc
1 /*
2   fretboard-engraver.cc -- part of GNU LilyPond
3
4   (c)  2006  Han-Wen Nienhuys
5 */
6
7 #include <cctype>
8 #include <cstdio>
9 using namespace std;
10
11 #include "context.hh"
12 #include "item.hh"
13 #include "engraver.hh"
14 #include "pitch.hh"
15 #include "stream-event.hh"
16 #include "warn.hh"
17
18 #include "translator.icc"
19
20 /**
21    make (guitar-like) tablature note
22 */
23 class Fretboard_engraver : public Engraver
24 {
25   Item *fret_board_;
26   
27   vector<Stream_event*> note_events_;
28   vector<Stream_event*> tabstring_events_;
29 public:
30   TRANSLATOR_DECLARATIONS (Fretboard_engraver);
31
32 protected:
33   DECLARE_TRANSLATOR_LISTENER (note);
34   DECLARE_TRANSLATOR_LISTENER (string_number);
35   void process_music ();
36
37   void stop_translation_timestep ();
38 };
39
40 Fretboard_engraver::Fretboard_engraver ()
41 {
42   fret_board_ = 0;
43 }
44
45 IMPLEMENT_TRANSLATOR_LISTENER (Fretboard_engraver, note);
46 void
47 Fretboard_engraver::listen_note (Stream_event *ev)
48 {
49   note_events_.push_back (ev);
50 }
51
52 IMPLEMENT_TRANSLATOR_LISTENER (Fretboard_engraver, string_number);
53 void
54 Fretboard_engraver::listen_string_number (Stream_event *ev)
55 {
56   tabstring_events_.push_back (ev);
57 }
58
59 void
60 Fretboard_engraver::process_music ()
61 {
62   if (!note_events_.size ())
63     return ;
64
65   fret_board_ = make_item ("FretBoard", note_events_[0]->self_scm ());
66
67   SCM proc = get_property ("noteToFretFunction");
68   if (ly_is_procedure (proc))
69     {
70       scm_call_4 (proc,
71                   context ()->self_scm (),
72                   fret_board_->self_scm (),
73                                
74                   ly_cxx_vector_to_list (note_events_),
75                   ly_cxx_vector_to_list (tabstring_events_));
76     }
77 }
78
79 void
80 Fretboard_engraver::stop_translation_timestep ()
81 {
82   fret_board_ = 0;
83   note_events_.clear ();
84   tabstring_events_.clear ();
85 }
86
87 ADD_TRANSLATOR (Fretboard_engraver,
88                 /* doc */
89                 "Generate one or more tablature noteheads from event of type"
90                 " @code{NoteEvent}.",
91
92                 /* create */
93                 "FretBoard ",
94
95                 /* read */
96                 "stringTunings "
97                 "minimumFret "
98                 "tablatureFormat "
99                 "highStringOne ",
100
101                 /* write */
102                 ""
103                 );
104