]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
release: 0.1.45
[lilypond.git] / lily / lookup.cc
index 6bc298e14798138be4ee70d69fe3eb43c24de6a1..da4083afe6466b48b184662db60bfe071df2283b 100644 (file)
@@ -7,9 +7,9 @@
 
   TODO
   This doth suck. We should have PS output, and read spacing info from TFMs
-  
-  Glissando, bracket
-  
+
+  Glissando, 
+
 */
 
 #include "lookup.hh"
 #include "tex.hh"
 #include "scalar.hh"
 #include "paper-def.hh"
+#include "main.hh"
 
 Lookup::Lookup()
 {
-    paper_l_ = 0;
-    texsetting = "\\unknowntexsetting";
-    symtables_ = new Symtables;
+  paper_l_ = 0;
+  texsetting = "\\unknowntexsetting";
+  symtables_p_ = new Symtables;
 }
 
-Lookup::Lookup(Lookup const &s)
+Lookup::Lookup (Lookup const &s)
 {
-    paper_l_ = s.paper_l_;
-    texsetting = s.texsetting;
-    symtables_ = new Symtables(*s.symtables_);
+  paper_l_ = s.paper_l_;
+  texsetting = s.texsetting;
+  symtables_p_ = new Symtables (*s.symtables_p_);
 }
 Lookup::~Lookup()
 {
-    delete symtables_;
+  delete symtables_p_;
 }
 
 void
-Lookup::add(String s, Symtable*p)
+Lookup::add (String s, Symtable*p)
 {
-    symtables_->add(s, p);
+  symtables_p_->add (s, p);
 }
 
 void
-Lookup::print()const
+Lookup::print() const
 {
-    #ifndef NPRINT
-    mtor << "Lookup: " << texsetting << " {\n";
-    symtables_->print();
-    mtor << "}\n";
-    #endif
+#ifndef NPRINT
+  DOUT << "Lookup: " << texsetting << " {\n";
+  symtables_p_->print();
+  DOUT << "}\n";
+#endif
 }
 
-Symbol
-Lookup::text(String style, String text, int dir) const
+Atom
+Lookup::text (String style, String text, int dir) const
 {
-    Array<String> a;
-    a.push(text);
-    Symbol tsym =  (*symtables_)("style")->lookup(style);
-    a[0] = substitute_args(tsym.tex,a);
-
-    Symbol s = (*symtables_)("align")->lookup(dir);
-    s.tex = substitute_args(s.tex,a);
-    s.dim = tsym.dim;
-    return s;
+  Array<String> a;
+
+  a.push (text);
+  Atom tsym =  (*symtables_p_)("style")->lookup (style);
+  a[0] = substitute_args (tsym.tex_,a);
+
+  Atom s = (*symtables_p_)("align")->lookup (dir);
+  s.tex_ = substitute_args (s.tex_,a);
+  s.dim_ = tsym.dim_;
+  return s;
 }
 
 
 
-Symbol
-Lookup::ball(int j) const
+Atom
+Lookup::ball (int j) const
 {
-    if (j > 4)
-       j = 4;
+  if (j > 2)
+    j = 2;
 
-    Symtable * st = (*symtables_)("balls");
-    return st->lookup(String(j));
+  Symtable * st = (*symtables_p_)("balls");
+  return st->lookup (String (j));
 }
 
-Symbol
-Lookup::rest(int j, bool o) const
+Atom
+Lookup::rest (int j, bool o) const
 {
-    return (*symtables_)("rests")->lookup(String(j) + (o ? "o" : "") );
+  return (*symtables_p_)("rests")->lookup (String (j) + (o ? "o" : ""));
 }
 
-Symbol
-Lookup::fill(Box b) const
+Atom
+Lookup::fill (Box b) const
 {
-    Symbol s( (*symtables_)("param")->lookup("fill"));
-    s.dim = b;
-    return s;
+  Atom s ((*symtables_p_)("param")->lookup ("fill"));
+  s.dim_ = b;
+  return s;
 }
 
-Symbol
-Lookup::accidental(int j) const
+Atom
+Lookup::accidental (int j) const
 {
-    return (*symtables_)("accidentals")->lookup(String(j));
+  return (*symtables_p_)("accidentals")->lookup (String (j));
 }
 
 
