]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.38
authorfred <fred>
Sun, 24 Mar 2002 19:33:56 +0000 (19:33 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:33:56 +0000 (19:33 +0000)
90 files changed:
hdr/bar.hh
hdr/beam.hh
hdr/clef-item.hh [new file with mode: 0644]
hdr/complex-staff.hh [new file with mode: 0644]
hdr/complex-walker.hh [new file with mode: 0644]
hdr/directional-spanner.hh [new file with mode: 0644]
hdr/grouping.hh
hdr/input-file.hh [new file with mode: 0644]
hdr/input-music.hh [new file with mode: 0644]
hdr/input-staff.hh [new file with mode: 0644]
hdr/item.hh
hdr/key-item.hh [new file with mode: 0644]
hdr/local-key-item.hh [new file with mode: 0644]
hdr/lyric-item.hh [new file with mode: 0644]
hdr/lyricwalker.hh
hdr/meter.hh
hdr/midi-def.hh [new file with mode: 0644]
hdr/midi-item.hh [new file with mode: 0644]
hdr/midi-output.hh [new file with mode: 0644]
hdr/midi-stream.hh [new file with mode: 0644]
hdr/midi-walker.hh [new file with mode: 0644]
hdr/rest.hh
hdr/score-column.hh [new file with mode: 0644]
hdr/score-walker.hh [new file with mode: 0644]
hdr/script-def.hh [new file with mode: 0644]
hdr/script.hh
hdr/slur.hh
hdr/source-file.hh [new file with mode: 0644]
hdr/spanner.hh
hdr/staff-column.hh [new file with mode: 0644]
hdr/staff-elem-info.hh [new file with mode: 0644]
hdr/staff-walker.hh [new file with mode: 0644]
hdr/staffsym.hh
hdr/stem.hh
hdr/tex-stream.hh [new file with mode: 0644]
hdr/textitem.hh
hdr/textspanner.hh
hdr/time-description.hh [new file with mode: 0644]
hdr/voice-element.hh [new file with mode: 0644]
src/bar-reg.cc [new file with mode: 0644]
src/binary-source-file.cc
src/complex-staff.cc [new file with mode: 0644]
src/complex-walker.cc [new file with mode: 0644]
src/directional-spanner.cc [new file with mode: 0644]
src/duration.cc
src/grouping.cc
src/input-file.cc [new file with mode: 0644]
src/input-music.cc [new file with mode: 0644]
src/input-staff.cc [new file with mode: 0644]
src/item.cc
src/key-reg.cc [new file with mode: 0644]
src/lexerinit.cc
src/lily-stream.cc
src/lyricstaff.cc
src/lyricwalker.cc
src/main.cc
src/meter-reg.cc [new file with mode: 0644]
src/midi-def.cc [new file with mode: 0644]
src/midi-event.cc
src/midi-item.cc [new file with mode: 0644]
src/midi-main.cc
src/midi-output.cc [new file with mode: 0644]
src/midi-score.cc
src/midi-stream.cc [new file with mode: 0644]
src/midi-template.cc
src/midi-track.cc
src/midi-walker.cc [new file with mode: 0644]
src/my-midi-lexer.cc
src/my-midi-parser.cc
src/note.cc
src/request.cc
src/score-column.cc [new file with mode: 0644]
src/score-walker.cc [new file with mode: 0644]
src/script-reg.cc [new file with mode: 0644]
src/slur-reg.cc [new file with mode: 0644]
src/source-file.cc [new file with mode: 0644]
src/source.cc
src/spanner.cc
src/staff-column.cc [new file with mode: 0644]
src/staff-elem-info.cc [new file with mode: 0644]
src/staff-walker.cc [new file with mode: 0644]
src/stem-beam-reg.cc [new file with mode: 0644]
src/template2.cc
src/template3.cc
src/template6.cc
src/tex-stream.cc [new file with mode: 0644]
src/tex.cc
src/text-reg.cc [new file with mode: 0644]
src/time-description.cc [new file with mode: 0644]
src/warn.cc

index e83a7681c6654b6dc15ec7322077b1f728b87699..3727358d96f3c2659e537a467dcfba1a65f0c23f 100644 (file)
@@ -12,7 +12,7 @@ struct Bar: Item {
     String type;
     
     Bar(String type);
-    const char * name() const;
+NAME_MEMBERS(Bar);
     void do_print() const;
     Molecule*brew_molecule_p()const;
 };
index eb8020c53ade4b5e4453b29c59d8504f48ae73f1..8eb2f148b557b2af4a50357362d6f473aa1ea9b8 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef BEAM_HH
 #define BEAM_HH
 #include "proto.hh"
-#include "directionalspanner.hh"
+#include "directional-spanner.hh"
 #include "plist.hh"
 
 /** a beam connects multiple stems Beam adjusts the stems its owns to
@@ -23,7 +23,7 @@ struct Beam:  public Directional_spanner {
    
 
     /* *************** */
-    const char * name() const;
+NAME_MEMBERS(Beam);
     
     virtual Interval width()const;    
     Offset center() const;
diff --git a/hdr/clef-item.hh b/hdr/clef-item.hh
new file mode 100644 (file)
index 0000000..341204f
--- /dev/null
@@ -0,0 +1,31 @@
+
+/*
+  clef-item.hh -- declare Clef_item
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef CLEFITEM_HH
+#define CLEFITEM_HH
+#include "item.hh"
+
+
+struct Clef_item : Item {
+    String type;
+    int y_off;
+
+    /// is this a change clef (smaller size)?
+    bool change;
+
+
+    /* *************** */
+NAME_MEMBERS(Clef_item);
+    Clef_item();
+    void read(Clef_register const&);
+    void read(String);
+    Molecule* brew_molecule_p()const;
+};
+
+#endif // CLEFITEM_HH
+
+
diff --git a/hdr/complex-staff.hh b/hdr/complex-staff.hh
new file mode 100644 (file)
index 0000000..0a37e3a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+  complex-staff.hh -- declare Complex_staff
+
+  (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef COMPLEXSTAF_HH
+#define COMPLEXSTAF_HH
+
+
+#include "key.hh"
+#include "staff.hh"
+#include "staff-walker.hh"
+
+/// 
+struct Complex_staff : Staff {
+
+    /* *************** */
+
+    virtual void set_output(PScore *);
+    virtual Staff_walker *get_walker_p();
+};
+
+#endif // COMPLEXSTAF_HH
+
diff --git a/hdr/complex-walker.hh b/hdr/complex-walker.hh
new file mode 100644 (file)
index 0000000..861cee7
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+  complex-walker.hh -- declare Complex_walker
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef COMPLEXWALKER_HH
+#define COMPLEXWALKER_HH
+
+#include "proto.hh"
+#include "staff-walker.hh"
+#include "staff-elem-info.hh"
+
+/**
+  A staff walker which uses registers to decide what to print
+ */
+class Complex_walker: public Staff_walker {
+    bool try_command_request(Command_req *req_l);
+    void do_announces();
+    void try_request(Request*req);    
+
+
+    
+public:
+    int c0_position_i_;    
+    Walker_registers *walk_regs_p_;
+    
+    /* *************** */
+
+    void regs_process_requests();
+    void typeset_element(Staff_elem *elem_p);
+    void announce_element(Staff_elem_info);
+    virtual void process_requests();
+    virtual void do_post_move();
+    virtual void do_pre_move();
+
+    Complex_walker(Complex_staff*);
+    ~Complex_walker();
+
+    Complex_staff *staff();
+private:
+};
+
+
+#endif // COMPLEXWALKER_HH
+
+
diff --git a/hdr/directional-spanner.hh b/hdr/directional-spanner.hh
new file mode 100644 (file)
index 0000000..9399b71
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+  directional-spanner.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef DIRECTIONALSPANNER_HH
+#define DIRECTIONALSPANNER_HH
+
+#include "spanner.hh"
+
+/// a spanner which can be pointing "up" or "down"
+struct Directional_spanner : Spanner{
+    
+    /// -1 below heads, +1 above heads.
+    int dir_i_;
+
+    /// offset of "center" relative to left-column/0-pos of staff
+    virtual Offset center() const=0;
+    virtual void set_default_dir()=0;
+    Directional_spanner();
+    
+};
+
+#endif // DIRECTIONALSPANNER_HH
+
index 72d2960f827beb03364c3b5c212efe3f08137a67..06b4421b0a6a22462f3256d086682550db09622e 100644 (file)
@@ -44,8 +44,10 @@ struct Rhythmic_grouping {
 
     Array<int> generate_beams(Array<int>, int&);
 
-    /// multiply self to span #i#
-    void extend(MInterval i);
+    /** multiply self to span #i#.
+      In implementation, this isn't really const, but conceptually it is.
+      */
+    void extend(MInterval i) const;
     void translate(Moment);
 private:
     void init();
diff --git a/hdr/input-file.hh b/hdr/input-file.hh
new file mode 100644 (file)
index 0000000..a01ea75
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+  input-file.hh -- declare Input_file
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#ifndef INPUT_FILE_HH
+#define INPUT_FILE_HH
+#include <FlexLexer.h>
+#include "proto.hh"
+#include "fproto.hh"
+#include "varray.hh"
+#include "string.hh"
+
+struct Input_file {
+       istream* is;
+       char const* defined_ch_c_l_;
+       Source_file* sourcefile_l_;
+       int line;
+       String name;
+
+       Input_file(String);
+       ~Input_file();
+};
+
+#endif // INPUT_FILE_HH
diff --git a/hdr/input-music.hh b/hdr/input-music.hh
new file mode 100644 (file)
index 0000000..1d7a8ca
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+  input-music.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef INPUTMUSIC_HH
+#define INPUTMUSIC_HH
+
+#include "plist.hh"
+#include "proto.hh"
+#include "voice.hh"
+#include "moment.hh"
+
+struct Voice_list : public PointerList<Voice*> {
+    void translate_time(Moment dt);
+};
+
+/**
+
+  A set voices.
+  Input_music is anything that can simply be regarded as/converted to
+  a set of voices "cooperating" or independant. It has some basic
+  characteristics that real music has too:
+
+  - it is rhythmic (it has a length, and can be translated horizontally)
+  - a pitch (it can be transposed)
+
+  */
+struct Input_music {
+    virtual Voice_list convert()const=0;
+    void check_plet(Voice_element* velt_l);
+    virtual Moment length()const=0;
+    virtual void translate_time(Moment dt)=0;
+    virtual ~Input_music(){}
+    virtual void print() const =0;
+    virtual void set_default_group(String)=0;
+    virtual bool find_plet_start_bo(char c, Moment& moment_r) = 0;
+    virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i) = 0;
+    // virtual void transpose(...) const =0;
+    
+    
+    virtual Input_music *clone() const = 0;
+    virtual Simple_music *simple() { return 0; }
+};
+
+/// Simple music consists of one voice
+struct Simple_music : Input_music {
+    Voice voice_;
+
+    /* *** */
+    virtual Simple_music*simple() { return this; }  
+    void add(Voice_element*);
+    virtual void set_default_group(String g) { voice_.set_default_group(g); }
+    virtual Moment length()const;
+    virtual Voice_list convert()const;
+    virtual void translate_time(Moment dt);
+    virtual void print() const;
+    virtual bool find_plet_start_bo(char c, Moment& moment_r);
+    virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+    virtual Input_music *clone() const {
+       return new Simple_music(*this);
+    }
+
+};
+
+/// Complex_music consists of multiple voices
+struct Complex_music : Input_music {
+    IPointerList<Input_music*> elts;
+    /* *************** */
+    virtual void set_default_group(String g);
+    void add(Input_music*);
+    Complex_music();
+    Complex_music(Complex_music const &);
+    virtual void print() const ;
+    void concatenate(Complex_music*);
+    virtual bool find_plet_start_bo(char c, Moment& moment_r);
+    virtual void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+};
+
+
+/**
+  A voice like list of music.
+
+  different music forms which start after each other ( concatenated,
+  stacked "horizontally )
+ */
+
+struct Music_voice : Complex_music {
+    
+    /* *************** */
+    Moment length()const;
+    virtual void translate_time(Moment dt);
+    virtual Voice_list convert()const;
+    void add_elt(Voice_element*);
+    virtual Input_music *clone() const {
+       return new Music_voice(*this);
+    }
+    virtual void print() const ;
+};
+
+/**
+  Multiple musicstuff stacked on top of each other
+  chord like :
+
+  - different music forms which start at the same time ( stacked "vertically" )
+  
+  */
+struct Music_general_chord : Complex_music {
+
+
+    /* *************** */
+
+    virtual Moment length()const;
+    virtual Voice_list convert()const;
+    virtual void translate_time(Moment dt);
+    void add_elt(Voice_element*);
+    virtual Input_music *clone() const {
+       return new Music_general_chord(*this);
+    }
+    
+    virtual void print() const ;
+};
+
+struct Multi_voice_chord : Music_general_chord {
+    void set_default_group(String);
+    virtual Input_music *clone() const {
+       return new Multi_voice_chord(*this);
+    }
+};
+struct Voice_group_chord : Music_general_chord {
+
+    virtual Input_music *clone() const {
+       return new Voice_group_chord(*this);
+    }
+};
+#endif // INPUTMUSIC_HH
diff --git a/hdr/input-staff.hh b/hdr/input-staff.hh
new file mode 100644 (file)
index 0000000..3b874a1
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  input-staff.hh -- declare Input_staff
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef INPUTSTAFF_HH
+#define INPUTSTAFF_HH
+
+#include "string.hh"
+#include "plist.hh"
+#include "varray.hh"
+#include "proto.hh"
+
+struct Input_staff {
+    
+    const char * defined_ch_c_l_;
+    String type;
+    
+    IPointerList<Input_music*> music_;
+    Input_music * score_wide_music_p_;
+    
+    /* *************** */
+    ~Input_staff();
+    void add(Input_music*m);
+    Input_staff(Input_staff const&);
+    Input_staff(String);
+    void set_score_wide(Input_music*m);
+    Staff* parse(Score*, Input_music *score_wide);
+    void print() const;
+};
+
+
+#endif // INPUTSTAFF_HH
+
index a5a9442dc971439c76fc1099433aa18e37fc2c2c..d1fc8c8bfa7985288772b7f201d54e894ac42b43 100644 (file)
@@ -4,7 +4,7 @@
 #include "glob.hh"
 #include "boxes.hh"
 #include "string.hh"
-#include "staffelem.hh"
+#include "staff-elem.hh"
 
 /**
  a horizontally fixed size element of the score
@@ -24,7 +24,8 @@ struct Item : Staff_elem {
     virtual Item *item() { return this; }
     Item();
     void do_print()const;
-    const char*name()const;
+
+    NAME_MEMBERS(Item);
 };
 
 
diff --git a/hdr/key-item.hh b/hdr/key-item.hh
new file mode 100644 (file)
index 0000000..e56af8e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+  key-item.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef KEYITEM_HH
+#define KEYITEM_HH
+
+#include "item.hh"
+#include "varray.hh"
+
+
+/// An item which places accidentals at the start of the line
+struct Key_item : Item {
+    Array<int> pitch;
+    Array<int> acc;
+    int c_position;
+
+    
+    /* *************** */
+NAME_MEMBERS(Key_item);
+    Key_item(int cposition);
+    void add(int pitch, int acc);
+    void read(const Key_register&);
+    void set_c_position(int);
+    void preprocess();
+    Molecule* brew_molecule_p()const;
+};
+
+#endif // KEYITEM_HH
diff --git a/hdr/local-key-item.hh b/hdr/local-key-item.hh
new file mode 100644 (file)
index 0000000..96bad99
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+  local-key-item.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef LOCALKEYITEM_HH
+#define LOCALKEYITEM_HH
+#include "item.hh"
+#include "varray.hh"
+
+struct Local_acc {
+    int name , acc, octave;
+    static int compare(Local_acc&, Local_acc&);
+};
+
+struct Local_key_item : Item {
+NAME_MEMBERS(Local_key_item);
+    Array<Local_acc> accs;
+    Array<Item*> support_items_;
+    int c0_position;
+
+    /* *************** */
+    
+    Local_key_item(int c0position);
+    void add(Item*);
+    void add(int oct, int pitch, int acc);
+    void add(Melodic_req*);
+    void do_pre_processing();    
+    Molecule* brew_molecule_p()const;
+};
+#endif // LOCALKEYITEM_HH
+
diff --git a/hdr/lyric-item.hh b/hdr/lyric-item.hh
new file mode 100644 (file)
index 0000000..dfbaf98
--- /dev/null
@@ -0,0 +1,19 @@
+//
+//  lyric-item.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef LYRIC_ITEM_HH
+#define LYRIC_ITEM_HH
+
+#include "textitem.hh"
+  
+struct Lyric_item : Text_item {
+    /* *************** */
+    Lyric_item(Lyric_req* lreq_l, int voice_count_i);
+    virtual void do_pre_processing();    
+};
+
+
+#endif // LYRIC_ITEM_HH //
+
index 40ef06d97291cb9e20b023ee6c51e38adfea511e..1a8052388323c48fa6fbd6917ab9df91a626d5f4 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "proto.hh"
 #include "grouping.hh"
