--- /dev/null
+/*
+ file-storage.cc -- implement Mapped_file_storage
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ Jan Nieuwenhuizen <jan@digicash.com>
+*/
+#include <sys/types.h> // open, mmap
+#include <sys/stat.h> // open
+#include <sys/mman.h> // mmap
+#include <limits.h> // INT_MAX
+#include <fcntl.h> // open
+#include <unistd.h> // close, stat
+#include <stdio.h> // fdopen
+#include <string.h> // strerror
+#include <errno.h> // errno
+
+
+
+#include "string.hh"
+#include "proto.hh"
+#include "warn.hh"
+#include "file-storage.hh"
+
+Mapped_file_storage::Mapped_file_storage(String s)
+{
+ data_caddr_ = 0;
+ fildes_i_ = 0;
+ size_off_ = 0;
+ open(s);
+}
+
+char const*
+Mapped_file_storage::ch_C() const
+{
+ return (char const*)data_caddr_;
+}
+
+void
+Mapped_file_storage::map()
+{
+ if (fildes_i_ == -1)
+ return;
+
+ data_caddr_ = (caddr_t)mmap((void*)0, size_off_, PROT_READ, MAP_SHARED, fildes_i_, 0);
+
+ if ((int)data_caddr_ == -1)
+ warning(String("can't map: error no: ") + strerror(errno));
+}
+
+
+void
+Mapped_file_storage::open(String name_str)
+{
+ fildes_i_ = ::open(name_str, O_RDONLY);
+
+ if (fildes_i_ == -1)
+ {
+ warning(String("can't open: ") + name_str + String(": ") + strerror(errno));
+ return;
+ }
+
+ struct stat file_stat;
+ fstat(fildes_i_, &file_stat);
+ size_off_ = file_stat.st_size;
+ map();
+}
+
+void
+Mapped_file_storage::unmap()
+{
+ if (data_caddr_)
+ {
+ munmap(data_caddr_, size_off_);
+ data_caddr_ = 0;
+ size_off_ = 0;
+ }
+}
+
+void
+Mapped_file_storage::close()
+{
+ unmap();
+ if (fildes_i_)
+ {
+ ::close(fildes_i_);
+ fildes_i_ = 0;
+ }
+}
+
+int
+Mapped_file_storage::length_i() const
+{
+ return size_off_;
+}
+
+Mapped_file_storage::~Mapped_file_storage()
+{
+ close();
+}
Stupid but foolproof way of opening files.
TODO
- Should use obstack. Should check IO status
+ Should check IO status
This is of course a build it yourself version of mmap, so we should
have been using that... (see Mapped_file_storage) But we noticed
some problems with this (unexplained lexer crashes)
- */
+ [Some versions later] The crashes aren't caused by the mmap
+ code. But no reason to take it out, is there? */
Simple_file_storage::Simple_file_storage(String s)
{
- data_p_ =0;
- FILE * f = fopen ( s.ch_C(), "r");
- if ( !f )
- {
- warning("can't open file\n");
- return ;
- }
+ data_p_ =0;
+ /*
+ let's hope that "b" opens anything binary, and does not apply
+ CR/LF translation
+ */
+ FILE * f = fopen (s.ch_C(), "rb");
+ if (!f)
+ {
+ warning("can't open file\n");
+ return ;
+ }
- int ret = fseek( f, 0, SEEK_END);
- len_i_ = ftell(f);
- rewind(f);
- data_p_ = new char[len_i_+1];
- data_p_[len_i_] = 0;
- ret = fread(data_p_, sizeof(char), len_i_, f);
- assert (ret==len_i_);
- fclose(f);
+ int ret = fseek(f, 0, SEEK_END);
+ len_i_ = ftell(f);
+ rewind(f);
+ data_p_ = new char[len_i_+1];
+ data_p_[len_i_] = 0;
+ ret = fread(data_p_, sizeof(char), len_i_, f);
+
+
+#if 1 // ugh, \r\n -> \n translation
+ assert (ret==len_i_);
+#endif
+ fclose(f);
}
char const*
Simple_file_storage::ch_C() const
{
- return data_p_;
+ return data_p_;
}
int
-Simple_file_storage::length_i()const
+Simple_file_storage::length_i() const
{
- return len_i_;
+ return len_i_;
}
Simple_file_storage::~Simple_file_storage()
{
- delete []data_p_;
+ delete []data_p_;
}
MAJOR_VERSION = 0
MINOR_VERSION = 1
-PATCH_LEVEL = 9
+PATCH_LEVEL = 11
# use to send patches, always empty for released version:
# include separator: ".postfix", "-pl" makes rpm barf
Bow::Bow()
{
- left_pos_i_ = right_pos_i_ = 0;
- left_dx_f_ = right_dx_f_ = 0.0;
+ pos_i_drul_[LEFT] = pos_i_drul_[RIGHT] = 0;
+ dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
}
Offset
Bow::center() const
{
- int dy = right_pos_i_-left_pos_i_;
+ int dy = pos_i_drul_[RIGHT]-pos_i_drul_[LEFT];
Real w = width().length ();
Molecule*output = new Molecule;
Real w = width().length ();
- int dy = right_pos_i_ - left_pos_i_;
+ int dy = pos_i_drul_[RIGHT] - pos_i_drul_[LEFT];
Real nw_f = paper()->note_width ();
Real nh_f = paper()->internote_f ();
- w+= (right_dx_f_ - left_dx_f_) * nw_f ;
+ w+= (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]) * nw_f ;
Real round_w = w; // slur lookup rounds the slurwidth .
- Symbol sl = paper()->lookup_l ()->slur (dy , round_w, dir_i_);
+ Symbol sl = paper()->lookup_l ()->slur (dy , round_w, dir_);
Real error = w-round_w;
Atom a (sl);
- a.translate (Offset ((left_dx_f_ + 0.5)*nw_f + error/2,
- left_pos_i_ * nh_f));
+ a.translate (Offset ((dx_f_drul_[LEFT] + 0.5)*nw_f + error/2,
+ pos_i_drul_[LEFT] * nh_f));
output->add (a);
return output;
}
{
assert (abs (dir) == 1);
int j = dir > 0 ? 0 : 3;
- if ( h_shift_b)
+ if (h_shift_b)
j += dir;
return j;
}
for (int i=0; i < clash_l_arr_.size(); i++)
{
Note_column* c_l = clash_l_arr_[i];
- if (! c_l->dir_i_)
+ if (! c_l->dir_)
{
warning ("No stem direction set. Ignoring column in clash. ");
continue;
}
- int d = (c_l->dir_i_);
+ int d = (c_l->dir_);
clash_group_arr_a[idx (d, c_l->h_shift_b_)].push (c_l);
}
--- /dev/null
+/*
+ beam-grav.hh -- declare Beam_engraver
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef BEAM_GRAV_HH
+#define BEAM_GRAV_HH
+
+#include "engraver.hh"
+#include "drul-array.hh"
+
+/**
+ Generate a beam. Eats stems.
+ */
+class Beam_engraver : public Engraver
+{
+ Drul_array<Beam_req *> span_reqs_drul_;
+ Beam *beam_p_;
+ Rhythmic_grouping *current_grouping_p_;
+
+public:
+ DECLARE_MY_RUNTIME_TYPEINFO;
+ Beam_engraver();
+protected:
+ virtual void do_removal_processing();
+ virtual void do_process_requests();
+ virtual bool do_try_request (Request*);
+ virtual void acknowledge_element (Score_elem_info);
+ virtual void do_pre_move_processing();
+};
+
+#endif // BEAM_GRAV_HH
*/
class Crescendo : public Spanner , public Staff_side {
public:
- int grow_dir_i_;
+ int grow_dir_;
-/// if there is a dynamic at the end, make the sign smaller.
- bool right_dyn_b_;
+ /// if there is a dynamic at the end, make the sign smaller.
+ Drul_array<bool> dyn_b_drul_;
- /// if there is a dynamic at the end, make the sign smaller.
- bool left_dyn_b_;
- Crescendo();
+ Crescendo();
protected:
- SCORE_ELEM_CLONE(Crescendo);
- virtual Molecule*brew_molecule_p()const;
- virtual Interval symbol_height()const;
- DECLARE_MY_RUNTIME_TYPEINFO;
+ SCORE_ELEM_CLONE(Crescendo);
+ virtual Molecule*brew_molecule_p() const;
+ virtual Interval symbol_height() const;
+ DECLARE_MY_RUNTIME_TYPEINFO;
private:
- Symbol get_symbol()const;
-
+ Symbol get_symbol() const;
};
#endif // CRESCENDO_HH
public:
/// -1 below heads, +1 above heads.
- int dir_i_;
+ Direction dir_;
Directional_spanner();
/// offset of "center" relative to left-column/0-pos of staff
#include "engraver.hh"
class Dynamic_engraver : public Engraver {
- int dir_i_;
+ Direction dir_;
Text_item * dynamic_p_;
Crescendo * to_end_cresc_p_;
Crescendo * cresc_p_;
class Head_column : public Script_column
{
public:
- Link_array<Note_head> head_l_arr_;
- /** The relative position of the "voice" containing this
- chord. Normally this would be the same as the stem direction,
- but rests do not have stems.
-
- Hmm. outdated.. Rests *do* have stems.
- */
-
- int dir_i_;
- Stem* stem_l_;
-
- void add (Note_head*);
- virtual void add (Script*s);
- virtual void set (Stem*);
- Head_column();
- DECLARE_MY_RUNTIME_TYPEINFO;
+ Link_array<Note_head> head_l_arr_;
+ /** The relative position of the "voice" containing this
+ chord. Normally this would be the same as the stem direction,
+ but rests do not have stems.
+
+ Hmm. outdated.. Rests *do* have stems.
+ */
+
+ Direction dir_;
+ Stem* stem_l_;
+
+ void add (Note_head*);
+ virtual void add (Script*s);
+ void set (Stem*);
+ Head_column();
+ DECLARE_MY_RUNTIME_TYPEINFO;
protected:
- virtual void do_pre_processing();
- virtual void do_print()const;
- virtual void do_substitute_dependency (Score_elem*,Score_elem*);
+ virtual void do_pre_processing();
+ virtual void do_print() const;
+ virtual void do_substitute_dependency (Score_elem*,Score_elem*);
};
#endif // HEAD_COLUMN_HH
#include "elem-group.hh"
#include "axis-group-item.hh"
+/**
+ Group stuff in horizontal sense. Example: Paper_column
+ */
class Horizontal_group_item : public Axis_group_item, public Horizontal_group_element {
protected:
- virtual void remove_all() { Horizontal_group_element::remove_all (); }
- virtual void do_print() const;
+ virtual void remove_all() { Horizontal_group_element::remove_all (); }
+ virtual void do_unlink () {
+ Axis_group_item::do_unlink ();
+ }
+ virtual void do_junk_links() {
+ Axis_group_item::do_junk_links();
+ }
+ virtual void do_print() const;
public:
- virtual void add_element (Score_elem*e) { Horizontal_group_element::add_element (e); }
- virtual void remove_element (Score_elem*e) { Horizontal_group_element::remove_element (e); }
- DECLARE_MY_RUNTIME_TYPEINFO;
- SCORE_ELEM_CLONE(Horizontal_group_item);
-
-
+ virtual void add_element (Score_elem*e) { Horizontal_group_element::add_element (e); }
+ virtual void remove_element (Score_elem*e) { Horizontal_group_element::remove_element (e); }
+ DECLARE_MY_RUNTIME_TYPEINFO;
+ SCORE_ELEM_CLONE(Horizontal_group_item);
};
#endif // HORIZONTAL_GROUP_ITEM_HH
Note_column *ncol_p_;
Rest_column *restcol_p_;
bool h_shift_b_;
- int dir_i_;
+ Direction dir_;
- bool acceptable_elem_b (Score_elem const*)const;
+ bool acceptable_elem_b (Score_elem const*) const;
protected:
virtual void set_feature (Feature);
virtual void acknowledge_element (Score_elem_info);
#include "virtual-methods.hh"
#include "input.hh"
#include "music.hh"
+#include "direction.hh"
/**
a voice element wants something printed.
bool equal_b (Request*) const;
protected:
virtual bool do_equal_b (Request*) const;
- virtual void do_print()const;
+ virtual void do_print() const;
};
#define REQUESTMETHODS(T,accessor) \
this also a request */
class Script_req : public virtual Request {
public:
- int dir_i_;
+ Direction dir_;
General_script_def *scriptdef_p_;
/* *************** */
- bool do_equal_b (Request*)const;
+ bool do_equal_b (Request*) const;
Script_req();
REQUESTMETHODS(Script_req,script);
Array<Slur_req*> new_slur_req_l_arr_;
Array<Slur *> slur_l_stack_;
Array<Slur*> end_slur_l_arr_;
- int dir_i_;
+ Direction dir_;
/* *************** */
protected:
virtual ~Slur_engraver();
--- /dev/null
+/*
+ stem-grav.hh -- declare Stem_engraver
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STEM_GRAV_HH
+#define STEM_GRAV_HH
+
+#include "engraver.hh"
+
+/**
+ Make stems upon receiving noteheads.
+ */
+class Stem_engraver : public Engraver
+{
+ Direction dir_;
+ Stem *stem_p_;
+ Rhythmic_req *rhythmic_req_l_;
+protected:
+ virtual void acknowledge_element (Score_elem_info);
+ virtual void do_pre_move_processing ();
+ virtual void set_feature (Feature dir_i_);
+
+public:
+ Stem_engraver();
+ DECLARE_MY_RUNTIME_TYPEINFO;
+};
+
+#endif // STEM_GRAV_HH
class Text_engraver : public Engraver{
Text_item * text_p_;
Text_req * text_req_l_;
- int dir_i_;
+ Direction dir_;
/* *************** */
protected:
virtual void set_feature (Feature);
Tie * tie_p_;
Moment end_mom_;
Tie_req * req_l_;
- int dir_i_;
+ Direction dir_;
Tie_req *end_req_l_;
Melodic_req * end_melodic_req_l_;
Melodic_req * melodic_req_l_;
#include "lily-proto.hh"
#include "virtual-methods.hh"
+/** Make some kind of #Element#s from Requests. Elements are made by
+ hierarchically grouped #Translator#s
+ */
class Translator {
public:
- String id_str_;
+ String id_str_;
- int iterator_count_;
+ int iterator_count_;
- virtual Global_translator *global_l() { return 0; }
-
- /// Score_register = 0, Staff_registers = 1, etc)
- virtual void print()const;
- virtual int depth_i()const=0;
- virtual bool is_bottom_engraver_b() const { return false; }
- virtual bool try_request (Request*);
- virtual Translator *find_get_translator_l (String name, String id)=0;
- virtual Translator *ancestor_l (int l=1)=0;
- virtual ~Translator(){}
- DECLARE_MY_RUNTIME_TYPEINFO;
- Translator();
- virtual Translator *get_default_interpreter()=0;
+ virtual Global_translator *global_l() { return 0; }
+
+ virtual void print() const;
+
+ /// Score_register = 0, Staff_registers = 1, etc)
+ virtual int depth_i() const=0;
+ virtual bool is_bottom_engraver_b() const { return false; }
+ virtual bool try_request (Request*);
+ virtual Translator *find_get_translator_l (String name, String id)=0;
+ virtual Translator *ancestor_l (int l=1)=0;
+ virtual ~Translator(){}
+ DECLARE_MY_RUNTIME_TYPEINFO;
+ Translator();
+ virtual Translator *get_default_interpreter()=0;
};
#endif // TRANSLATOR_HH
*/
class Voice_group_engravers : public Engraver_group_engraver {
Moment termination_mom_;
- int dir_i_;
+ Direction dir_;
protected:
virtual void do_print() const;
get_script_req (int d , General_script_def*def)
{
Musical_script_req* script_req_p = new Musical_script_req;
- script_req_p->dir_i_ =d;
+ script_req_p->dir_ =d;
script_req_p->scriptdef_p_=def;
return script_req_p;
}
if (!(stem_l->beams_left_i_ || stem_l->beams_right_i_))
return;
- int dir_i = rest_l_arr_[0]->dir_i_;
+ int dir_i = rest_l_arr_[0]->dir_;
int midpos = 4;
#if 1
// ugh
int stem_length_i = 7 - 2;
// ugh, Stem::stem_start vs Stem::stem_end
- int pos = (stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
+ int pos = (int)(stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
#else // nogo: stem_start not set for rests?
int pos = (stem_l->stem_start_f() - midpos) + dir_i * 2;
#endif
{
int dy = rest_l_arr_.size() > 2 ? 6 : 4;
- rest_l_arr_[0]->translate_heads (rest_l_arr_[0]->dir_i_ *dy);
+ rest_l_arr_[0]->translate_heads (rest_l_arr_[0]->dir_ *dy);
// top is last element...
- rest_l_arr_.top()->translate_heads (rest_l_arr_.top ()->dir_i_* dy);
+ rest_l_arr_.top()->translate_heads (rest_l_arr_.top ()->dir_* dy);
}
// meisjes met jongetjes
else
int dir_i = -1;
rest_l_arr_[0]->translate_heads (dir_i * 3);
#else
- // int dir_i = - ncol_l_arr_[0]->dir_i_;
- int dir_i = rest_l_arr_[0]->dir_i_;
+ // int dir_i = - ncol_l_arr_[0]->dir_;
+ int dir_i = rest_l_arr_[0]->dir_;
// hope it's 4: if it works->doco
int midpos = 4;
{
// how to know whether to sort?
ncol_l_arr_[i]->sort();
- for ( int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
+ for (int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
minpos = minpos >? dir_i *
(ncol_l_arr_[i]->head_l_arr_[j]->position_i_ -midpos) + sep_i;
}
void
-Script_column::do_print()const
+Script_column::do_print() const
{
#ifndef NPRINT
DOUT << "scripts: " << script_l_arr_.size() << '\n';
idx (bool inside, int dir)
{
int j = (dir+1);
- if ( !inside)
- j ++;
+ if (!inside)
+ j ++;
return j;
}
Script_column::do_pre_processing()
{
if (!script_l_arr_.size())
- return;
+ return;
/* up+inside, up+outside, down+inside, down+outside */
Array<Script*> placed_l_arr_a[4];
for (int i=0; i < script_l_arr_.size(); i++)
{
- Script*s_l = script_l_arr_[i];
- placed_l_arr_a[idx (s_l->inside_staff_b_ , s_l->dir_i_) ].push (s_l);
+ Script*s_l = script_l_arr_[i];
+ placed_l_arr_a[idx (s_l->inside_staff_b_ , s_l->dir_) ].push (s_l);
}
for (int j =0; j <4; j++)
{
- placed_l_arr_a[j].sort (Script::compare);
+ placed_l_arr_a[j].sort (Script::compare);
}
for (int j =0; j < 4; j++)
{
- if (placed_l_arr_a[j].size())
- for (int i=0; i < support_l_arr_.size(); i++)
- placed_l_arr_a[j][0]->add_support (support_l_arr_[i]);
+ if (placed_l_arr_a[j].size())
+ for (int i=0; i < support_l_arr_.size(); i++)
+ placed_l_arr_a[j][0]->add_support (support_l_arr_[i]);
}
Item * support_l=0;
int j = 0;
for (; j < 2; j++)
{
- for (int i=0; i < placed_l_arr_a[j].size(); i++)
- {
- if (support_l)
- placed_l_arr_a[j][i]->add_support (support_l);
- support_l = placed_l_arr_a[j][i];
- }
+ for (int i=0; i < placed_l_arr_a[j].size(); i++)
+ {
+ if (support_l)
+ placed_l_arr_a[j][i]->add_support (support_l);
+ support_l = placed_l_arr_a[j][i];
+ }
}
support_l = 0;
for (; j < 4; j++)
{
- for (int i=0; i < placed_l_arr_a[j].size(); i++)
- {
- if (support_l)
- placed_l_arr_a[j][i]->add_support (support_l);
- support_l = placed_l_arr_a[j][i];
- }
+ for (int i=0; i < placed_l_arr_a[j].size(); i++)
+ {
+ if (support_l)
+ placed_l_arr_a[j][i]->add_support (support_l);
+ support_l = placed_l_arr_a[j][i];
+ }
}
}
{
if (o->item())
{
- script_l_arr_.substitute ((Script*)o->item(),(Script*) (n?n->item ():0));
- support_l_arr_.substitute (o->item(), (n?n->item ():0));
+ script_l_arr_.substitute ((Script*)o->item(),(Script*) (n?n->item ():0));
+ support_l_arr_.substitute (o->item(), (n?n->item ():0));
}
}
Script_engraver::do_try_request (Request *r_l)
{
if (!r_l->musical() || ! r_l->musical ()->musicalscript ())
- return false ;
+ return false ;
for (int i=0; i < script_req_l_arr_.size(); i++)
{
- if ( r_l->equal_b (script_req_l_arr_[i]))
- return true;
+ if (r_l->equal_b (script_req_l_arr_[i]))
+ return true;
}
script_req_l_arr_.push (r_l->script());
{
for (int i=0; i < script_req_l_arr_.size(); i++)
{
- Script_req* l=script_req_l_arr_[i];
- Script *p =new Script;
- p->dir_i_ = l->dir_i_;
- p->specs_l_ = l->scriptdef_p_;
- script_p_arr_.push (p);
- announce_element (Score_elem_info (p, l));
+ Script_req* l=script_req_l_arr_[i];
+ Script *p =new Script;
+ p->dir_ = l->dir_;
+ p->specs_l_ = l->scriptdef_p_;
+ script_p_arr_.push (p);
+ announce_element (Score_elem_info (p, l));
}
}
Staff_symbol* s_l = get_staff_info().staff_sym_l_;
for (int i=0; i < script_p_arr_.size(); i++)
{
- Script*script_p = script_p_arr_[i];
- script_p->set_staffsym (s_l);
- typeset_element (script_p);
+ Script*script_p = script_p_arr_[i];
+ script_p->set_staffsym (s_l);
+ typeset_element (script_p);
}
script_p_arr_.clear();
}