-Symbol
-Lookup::bar(String s, Real h) const
+Atom
+Lookup::bar (String s, Real h) const
 {
-    Array<String> a;
-    a.push(print_dimen( h));
-    Symbol ret=(*symtables_)("bars")->lookup(s);;
-    ret.tex = substitute_args(ret.tex, a);
-    ret.dim.y = Interval( 0, h);
-    return ret;
+  Array<String> a;
+  a.push (print_dimen (h));
+  Atom ret=(*symtables_p_)("bars")->lookup (s);
+  ret.tex_ = substitute_args (ret.tex_, a);
+  ret.dim_.y() = Interval (-h/2, h/2);
+  return ret;
 }
 
-Symbol
-Lookup::script(String s) const
+Atom
+Lookup::script (String s) const
 {
-    return (*symtables_)("scripts")->lookup(s);
+  return (*symtables_p_)("scripts")->lookup (s);
 }
 
-Symbol
-Lookup::dynamic(String s) const
+Atom
+Lookup::dynamic (String s) const
 {
-    return (*symtables_)("dynamics")->lookup(s);
+  return (*symtables_p_)("dynamics")->lookup (s);
 }
 
-Symbol
-Lookup::clef(String s) const
+Atom
+Lookup::clef (String s) const
 {
-    return (*symtables_)("clefs")->lookup(s);
+  return (*symtables_p_)("clefs")->lookup (s);
 }
-Symbol
-Lookup::dots(int j) const
+
+Atom
+Lookup::dots () const
 {
-    if (j>3) {
-       j = 3;
-       warning("max 3 dots");  // todo
-    }
-    return (*symtables_)("dots")->lookup(j);
+  return (*symtables_p_)("dots")->lookup ("dot");
 }
 
-Symbol
-Lookup::flag(int j) const
+Atom
+Lookup::flag (int j, Direction d) const
 {
-    return (*symtables_)("flags")->lookup(j);
+  char c = (d == UP) ? 'u' : 'd';
+  return (*symtables_p_)("flags")->lookup (c + String (j));
 }
 
-Symbol
-Lookup::streepjes(int i) const
+Atom
+Lookup::streepje (int type) const
 {
-    assert(i);
-    
-    int arg;
-    String idx;
-    
-    if (i < 0) {
-       idx = "botlines";
-       arg = -i;
-    } else {
-       arg = i;
-       idx = "toplines";
-    }
-    Symbol ret = (*symtables_)("streepjes")->lookup(idx);
-    
-    Array<String> a;
-    a.push(arg);
-    ret.tex = substitute_args(ret.tex, a);
+  if (type > 2)
+    type = 2;
 
-    return ret;
+  Symtable * st = (*symtables_p_)("balls");
+  
+  return st->lookup (String (type) + 'l');
 }
 
-Symbol
-Lookup::hairpin(Real &wid, bool decresc) const
+Atom
+Lookup::hairpin (Real &wid, bool decresc, bool continued) const
 {
-    int idx = int(rint(wid / 6 PT));
-    if(!idx) idx ++;
-    wid = idx*6 PT;
-    String idxstr = (decresc)? "decrescendosym" : "crescendosym";
-    Symbol ret=(*symtables_)("param")->lookup(idxstr);
-       
-    Array<String> a;
-    a.push(idx);
-    ret.tex = substitute_args(ret.tex, a);
-    ret.dim.x = Interval(0,wid);
-    return ret;
+  bool embedded_b = postscript_global_b;
+  String embed;
+  Atom ret;  
+  if (embedded_b)
+    {
+      Real height = paper_l_->get_var ("barsize") / 6;
+      embed = "\\embeddedps{\n" ;
+      embed += String (wid) + " " 
+       + String (height) + " " 
+       + String (continued ? height/2 : 0) + 
+       + " draw_"  + String(decresc ? "de" : "") + "cresc}\n";
+      ret.tex_ = embed;
+    }
+  else
+    {
+      if (wid > 32 * 6 PT)
+       {
+         warning (_("Crescendo too long (") + print_dimen (wid) 
+                  +_( ") shrinking (ugh)"));
+         wid = 32*6 PT;
+       }
+      int idx = int (rint (wid / 6 PT));
+      if (!idx) idx ++;
+      wid = idx*6 PT;
+      String idxstr = (decresc)? "decrescendosym" : "crescendosym";
+      ret=(*symtables_p_)("param")->lookup (idxstr);
+      
+      Array<String> a;
+      a.push (idx);
+      ret.tex_ = substitute_args (ret.tex_, a);
+    }
+  
+  ret.dim_.x() = Interval (0,wid);
+  // ret.translate_axis (-ret.dim_[Y_AXIS][DOWN], Y_AXIS);
+  return ret;
 }
 