-#include "staffwalker.hh"
+#include "staff-walker.hh"
 
 /// a simple walker which collects words, and then print them, first on top
 struct Lyric_walker: Staff_walker {
index 7de58e7c64748eafd1df71d03371f82c0af9c840..928434b28a16bc56fe99cd763cc215dc2de9dadf 100644 (file)
@@ -13,7 +13,7 @@
 struct Meter: Item {
     Array<Scalar> args;
     /* *************** */
-    const char * name() const;
+NAME_MEMBERS(Meter);
     
     Meter(Array<Scalar> args) ;
     Molecule*brew_molecule_p() const;
diff --git a/hdr/midi-def.hh b/hdr/midi-def.hh
new file mode 100644 (file)
index 0000000..7a559ad
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+  midi-def.hh -- declare 
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
+
+#ifndef MIDIDEF_HH
+#define MIDIDEF_HH
+#include "proto.hh"
+#include "real.hh"
+#include "string.hh"
+#include "moment.hh"
+
+
+/** 
+ */
+struct Midi_def {
+    /// output file name
+    String outfile_str_;
+
+    /// duration of whole note
+    Real whole_seconds_f_;
+
+    Midi_def();
+    Midi_def(Midi_def const& midi_c_r);
+    ~Midi_def();
+
+    Real duration_to_seconds_f(Moment);
+    int get_tempo_i( Moment moment );
+    void set_tempo( Moment moment, int count_per_minute_i );
+    void print() const;
+};
+
+#endif // MIDIDEF_HH //
+
diff --git a/hdr/midi-item.hh b/hdr/midi-item.hh
new file mode 100644 (file)
index 0000000..6688e95
--- /dev/null
@@ -0,0 +1,85 @@
+//
+//  midi-item.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef MIDI_ITEM_HH
+#define MIDI_ITEM_HH
+#include "string.hh"
+#include "proto.hh"
+
+struct Midi_item {
+    /* *************** */
+    static String i2varint_str( int i );
+    virtual void output_midi( Midi_stream& midi_stream_r );
+    virtual String str() = 0;
+};
+
+struct Midi_note : public Midi_item {
+    /* *************** */
+    int const c0_pitch_i_c_ = 60;
+    Byte dynamic_byte_;
+
+    /**
+      Generate a note-event on a channel pitch.
+
+      @param #melreq_l# is the pitch. 
+     */
+    Midi_note( Melodic_req* melreq_l, int channel_i, bool on_b );
+
+    virtual String str();
+
+    int channel_i_;
+    int on_b_;
+    int pitch_i_;
+};
+
+struct Midi_duration : public Midi_item {
+    /* *************** */
+    Midi_duration( Real seconds_f );
+
+    virtual String str();
+
+    Real seconds_f_;
+};
+
+struct Midi_chunk : Midi_item {
+    /* *************** */
+    Midi_chunk();
+
+    void add( String str );
+    void set( String header_str, String data_str, String footer_str );
+    virtual String str();
+
+private:
+    String data_str_;
+    String footer_str_;
+    String header_str_;
+};
+
+struct Midi_header : Midi_chunk {
+    /* *************** */
+    Midi_header( int format_i, int tracks_i, int clocks_per_4_i );
+};
+
+struct Midi_tempo : Midi_item {
+    /* *************** */
+    Midi_tempo( int tempo_i );
+
+    virtual String str();
+
+    int tempo_i_;
+};
+
+struct Midi_track : Midi_chunk {
+    /* *************** */
+    int number_i_;
+    Midi_track( int number_i );
+
+    void add( int delta_time_i, String event );
+//     void add( Moment delta_time_moment, Midi_item& mitem_r );
+    void add( Moment delta_time_moment, Midi_item* mitem_l );
+};
+
+#endif // MIDI_ITEM_HH //
+
diff --git a/hdr/midi-output.hh b/hdr/midi-output.hh
new file mode 100644 (file)
index 0000000..a590f5a
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+  midi-output.hh -- declare Midi_output
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef MIDIOUTPUT_HH
+#define MIDIOUTPUT_HH
+#include "pscore.hh"
+
+struct Midi_output {
+    Midi_stream*    midi_stream_l_;
+    Midi_output(Score* score_l, Midi_def* );
+    void do_staff(Staff*st_l, int count);
+
+    Midi_def* midi_l_;
+};
+#endif // MIDIOUTPUT_HH
diff --git a/hdr/midi-stream.hh b/hdr/midi-stream.hh
new file mode 100644 (file)
index 0000000..6946bfd
--- /dev/null
@@ -0,0 +1,32 @@
+//
+//  midi-stream.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef MIDI_STREAM_HH
+#define MIDI_STREAM_HH
+
+#include <iostream.h>
+#include "string.hh"
+
+/// Midi output
+struct Midi_stream {
+    ostream* os_p_;
+    String filename_str_;
+    int clocks_per_4_i_;
+    int tracks_i_;
+    
+    Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i_ );
+    ~Midi_stream();
+
+    Midi_stream& operator <<( String str );
+    Midi_stream& operator <<( Midi_item& mitem_r );
+    Midi_stream& operator <<( int i );
+
+    void header();
+    void open();
+
+//private:
+//    Midi_stream(Midi_stream const&);
+};
+#endif // MIDI_STREAM_HH //
diff --git a/hdr/midi-walker.hh b/hdr/midi-walker.hh
new file mode 100644 (file)
index 0000000..e7c2638
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+  midi-walker.hh -- declare Midi_walker
+
+  (c) 1996,97 Han-Wen Nienhuys, Jan Nieuwenhuizen <jan@digicash.com>
+  */
+
+#ifndef MIDIWALKER_HH
+#define MIDIWALKER_HH
+
+#include "proto.hh"
+#include "grouping.hh"
+#include "staff-walker.hh"
+#include "pcursor.hh"
+#include "pqueue.hh"
+
+
+/**
+  a simple walker which collects midi stuff, and then outputs.
+
+  Should derive from Staff_walker
+  */
+class Midi_walker : public PCursor<Staff_column*> {
+    Midi_track *track_l_;
+    PQueue<Melodic_req*, Moment> stop_notes;
+    Moment last_moment_;
+
+    /* *************** */
+    void do_stop_notes(Moment);
+    
+    void output_event(Midi_item&, Moment);
+public:
+    
+    Midi_walker(Staff*, Midi_track*);
+    void process_requests();
+    ~Midi_walker();
+};
+
+
+#endif // MIDIWALKER_HH
+
+
index d03bd0c96f800657721f890a6066000c51bc8f19..85c72666772e62cd55c3a17414ca4ed16986add1 100644 (file)
@@ -18,7 +18,7 @@ struct Rest : Item {
 
     Rest(int dur,int dots);
     void do_print()const;
-    const char * name() const;
+NAME_MEMBERS(Rest);
     Molecule* brew_molecule_p()const;
 };
 #endif 
diff --git a/hdr/score-column.hh b/hdr/score-column.hh
new file mode 100644 (file)
index 0000000..e961d04
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+  sccol.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SCCOL_HH
+#define SCCOL_HH
+#include "proto.hh"
+#include "varray.hh"
+#include "moment.hh"
+
+
+/**
+
+    When typesetting hasn't started on PScore yet, the columns which
+    contain data have a rhythmical position. Score_column is the type
+    with a rhythmical time attached to it. The calculation of
+    idealspacing is done with data in these columns. (notably: the
+    #durations# field)
+
+    */
+
+class Score_column {
+    friend class Score;
+    friend class Score_walker;
+
+    bool musical_b_;
+    Moment when_;
+    void set_breakable();
+public:
+    /// indirection to column
+    PCol * pcol_l_;
+
+    /// length of notes/rests in this column
+    Array<Moment> durations;
+    
+    /* *************** */
+
+    Moment when() {  return when_; }
+    Score_column(Moment when);       
+    static int compare(Score_column & c1, Score_column &c2);
+    void add_duration(Moment );
+    void preprocess();
+    bool breakable_b();
+    bool musical_b() { return musical_b_; }
+    bool used_b();
+    void print() const;
+
+
+};
+
+instantiate_compare(Score_column&, Score_column::compare);
+
+#endif // SCCOL_HH
+
+
+
+
diff --git a/hdr/score-walker.hh b/hdr/score-walker.hh
new file mode 100644 (file)
index 0000000..b3d3042
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+  score-walker.hh -- declare Score_walker
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef SCOREWALKER_HH
+#define SCOREWALKER_HH
+#include "pcursor.hh"
+#include "proto.hh"
+#include "varray.hh"
+
+
+/**
+  walk through the score_columns, and while doing so, walk all staffs in a score.
+  */
+class Score_walker : public PCursor<Score_column *>
+{
+    Score* score_l_;
+    /// walkers for the individual staves.
+    Array<Staff_walker *> walker_p_arr_;
+    Array<Staff_walker *> disallow_break_walk_l_arr;
+    int disallow_break_count_;
+    void reinit();
+public:
+    void allow_break(Staff_walker*w);
+    Score_walker(Score*);
+    ~Score_walker();
+    Moment when();
+    void operator++(int);
+    /// process staff walkers. 
+    void process();
+};
+#endif // SCOREWALKER_HH
diff --git a/hdr/script-def.hh b/hdr/script-def.hh
new file mode 100644 (file)
index 0000000..8b5be32
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+  script-def.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef SCRIPTDEF_HH
+#define SCRIPTDEF_HH
+#include "string.hh"
+struct Script_def{
+    int stemdir;
+    int staffdir;
+
+    bool invertsym;
+    String symidx;
+
+    /* *************** */
+    int compare(Script_def const &);
+    void print() const;
+    Script_def(String, int, int ,bool);
+};
+
+
+#endif // SCRIPTDEF_HH
+
index 7c089e3a5426475b286df86a655b49c1418cfc1e..df408f04354b54c9b0550792a8882da0419f5b0b 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef SCRIPT_HH
 #define SCRIPT_HH
 
-#include "scriptdef.hh"
+#include "script-def.hh"
 #include "item.hh"
   
 struct Script : Item {
@@ -20,8 +20,8 @@ struct Script : Item {
     Array<Item *> support;
 
     /* *************** */
-    const char * name() const;    
-    Molecule*  brew_molecule_p()const;
+    NAME_MEMBERS(Script);
+    Molecule *brew_molecule_p()const;
     virtual void do_post_processing();
     virtual void do_pre_processing();
     Script(Script_req*, int staffsize);
@@ -30,9 +30,9 @@ struct Script : Item {
     Interval support_height()const;
     virtual Interval width() const;
 private:
-    void       set_symdir();
-    void       set_default_dir();
-    void       set_default_index();
+    void set_symdir();
+    void set_default_dir();
+    void set_default_index();
     Symbol symbol()const;
 };
 
index c3e6a93c7619701a678908b7179dd5b5cbe39eff..87f1fe855ea71bd7fc623a4dd818e8bae80fb26c 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef SLUR_HH
 #define SLUR_HH
 
-#include "directionalspanner.hh"
+#include "directional-spanner.hh"
 #include "fproto.hh"
 #include "varray.hh"
 
@@ -29,7 +29,7 @@ struct Slur : Directional_spanner {
     void process();
 private:
     Molecule*brew_molecule_p()const;
-    const char * name() const;
+    NAME_MEMBERS(Slur);
 };
 
 #endif // SLUR_HH
diff --git a/hdr/source-file.hh b/hdr/source-file.hh
new file mode 100644 (file)
index 0000000..7f7168e
--- /dev/null
@@ -0,0 +1,40 @@
+//
+//  source-file.hh -- declare Source_file
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef SOURCE_FILE_HH
+#define SOURCE_FILE_HH
+
+/// class for reading and mapping a file. 
+class Source_file
+{
+public:
+    /** Ugh! filename gets changed! The path to the opened file may
+       change, since it might be searched in multiple directories.  */
+    Source_file( String& filename_str_r );
+    virtual ~Source_file();
+
+    char const* ch_c_l();
+    virtual String error_str( char const* pos_ch_c_l );
+    istream* istream_l();
+    bool in_b( char const* pos_ch_c_l );
+    off_t length_off();
+    virtual int line_i( char const* pos_ch_c_l );
+    String name_str();
+    String file_line_no_str( char const* ch_c_l );
+
+private:
+    void close();
+    void map();
+    void open();
+    void unmap();
+
+    istream* istream_p_;
+    int fildes_i_;
+    String name_str_;
+    off_t size_off_;
+    caddr_t data_caddr_;
+};
+
+#endif // SOURCE_FILE_HH //
index 878d48d6e02b35ef4e2cf66d86077048796aa137..43a3567fa52faf609869d1d3b9bc7aa3117fa391 100644 (file)
@@ -8,7 +8,7 @@
 #define SPANNER_HH
 
 #include "proto.hh"
-#include "staffelem.hh"
+#include "staff-elem.hh"
 
 
 /** a symbol which is attached between two columns. A spanner is a symbol which spans across several columns, so its
@@ -38,7 +38,7 @@ struct Spanner:Staff_elem {
     Spanner();
     virtual Interval width()const;
     void do_print()const;
-    const char* name()const;
+
     Spanner *broken_at(PCol *c1,  PCol *c2) const;
     virtual Spanner* spanner() { return this; }
 protected:
@@ -48,6 +48,7 @@ protected:
     PRE
     c1 >= start, c2  <= stop
     */
-    virtual Spanner *do_break_at( PCol *c1,  PCol *c2) const=0; 
+    virtual Spanner *do_break_at( PCol *c1,  PCol *c2) const=0;
+    NAME_MEMBERS(Spanner);
 };
 #endif
diff --git a/hdr/staff-column.hh b/hdr/staff-column.hh
new file mode 100644 (file)
index 0000000..dd6303e
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  staff-column.hh -- declare Staff_column
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFCOLUMN_HH
+#define STAFFCOLUMN_HH
+#include "proto.hh"
+#include "varray.hh"
+#include "moment.hh"
+
+/// store simultaneous requests
+class Staff_column {
+
+    Staff_column(Staff_column const&);
+
+public:
+    Array<Request*> creationreq_l_arr_;
+    Array<Request*> musicalreq_l_arr_;
+    Array<Request*> commandreq_l_arr_;
+    Staff * staff_l_;
+
+    /// fields to collect timing data vertically.
+    Array<Timing_req*> timing_req_l_arr_;
+    Score_column *musical_column_l_, *command_column_l_;
+
+    /* *************** */
+    
+    Staff_column();
+
+    Moment when() const;
+    void set_cols(Score_column *c1, Score_column *c2);
+    void add(Voice_element*ve);
+    void OK() const;
+    ~Staff_column();
+    void typeset_breakable_items(Array<Item *> &pre_p_arr,
+                                Array<Item *> &nobreak_p_arr,
+                                Array<Item *> &post_p_arr);
+    void typeset_musical_item(Item *i);
+protected:
+     void setup_one_request(Request*);
+};
+
+
+
+#endif // STAFFCOLUMN_HH
+
diff --git a/hdr/staff-elem-info.hh b/hdr/staff-elem-info.hh
new file mode 100644 (file)
index 0000000..9c6264a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+  staff-elem-info.hh -- declare Staff_elem_info
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef STAFFELEMINFO_HH
+#define STAFFELEMINFO_HH
+
+#include "proto.hh"
+#include "varray.hh"
+/// data container.
+struct Staff_elem_info {
+    Staff_elem * elem_p_;
+    Request*req_l_;
+    const Voice * voice_l_;
+    Array<Request_register*> origin_reg_l_arr_;
+
+
+    /* *** */
+    Staff_elem_info(Staff_elem*, Request*);
+    Staff_elem_info();
+};
+
+struct Staff_info {
+    int *c0_position_i_;
+    Staff_walker *walk_l_;
+    const Time_description *time_c_l_;
+    const Rhythmic_grouping *rhythmic_c_l_;
+};
+
+
+struct Features {
+    bool initialiser_b_;
+    int direction_i_;
+    
+    Features();
+    static Features dir(int);
+};
+#endif // STAFFELEMINFO_HH
diff --git a/hdr/staff-walker.hh b/hdr/staff-walker.hh
new file mode 100644 (file)
index 0000000..fb0d098
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+  staff-walker.hh -- declare Staff_walker
+  
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef STAFFWALKER_HH
+#define STAFFWALKER_HH
+
+#include "proto.hh"
+#include "time-description.hh"
+#include "pcursor.hh"
+
+/**
+  manage run-time info when walking staffcolumns such as: key,
+  meter, pending beams & slurs
+  */
+struct Staff_walker : public PCursor<Staff_column*> {
+    Staff * staff_l_;
+    PScore * pscore_l_;
+    Score_walker *score_walk_l_;
+    Time_description time_;
+    Rhythmic_grouping *default_grouping;
+    
+    /* *************** */
+
+    Moment when() const;    
+    virtual ~Staff_walker();
+    Staff_walker(Staff*, PScore*);
+    void process() ;
+
+    void operator++(int);
+    void allow_break();
+
+protected:
+    /// every time before ++ is called
+    virtual void do_pre_move(){}
+    /// every time after ++ is called
+    virtual void do_post_move(){}
+    virtual void process_requests()=0;
+private:
+    void process_timing_reqs();
+    Staff_walker(Staff_walker const&);
+};
+
+#endif // STAFFWALKER_HH
+
index 294a0218a0c678d34eb186e1e2ebbdd2abfefa50..bcec2bfaff803f148b48fb1e6ac6ba8e16debd39 100644 (file)
@@ -20,7 +20,7 @@ public:
     /// this many lines.
     int no_lines_i_;
 
-    const char *name()const;
+    NAME_MEMBERS(Staff_symbol);
     Staff_symbol(int lines);
     virtual Molecule* brew_molecule_p() const;
     void set_extent(PCol* p1, PCol* p2);
index 2aafd66074c0ba1db2f5de7faa5eccd3b81d4c0f..34776ea49cec6b45965221871b18e516d3d28f0a 100644 (file)
@@ -61,7 +61,8 @@ struct Stem : Item {
     
     /// ensure that this Stem also encompasses the Notehead #n#
     void add(Notehead*n);
-    const char * name() const;
+
+    NAME_MEMBERS(Stem);
 
     Real hindex()const;
     void do_print() const;
diff --git a/hdr/tex-stream.hh b/hdr/tex-stream.hh
new file mode 100644 (file)
index 0000000..4d5805c
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef TSTREAM__HH
+#define TSTREAM__HH
+
+#include <iostream.h>
+#include "string.hh"
+
+
+/** TeX output.
+  Use this class for writing to a TeX file.
+  It counts braces to prevent nesting errors, and
+  it will add a comment sign before each newline.
+  */
+struct Tex_stream {
+    bool outputting_comment;
+    ostream *os;
+    int nest_level;
+    
+    /// open a file for writing
+    Tex_stream(String filename);
+    void header();
+    /// delegate conversion to string class.
+    Tex_stream &operator<<(String);
+
+    /// close the file
+    ~Tex_stream();
+private:
+    Tex_stream(Tex_stream const&);
+};
+#endif
index 4e0e454941b85fde587ab1fd7a34345196a0dbc5..ae0b55630800943c1f638d8cf14e1b7f066acd5e 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef TEXT_ITEM_HH
 #define TEXT_ITEM_HH
 
-#include "textdef.hh"
+#include "text-def.hh"
 #include "item.hh"
   
 struct Text_item : Item {
@@ -17,7 +17,7 @@ struct Text_item : Item {
     Text_def* tdef_l_;
     
     /* ***************/
-    const char * name() const;    
+    NAME_MEMBERS(Text_item);
     virtual void set_default_index();
     Molecule* brew_molecule_p() const;
     void do_pre_processing();
index 586d25a5d84114ca955d9e8f869e13954c7d6213..dbdea979ad25a1e277bd12643983806adb9472a2 100644 (file)
@@ -8,8 +8,8 @@
 #define TEXTSPANNER_HH
 
 #include "string.hh"
-#include "directionalspanner.hh"
-#include "textdef.hh"
+#include "directional-spanner.hh"
+#include "text-def.hh"
 
 /** a spanner which puts texts on top of other spanners.  Use for
   triplets, eentweetjes, ottava, etc.  */
@@ -20,10 +20,10 @@ struct Text_spanner : Spanner {
 
     /* *************** */
 
-    const char * name() const;
-    virtual    void do_pre_processing();
-    virtual    void do_post_processing();
-    virtual    Interval height() const ;
+    NAME_MEMBERS(Text_spanner);
+    virtual void do_pre_processing();
+    virtual void do_post_processing();
+    virtual Interval height() const ;
     virtual Molecule* brew_molecule_p()const;
     virtual void do_print() const;
     virtual Spanner* do_break_at(PCol*,PCol*)const;
diff --git a/hdr/time-description.hh b/hdr/time-description.hh
new file mode 100644 (file)
index 0000000..7e366ec
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+  moment.hh -- part of LilyPond
+
+  (c) 1996,97 Han-Wen Nienhuys
+*/
+
+#ifndef tdes_HH
+#define tdes_HH
+
+#include "moment.hh"
+
+/// full info on where we are
+struct Time_description {
+    Moment when_;
+
+    /// if true, no bars needed, no reduction of whole_in_measure
+    bool cadenza_b_;
+    
+    /// current measure info
+    Moment whole_per_measure_;
+
+    /// where am i 
+    Moment whole_in_measure_;
+
+    /// how long is one beat?
+    Moment one_beat_;
+
+    /// idem
+    int bars_i_;
+
+    /* *************** */
+    void set_cadenza(bool);
+    void OK() const;
+    Time_description();
+    void add(Moment dt);
+    String str()const;
+    void print() const;
+    void setpartial(Moment p);
+    Moment barleft();
+    void set_meter(int,int);
+    static int compare (Time_description&, Time_description&);
+};
+
+#include "compare.hh"
+
+
+instantiate_compare(Time_description&,Time_description::compare);
+
+#endif // Time_description_HH
+
diff --git a/hdr/voice-element.hh b/hdr/voice-element.hh
new file mode 100644 (file)
index 0000000..0c5b6b1
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+  voice-element.hh -- declare Voice_element
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+
+#ifndef VOICE_ELEMENT_HH
+#define VOICE_ELEMENT_HH
+
+#include "proto.hh"
+#include "plist.hh"
+#include "moment.hh"
+
+/** one horizontal bit.  Voice_element is nothing but a container for
+    *the requests, */
+struct Voice_element {
+    Moment duration;
+    char const* defined_ch_c_l_;
+    const Voice *voice_l_;
+    IPointerList<Request*> reqs;
+
+    /* *************** */
+    
+    Voice_element();
+    Voice_element(Voice_element const & src );
+
+    void add(Request*);
+    bool find_plet_start_bo(char c, Moment& moment_r);
+    void print ()const;
+    void set_default_group(String id);
+    void set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i);
+};
+
+#endif // VOICE-ELEMENT_HH
diff --git a/src/bar-reg.cc b/src/bar-reg.cc
new file mode 100644 (file)
index 0000000..b72eca8
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+  bar-reg.cc -- implement Bar_register
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "bar-reg.hh"
+#include "bar.hh"
+#include "commandrequest.hh"
+#include "score-column.hh"
+#include "time-description.hh"
+
+Bar_register::Bar_register()
+{
+    post_move_processing();
+}
+
+bool
+Bar_register::try_request(Request*r_l)
+{
+    Command_req* c_l = r_l->command();
+    if (!c_l|| !c_l->bar()) 
+       return false;
+
+    assert(!bar_req_l_);
+    bar_req_l_ = c_l->bar();
+
+    return true;
+}
+
+void
+Bar_register::process_requests()
+{
+    if (bar_req_l_ ) {
+       bar_p_ = new Bar(bar_req_l_->type_str_);
+    } else if (!get_staff_info().time_c_l_->whole_in_measure_) {
+       bar_p_ = new Bar("|");
+    }
+    
+    if (bar_p_){
+       announce_element(Staff_elem_info(bar_p_, bar_req_l_) );
+    }
+}
+
+void
+Bar_register::split_bar(Bar *& pre, Bar * no, Bar * &post)
+{
+    String s= no->type;
+    if (s == ":|:") {
+       pre = new Bar(":|");
+       post = new Bar("|:");
+    }else if (s=="|:") {
+       post = new Bar(s);
+    } else {
+       pre = new Bar(*no);
+    }
+}
+
+void 
+Bar_register::pre_move_processing()
+{
+      if (bar_p_) {
+         Bar * post_p =0;
+         Bar * pre_p =0;
+         split_bar(pre_p, bar_p_, post_p);
+         
+         typeset_breakable_item(pre_p, bar_p_, post_p);
+         bar_p_ =0;
+      }
+}
+
+void
+Bar_register::post_move_processing()
+{
+    bar_req_l_ = 0;
+    bar_p_ =0;
+}
index 8545f221e9f260c80675df0cea252eafe93ffa4f..39eec37254bc0789298853b8a658ab81fdda4e7e 100644 (file)
@@ -1,6 +1,11 @@
-//
-// binary-source-file.cc
-//
+/*
+  binary-source-file.cc -- implement Binary_source_file
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Jan Nieuwenhuizen
+*/
+
 
 #include <limits.h>            // INT_MAX
 #include <assert.h>
@@ -9,8 +14,9 @@
 #include "plist.hh"
 #include "string.hh"
 #include "debug.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "binary-source-file.hh"
+#include "string-convert.hh"
 
 Binary_source_file::Binary_source_file( String& filename_str )
        : Source_file( filename_str )
diff --git a/src/complex-staff.cc b/src/complex-staff.cc
new file mode 100644 (file)
index 0000000..bb13274
--- /dev/null
@@ -0,0 +1,37 @@
+#include "complex-staff.hh"
+#include "complex-walker.hh"
+#include "score.hh"
+#include "pscore.hh"
+#include "staffsym.hh"
+#include "score-column.hh"
+
+const NO_LINES = 5;
+
+/** Aside from putting fields right, this generates the staff symbol.
+ */
+void
+Complex_staff::set_output(PScore* pscore_l )
+{
+    pstaff_l_ = new PStaff(pscore_l);
+    pscore_l_ = pscore_l;
+    pscore_l_->add(pstaff_l_);
+
+    Staff_symbol *span_p = new Staff_symbol(NO_LINES);
+    
+    Score_column* col_last
+       =score_l_->find_col(score_l_->last(), false);
+    Score_column* col_first=
+       score_l_->find_col(0, false);
+       
+    span_p->set_extent(col_first->pcol_l_->postbreak_p_,
+                      col_last->pcol_l_->prebreak_p_);
+
+    pscore_l_->typeset_spanner(span_p, pstaff_l_);
+}
+
+
+Staff_walker * 
+Complex_staff::get_walker_p()
+{
+    return new Complex_walker(this);
+}
diff --git a/src/complex-walker.cc b/src/complex-walker.cc
new file mode 100644 (file)
index 0000000..9fbd052
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+  complex-walker.cc -- implement Complex_walker
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "staff-column.hh"
+#include "voice.hh"
+#include "pscore.hh"
+#include "complex-staff.hh"
+#include "debug.hh"
+#include "voice-group-regs.hh"
+#include "voice-regs.hh"
+#include "complex-walker.hh"
+//#include "misc.hh"
+#include "commandrequest.hh"
+#include "walkregs.hh"
+
+void
+Complex_walker::do_post_move()
+{
+    walk_regs_p_->post_move_processing();
+}
+
+void
+Complex_walker::do_pre_move()
+{
+    walk_regs_p_->pre_move_processing();
+}
+
+void
+Complex_walker::do_announces()
+{
+    walk_regs_p_->do_announces();
+}
+
+bool
+Complex_walker::try_command_request(Command_req *req_l)
+{
+    return walk_regs_p_->try_request(req_l);
+}
+
+void
+Complex_walker::try_request(Request*req)
+{
+    walk_regs_p_->try_request(req);
+}
+
+void
+Complex_walker::process_requests()
+{
+    Staff_column*c =ptr();
+
+    for (int i=0; i < c->creationreq_l_arr_.size(); i++) {
+       try_request(c->creationreq_l_arr_[i]);
+    }    
+    for (int i=0; i < c->commandreq_l_arr_.size(); i++) {
+       try_request(c->commandreq_l_arr_[i]);
+    }
+
+    for (int i=0; i < c->musicalreq_l_arr_.size(); i++) {
+       try_request(c->musicalreq_l_arr_[i]);
+    }
+
+    regs_process_requests();
+    do_announces();
+}
+
+void
+Complex_walker::regs_process_requests()
+{
+    walk_regs_p_->process_requests();
+}
+
+void
+Complex_walker::typeset_element(Staff_elem *elem_p)
+{
+    if (!elem_p)
+       return;
+    if (elem_p->spanner())
+       pscore_l_->typeset_spanner(elem_p->spanner(), staff()->pstaff_l_);
+    else
+       ptr()->typeset_musical_item(elem_p->item()); 
+}
+
+Complex_walker::Complex_walker(Complex_staff*s)
+    : Staff_walker(s, s->pstaff_l_->pscore_l_)
+{
+    walk_regs_p_ = new Walker_registers(this);    
+    do_post_move();
+}
+
+
+Complex_walker::~Complex_walker()
+{
+}
+
+Complex_staff*
+Complex_walker::staff()
+{
+    return (Complex_staff*) staff_l_;
+}
+
+
+
diff --git a/src/directional-spanner.cc b/src/directional-spanner.cc
new file mode 100644 (file)
index 0000000..7e2bb7c
--- /dev/null
@@ -0,0 +1,6 @@
+#include "directional-spanner.hh"
+
+Directional_spanner::Directional_spanner()
+{
+    dir_i_ = 0;
+}
index 6a251235ea3a6fb066eeeebdca1b4de77e0affcb..a7a1c5dfcf5d74608acfb689beb3e856423ff228 100644 (file)
@@ -8,7 +8,7 @@
 #include "proto.hh"         // ugh, these all for midi-main.hh 
 #include "plist.hh"
 #include "string.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 #include "midi-main.hh"    // *tors
 
index 6c2e6760c800d41e9302da62e9a2775888ef4c57..bc665a19c03a453b309e0c391f008354a8cab16b 100644 (file)
@@ -316,7 +316,7 @@ Rhythmic_grouping::translate(Moment m)
 }
 
 void
-Rhythmic_grouping::extend(MInterval m)
+Rhythmic_grouping::extend(MInterval m)const
 {    
     assert(m.left >= interval().left);
     while (m.right  >interval().right ) {
@@ -325,7 +325,7 @@ Rhythmic_grouping::extend(MInterval m)
            a[i] =new Rhythmic_grouping(*children[i]);
            a[i]->translate(children.top()->interval().right);      
        }
-       children.concat(a);
+       ((Rhythmic_grouping*)this)->children.concat(a);
     }
     assert(m.right <= interval().right);
     OK();
diff --git a/src/input-file.cc b/src/input-file.cc
new file mode 100644 (file)
index 0000000..a0f1018
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+  input-file.cc -- implement Input_file
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl> Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
+#include <iostream.h>
+#include <strstream.h>
+#include "proto.hh"
+#include "plist.hh"
+#include "input-file.hh"
+#include "debug.hh"
+#include "source-file.hh"
+#include "binary-source-file.hh"
+#include "source.hh"
+
+Input_file::Input_file(String s)
+{
+       name = s;
+       line = 1;
+       String pf(s);
+       if ( pf == "" ) {
+               is = &cin;
+               defined_ch_c_l_ = 0;
+               sourcefile_l_ = 0;
+       }
+       else {
+               Source_file* sourcefile_p = 0;
+               // ugh, very dirty, need to go away
+               if ( ( pf.right_str( 3 ).lower_str() == "mid" ) || ( pf.right_str( 4 ).lower_str() == "midi" ) )
+                   sourcefile_p = new Binary_source_file( pf );
+               else
+                   sourcefile_p = new Source_file( pf );
+               source_l_g->add( sourcefile_p );
+               sourcefile_l_ = sourcefile_p;
+               is = sourcefile_l_->istream_l();
+               defined_ch_c_l_ = sourcefile_l_->ch_c_l();
+       }
+       cout << "[" << pf << flush;
+}
+
+Input_file::~Input_file()
+{
+       cout << "]" << flush;  
+}
diff --git a/src/input-music.cc b/src/input-music.cc
new file mode 100644 (file)
index 0000000..f1047e8
--- /dev/null
@@ -0,0 +1,252 @@
+#include "debug.hh"
+#include "input-music.hh"
+#include "voice.hh"
+#include "musicalrequest.hh"
+#include "voice-element.hh"
+
+void
+Input_music::check_plet(Voice_element* velt_l)
+{
+    for (iter_top(velt_l->reqs,i); i.ok(); i++)
+       if ( i->plet() ) {
+           Moment start_moment = 0;
+           if ( !find_plet_start_bo( i->plet()->type_c_, start_moment ) ) {
+               error( "begin of plet not found", i->defined_ch_c_l_ );
+               break;
+           }
+           Moment moment = 0;
+           set_plet_backwards( moment, start_moment, i->plet()->dur_i_, i->plet()->type_i_ );
+           i.del();
+           break;
+        }
+}
+
+void
+Simple_music::add(Voice_element*v)
+{
+    voice_.add(v);
+}
+
+Moment
+Simple_music::length()const
+{
+    return voice_.last();
+}
+void
+Simple_music::translate_time(Moment t)
+{
+    voice_.start += t;
+}
+
+Voice_list
+Simple_music::convert()const
+{
+    Voice_list l;
+    l.bottom().add(new Voice(voice_));
+    return l;
+}
+
+
+void
+Simple_music::print() const
+{
+    mtor << "Simple_music {";
+    voice_.print();
+    mtor << "}\n";
+}
+bool
+Simple_music::find_plet_start_bo(char c, Moment& moment_r)
+{
+    return voice_.find_plet_start_bo(c, moment_r);
+}
+void 
+Simple_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
+{
+    voice_.set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
+}
+
+/* *************** */
+
+void
+Complex_music::add(Input_music*v)
+{
+    elts.bottom().add(v);
+}
+
+void
+Complex_music::print() const
+{
+    for (iter_top(elts,i); i.ok(); i++)
+        i->print();
+}
+
+void
+Complex_music::concatenate(Complex_music*h)
+{
+    for (iter_top(h->elts,i); i.ok(); i++)
+       add(i->clone());    
+}
+
+Complex_music::Complex_music()
+{
+}
+
+Complex_music::Complex_music(Complex_music const&s)
+{
+    for (iter_top(s.elts,i); i.ok(); i++)
+       add(i->clone());
+}
+void
+Complex_music::set_default_group(String g)
+{
+    for (iter_top(elts,i); i.ok(); i++)
+           i->set_default_group(g);
+}
+bool
+Complex_music::find_plet_start_bo(char c, Moment& moment_r)
+{
+    for (iter_bot(elts,i); i.ok(); i--) {
+        if ( i->find_plet_start_bo(c, moment_r) )
+           return true;
+    }
+    return false;
+}
+void 
+Complex_music::set_plet_backwards(Moment& now_moment_r, Moment until_moment, int num_i, int den_i)
+{
+    for (iter_bot(elts,i); i.ok(); i--) {
+       i->set_plet_backwards(now_moment_r, until_moment, num_i, den_i);
+    }
+}
+/* *************************************************************** */
+
+void
+Music_voice::print() const
+{
+    mtor << "Music_voice {";
+    Complex_music::print();    
+    mtor << "}\n";
+}
+
+void
+Music_voice::add_elt(Voice_element*v)
+{
+    PCursor<Input_music*> c(elts.bottom());
+    if (!c.ok() || !c->simple()) {
+       Simple_music*vs = new Simple_music;
+       
+       c.add(vs);
+    }
+    
+    c = elts.bottom();
+    Simple_music *s = c->simple();
+    s->add(v);             
+
+    check_plet(v);
+}
+
+Moment
+Music_voice::length()const
+{
+    Moment l = 0;
+    
+    for (iter_top(elts,i); i.ok(); i++)
+       l += i->length();
+    return l;
+}
+
+    
+Voice_list
+Music_voice::convert()const
+{
+    Voice_list l;
+    Moment here = 0;
+    
+    for (iter_top(elts,i); i.ok(); i++) {
+       Moment len = i->length();       
+       Voice_list k(i->convert());
+       k.translate_time(here); 
+       l.concatenate(k);
+       here +=len;     
+    }
+    return l;    
+}
+
+void
+Music_voice::translate_time(Moment t)
+{
+    elts.bottom()->translate_time(t);
+}
+
+    
+    
+/* *************** */
+
+void
+Music_general_chord::add_elt(Voice_element*v)
+{
+    Simple_music*vs = new Simple_music;
+    vs->add(v);
+    elts.bottom().add(vs);
+
+    check_plet(v);
+}
+
+void
+Music_general_chord::print() const
+{
+    mtor << "Music_general_chord {";
+    Complex_music::print();
+     mtor << "}\n";
+}
+
+void
+Music_general_chord::translate_time(Moment t)
+{
+    for (iter_top(elts,i); i.ok(); i++) 
+       i->translate_time(t);    
+}
+
+Moment
+Music_general_chord::length()const
+{
+    Moment l =0;
+    
+    for (iter_top(elts,i); i.ok(); i++) 
+       l = l >? i->length();
+    return l;
+}
+
+Voice_list
+Music_general_chord::convert()const
+{
+    Voice_list l;
+    for (iter_top(elts,i); i.ok(); i++) {
+       Voice_list k(i->convert());
+       l.concatenate(k);
+    }
+    return l;
+}
+
+/* *************** */
+
+void
+Multi_voice_chord::set_default_group(String g)
+{
+    int j=0;
+    for (iter_top(elts, i); i.ok(); i++) {
+       i->set_default_group(g + String(j));
+       j++;
+    }
+}
+
+
+/* *************** */
+
+void
+Voice_list::translate_time(Moment x)
+{
+    for (iter_top(*this,i); i.ok(); i++)
+       i->start += x;    
+}
+
diff --git a/src/input-staff.cc b/src/input-staff.cc
new file mode 100644 (file)
index 0000000..9e3958e
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+  input-staff.cc -- implement Input_staff
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "score.hh"
+#include "input-music.hh"
+#include "input-staff.hh"
+#include "staff.hh"
+#include "complex-staff.hh"
+#include "lyricstaff.hh"
+
+#include "lexer.hh"
+
+
+Input_staff::Input_staff(String s)
+{
+    score_wide_music_p_ =0;
+    type= s;
+    defined_ch_c_l_ = 0;
+}
+
+void
+Input_staff::add(Input_music*m)
+{
+    music_.bottom().add(m);
+}
+
+Staff*
+Input_staff::parse(Score*score_l, Input_music *default_score_wide)
+{
+    Staff *p=0;
+    if (type == "melodic")
+       p = new Complex_staff;
+    else if (type == "lyric")
+       p = new Lyric_staff;
+    else {
+       error( "Unknown staff-type `" + type +"\'", defined_ch_c_l_ );
+       exit( 1 );
+    }
+
+    p->score_l_ = score_l;
+    
+    for (iter_top(music_,i); i.ok(); i++) {
+       Voice_list vl = i->convert();
+       p->add(vl);
+    }
+    Voice_list vl =  (score_wide_music_p_) ? score_wide_music_p_->convert()
+       : default_score_wide->convert();
+    p->add(vl);
+    return p;
+}
+
+Input_staff::Input_staff(Input_staff const&s)
+{    
+    for (iter_top(s.music_,i); i.ok(); i++)
+       add(i->clone());
+    defined_ch_c_l_ = s.defined_ch_c_l_;
+    type = s.type;
+    score_wide_music_p_ = (s.score_wide_music_p_) ?
+       s.score_wide_music_p_->clone() : 0;
+}
+
+void
+Input_staff::print() const
+{
+#ifndef NPRINT
+    mtor << "Input_staff {\n";
+    for (iter_top(music_,i); i.ok(); i++)
+       i->print();
+    mtor << "}\n";
+#endif
+}
+void
+Input_staff::set_score_wide(Input_music *m_p)
+{
+    delete score_wide_music_p_;
+    score_wide_music_p_ = m_p;
+}
+
+Input_staff::~Input_staff()
+{
+    delete score_wide_music_p_;
+}
index 3ea6c0445ec85d5017bbb6d1f697dfb28a041ee1..e653c46ac6dfdd74387abe4f260323a3eb9914e2 100644 (file)
@@ -1,7 +1,7 @@
 #include "debug.hh"
 #include "item.hh"
 
-NAME_METHOD(Item);
+
 
 Item::Item()
 {
diff --git a/src/key-reg.cc b/src/key-reg.cc
new file mode 100644 (file)
index 0000000..84b0e26
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+  key-reg.cc -- implement Key_register
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+
+  todo: key undo
+  
+  */
+#include "time-description.hh"
+#include "key-reg.hh"
+#include "key-item.hh"
+#include "commandrequest.hh"
+#include "staff-column.hh"
+#include "local-key-reg.hh"
+#include "musicalrequest.hh"
+
+Key_register::Key_register()
+{
+    post_move_processing();
+}
+
+bool
+Key_register::try_request(Request * req_l)
+{
+    Command_req* creq_l= req_l->command();
+     if (!creq_l|| !creq_l->keychange())
+       return false;
+     
+    assert(!keyreq_l_);                // todo
+    keyreq_l_ = creq_l->keychange();
+    read_req(keyreq_l_);
+    return true;
+}
+
+void
+Key_register::acknowledge_element(Staff_elem_info info)
+{
+    Command_req * r_l = info.req_l_->command() ;
+    if (r_l && r_l->clefchange() && !kit_p_) {
+       int c0_i= *get_staff_info().c0_position_i_;
+        kit_p_ = new Key_item(c0_i);
+        kit_p_->read(*this);
+        announce_element(Staff_elem_info(kit_p_, keyreq_l_));
+    }
+}
+
+void
+Key_register::process_requests()
+{
+    const Time_description *time_l = get_staff_info().time_c_l_;
+
+    if (!keyreq_l_ &&
+       (!time_l->whole_in_measure_|| !time_l->when_)) {
+       default_key_b_ = true;
+    }
+
+     if ( default_key_b_ || keyreq_l_) {
+        int c0_i= *get_staff_info().c0_position_i_;
+        kit_p_ = new Key_item(c0_i);
+        kit_p_->read(*this);
+        announce_element(Staff_elem_info(kit_p_, keyreq_l_));
+     }
+}
+
+void
+Key_register::pre_move_processing()
+{
+    if (kit_p_) {
+       if (default_key_b_) 
+           typeset_breakable_item(0,0,kit_p_);
+       else 
+           typeset_breakable_item(
+               new Key_item(*kit_p_), kit_p_, new Key_item(*kit_p_));
+       kit_p_ = 0;
+    }
+}
+
+
+    
+void
+Key_register::read_req(Key_change_req * r)
+{
+    accidental_idx_arr_.set_size(0);
+    for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
+       int n_i=r->melodic_p_arr_[i]->notename_i_;
+       key_.set(n_i, r->melodic_p_arr_[i]->accidental_i_);
+       accidental_idx_arr_.push(n_i);
+    }
+}
+
+void
+Key_register::post_move_processing()
+{
+    keyreq_l_ = 0;
+    default_key_b_ = false;
+    kit_p_ = 0;
+}
index 02dd000e638bc7edbe7e6eb9c6704fed992fee4f..2eb9ed4e50d64620c0e846d17f4b57d6de9ad5ba 100644 (file)
@@ -13,7 +13,7 @@
 #include "lexer.hh"
 #include "debug.hh"
 #include "main.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 
 My_flex_lexer *lexer=0;
index 2a4d4a4417e076047147f05b99ba5be1459bab7b..4b7948142424473c27c879b86a3cdf70b3eddd6e 100644 (file)
@@ -15,7 +15,7 @@
 #include "string.hh"
 
 #include "moment.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 #include "midi-main.hh"    // *tors
 
index 8ee179332808acd0cd8c19305289cf8c491d8c47..abefcd2048203cd63db417bddea8c78bacf63fe3 100644 (file)
@@ -1,6 +1,6 @@
 #include "musicalrequest.hh"
 #include "voice.hh"
-#include "staffwalker.hh"
+#include "staff-walker.hh"
 #include "debug.hh"
 #include "staff.hh"
 #include "lyricstaff.hh"
index c77b716ec2afefba960dc10c9095eb4f492774a1..6abc2192a9c5ec0c4f43b267e5fe6861de2cb000 100644 (file)
@@ -12,8 +12,8 @@
 #include "lyricstaff.hh"
 #include "lyricwalker.hh"
 #include "debug.hh"
-#include "lyricitem.hh"
-#include "staffcolumn.hh"
+#include "lyric-item.hh"
+#include "staff-column.hh"
 
 void
 Lyric_walker::process_requests()
index 450545ab253dda4d13f201faf307b746e6acbebc..058db492d9112bdb5e8ad357f9d020432593eba6 100644 (file)
@@ -8,7 +8,7 @@
 #include "main.hh"
 #include "path.hh"
 #include "config.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 
 Source source;
@@ -19,7 +19,7 @@ extern void parse_file(String,String);
 
 void
 destill_inname( String &name_str_r);
-long_option_init theopts[] = {
+Long_option_init theopts[] = {
     1, "output", 'o',
     0, "warranty", 'w',
     0, "help", 'h',
@@ -91,7 +91,7 @@ main (int argc, char **argv)
     cout << get_version();
     String init_str("symbol.ini");
     
-    while (long_option_init * opt = oparser()) {
+    while (Long_option_init * opt = oparser()) {
        switch ( opt->shortname){
        case 'o':
            set_default_output(oparser.optarg);
diff --git a/src/meter-reg.cc b/src/meter-reg.cc
new file mode 100644 (file)
index 0000000..a27737c
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+  meter-reg.cc -- implement Meter_register
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "meter-reg.hh"
+#include "meter.hh"
+#include "commandrequest.hh"
+
+Meter_register::Meter_register()
+
+{
+    post_move_processing();
+}
+
+bool
+Meter_register::try_request(Request*r_l)
+{
+    Command_req* creq_l= r_l->command();
+     if (!creq_l || !creq_l->meterchange()) 
+       return false;
+
+    assert(!meter_req_l_);
+    meter_req_l_ = r_l->command()->meterchange();
+
+    return true;
+}
+
+void
+Meter_register::process_requests()
+{
+    if (meter_req_l_ ) {
+       Array<Scalar> args;
+       args.push(meter_req_l_->beats_i_);
+       args.push(meter_req_l_->one_beat_i_);
+       
+       meter_p_ = new Meter(args);
+    }
+
+    if (meter_p_)
+       announce_element(Staff_elem_info(meter_p_, meter_req_l_) );
+}
+
+void
+Meter_register::pre_move_processing()
+{
+    if (meter_p_) {
+       Meter * post_p =new Meter(*meter_p_);
+       Meter * pre_p =new Meter(*meter_p_);
+       
+       typeset_breakable_item(pre_p, meter_p_, post_p);
+       meter_p_ =0;
+    }
+}
+
+void
+Meter_register::post_move_processing()
+{
+    meter_req_l_ = 0;
+    meter_p_ =0;
+}
diff --git a/src/midi-def.cc b/src/midi-def.cc
new file mode 100644 (file)
index 0000000..5430823
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// midi-def.cc -- implement midi output
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <math.h>
+#include "misc.hh"
+#include "midi-def.hh"
+#include "debug.hh"
+
+// classes, alphasorted
+//     statics
+//     constructors
+//     destructor
+//     routines, alphasorted
+
+Midi_def::Midi_def()
+{
+    set_tempo( Moment( 1, 4 ), 60 );
+    outfile_str_ = "lelie.midi"; 
+}
+
+Midi_def::Midi_def( Midi_def const& midi_c_r )
+{
+    whole_seconds_f_ = midi_c_r.whole_seconds_f_;
+    outfile_str_ = midi_c_r.outfile_str_;
+}
+
+Midi_def::~Midi_def()
+{
+}
+
+Real
+Midi_def::duration_to_seconds_f( Moment moment )
+{
+    if (!moment)
+       return 0;
+    
+    return whole_seconds_f_ * moment;
+}
+
+int
+Midi_def::get_tempo_i( Moment moment )
+{
+    return Moment( whole_seconds_f_ ) * Moment( 60 ) * moment;
+}
+
+void
+Midi_def::print() const
+{
+#ifndef NPRINT
+    mtor << "Midi {4/min: " << Real( 60 ) / ( whole_seconds_f_ * 4 );
+    mtor << "out: " << outfile_str_;
+    mtor << "}\n";
+#endif
+}
+
+void
+Midi_def::set_tempo( Moment moment, int count_per_minute_i )
+{
+    whole_seconds_f_ = Moment( count_per_minute_i ) / Moment( 60 ) / moment;
+}
index e62a888a8351aacbff0cd9c874d40ccea5bf161b..36d6694779d3006e37256dbfa3372c81a78d9ab2 100644 (file)
@@ -9,7 +9,7 @@
 #include "plist.hh"      // all for midi-main.hh
 #include "string.hh"
 #include "source.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "midi-main.hh"  // *tors
 #include "moment.hh"
 #include "duration.hh"
diff --git a/src/midi-item.cc b/src/midi-item.cc
new file mode 100644 (file)
index 0000000..9d121cf
--- /dev/null
@@ -0,0 +1,196 @@
+//
+// midi-item.cc
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <limits.h>
+#include "plist.hh"
+#include "pcol.hh"
+#include "debug.hh"
+#include "misc.hh"
+#include "request.hh"
+#include "musicalrequest.hh"
+#include "voice.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "string-convert.hh"
+
+Midi_chunk::Midi_chunk()
+{
+}
+
+void
+Midi_chunk::add( String str )
+{
+    data_str_ += str;
+}
+
+void
+Midi_chunk::set( String header_str, String data_str, String footer_str )
+{
+    data_str_ = data_str;
+    footer_str_ = footer_str;
+    header_str_ = header_str;
+}
+  
+String
+Midi_chunk::str()
+{
+    String str = header_str_;
+    String length_str = String_convert::i2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' );
+    length_str = String_convert::hex2bin_str( length_str );
+    str += length_str;
+    str += data_str_;
+    str += footer_str_;
+    return str;
+}
+
+Midi_duration::Midi_duration( Real seconds_f )
+{
+    seconds_f_ = seconds_f;
+}
+
+String
+Midi_duration::str()
+{
+    return String( "<duration: " ) + String( seconds_f_ ) + ">";
+}
+
+Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i )
+{
+    String str;
+       
+    String format_str = String_convert::i2hex_str( format_i, 4, '0' );
+    str += String_convert::hex2bin_str( format_str );
+       
+    String tracks_str = String_convert::i2hex_str( tracks_i, 4, '0' );
+    str += String_convert::hex2bin_str( tracks_str );
+
+    String tempo_str = String_convert::i2hex_str( clocks_per_4_i, 4, '0' );
+    str += String_convert::hex2bin_str( tempo_str );
+
+    set( "MThd", str, "" );
+}
+
+String
+Midi_item::i2varint_str( int i )
+{
+    int buffer_i = i & 0x7f;
+    while ( (i >>= 7) > 0 ) {
+       buffer_i <<= 8;
+       buffer_i |= 0x80;
+       buffer_i += (i & 0x7f);
+    }
+
+    String str;
+    while ( 1 ) {
+       str += (char)buffer_i;
+       if ( buffer_i & 0x80 )
+           buffer_i >>= 8;
+       else
+           break;
+    }
+    return str;
+}
+
+void 
+Midi_item::output_midi( Midi_stream& midi_stream_r )
+{
+    midi_stream_r << str();
+}
+
+
+Midi_note::Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo  )
+{
+    assert(melreq_l);
+    pitch_i_ = melreq_l->pitch() + c0_pitch_i_c_;   
+    channel_i_ = channel_i;
+
+    // poor man-s staff dynamics:
+    dynamic_byte_ =  (melreq_l)? 0x64 - 0x10 * channel_i_:0;
+    on_b_ = on_bo;
+}
+
+String
+Midi_note::str()
+{
+    if ( pitch_i_ != INT_MAX ) {
+       Byte status_byte = ( on_b_ ? 0x90 : 0x80 ) + channel_i_;
+       String str = String( (char)status_byte );
+       str += (char)pitch_i_;
+       // poor man-s staff dynamics:
+       str += (char)dynamic_byte_;
+       return str;
+    }
+    return String( "" );
+}
+
+Midi_tempo::Midi_tempo( int tempo_i )
+{
+    tempo_i_ = tempo_i;
+}
+
+String
+Midi_tempo::str()
+{
+    int useconds_per_4_i = 60 * (int)1e6 / tempo_i_;
+    String str = "ff5103";
+    str += String_convert::i2hex_str( useconds_per_4_i, 6, '0' );
+    return String_convert::hex2bin_str( str );
+}
+
+Midi_track::Midi_track( int number_i )
+{
+//                4D 54 72 6B     MTrk
+//                00 00 00 3B     chunk length (59)
+//        00      FF 58 04 04 02 18 08    time signature
+//        00      FF 51 03 07 A1 20       tempo
+// FF 59 02 sf mi  Key Signature
+//         sf = -7:  7 flats
+//         sf = -1:  1 flat
+//         sf = 0:  key of C
+//         sf = 1:  1 sharp
+//         sf = 7: 7 sharps
+//         mi = 0:  major key
+//         mi = 1:  minor key
+
+    number_i_ = number_i;
+       
+    char const* data_ch_c_l = "00" "ff58" "0404" "0218" "08"
+//     "00" "ff51" "0307" "a120"
+// why a key at all, in midi?
+// key: C
+       "00" "ff59" "02" "00" "00"
+// key: F (scsii-menuetto)
+//                               "00" "ff59" "02" "ff" "00"
+       ;
+
+    String data_str;
+    // only for format 0 (currently using format 1)?
+    data_str += String_convert::hex2bin_str( data_ch_c_l );
+
+    char const* footer_ch_c_l = "00" "ff2f" "00";
+    String footer_str = String_convert::hex2bin_str( footer_ch_c_l );
+
+    set( "MTrk", data_str, footer_str );
+}
+
+void 
+Midi_track::add( int delta_time_i, String event_str )
+{
+    assert(delta_time_i >= 0);
+    Midi_chunk::add( i2varint_str( delta_time_i ) + event_str );
+}
+
+void 
+Midi_track::add( Moment delta_time_moment, Midi_item* mitem_l )
+{
+    // use convention of 384 clocks per 4
+    // use Duration_convert
+    int delta_time_i = delta_time_moment * Moment( 384 ) / Moment( 1, 4 );
+    add( delta_time_i, mitem_l->str() );
+}
+
index 5dfdf64662bf89b11c4a23ebca8d8b1881ecee09..90aad5299e826d12e88ac08402a16038d095b361 100644 (file)
@@ -13,7 +13,7 @@
 #include "string.hh"
 #include "lgetopt.hh"
 #include "source.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "midi-main.hh"
 #include "moment.hh"
 #include "duration.hh"
diff --git a/src/midi-output.cc b/src/midi-output.cc
new file mode 100644 (file)
index 0000000..af298f7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+  midi-output.cc -- implement Midi_output
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwehuizen <jan@digicash.com> 
+*/
+
+#include "plist.hh"
+#include "debug.hh"
+#include "score.hh"
+#include "staff.hh"
+#include "midi-stream.hh"
+#include "midi-def.hh"
+#include "midi-output.hh"
+#include "midi-walker.hh"
+#include "midi-item.hh"
+#include "staff-column.hh"
+#include "musicalrequest.hh"
+
+
+Midi_output:: Midi_output(Score* score_l, Midi_def* midi_l )
+{
+    midi_l_ = midi_l;
+
+    Midi_stream midi_stream(midi_l->outfile_str_,
+                           score_l->staffs_.size(),
+                           384 );
+// oeps, not tempo, but clocks per 4 (384 convention)
+// must set tempo in tempo request
+//                         midi_l->get_tempo_i(Moment(1, 4)));
+
+    midi_stream_l_ = &midi_stream;
+    int track_i=0;
+
+    for (iter_top(score_l->staffs_,i); i.ok(); i++) {
+       do_staff(i, track_i++);
+    }
+
+}
+
+void
+Midi_output::do_staff(Staff*st_l,int track_i)
+{
+    Midi_track midi_track( track_i );
+    Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) );
+    midi_track.add( Moment( 0.0 ), &midi_tempo );
+    for (Midi_walker w (st_l, &midi_track); w.ok(); w++)
+       w.process_requests();
+
+    *midi_stream_l_  << midi_track;
+}  
index f24f9093d1178d43125eda84c589e7d04fdecddf..02905b8718870274de247480e05c55cc96d276f3 100644 (file)
@@ -8,7 +8,7 @@
 #include "string.hh"
 #include "moment.hh"
 #include "duration.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 #include "midi-main.hh"    // *tors
 #include "midi-event.hh"
diff --git a/src/midi-stream.cc b/src/midi-stream.cc
new file mode 100644 (file)
index 0000000..3630831
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// midi-stream.cc
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <fstream.h>
+#include <time.h>
+#include "main.hh"
+#include "misc.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "debug.hh"
+#include "string-convert.hh"
+
+Midi_stream::Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i ) 
+{
+    filename_str_ = filename_str;
+    tracks_i_ = tracks_i;
+    clocks_per_4_i_ = clocks_per_4_i;
+    os_p_ = 0;
+    open();
+    header();
+}
+
+Midi_stream::~Midi_stream()
+{
+    delete os_p_;
+}
+
+Midi_stream&
+Midi_stream::operator <<( String str )
+{
+    // still debugging...
+    if ( check_debug )
+       str = String_convert::bin2hex_str( str );
+    // string now 1.0.26-2 handles binary streaming
+    *os_p_ << str;
+    return *this;
+}
+
+Midi_stream&
+Midi_stream::operator <<( Midi_item& mitem_r )
+{
+    mitem_r.output_midi( *this );
+    if ( check_debug )
+        *os_p_ << "\n";
+    return *this;
+}
+
+Midi_stream&
+Midi_stream::operator <<( int i )
+{
+    // output binary string ourselves
+    *this << Midi_item::i2varint_str( i );
+    return *this;
+}
+
+void
+Midi_stream::header()
+{
+//    *os_p_ << "% Creator: " << get_version();
+//    *os_p_ << "% Automatically generated, at ";
+//    time_t t(time(0));
+//    *os_p_ << ctime(&t);
+
+//                4D 54 68 64     MThd
+//    String str = "MThd";
+//                00 00 00 06     chunk length
+//                00 01   format 1
+//                00 01   one track
+//                00 60   96 per quarter-note
+
+//    char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
+//    str += String_convert::hex2bin_str( ch_c_l );
+//    *os_p_ << str;
+
+//      *this << Midi_header( 1, 1, tempo_i_ );
+      *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
+}
+
+void
+Midi_stream::open()
+{
+    os_p_ = new ofstream( filename_str_ );
+    if ( !*os_p_ )
+       error ("can't open `" + filename_str_ + "\'" );
+}
index c4caa838b4d28bf2fdf7f1af29bfa5411145a7bd..c2bfd01eaa3766538748bc0b7d82203a8eceeb28 100644 (file)
@@ -14,7 +14,7 @@ class ostream;
 #include "plist.tcc"
 #include "pcursor.tcc"
 #include "string.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 
 #include "moment.hh"
 #include "duration.hh"
index 99bd9dee8c1d80f327e3ed2bafaef313c09b6b78..6fccd518ec365ad958ed50bcddeca5e531266cbd 100644 (file)
@@ -6,7 +6,7 @@
 #include "proto.hh"
 #include "plist.hh"
 #include "string.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 #include "midi-main.hh"    // *tors
 
diff --git a/src/midi-walker.cc b/src/midi-walker.cc
new file mode 100644 (file)
index 0000000..801ba32
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+  midi-walker.cc -- implement Midi_walker
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
+#include "musicalrequest.hh"
+#include "pscore.hh"
+#include "staff.hh"
+#include "midi-walker.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "debug.hh"
+#include "staff-column.hh"
+
+Midi_walker::Midi_walker(Staff *st_l, Midi_track* track_l)
+    : PCursor<Staff_column*>(st_l->cols_)
+{
+    track_l_ = track_l;
+    last_moment_= 0;
+}
+
+/**
+  output notestop events for all notes which end before #max_moment#
+ */
+void
+Midi_walker::do_stop_notes(Moment max_moment)
+{
+    while (stop_notes.size() && stop_notes.front_idx() <= max_moment) {
+       Moment stop_moment = stop_notes.front_idx();
+       Melodic_req * req_l = stop_notes.get();
+       
+       Midi_note note(req_l, track_l_->number_i_, false);
+       output_event(note, stop_moment);
+    }
+}
+/** advance the track to #now#, output the item, and adjust current
+  "moment".  */
+void
+Midi_walker::output_event(Midi_item &i, Moment now)
+{
+    Moment delta_t = now - last_moment_ ;
+    last_moment_ += delta_t;
+    track_l_->add(delta_t, &i );    
+}
+
+void
+Midi_walker::process_requests()
+{
+    do_stop_notes(ptr()->when());
+    for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ )  {
+
+       Rhythmic_req *n = ptr()->musicalreq_l_arr_[i]->rhythmic();
+       if ( !n)
+           continue;
+       Note_req * note_l = n->note();
+       if (!note_l)
+           continue;
+       
+       Midi_note note(note_l, track_l_->number_i_, true);
+       stop_notes.enter(note_l, n->duration() + ptr()->when() );
+       output_event(note, ptr()->when());
+    }
+}
+
+Midi_walker::~Midi_walker()
+{
+    do_stop_notes( last_moment_ + Moment(10,1)); // ugh
+}
index c261e5c503c9d7c1d4f2815752cbbf05c4c5fd4b..4aa37d31469ad43c2d908f1e820bece172f5cf43 100644 (file)
@@ -4,8 +4,8 @@
 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
 
 #include "debug.hh"
-#include "inputfile.hh"
-#include "sourcefile.hh"
+#include "input-file.hh"
+#include "source-file.hh"
 #include "my-midi-lexer.hh"
 
 int
index 62f4d499c888d0b973b0d518a923933b03eb0edf..31555f79af542aa7b39dc25bda168e02e5e98c9a 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "plist.hh"        // ugh
 #include "string.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 #include "midi-main.hh"    // *tors
 
index 0f7eb8e85fb70e14b760bf0585bc9cf1871ab63e..496d892e5b872223cb717d22c181a0b527e8e3b1 100644 (file)
 #include "notename.hh"
 #include "identparent.hh"
 #include "varray.hh"
-#include "textdef.hh"
+#include "text-def.hh"
 #include "parseconstruct.hh"
-#include "inputmusic.hh"
+#include "input-music.hh"
+#include "voice-element.hh"
 
 int default_duration = 4, default_dots=0, default_octave=0;
 int default_plet_type = 1, default_plet_dur = 1;
index 991be88550463031a76447cc13eae7a34daba4c9..ecfe68c881a3470d4504b08c3cc5f9a15d1b5371 100644 (file)
@@ -9,8 +9,10 @@
 #include "musicalrequest.hh"
 #include "misc.hh"
 #include "debug.hh"
-#include "scriptdef.hh"
-#include "textdef.hh"
+#include "script-def.hh"
+#include "text-def.hh"
+#include "voice.hh"
+#include "voice-element.hh"
 
 void
 Stem_req::do_print() const
@@ -288,3 +290,11 @@ Skip_req::do_print() const
     mtor << "duration: " << duration();
 }
 
+Voice *
+Request::voice_l()
+{
+    if (!elt_l_)
+       return 0;
+    else
+       return (Voice*)elt_l_->voice_l_;
+}
diff --git a/src/score-column.cc b/src/score-column.cc
new file mode 100644 (file)
index 0000000..4387630
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+  score-column.cc -- implement Score_column
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "pcol.hh"
+#include "score-column.hh"
+
+int
+Score_column::compare(Score_column & c1, Score_column &c2)
+{
+       return sign(c1.when_ - c2.when_);
+}
+
+void
+Score_column::set_breakable()
+{
+    pcol_l_->set_breakable();
+}
+
+Score_column::Score_column(Moment w)
+{
+    when_ = w;
+    pcol_l_ = new PCol(0);
+    musical_b_ = false;
+}
+
+bool
+Score_column::used_b() {
+    return pcol_l_->used_b();
+}
+
+void
+Score_column::print() const
+{
+#ifndef NPRINT
+    mtor << "Score_column { mus "<< musical_b_ <<" at " <<  when_<<'\n';
+    mtor << "durations: [";
+    for (int i=0; i < durations.size(); i++)
+       mtor << durations[i] << " ";
+    mtor << "]\n";
+    pcol_l_->print();
+    mtor << "}\n";
+#endif
+}
+
+int
+Moment_compare(Moment &a , Moment& b)
+{
+    return sign(a-b);
+}
+
+void
+Score_column::preprocess()
+{
+    durations.sort(Moment_compare);
+}
+void
+Score_column::add_duration(Moment d)
+{
+    assert(d);
+    for (int i = 0; i< durations.size(); i++) {
+       if (d == durations[i])
+           return ;
+    }
+    durations.push(d);
+}
+
+bool
+Score_column::breakable_b()
+{
+    return pcol_l_->breakable_b();
+}
diff --git a/src/score-walker.cc b/src/score-walker.cc
new file mode 100644 (file)
index 0000000..a780b05
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+  score-walker.cc -- implement Score_walker
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "debug.hh"
+#include "plist.hh"
+#include "score-walker.hh"
+#include "score.hh"
+#include "staff-walker.hh"
+#include "staff.hh"
+#include "score-column.hh"
+
+Score_walker::Score_walker(Score *s)
+    :PCursor<Score_column *> (s->cols_)
+{
+    score_l_ = s;
+    for (iter_top(s->staffs_,i); i.ok(); i++) {
+       Staff_walker* w_p=i->get_walker_p();
+       w_p->score_walk_l_ =this;
+       walker_p_arr_.push(w_p);
+    }
+
+    if(ok()) {
+       s->find_col(0, false)->set_breakable();
+       s->find_col(s->last(), false)->set_breakable();
+    }
+    reinit();
+}
+
+
+void
+Score_walker::reinit()
+{
+    disallow_break_walk_l_arr = walker_p_arr_;
+    disallow_break_count_ = disallow_break_walk_l_arr.size();
+}
+
+
+/** Advance the cursor, and all Staff_walkers contained in this. Reset
+  runtime fields */
+void 
+Score_walker::operator ++(int )
+{
+    Moment last = ptr()->when();
+    
+    PCursor<Score_column *>::operator++(0);
+    if (ok() && ptr()->when() == last)
+       PCursor<Score_column *>::operator++(0);
+    reinit();
+    if (!ok())
+       return;
+    for (int i=0; i< walker_p_arr_.size(); i++) {
+       if (walker_p_arr_[i]->ok() &&
+           walker_p_arr_[i]->when() < when()) {
+
+           walker_p_arr_[i]->operator++(0);
+       }
+    }
+}
+
+/** Allow the command_column to be breakable for one staff. If all
+  staffs allow, then allow a break here.  */
+void
+Score_walker::allow_break(Staff_walker*w)
+{
+    for (int i=0; i < disallow_break_walk_l_arr.size(); i++) {
+       if (w == disallow_break_walk_l_arr[i]) {
+           disallow_break_count_ --;
+           disallow_break_walk_l_arr[i] =0;
+
+           if (!disallow_break_count_) {
+               PCursor<Score_column*> col_cursor = *this;
+               if (ptr()->musical_b())
+                   col_cursor --;
+               col_cursor->set_breakable();
+           }
+       }
+    }
+}
+
+Moment
+Score_walker::when()
+{
+    return ptr()->when();
+}
+
+void
+Score_walker::process()
+{
+    for (int i=0; i < walker_p_arr_.size(); i++) {
+       Staff_walker *w = walker_p_arr_[i];
+       if ( w->ok() && w->when() == when() ) {
+           walker_p_arr_[i]->process();
+       }
+    }
+    if (when().denominator() == 1) {
+       *mlog << "." <<flush;
+    }
+}
+
+Score_walker::~Score_walker()
+{
+    for (int i=0; i < walker_p_arr_.size(); i++) 
+       delete walker_p_arr_[i];
+    assert( !score_l_->find_col(score_l_->last(), true)->used_b());
+}
+
+
diff --git a/src/script-reg.cc b/src/script-reg.cc
new file mode 100644 (file)
index 0000000..6cfba0f
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+  script-reg.cc -- implement Script_register
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "script-reg.hh"
+#include "script.hh"
+#include "musicalrequest.hh"
+#include "complex-walker.hh"
+#include "stem.hh"
+
+Script_register::Script_register()
+{
+    script_p_ = 0;
+    post_move_processing();
+}
+
+bool
+Script_register::try_request(Request *r_l)
+{
+    if (!r_l->script())
+       return false ;
+
+    if (script_req_l_
+       && Script_req::compare(*script_req_l_, *r_l->script()))
+       
+       return false;
+
+    script_req_l_ = r_l->script();
+    
+    return true;
+}
+
+void
+Script_register::process_requests()
+{
+    if (script_req_l_) {
+       script_p_ = new Script(script_req_l_, 10);
+       announce_element(
+           Staff_elem_info(script_p_, script_req_l_));
+    }
+}
+
+void
+Script_register::acknowledge_element(Staff_elem_info info)
+{
+    if (!script_p_)
+       return;
+    if (info.elem_p_->name() == Stem::static_name())
+       script_p_->set_stem((Stem*)info.elem_p_);
+    else if (info.req_l_->rhythmic())
+       script_p_->set_support(info.elem_p_->item());
+}
+
+void
+Script_register::pre_move_processing()
+{
+    if (script_p_){
+       script_p_->dir = dir_i_;
+       typeset_element(script_p_);
+       script_p_ = 0;
+    }
+}
+void
+Script_register::post_move_processing()
+{
+    script_req_l_ = 0;
+}
+
+void
+Script_register::set_feature(Features i)
+{
+    if (i.direction_i_|| i.initialiser_b_)
+       dir_i_ = i.direction_i_;
+}
diff --git a/src/slur-reg.cc b/src/slur-reg.cc
new file mode 100644 (file)
index 0000000..15a9af8
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+  slur-reg.cc -- implement Slur_register
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "plist.hh"
+#include "musicalrequest.hh"
+#include "complex-walker.hh"
+#include "slur-reg.hh"
+#include "slur.hh"
+#include "debug.hh"
+#include "notehead.hh"
+
+void
+Slur_register::set_feature(Features i)
+{
+    dir_i_ = i.direction_i_;
+}
+
+Slur_register::Slur_register()
+{
+    set_feature(Features::dir(0));
+}
+
+bool
+Slur_register::try_request(Request *req_l)
+{
+    if(!req_l->slur())
+       return false;
+
+    new_slur_req_l_arr_.push(req_l->slur());
+    return true;
+}
+
+void
+Slur_register::acknowledge_element(Staff_elem_info info)
+{
+    if (info.elem_p_->name() == Notehead::static_name()) { 
+       Notehead *head_p =(Notehead*) info.elem_p_ ;// ugh
+       for (int i = 0; i < slur_l_stack_.size(); i++)
+           slur_l_stack_[i]->add(head_p );
+       for (int i = 0; i < end_slur_l_arr_.size(); i++)
+           end_slur_l_arr_[i]->add(head_p);
+    }
+}
+/*
+  abracadabra
+  */
+void
+Slur_register::process_requests()
+{
+    Array<Slur*> start_slur_l_arr_;
+    for (int i=0; i< new_slur_req_l_arr_.size(); i++) {
+       Slur_req* slur_req_l = new_slur_req_l_arr_[i];
+       // end slur: move the slur to other array
+       if (slur_req_l->spantype == Span_req::STOP) {
+           if (slur_l_stack_.empty())
+               warning("can't find slur to end",
+                     slur_req_l->defined_ch_c_l_);
+           else {
+               end_slur_l_arr_.push(slur_l_stack_.pop());
+               requests_arr_.pop();
+           }
+       } else  if (slur_req_l->spantype == Span_req::START) {
+           // push a new slur onto stack.
+           //(use temp. array to wait for all slur STOPs)
+           Slur * s_p =new Slur;
+           requests_arr_.push(slur_req_l);
+           start_slur_l_arr_.push(s_p);
+           announce_element(Staff_elem_info(s_p, slur_req_l));
+       }
+    }
+    for (int i=0; i < start_slur_l_arr_.size(); i++)
+       slur_l_stack_.push(start_slur_l_arr_[i]);
+}
+
+void
+Slur_register::pre_move_processing()
+{
+    for (int i = 0; i < end_slur_l_arr_.size(); i++) {
+       if (dir_i_) 
+           end_slur_l_arr_[i]->dir_i_ = dir_i_;
+       typeset_element(end_slur_l_arr_[i]);
+    }
+    end_slur_l_arr_.set_size(0);
+}
+
+void
+Slur_register::post_move_processing()
+{
+    new_slur_req_l_arr_.set_size(0);
+}
+Slur_register::~Slur_register()
+{
+    for (int i=0; i < requests_arr_.size(); i++) {
+       warning("unterminated slur", requests_arr_[i]->defined_ch_c_l_);
+    }
+}
diff --git a/src/source-file.cc b/src/source-file.cc
new file mode 100644 (file)
index 0000000..f0d21bf
--- /dev/null
@@ -0,0 +1,207 @@
+//
+// source-file.cc
+//
+
+#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 <assert.h>
+#include <strstream.h>
+
+#include "string.hh"
+#include "proto.hh"
+#include "plist.hh"
+#include "lexer.hh"
+#include "debug.hh"
+#include "parseconstruct.hh"
+#include "main.hh"                     // find_file
+
+#include "source-file.hh"
+
+Source_file::Source_file( String &filename_str )
+{
+    data_caddr_ = 0;
+    fildes_i_ = 0;
+    size_off_ = 0;
+    name_str_ = filename_str;
+    istream_p_ = 0;
+
+    open();
+    map();
+    // ugh!?, should call name_str() ! 
+    filename_str = name_str_;
+}
+
+Source_file::~Source_file()
+{
+    delete istream_p_;
+    istream_p_ = 0;
+    unmap();
+    close();
+}
+
+char const*
+Source_file::ch_c_l()
+{
+    assert( this );
+    return (char const*)data_caddr_;
+}
+
+void
+Source_file::close()
+{
+    if ( fildes_i_ ) {
+       ::close( fildes_i_ );
+       fildes_i_ = 0;
+    }
+}
+
+String
+Source_file::error_str( char const* pos_ch_c_l )
+{
+    assert( this );
+    if ( !in_b( pos_ch_c_l ) )
+       return "";
+
+    char const* begin_ch_c_l = pos_ch_c_l;
+    char const* data_ch_c_l = ch_c_l();
+    while ( begin_ch_c_l > data_ch_c_l )
+        if ( *--begin_ch_c_l == '\n' ) {
+           begin_ch_c_l++;
+           break;
+       }
+
+    char const* end_ch_c_l = pos_ch_c_l;
+    while ( end_ch_c_l < data_ch_c_l + size_off_ )
+        if ( *end_ch_c_l++ == '\n' ) {
+           break;
+       }
+    end_ch_c_l--;
+
+#if 1
+//    String( char const* p, int length ) is missing!?
+    String line_str( (Byte const*)begin_ch_c_l, end_ch_c_l - begin_ch_c_l );
+#else
+    int length_i = end_ch_c_l - begin_ch_c_l;
+    char* ch_p = new char[ length_i + 1 ];
+    strncpy( ch_p, begin_ch_c_l, length_i );
+    ch_p[ length_i ] = 0;
+    String line_str( ch_p );
+    delete ch_p;
+#endif
+
+    int error_col_i = 0;
+    char const* scan_ch_c_l = begin_ch_c_l;
+    while ( scan_ch_c_l < pos_ch_c_l )
+       if ( *scan_ch_c_l++ == '\t' )
+           error_col_i = ( error_col_i / 8 + 1 ) * 8;
+       else
+           error_col_i++;
+
+    String str = line_str.left_str( pos_ch_c_l - begin_ch_c_l ) 
+       + String( '\n' )
+       + String( ' ', error_col_i ) 
+       + line_str.mid_str( pos_ch_c_l - begin_ch_c_l + 1, INT_MAX ); // String::mid should take 0 arg..
+    return str;
+}
+
+bool
+Source_file::in_b( char const* pos_ch_c_l )
+{
+    return ( pos_ch_c_l && ( pos_ch_c_l >= ch_c_l() ) && ( pos_ch_c_l < ch_c_l() + size_off_ ) );
+}
+
+istream*
+Source_file::istream_l()
+{
+    assert( fildes_i_ );
+    if ( !istream_p_ ) {
+       if ( size_off_ ) // can-t this be done without such a hack?
+           istream_p_ = new istrstream( ch_c_l(), size_off_ );
+        else {
+           istream_p_ = new istrstream( "", 0 );
+           istream_p_->set(ios::eofbit);
+       }
+    }
+    return istream_p_;
+}
+
+off_t
+Source_file::length_off()
+{
+    return size_off_;
+}
+
+int
+Source_file::line_i( char const* pos_ch_c_l )
+{
+    if ( !in_b( pos_ch_c_l ) )
+       return 0;
+
+    int i = 1;
+    char const* scan_ch_c_l = ch_c_l();
+    while ( scan_ch_c_l < pos_ch_c_l )
+       if ( *scan_ch_c_l++ == '\n' )
+               i++;
+    return i;
+}
+
+void
+Source_file::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 )
+       // ugh: defined_ch_c_l...
+       warning( String( "can't map: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); //lexer->here_ch_c_l() );
+}
+
+String
+Source_file::name_str()
+{
+    return name_str_;
+}
+
+void
+Source_file::open()
+{
+    String name_str = find_file( name_str_ );
+    if ( name_str != "" ) 
+        name_str_ = name_str;
+
+    fildes_i_ = ::open( name_str_, O_RDONLY ); 
+           
+    if ( fildes_i_ == -1 ) {
+       warning( String( "can't open: " ) + name_str_ + String( ": " ) + strerror( errno ), defined_ch_c_l ); // lexer->here_ch_c_l() );
+        return;
+    }
+
+    struct stat file_stat;
+    fstat( fildes_i_, &file_stat );
+    size_off_ = file_stat.st_size;
+}
+
+void
+Source_file::unmap()
+{
+    if ( data_caddr_ ) {
+       munmap( data_caddr_, size_off_ );
+       data_caddr_ = 0;
+       size_off_ = 0;
+    }
+}
+String
+Source_file::file_line_no_str(char const *ch_c_l )
+{
+    return name_str() + ": "
+       + String( line_i( ch_c_l ) );
+}
index 519a6fe96aad58dea7f6d1558e3b9ebe587512cc..8a8c52883591bfa49930fec798e3c9afc8746d81 100644 (file)
@@ -8,7 +8,7 @@
 #include "proto.hh"
 #include "plist.hh"
 
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 
 Source::Source()
index 15efb59071a9862f4554a425439155b85c67e747..cc57686393455e9fe4f1cad6196b2315586b2551 100644 (file)
@@ -2,7 +2,7 @@
 #include "spanner.hh"
 #include "pcol.hh"
 
-NAME_METHOD(Spanner);
+
 
 void
 Spanner::do_print()const
diff --git a/src/staff-column.cc b/src/staff-column.cc
new file mode 100644 (file)
index 0000000..546a2a6
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+  staff-column.cc -- implement Staff_column
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+#include "staff.hh"
+#include "voice.hh"
+#include "time-description.hh"
+#include "score-column.hh"
+#include "staff-column.hh"
+#include "commandrequest.hh"
+#include "musicalrequest.hh"
+#include "interval.hh"
+#include "pscore.hh"
+#include "item.hh"
+#include "pcol.hh"
+#include "voice-element.hh"
+
+void
+Staff_column::OK() const
+{
+#ifndef NDEBUG
+    assert (command_column_l_->when() == musical_column_l_->when());
+#endif
+}
+
+Moment
+Staff_column::when() const
+{
+    return (command_column_l_)?
+       command_column_l_->when():
+       musical_column_l_->when();
+}
+
+void
+Staff_column::add(Voice_element*ve)
+{
+    for (iter_top(ve->reqs,j); j.ok(); j++) {
+       if (j->command()) {
+           Command_req * c_l = j->command();
+           if (c_l->timing()) {
+               timing_req_l_arr_.push(j->command()->timing());
+           }
+           if (c_l->groupchange())
+               creationreq_l_arr_.push(c_l);
+           else if (!c_l->barcheck() &&  !c_l->partial() &&
+               !c_l->measuregrouping())
+               setup_one_request(j);   // no need to bother children
+       } else {
+           if (j->rhythmic()) {
+               musical_column_l_->add_duration(j->rhythmic()->duration());
+           }
+           if (!j->musical()->skip())
+               setup_one_request(j);
+       }
+    }
+}
+
+Staff_column::Staff_column()
+{
+    musical_column_l_ = 0;
+    command_column_l_ = 0;
+    staff_l_ = 0;
+}
+
+
+
+
+Staff_column::~Staff_column()
+{
+}
+
+void
+Staff_column::set_cols(Score_column*c1, Score_column*c2)
+{
+    command_column_l_ = c1;
+    musical_column_l_ = c2;
+}
+
+void
+Staff_column::setup_one_request(Request * j)
+{
+    if (j->command()) // ugh
+       commandreq_l_arr_.push(j);
+    else if (j->musical())
+       musicalreq_l_arr_.push(j);
+}
+
+void
+Staff_column::typeset_musical_item(Item*i)
+{
+    assert(i);
+    Score_column * scorecolumn_l = musical_column_l_;
+    musical_column_l_->pcol_l_->pscore_l_->typeset_item(i, scorecolumn_l->pcol_l_,
+                                                       staff_l_->pstaff_l_);
+}
+
+/**
+  align items in #item_l_arr#,
+
+  @return the width of the items after aligning.
+ */
+Interval
+align_items(Array<Item*> item_l_arr)
+{
+    Interval wid(0,0);
+    for  (int i =0; i < item_l_arr.size(); i++) {
+       Interval item_width= item_l_arr[i]->width();
+       Real dx =wid.right - item_width.left;
+       item_width += dx;
+       item_l_arr[i]->translate(Offset(dx ,0));
+       wid.unite(item_width);
+    }
+    return wid;
+}
+
+void 
+translate_items(Real x,  Array<Item*> item_l_arr)
+{
+    for  (int i =0; i < item_l_arr.size(); i++) 
+       item_l_arr[i]->translate(Offset(x, 0));
+}
+/*
+  UGR
+  This still sux
+  */
+void
+Staff_column::typeset_breakable_items(Array<Item *> &pre_p_arr,
+                                     Array<Item *> &nobreak_p_arr,
+                                     Array<Item *> &post_p_arr)
+{
+    PCol * c= command_column_l_->pcol_l_;
+    PScore *ps_l=command_column_l_->pcol_l_->pscore_l_;
+    
+    if (!c->breakable_b()) {     
+       for  (int i =0; i < pre_p_arr.size(); i++)
+           delete pre_p_arr[i];
+       pre_p_arr.set_size(0);
+       for  (int i =0; i < post_p_arr.size(); i++)
+           delete post_p_arr[i];
+       post_p_arr.set_size(0);
+    }
+
+      
+    for  (int i =0; i < pre_p_arr.size(); i++) {
+       ps_l->typeset_item(pre_p_arr[i], c, staff_l_->pstaff_l_,0);
+    }
+    for  (int i =0; i < nobreak_p_arr.size(); i++) {
+       ps_l->typeset_item(nobreak_p_arr[i], c, staff_l_->pstaff_l_,1);
+    }
+    for  (int i =0; i < post_p_arr.size(); i++) {
+       ps_l->typeset_item(post_p_arr[i], c, staff_l_->pstaff_l_,2);
+    }
+
+    Interval pre_wid= align_items(pre_p_arr);
+    translate_items( -pre_wid.right, pre_p_arr);
+    align_items(nobreak_p_arr);
+    Interval post_wid =align_items(post_p_arr);
+    translate_items (-post_wid.left , post_p_arr);
+
+    pre_p_arr.set_size(0);
+    post_p_arr.set_size(0);
+    nobreak_p_arr.set_size(0);
+}
diff --git a/src/staff-elem-info.cc b/src/staff-elem-info.cc
new file mode 100644 (file)
index 0000000..9a6283e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+  staff-elem-info.cc -- implement Staff_elem_info
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "staff-elem-info.hh"
+#include "request.hh"
+
+Staff_elem_info::Staff_elem_info(Staff_elem*s_l, Request*r_l)
+{
+    elem_p_ = s_l;
+    voice_l_ =  (r_l)?r_l->voice_l():0;
+    req_l_ = r_l;
+}
+
+Staff_elem_info::Staff_elem_info()
+{
+    elem_p_ = 0;
+    voice_l_ = 0;
+
+    req_l_ = 0;
+}
+
+Features::Features()
+{
+    direction_i_ = 0;
+    initialiser_b_ = false;
+}
+
+Features
+Features::dir(int d) return f;
+{
+    f.initialiser_b_ = true;
+    f.direction_i_ = d;
+}
diff --git a/src/staff-walker.cc b/src/staff-walker.cc
new file mode 100644 (file)
index 0000000..a383d35
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+  staff-walker.cc -- implement Staff_walker
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "grouping.hh"
+#include "staff.hh"
+#include "musicalrequest.hh"
+#include "staff-walker.hh"
+#include "staff-column.hh"
+#include "score-column.hh"
+#include "debug.hh"
+#include "time-description.hh"
+#include "commandrequest.hh"
+#include "grouping.hh"
+#include "score-walker.hh"
+
+Staff_walker::~Staff_walker()
+{
+    do_pre_move();
+}
+
+Staff_walker::Staff_walker(Staff_walker const &s)
+    :PCursor<Staff_column*> (s)
+{
+    assert(false);
+}
+
+Staff_walker::Staff_walker(Staff * s, PScore*ps )
+    : PCursor<Staff_column*> (s->cols_)
+{
+    staff_l_ = s;
+    pscore_l_ = ps;
+    
+    // should be in tdes. TODO
+    default_grouping = new Rhythmic_grouping(MInterval(0, 1), 4); 
+    score_walk_l_ = 0;
+}
+
+Moment
+Staff_walker::when() const
+{
+    return ptr()->when();
+}
+
+
+void
+Staff_walker::process_timing_reqs()
+{
+    for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
+       Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
+       if (tr_l->meterchange()) {
+           int b_i=tr_l->meterchange()->beats_i_;
+           int o_i = tr_l->meterchange()->one_beat_i_;
+           time_.set_meter(b_i, o_i);
+                       
+           *default_grouping = Rhythmic_grouping(
+               MInterval(0,Moment(b_i, o_i)), b_i);
+       } 
+    }
+    
+    for (int i=0; i < ptr()->timing_req_l_arr_.size(); i++) {
+       Timing_req * tr_l = ptr()->timing_req_l_arr_[i];
+       if (tr_l->partial()) {
+           time_.setpartial(tr_l->partial()->duration_);
+       } else if (tr_l->barcheck() && time_.whole_in_measure_) {
+           warning( "Barcheck failed", tr_l->defined_ch_c_l_ );
+       } else if (tr_l->cadenza()) {
+           time_.set_cadenza(tr_l->cadenza()->on_b_);
+       } else if (tr_l->measuregrouping()) {
+           *default_grouping = parse_grouping(
+               tr_l->measuregrouping()->beat_i_arr_,
+               tr_l->measuregrouping()->elt_length_arr_);
+       }
+    }
+    time_.OK();
+}
+
+void
+Staff_walker::operator++(int i)
+{
+    Moment last = when();
+
+    do_pre_move();
+    PCursor<Staff_column*>::operator++(i);
+    if (ok() ) {
+       Moment delta_t = when() - last;
+       assert(delta_t >0);
+       time_.add( delta_t );
+    }
+    do_post_move();
+}
+
+void
+Staff_walker::process()
+{
+    process_timing_reqs();    
+    process_requests();
+}
+
+void 
+Staff_walker::allow_break()
+{
+    score_walk_l_->allow_break(this);
+}
diff --git a/src/stem-beam-reg.cc b/src/stem-beam-reg.cc
new file mode 100644 (file)
index 0000000..f08b02f
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+  stem-beam-reg.cc -- part of LilyPond
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "stem-beam-reg.hh"
+#include "beam.hh"
+#include "stem.hh"
+#include "grouping.hh"
+#include "textspanner.hh"
+#include "complex-walker.hh"
+#include "complex-staff.hh"
+#include "debug.hh"
+#include "grouping.hh"
+#include "notehead.hh"
+
+Stem_beam_register::Stem_beam_register()
+{
+    post_move_processing();
+    current_grouping = 0;
+    beam_p_ = 0;
+    set_feature(Features::dir(0));
+    start_req_l_ = 0;
+}
+
+bool
+Stem_beam_register::try_request(Request*req_l)
+{
+    if ( req_l->beam() ) {
+       if (bool(beam_p_ ) == bool(req_l->beam()->spantype == Span_req::START))
+           return false;
+       
+       if (beam_req_l_ && Beam_req::compare(*beam_req_l_ , *req_l->beam()))
+           return false;
+       
+       beam_req_l_ = req_l->beam();
+       return true;
+    }
+    
+    if ( req_l->stem() ) {
+       if (current_grouping && !current_grouping->child_fit_query(
+           get_staff_info().time_c_l_->whole_in_measure_))
+           return false;
+
+       if (stem_req_l_ && Stem_req::compare(*stem_req_l_, *req_l->stem()))
+           return false;
+
+       stem_req_l_ = req_l->stem();
+       return true;
+    }
+    return false;
+}
+
+void
+Stem_beam_register::process_requests()
+{
+    if (beam_req_l_) {
+       if (beam_req_l_->spantype == Span_req::STOP) {
+           end_beam_b_ = true;
+           start_req_l_ = 0;
+       } else {
+           beam_p_ = new Beam;
+           start_req_l_ = beam_req_l_;
+
+           current_grouping = new Rhythmic_grouping;
+           if (beam_req_l_->nplet) {
+               Text_spanner* t = new Text_spanner();
+               t->set_support(beam_p_);
+               t->spec.align_i_ = 0;
+               t->spec.text_str_ = beam_req_l_->nplet;
+               t->spec.style_str_="italic";
+               typeset_element(t);
+           }
+            
+       }
+    }
+
+    if (stem_req_l_) {
+       stem_p_ = new Stem(4);
+       if (current_grouping)
+           current_grouping->add_child(
+               get_staff_info().time_c_l_->whole_in_measure_,
+               stem_req_l_->duration());
+
+       stem_p_->flag = stem_req_l_->balltype;
+
+       if (beam_p_) {
+           if (stem_req_l_->balltype<= 4)
+               warning( "stem doesn't fit in Beam",
+                        stem_req_l_->defined_ch_c_l_);
+           else
+               beam_p_->add(stem_p_);
+           stem_p_->print_flag = false;
+       } else {
+           stem_p_->print_flag = true;
+       }
+       
+       announce_element(Staff_elem_info(stem_p_, stem_req_l_));
+    }
+}
+
+void
+Stem_beam_register::acknowledge_element(Staff_elem_info info)
+{
+    if (!stem_p_)
+       return;
+
+    if (info.elem_p_->name() == Notehead::static_name() &&
+       stem_req_l_->duration() == info.req_l_->rhythmic()->duration())
+       
+       stem_p_->add((Notehead*)info.elem_p_);
+}
+
+void
+Stem_beam_register::pre_move_processing()
+{
+    if (stem_p_) {
+       if (default_dir_i_)
+           stem_p_->dir = default_dir_i_;
+       
+       typeset_element(stem_p_);
+       stem_p_ = 0;
+    }
+    if (beam_p_ && end_beam_b_) {
+       const Rhythmic_grouping * rg_c_l = get_staff_info().rhythmic_c_l_;
+       rg_c_l->extend(current_grouping->interval());
+       beam_p_->set_grouping(*rg_c_l, *current_grouping);
+       typeset_element(beam_p_);
+       delete current_grouping;
+       current_grouping = 0;
+       beam_p_ = 0;
+    }
+    end_beam_b_ = false;
+}
+void
+Stem_beam_register::post_move_processing()
+{
+    stem_p_ = 0;
+    beam_req_l_ = 0;
+    stem_req_l_ = 0;
+    end_beam_b_ = false;
+}
+
+Stem_beam_register::~Stem_beam_register()
+{
+    if (beam_p_)
+       warning("unterminated beam", start_req_l_->defined_ch_c_l_);
+}
+
+void
+Stem_beam_register::set_feature(Features i)
+{
+    default_dir_i_ = i.direction_i_;
+}
index b3b8624ef06b1aa3b4d159e4c7ab4c56d17a9231..0f581474c3f1b7f8747f9b999d21f52c4d4364e9 100644 (file)
@@ -8,10 +8,11 @@
 
 #include "symbol.hh"
 #include "voice.hh"
+#include "voice-element.hh"
 #include "musicalrequest.hh"
 #include "staff.hh"
-#include "scorecolumn.hh"
-#include "staffcolumn.hh"
+#include "score-column.hh"
+#include "staff-column.hh"
 #include "spanner.hh"
 #include "plist.tcc"
 #include "pcursor.tcc"
index 185c1850763ff37d6c2af81dc43380b40ac24ff0..7df0ef372bcb373b8ac6d42eec74285110bfad76 100644 (file)
@@ -1,10 +1,10 @@
 #include "request.hh"
-#include "inputscore.hh"
-#include "inputstaff.hh"
-#include "inputmusic.hh"
+#include "input-score.hh"
+#include "input-staff.hh"
+#include "input-music.hh"
 #include "molecule.hh"
-#include "sourcefile.hh"
-
+#include "source-file.hh"
+#include "voice-element.hh"
 #include "plist.tcc"
 #include "pcursor.tcc"
 
index e85062003e9b38e7467755adcff5feeec883bff7..0401c8cd938ff9c135381455f165426db01403cc 100644 (file)
@@ -1,8 +1,8 @@
 #include "proto.hh"
 #include "plist.tcc"
 #include "register.hh"
-#include "voicegroupregs.hh"
-#include "voiceregs.hh"
+#include "voice-group-regs.hh"
+#include "voice-regs.hh"
 
 
 IPL_instantiate(Voice_registers);
diff --git a/src/tex-stream.cc b/src/tex-stream.cc
new file mode 100644 (file)
index 0000000..5722599
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+  tex-stream.cc -- implement Tex_stream
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include <fstream.h>
+#include <time.h>
+
+#include "tex.hh"
+#include "main.hh"
+#include "tex-stream.hh"
+#include "debug.hh"
+
+Tex_stream::Tex_stream(String filename) 
+{
+    os = new ofstream(filename);
+    if (!*os)
+       error("can't open `" + filename+"\'");
+    nest_level = 0;
+    outputting_comment=false;
+    header();
+}
+void
+Tex_stream::header()
+{
+    *os << "% Creator: " << get_version();
+    *os << "% Automatically generated, at ";
+    time_t t(time(0));
+    *os << ctime(&t);
+}
+Tex_stream::~Tex_stream()
+{
+    delete os;
+    assert(nest_level == 0);
+}
+
+// print string. don't forget indent.
+Tex_stream &
+Tex_stream::operator<<(String s)
+{
+    
+    for (const char *cp = s; *cp; cp++) {
+       if (outputting_comment) {
+           *os << *cp;
+           if (*cp == '\n') {
+               outputting_comment=false;
+
+           }
+           continue;
+       }
+       switch(*cp) 
+           {
+           case '%':
+               outputting_comment = true;
+               *os << *cp;
+               break;
+           case '{':
+               nest_level++;
+               *os << *cp;             
+               break;
+           case '}':
+               nest_level--;           
+               *os << *cp;
+               
+               if (nest_level < 0) {
+                   delete os;  // we want to see the remains.
+                   assert(nest_level>=0);
+               }
+               /* FALLTHROUGH */
+               
+           case '\n':
+               *os << "%\n";
+               *os << String(' ', nest_level);
+               break;        
+           default:
+               *os << *cp;
+               break;
+           }
+    }
+    return *this;
+}
+
+
+/* *************************************************************** */
index d7f1162d29bb2a871a209acc904eb89b83f77887..e8349e63cc290de1f0cc4627c7fc6d20ccc5ee2e 100644 (file)
@@ -15,8 +15,9 @@ static void
 substitute_arg(String& r, String arg)
 {
     int p = r.index_i('%');
-    if (!p ) return ;
-    else p--;
+    if (p < 0)
+       return ;
+
     r = r.left_str(p) + arg + r.right_str(r.length_i() - p -1);
 }
 
@@ -27,10 +28,11 @@ substitute_args(String source, Array<String> args)
     String retval (source);
     for (int i = 0 ; i < args.size(); i++)
         substitute_arg(retval, args[i]);
-    while (retval.index_i('%'))
+    while (retval.index_i('%') >= 0)
         substitute_arg(retval, "");
     return retval;
 }
