]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/fretboard-engraver.cc
Midi2ly: Add doco and changes.
[lilypond.git] / lily / fretboard-engraver.cc
index e1b78a52206c1e08ef777d2c71b4f1248c569c2d..cb4345ccad9870b89c5528ce17a6870e56da4a6f 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2006--2010 Han-Wen Nienhuys
+  Copyright (C) 2006--2011 Han-Wen Nienhuys
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 #include <cstdio>
 using namespace std;
 
+#include "articulations.hh"
 #include "context.hh"
 #include "item.hh"
 #include "engraver.hh"
@@ -36,24 +37,25 @@ using namespace std;
 class Fretboard_engraver : public Engraver
 {
   Item *fret_board_;
-  
-  vector<Stream_event*> note_events_;
-  vector<Stream_event*> tabstring_events_;
+
+  vector<Stream_event *> note_events_;
+  vector<Stream_event *> tabstring_events_;
+  vector<Stream_event *> fingering_events_;
 public:
   TRANSLATOR_DECLARATIONS (Fretboard_engraver);
 
 protected:
   void stop_translation_timestep ();
   void process_music ();
-  virtual void derived_mark() const;
+  virtual void derived_mark () const;
   DECLARE_TRANSLATOR_LISTENER (note);
   DECLARE_TRANSLATOR_LISTENER (string_number);
+  DECLARE_TRANSLATOR_LISTENER (fingering);
 
 private:
   SCM last_fret_notes_;
 };
 
-
 void
 Fretboard_engraver::derived_mark () const
 {
@@ -80,28 +82,39 @@ Fretboard_engraver::listen_string_number (Stream_event *ev)
   tabstring_events_.push_back (ev);
 }
 
+IMPLEMENT_TRANSLATOR_LISTENER (Fretboard_engraver, fingering);
+void
+Fretboard_engraver::listen_fingering (Stream_event *ev)
+{
+  fingering_events_.push_back (ev);
+}
+
 void
 Fretboard_engraver::process_music ()
 {
   if (!note_events_.size ())
-    return ;
-
+    return;
+
+  SCM tab_strings = articulation_list (note_events_,
+                                      tabstring_events_,
+                                      "string-number-event");
+  SCM fingers = articulation_list (note_events_,
+                                  fingering_events_,
+                                  "fingering-event");
   fret_board_ = make_item ("FretBoard", note_events_[0]->self_scm ());
   SCM fret_notes = ly_cxx_vector_to_list (note_events_);
   SCM proc = get_property ("noteToFretFunction");
   if (ly_is_procedure (proc))
-    {
-     scm_call_4 (proc,
-                context ()->self_scm (),
-                fret_board_->self_scm (),
-                fret_notes,           
-                ly_cxx_vector_to_list (tabstring_events_));
-    }
-  SCM changes = get_property("chordChanges");
-  if (to_boolean (changes) && scm_is_pair(last_fret_notes_)
+    scm_call_4 (proc,
+               context ()->self_scm (),
+               fret_notes,
+               scm_list_2 (tab_strings, fingers),
+               fret_board_->self_scm ());
+  SCM changes = get_property ("chordChanges");
+  if (to_boolean (changes) && scm_is_pair (last_fret_notes_)
       && ly_is_equal (last_fret_notes_, fret_notes))
     fret_board_->set_property ("begin-of-line-visible", SCM_BOOL_T);
-  
+
   last_fret_notes_ = fret_notes;
 }
 
@@ -111,26 +124,29 @@ Fretboard_engraver::stop_translation_timestep ()
   fret_board_ = 0;
   note_events_.clear ();
   tabstring_events_.clear ();
+  fingering_events_.clear ();
 }
 
 ADD_TRANSLATOR (Fretboard_engraver,
                /* doc */
-               "Generate one or more tablature noteheads from event of type"
+               "Generate fret diagram from one or more events of type"
                " @code{NoteEvent}.",
 
                /* create */
                "FretBoard ",
 
                /* read */
-                "chordChanges "
-               "stringTunings "
-               "minimumFret "
-                "maximumFretStretch "
-               "tablatureFormat "
+               "chordChanges "
+               "defaultStrings "
                "highStringOne "
-                "predefinedDiagramTable",
+               "maximumFretStretch "
+               "minimumFret "
+               "noteToFretFunction "
+               "predefinedDiagramTable "
+               "stringTunings "
+               "tablatureFormat ",
 
                /* write */
                ""
-               );
+                );