-Symbol
-Lookup::linestaff(int lines, Real wid) const
+Atom
+Lookup::meter (Array<Scalar> a) const
 {
-    Real internote_f = paper_l_ ->internote_f();
-    Symbol s;
-    s.dim.x = Interval(0,wid);
-    Real dy = (lines >0) ? (lines-1)*internote_f : 0;
-    s.dim.y = Interval(0,dy);
-
-    Array<String> a;
-    a.push(lines);
-    a.push(print_dimen(wid));
-
-    s.tex = (*symtables_)("param")->lookup("linestaf").tex;
-    s.tex = substitute_args(s.tex, a);
-
-    return s;
+  Atom s((*symtables_p_)("param")->lookup ("meter"));
+  s.tex_ = substitute_args (s.tex_,a);
+  return s;
 }
 
 
-Symbol
-Lookup::meter(Array<Scalar> a) const
+Atom
+Lookup::stem (Real y1,Real y2) const
 {
-    Symbol s;
-    s.dim.x = Interval( 0 PT, 10 PT);
-    s.dim.y = Interval(0, 20 PT);      // todo
-    String src = (*symtables_)("param")->lookup("meter").tex;
-    s.tex = substitute_args(src,a);
-    return s;    
-}
+  if (y1 > y2)
+    {
+      Real t = y1;
+      y1 = y2;
+      y2 = t;
+    }
+  Atom s;
 
+  s.dim_.x() = Interval (0,0);
+  s.dim_.y() = Interval (y1,y2);
 
-Symbol
-Lookup::stem(Real y1,Real y2) const
-{
-    if (y1 > y2) {
-       Real t = y1;
-       y1 = y2;
-       y2 = t;
-    }
-    Symbol s;
-    
-    s.dim.x = Interval(0,0);
-    s.dim.y = Interval(y1,y2);
-    
-    Array<String> a;
-    a.push(print_dimen(y1));
-    a.push(print_dimen(y2));
-       
-    String src = (*symtables_)("param")->lookup("stem").tex;
-    s.tex = substitute_args(src,a);
-    return s;
+  Array<String> a;
+  a.push (print_dimen (y1));
+  a.push (print_dimen (y2));
+
+  String src = (*symtables_p_)("param")->lookup ("stem").tex_;
+  s.tex_ = substitute_args (src,a);
+  return s;
 }
 
 /*
-  should be handled via TeX code and Lookup::bar()
+  should be handled via Tex_ code and Lookup::bar()
  */
-Symbol
-Lookup::vbrace(Real &y) const
+Atom
+Lookup::vbrace (Real &y) const
 {
-    if (y < 2* 20 PT) {
-       warning ( "piano brace too small (" + print_dimen(y)+ ")");
-       y = 2*20 PT;
-    }
-    if (y > 67 * 2 PT) {
-       warning ( "piano brace too big (" + print_dimen(y)+ ")");       
-       y = 67 *2 PT;
-    }
-    
-    int idx = int(rint((y/2.0 - 20 ) + 148));
-    
-    Symbol s = (*symtables_)("param")->lookup("brace");
+  Atom brace = (*symtables_p_)("param")->lookup ("brace");
+  Interval ydims = brace.dim_[Y_AXIS];
+  Real min_y = ydims[LEFT];
+  Real max_y = ydims[RIGHT];
+  Real step = 1.0 PT;
+  if (y < min_y)
     {
-       Array<String> a;
-       a.push(idx);
-       s.tex = substitute_args(s.tex,a);
-       s.dim.y = Interval(0,y);
+      warning (_("piano brace too small (") + print_dimen (y)+ ")");
+      y = min_y;
     }
+  if (y > max_y)
     {
-       Array<String> a;
-       a.push(print_dimen( y/2 ));
-       a.push(print_dimen(0));
-       a.push(s.tex);
-       s.tex = substitute_args("\\placebox{%}{%}{%}", a);
+      warning (_("piano brace too big (") + print_dimen (y)+ ")");
+      y = max_y;
     }
 
-       
-    return s;
+  
+  int idx = int (rint ((y- min_y)/step)) + 1;
+  
+  {
+    Array<String> a;
+    a.push (idx);
+    brace.tex_ = substitute_args (brace.tex_,a);
+    brace.dim_[Y_AXIS] = Interval (-y/2,y/2);
+  }
+
+  return brace;
 }