+
 String
 substitute_args(String source, Array<Scalar> args)    
 {
diff --git a/src/text-reg.cc b/src/text-reg.cc
new file mode 100644 (file)
index 0000000..5232549
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+  text-reg.cc -- implement Text_register
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "text-reg.hh"
+#include "textitem.hh"
+
+Text_register::Text_register()
+{
+    text_p_ = 0;
+    set_feature(Features::dir(0));
+    post_move_processing();
+}
+
+bool
+Text_register::try_request(Request*req_l)
+{
+    if (!req_l->text())
+       return false;
+    if (text_req_l_ &&
+       Text_req::compare(*req_l->text(), *text_req_l_))
+
+       return false;
+
+    text_req_l_ = req_l->text();
+    return true;
+}
+
+void
+Text_register::process_requests()
+{
+    
+    if (text_req_l_) {
+       text_p_ = new Text_item(text_req_l_, 10); // UGH
+       announce_element(Staff_elem_info(text_p_, text_req_l_));
+    }
+}
+void
+Text_register::pre_move_processing()
+{
+    if (text_p_) {
+       text_p_->dir_i_ = dir_i_;
+       typeset_element(text_p_);
+       text_p_ = 0;
+    }
+}
+void
+Text_register::set_feature(Features i)
+{
+    dir_i_ = i.direction_i_;
+}
+void
+Text_register::post_move_processing()
+{
+    text_req_l_ = 0;
+}
diff --git a/src/time-description.cc b/src/time-description.cc
new file mode 100644 (file)
index 0000000..a7b04ba
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+  time-description.cc -- implement Time_description
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "time-description.hh"
+#include "debug.hh"
+
+String
+Time_description::str()const
+{
+    String s( "Time_description { ");
+    if (cadenza_b_)
+       s+=String( " (cadenza) ");
+    s+= "at ";
+    s+=when_;
+    s+="\nmeter " + String(whole_per_measure_/one_beat_) +":" +
+       String(Rational(Rational(1)/one_beat_));
+    s+= "\nposition "+String( bars_i_) + ":"+ whole_in_measure_ +"\n}\n";
+    return s;
+}
+
+void
+Time_description::print() const
+{
+#ifndef NPRINT
+    mtor << str();
+#endif
+}
+void
+Time_description::OK() const
+{
+#ifndef NDEBUG
+    if (!cadenza_b_)
+       assert(whole_in_measure_ < whole_per_measure_);
+    assert(0 <= whole_in_measure_);
+    assert(one_beat_);
+#endif
+}
+
+void
+Time_description::set_cadenza(bool b)
+{
+    if (cadenza_b_ && !b) {
+       if (whole_in_measure_) {
+           bars_i_ ++;
+           whole_in_measure_ = 0;
+       }
+    }
+    cadenza_b_ = b ;
+}
+
+Time_description::Time_description()
+{
+    whole_per_measure_ = 1;
+    whole_in_measure_ =0;
+    one_beat_ = Moment(1,4);
+    when_ = 0;
+    bars_i_ = 0;
+    cadenza_b_ = false;
+}
+
+void
+Time_description::add(Moment dt)
+{
+    assert(dt >= Rational(0));
+    when_ +=  dt;
+    whole_in_measure_ += dt;
+       
+    while ( !cadenza_b_ && whole_in_measure_ >= whole_per_measure_ ) {
+       whole_in_measure_ -= whole_per_measure_;
+       bars_i_ ++;
+    }
+}
+
+void
+Time_description::set_meter(int l, int o)
+{
+    assert(o);
+    one_beat_ = Rational(1)/Moment(o);
+    whole_per_measure_ = Moment(l) * one_beat_;
+    if(whole_in_measure_)
+       error_t("Meterchange should be at start of measure", *this);
+}
+
+void
+Time_description::setpartial(Moment p)
+{
+    if (when_)
+       error_t ("Partial measure only allowed at beginning.", *this);
+    if (p<Rational(0)||p > whole_per_measure_)
+       error_t ("Partial measure has incorrect size", *this);
+    whole_in_measure_ = whole_per_measure_ - p;
+}
+
+Moment
+Time_description::barleft()
+{
+    assert(!cadenza_b_);
+    return whole_per_measure_-whole_in_measure_;
+}
+
+int
+Time_description::compare(Time_description &t1, Time_description&t2)
+{
+    int i = sign(t1.when_-t2.when_);
+
+    if (!i) {
+       assert(t1.bars_i_==t2.bars_i_);
+       assert(t1.one_beat_ == t2.one_beat_);
+       assert(t1.whole_in_measure_ == t2.whole_in_measure_);
+       assert(t1.whole_per_measure_ == t2.whole_per_measure_);
+    }
+
+    return i;
+}
index b57c6d2bdceda2f9dec0d93d088c485504bc2be2..b1a03579429bd96295a9096f368878f07ef697c3 100644 (file)
@@ -1,10 +1,10 @@
 #include "debug.hh"
 #include "lexer.hh"
 #include "moment.hh"
-#include "timedescription.hh"
+#include "time-description.hh"
 #include "proto.hh"
 #include "plist.hh"
-#include "sourcefile.hh"
+#include "source-file.hh"
 #include "source.hh"
 #include "main.hh"