]> git.donarmstrong.com Git - lilypond.git/commitdiff
partial: 1.1.7.jcn
authorJan Nieuwenhuizen <janneke@gnu.org>
Wed, 18 Nov 1998 16:09:22 +0000 (17:09 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Wed, 18 Nov 1998 16:09:22 +0000 (17:09 +0100)
lily/include/repeat-engraver.hh [new file with mode: 0644]
lily/include/volta-spanner.hh [new file with mode: 0644]
lily/repeat-engraver.cc [new file with mode: 0644]
lily/volta-spanner.cc [new file with mode: 0644]

diff --git a/lily/include/repeat-engraver.hh b/lily/include/repeat-engraver.hh
new file mode 100644 (file)
index 0000000..e3d6f9e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+  repeat-engraver.hh -- declare Repeat_engraver
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#ifndef REPEAT_ENGRAVER_HH
+#define REPEAT_ENGRAVER_HH
+
+#include "engraver.hh"
+
+/**
+  Generate repeat-bars |: :| for repeated-music
+  */
+class Repeat_engraver : public Engraver 
+{
+public:
+  Repeat_engraver ();
+  VIRTUAL_COPY_CONS(Translator);
+  
+protected:
+  virtual void acknowledge_element (Score_element_info i);
+  virtual void do_removal_processing ();
+  virtual bool do_try_music (Music *req_l);
+  virtual void do_process_requests();
+  virtual void do_pre_move_processing();
+  virtual void do_post_move_processing();
+
+private:
+  Link_array<Repeated_music> repeated_music_arr_;
+  Link_array<Music> alternative_music_arr_;
+  Link_array<Bar> bar_p_arr_;
+  Link_array<Volta_spanner> volta_p_arr_;
+  Array<Moment> stop_mom_arr_;
+  Array<Moment> alternative_start_mom_arr_;
+  Array<Moment> alternative_stop_mom_arr_;
+};
+
+#endif // REPEAT_ENGRAVER_HH
+
diff --git a/lily/include/volta-spanner.hh b/lily/include/volta-spanner.hh
new file mode 100644 (file)
index 0000000..18fd91a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+  volta-spanner.hh -- part of GNU LilyPond
+
+  (c) 1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#ifndef VOLTA_SPANNER_HH
+#define VOLTA_SPANNER_HH
+
+#include "text-def.hh"
+#include "pointer.hh"
+#include "directional-spanner.hh"
+
+/** Volta bracket with number */
+
+class Volta_spanner : public Directional_spanner
+{
+public:
+  Volta_spanner ();
+  void add_column (Note_column*);
+  P<Text_def>  tdef_p_;
+  Link_array<Note_column> column_arr_;
+  bool last_b_;
+protected:
+  virtual Molecule* brew_molecule_p () const;
+  VIRTUAL_COPY_CONS(Score_element);
+
+  virtual void do_add_processing ();
+  virtual void do_post_processing ();
+  virtual void do_substitute_dependency (Score_element*,Score_element*);
+};
+
+#endif // VOLTA_SPANNER_HH
+
diff --git a/lily/repeat-engraver.cc b/lily/repeat-engraver.cc
new file mode 100644 (file)
index 0000000..110169f
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+  repeat-engraver.cc -- implement Repeat_engraver
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#include "repeat-engraver.hh"
+#include "bar.hh"
+#include "musical-request.hh"
+#include "multi-measure-rest.hh"
+#include "command-request.hh"
+#include "time-description.hh"
+#include "engraver-group.hh"
+#include "repeated-music.hh"
+#include "time-description.hh"
+#include "volta-spanner.hh"
+#include "note-column.hh"
+
+ADD_THIS_TRANSLATOR (Repeat_engraver);
+
+Repeat_engraver::Repeat_engraver ()
+{
+}
+
+bool
+Repeat_engraver::do_try_music (Music* m)
+{
+  if (Repeated_music* r = dynamic_cast<Repeated_music *> (m))
+    {
+      repeated_music_arr_.push (r);
+      stop_mom_arr_.push (now_moment () + r->duration ());
+      // urg, something broken with alternative time...
+      //Moment alt_mom = now_moment () + r->repeat_p_->duration ();
+      Moment alt_mom = now_moment ();
+      for (PCursor<Music*> i (r->alternative_p_->music_p_list_p_->top ()); i.ok (); i++)
+        {
+         alternative_music_arr_.push (i.ptr ());
+         alternative_start_mom_arr_.push (alt_mom);
+         // urg, something broken with alternative time...
+         // alt_mom += i->duration ();
+         alt_mom += Moment (1);
+         alternative_stop_mom_arr_.push (alt_mom);
+       }
+      return true;
+    }
+  return false;
+}
+
+void
+Repeat_engraver::acknowledge_element (Score_element_info i)
+{
+  Moment now = now_moment ();
+  if (Note_column *nc = dynamic_cast<Note_column *> (i.elem_l_))
+    {
+      for (int i = 0; i < volta_p_arr_.size (); i++)
+        if ((now >= alternative_start_mom_arr_[i]) && volta_p_arr_[i])
+         volta_p_arr_[i]->add_column (nc);
+    }
+}
+
+void
+Repeat_engraver::do_removal_processing ()
+{
+  for (int i = 0; i < bar_p_arr_.size (); i++)
+    if (bar_p_arr_[i])
+      typeset_element (bar_p_arr_[i]);
+  for (int i = 0; i < volta_p_arr_.size (); i++)
+    if (volta_p_arr_[i])
+      typeset_element (volta_p_arr_[i]);
+}
+
+void
+Repeat_engraver::do_process_requests ()
+{  
+  for (int i = bar_p_arr_.size (); i < repeated_music_arr_.size (); i++)
+    {
+      Bar* bar_p = new Bar;
+      bar_p-> type_str_ = "|:";
+      bar_p_arr_.push (bar_p);
+      announce_element (Score_element_info (bar_p, repeated_music_arr_[i])); 
+    }
+  int bees = volta_p_arr_.size ();
+  for (int i = volta_p_arr_.size (); i < alternative_music_arr_.size (); i++)
+    {
+      Volta_spanner* v = new Volta_spanner;
+      if (i == alternative_music_arr_.size () - 1)
+        v->last_b_ = true;
+      Text_def* t = new Text_def;
+      t->text_str_ = to_str (i - bees + 1);
+      v->tdef_p_.set_p (t);
+      volta_p_arr_.push (v);
+      announce_element (Score_element_info (v, alternative_music_arr_[i]));
+    }
+}
+
+void 
+Repeat_engraver::do_pre_move_processing ()
+{
+  for (int i = bar_p_arr_.size (); i--; )
+    {
+      if (bar_p_arr_[i])
+        {
+         typeset_element (bar_p_arr_[i]);
+         bar_p_arr_[i] = 0;
+       }
+    }
+}
+
+void 
+Repeat_engraver::do_post_move_processing ()
+{
+  Moment now = now_moment ();
+  for (int i = bar_p_arr_.size (); i--; )
+    {
+      if (now >= stop_mom_arr_[i])
+       {
+         Bar* bar_p = new Bar;
+         bar_p-> type_str_ = ":|";
+         typeset_element (bar_p);
+         bar_p_arr_.del (i);
+         stop_mom_arr_.del (i);
+         repeated_music_arr_.del (i);
+       }
+    }
+  for (int i = volta_p_arr_.size (); i--; )
+    {
+      //if (now >= alternative_start_mom_arr_[i])
+      if (now >= alternative_stop_mom_arr_[i])
+        {
+         if (volta_p_arr_[i])
+           {
+             typeset_element (volta_p_arr_[i]);
+             volta_p_arr_[i] = 0;
+           }
+        }
+    }
+}
+
diff --git a/lily/volta-spanner.cc b/lily/volta-spanner.cc
new file mode 100644 (file)
index 0000000..884f8c9
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+  volta-spanner.cc -- implement Volta_spanner
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1998 Jan Nieuwenhuizen <janneke@gnu.org>
+*/
+
+#include "atom.hh"
+#include "box.hh"
+#include "debug.hh"
+#include "lookup.hh"
+#include "molecule.hh"
+#include "note-column.hh"
+#include "p-col.hh"
+#include "paper-def.hh"
+#include "volta-spanner.hh"
+#include "stem.hh"
+#include "text-def.hh"
+
+/*
+   Hmm, should probably make generic Bracket_spanner,
+   or and derive Plet and volta spanner from that.
+ */
+
+Volta_spanner::Volta_spanner ()
+{
+  dir_ = UP;
+  last_b_ = false;
+  tdef_p_.set_p (new Text_def);
+  tdef_p_->align_dir_ = CENTER;
+  tdef_p_->style_str_ = "nummer";
+}
+
+Molecule*
+Volta_spanner::brew_molecule_p () const
+{
+  Molecule* mol_p = new Molecule;
+
+  if (column_arr_.size ()){
+    Real w = width ().length ();
+    Real dy = column_arr_.top ()->extent (Y_AXIS) [dir_]
+      - column_arr_[0]->extent (Y_AXIS) [dir_];
+
+    Atom num (tdef_p_->get_atom (paper (), CENTER));
+    mol_p->add_atom (num);
+    mol_p->add_atom (lookup_l ()->volta (w, last_b_));
+  }
+  return mol_p;
+}
+  
+void
+Volta_spanner::do_add_processing ()
+{
+  if (column_arr_.size ())
+    {
+      set_bounds (LEFT, column_arr_[0]);
+      set_bounds (RIGHT, column_arr_.top ());  
+    }
+}
+  
+void
+Volta_spanner::do_post_processing ()
+{
+    if (column_arr_.size())
+       translate_axis (column_arr_[0]->extent (Y_AXIS)[dir_], Y_AXIS);
+}
+
+void
+Volta_spanner::do_substitute_dependency (Score_element* o, Score_element* n)
+{
+  if (Note_column *onc = dynamic_cast <Note_column *> (o))
+    column_arr_.substitute (onc, dynamic_cast<Note_column*> (n));
+}
+  
+void
+Volta_spanner::add_column (Note_column*n)
+{
+  column_arr_.push (n);
+  add_dependency (n);
+}
+