From 672e5b3b5ec1fb1b804c91206df8f51eb1af63e3 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 20:12:12 +0000 Subject: [PATCH] lilypond-1.0.1 --- flower/flower-debug.cc | 2 +- flower/include/array.hh | 235 +++++++++++++++++++++++++++++++ flower/include/array.icc | 66 +++++++++ flower/include/assoc.hh | 2 +- flower/include/string-convert.hh | 4 + flower/include/unionfind.hh | 2 +- flower/include/varray.icc | 3 +- flower/include/vector.hh | 5 +- input/test/clefs.ly | 26 ++-- input/test/grace.ly | 27 ++++ input/test/sizes.fly | 10 ++ lib/binary-source-file.cc | 8 +- lib/warn.cc | 4 +- lily/include/box.hh | 33 +++++ lily/include/tex-stream.hh | 5 +- lily/note.cc | 2 +- 16 files changed, 406 insertions(+), 28 deletions(-) create mode 100644 flower/include/array.hh create mode 100644 flower/include/array.icc create mode 100644 input/test/grace.ly create mode 100644 input/test/sizes.fly create mode 100644 lily/include/box.hh diff --git a/flower/flower-debug.cc b/flower/flower-debug.cc index f3131c8254..bb001511c2 100644 --- a/flower/flower-debug.cc +++ b/flower/flower-debug.cc @@ -14,7 +14,7 @@ void set_flower_debug (Dstream&ds, bool b) { #ifdef NPRINT if (b) - cout << _("Debug printout disabled. Compiled with NPRINT.") << endl; + cout << _ ("Debug output disabled. Compiled with NPRINT.") << endl; #endif flower_check_debug = b; diff --git a/flower/include/array.hh b/flower/include/array.hh new file mode 100644 index 0000000000..c40e639817 --- /dev/null +++ b/flower/include/array.hh @@ -0,0 +1,235 @@ +/* + (c) Han-Wen Nienhuys 1995,96,97 + + Distributed under GNU GPL +*/ + +#ifndef ARRAY_H +#define ARRAY_H +#include + +#ifndef INLINE +#define INLINE inline +#endif + +/// copy a bare (C-)array from #src# to #dest# sized #count# +template void arrcpy (T*dest, T*src, int count); + +/** + Scaleable array/stack template, for a type T with default constructor. + + + This template implements a scaleable vector. With (or without) range + checking. The type T should have a default constructor. It is + best suited for simple types, such as int, double or String, it + provides a paranoidly safe replacement for the new T[int] construct. + + You should \bf{never} store pointers to objects in an Array (since + the array may be relocated without the pointer knowing it). + + It uses stack terminology, (push, pop, top), and can be used as a stack. + + + */ +template +class Array +{ +protected: + /// maximum length of array. + int max_; + + /// the data itself + T *array_p_; + + /// stretch or shrink array. + void remax (int newmax) + { + T* newarr = new T[newmax]; + size_ = (newmax < size_) ? newmax : size_; + arrcpy (newarr, array_p_, size_); + + delete[] array_p_; + array_p_ = newarr; + max_ = newmax; + } + int size_; + +public: + /// check invariants + void OK() const + { + assert (max_ >= size_ && size_ >=0); + if (max_) assert (array_p_); + } + /** report the size_. + @see + {setsize_} + */ + int size() const + { return size_; } + + /// POST: size() == 0 + void clear() + { size_ = 0; } + + Array() + { array_p_ = 0; max_ =0; size_ =0; } + + // ugh, get around gcc 2.8.1 ice; see bezier.cc + Array (int i) + { + max_ = size_ = i; + array_p_ = new T[i]; + } + + + /** set the size_ to #s#. + POST: size() == s. + Warning: contents are unspecified */ + void set_size (int s) + { + if (s >= max_) remax (s); + size_ = s; + } + + ~Array() + { delete[] array_p_; } + + /// return a "new"ed copy of array + T* copy_array() const + { + T* Tarray = new T[size_]; + arrcpy (Tarray, array_p_, size_); + return Tarray; + } + // depracated + operator T*() const + { + return copy_array(); + } + void operator=(Array const & src) + { + set_size (src.size_); + arrcpy (array_p_,src.array_p_, size_); + } + Array (Array const & src) + { + array_p_ = src.copy_array(); + max_ = size_ = src.size_; + } + + /// tighten array size_. + void precompute() { + remax (size_); + } + + T * remove_array_p () { + T * p = array_p_; + size_ = 0; + max_ = 0; + array_p_ =0; + return p; + } + + /// access element + T &operator[] (int i) + { + return elem (i); + } + /// access element + T const & operator[] (int i) const + { + return elem (i); + } + /// access element + T &elem (int i) const + { + assert (i >=0&&i=0&& i < size_); + arrcpy (array_p_+i, array_p_+i+1, size_-i-1); + size_--; + } + // quicksort. + void sort (int (*compare)(T const&,T const&), + int lower = -1, int upper = -1); + void concat (Array const &src) + { + int s = size_; + set_size (size_ + src.size_); + arrcpy (array_p_+s,src.array_p_, src.size_); + } + Array slice (int lower, int upper) + { + assert (lower >= 0 && lower <=upper&& upper <= size_); + Array r; + int s =upper-lower; + r.set_size (s); + arrcpy (r.array_p_, array_p_ + lower, s); + return r; + } + void reverse(); +}; + +#include "array.icc" + +#endif diff --git a/flower/include/array.icc b/flower/include/array.icc new file mode 100644 index 0000000000..0077a01d08 --- /dev/null +++ b/flower/include/array.icc @@ -0,0 +1,66 @@ +/* + (c) Han-Wen Nienhuys 1995,96,97,98 + + Distributed under GNU GPL +*/ + + +#if 0 +#include "array.hh" +#ifdef INLINE +#undef INLINE +#endif + +#define INLINE +#endif + +/* + functions with loops don't inline + */ + +template INLINE void +arrcpy (T*dest, T*src, int count) +{ + for (int i_shadows_local=0; i_shadows_local < count ; i_shadows_local++) + *dest++ = *src++; +} + +template INLINE void +Array::insert (T k, int j) +{ + assert (j >=0 && j<= size_); + set_size (size_+1); + for (int i=size_-1; i > j; i--) + array_p_[i] = array_p_[i-1]; + array_p_[j] = k; +} + +template INLINE void +Array::sort (int (*compare)(T const&,T const&), + int lower = -1, int upper = -1) +{ + if (lower < 0) + { + lower = 0 ; + upper = size () - 1; + } + if (lower >= upper) + return; + swap (lower, (lower+upper)/2); + int last = lower; + for (int i= lower +1; i <= upper; i++) + if (compare (array_p_[i], array_p_[lower]) < 0) + swap (++last,i); + swap (lower, last); + sort (compare, lower, last-1); + sort (compare, last+1, upper); +} + +template INLINE void +Array::reverse () +{ + int h = size_/2; + for (int i =0,j = size_-1; i < h; i++,j--) + swap (i,j); +} + diff --git a/flower/include/assoc.hh b/flower/include/assoc.hh index f4558545a1..3840b4bd5a 100644 --- a/flower/include/assoc.hh +++ b/flower/include/assoc.hh @@ -1,7 +1,7 @@ #ifndef ASSOC_HH #define ASSOC_HH -#include "varray.hh" +#include "array.hh" #include /** diff --git a/flower/include/string-convert.hh b/flower/include/string-convert.hh index 4842eac2d7..3feba87bf2 100644 --- a/flower/include/string-convert.hh +++ b/flower/include/string-convert.hh @@ -7,6 +7,7 @@ #ifndef STRING_CONVERT_HH #define STRING_CONVERT_HH +#include #include "fproto.hh" #include "string.hh" @@ -18,6 +19,7 @@ class String_convert { static int hex2nibble_i (Byte byte); static Byte nibble2hex_byte (Byte byte); public: + static String bool_str (bool b); static String bin2dec_str (String bin_str); static String bin2hex_str (String bin_str); static String dec2bin_str (String str); @@ -27,6 +29,8 @@ public: static int dec2_i (String dec_str); static double dec2_f (String dec_str); static String double_str (double f, char const* fmt=0); + static String form_str (char const* format, ...); + static String vform_str (char const* format, va_list args); static int hex2_i (String str); static unsigned hex2_u (String str); static String hex2bin_str (String str); diff --git a/flower/include/unionfind.hh b/flower/include/unionfind.hh index 94a3e9f667..4f98d8801d 100644 --- a/flower/include/unionfind.hh +++ b/flower/include/unionfind.hh @@ -1,6 +1,6 @@ #ifndef UNIONFIND_HH #define UNIONFIND_HH -#include "varray.hh" +#include "array.hh" /* which points of a graph are connected?. diff --git a/flower/include/varray.icc b/flower/include/varray.icc index 4d8ccb9387..ae6b315fc8 100644 --- a/flower/include/varray.icc +++ b/flower/include/varray.icc @@ -1,3 +1,4 @@ +#error /* (c) Han-Wen Nienhuys 1995,96,97,98 @@ -6,7 +7,7 @@ #if 0 -#include "varray.hh" +#include "array.hh" #ifdef INLINE #undef INLINE #endif diff --git a/flower/include/vector.hh b/flower/include/vector.hh index 1d986c53b7..8b4d280cf5 100644 --- a/flower/include/vector.hh +++ b/flower/include/vector.hh @@ -3,7 +3,7 @@ #include #include "real.hh" -#include "varray.hh" +#include "array.hh" class Dstream; class String; @@ -41,7 +41,8 @@ public: dat.insert (v,i); } void del (int i) { dat.del (i); } - operator String() const; + + String str () const; void operator +=(Vector v) { assert (v.dim() == dim ()); diff --git a/input/test/clefs.ly b/input/test/clefs.ly index 3c14564347..a49133116b 100644 --- a/input/test/clefs.ly +++ b/input/test/clefs.ly @@ -1,17 +1,17 @@ \score { - \melodic{ \octave c'; - \clef "violin"; c1^"{violin}" \bar "||"; - \clef "french";c1^"{french}" \bar "||"; - \clef "soprano";c1^"{soprano}" \bar "||"; - \clef "mezzosoprano";c1^"{mezzosoprano}" \bar "||"; - \clef "alto";c1^"{alto}" \bar "||"; - \clef "tenor";c1^"{tenor}" \bar "||"; - \clef "baritone";c1^"{baritone}" \bar "||"; - \clef "varbaritone";c1^"{varbaritone}" \bar "||"; - \clef "G_8";c1^"{sub 8?}" \bar "||"; - \clef "G^8";c1^"{sup 8?}" \bar "|."; - \clef "bass";c1^"{bass}" \bar "||"; - \clef "subbass";c1^"{subbass}" \bar "|."; + \melodic{ + \clef "violin"; c'1^"{violin}" \bar "||"; + \clef "french";c'1^"{french}" \bar "||"; + \clef "soprano";c'1^"{soprano}" \bar "||"; + \clef "mezzosoprano";c'1^"{mezzosoprano}" \bar "||"; + \clef "alto";c'1^"{alto}" \bar "||"; + \clef "tenor";c'1^"{tenor}" \bar "||"; + \clef "baritone";c'1^"{baritone}" \bar "||"; + \clef "varbaritone";c'1^"{varbaritone}" \bar "||"; + \clef "G_8";c'1^"{sub 8?}" \bar "||"; + \clef "G^8";c'1^"{sup 8?}" \bar "|."; + \clef "bass";c'1^"{bass}" \bar "||"; + \clef "subbass";c'1^"{subbass}" \bar "|."; } \paper{ } diff --git a/input/test/grace.ly b/input/test/grace.ly new file mode 100644 index 0000000000..deec5f44f3 --- /dev/null +++ b/input/test/grace.ly @@ -0,0 +1,27 @@ + +\include "table13.ly"; +\include "table16.ly"; + +\score{ + < + \type Staff = a \melodic\relative c < +% {\grace b''8 \graceat a4 \ecarg g fis2 | a2 a } + {\tiny b''8*1/16 \normalsize a4*31/32 g fis2 | a2 a } + > + \type Staff = b \melodic\relative c < +% {\grace g''16 b16 \graceat a4 \ecarg g fis2 | } + {\tiny g''16*1/16 b16*1/16 \normalsize a4*31/32 g fis2 | a1 } + > + \type Staff = c \melodic\relative c < +% {\grace [2/48 g''16 b g]/1 \graceat a4 \ecarg g fis2 | a1 } + {\tiny [2/48 g''16 b g]/1 \normalsize a4*31/32 g fis2 | a1 } + > + > + \paper { + linewidth = 120.0\mm; + -2 = \symboltables { \table_thirteen } + -1 = \symboltables { \table_sixteen } + + } +} + diff --git a/input/test/sizes.fly b/input/test/sizes.fly new file mode 100644 index 0000000000..00923366a4 --- /dev/null +++ b/input/test/sizes.fly @@ -0,0 +1,10 @@ +% to see the magic: uncomment size stuff in init/paper20.ly + +c'4 c4 + +\property Voice.fontsize= "-2" +b16 * 1 / 2 ( +\property Voice.fontsize= "0" ) +g4 *31/32 + +a a g2 diff --git a/lib/binary-source-file.cc b/lib/binary-source-file.cc index 971d4d0c21..9bcf0e5f70 100644 --- a/lib/binary-source-file.cc +++ b/lib/binary-source-file.cc @@ -39,15 +39,15 @@ Binary_source_file::error_str (char const* pos_ch_c_l) const String pre_str ((Byte const*)begin_ch_c_l, pos_ch_c_l - begin_ch_c_l); pre_str = String_convert::bin2hex_str (pre_str); for (int i = 2; i < pre_str.length_i (); i += 3) - pre_str = pre_str.left_str (i) + " " + pre_str.cut (i, INT_MAX); + pre_str = pre_str.left_str (i) + " " + pre_str.cut_str (i, INT_MAX); String post_str ((Byte const*)pos_ch_c_l, end_ch_c_l - pos_ch_c_l); post_str = String_convert::bin2hex_str (post_str); for (int i = 2; i < post_str.length_i (); i += 3) - post_str = post_str.left_str (i) + " " + post_str.cut (i, INT_MAX); + post_str = post_str.left_str (i) + " " + post_str.cut_str (i, INT_MAX); String str = pre_str - + String ('\n') - + String (' ', pre_str.length_i () + 1) + + to_str ('\n') + + to_str (' ', pre_str.length_i () + 1) + post_str; return str; } diff --git a/lib/warn.cc b/lib/warn.cc index afdbd97f4f..afc6f7b9ce 100644 --- a/lib/warn.cc +++ b/lib/warn.cc @@ -4,7 +4,7 @@ void error (String s) { - cerr << _ ("error: ") << s << "\n"; + cerr << _ ("error: ") << s << '\n'; exit (1); } @@ -12,7 +12,7 @@ error (String s) void non_fatal_error (String s) { - cerr << _ ("error: ") << s << "\n"; + cerr << _ ("error: ") << s << '\n'; } void diff --git a/lily/include/box.hh b/lily/include/box.hh new file mode 100644 index 0000000000..b26c6e3695 --- /dev/null +++ b/lily/include/box.hh @@ -0,0 +1,33 @@ +/* + some 2D geometrical concepts +*/ + +#ifndef BOXES_HH +#define BOXES_HH + +#include "fproto.hh" +#include "real.hh" +#include "interval.hh" +#include "offset.hh" +#include "axes.hh" + + +struct Box { + Interval interval_a_[NO_AXES]; + + Interval &x() {return interval_a_[X_AXIS]; } + Interval &y(){ return interval_a_[Y_AXIS]; } + Interval x() const{ return interval_a_[X_AXIS]; } + Interval y() const{return interval_a_[Y_AXIS]; } + Interval operator[](Axis a) const; + Interval &operator[] (Axis a); + + void translate (Offset o); + /// smallest box enclosing #b# + void unite (Box b); + Box(); + Box (Interval ix, Interval iy); +}; + + +#endif diff --git a/lily/include/tex-stream.hh b/lily/include/tex-stream.hh index e8011bb3ee..e26c8328cb 100644 --- a/lily/include/tex-stream.hh +++ b/lily/include/tex-stream.hh @@ -22,8 +22,9 @@ public: /// open a file for writing Tex_stream (String filename); void header(); - /// delegate conversion to string class. - Tex_stream &operator<<(String); + + /// delegate conversion to scalar class + Tex_stream &operator <<(Scalar); /// close the file ~Tex_stream(); diff --git a/lily/note.cc b/lily/note.cc index 78e6429473..a32cabab79 100644 --- a/lily/note.cc +++ b/lily/note.cc @@ -11,7 +11,7 @@ #include "command-request.hh" #include "music-list.hh" #include "identifier.hh" -#include "varray.hh" +#include "array.hh" #include "text-def.hh" #include "parseconstruct.hh" -- 2.39.5