]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.39
authorfred <fred>
Tue, 4 Mar 1997 20:36:23 +0000 (20:36 +0000)
committerfred <fred>
Tue, 4 Mar 1997 20:36:23 +0000 (20:36 +0000)
lily/input-staff.cc [new file with mode: 0644]
lily/lyric-item.cc [new file with mode: 0644]
lily/lyric-staff.cc [new file with mode: 0644]
lily/lyric-walker.cc [new file with mode: 0644]
lily/stem-beam-reg.cc [new file with mode: 0644]
lily/text-spanner.cc [new file with mode: 0644]
lily/walk-regs.cc [new file with mode: 0644]

diff --git a/lily/input-staff.cc b/lily/input-staff.cc
new file mode 100644 (file)
index 0000000..8305a09
--- /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 "lyric-staff.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_;
+}
diff --git a/lily/lyric-item.cc b/lily/lyric-item.cc
new file mode 100644 (file)
index 0000000..c0adac7
--- /dev/null
@@ -0,0 +1,27 @@
+#include "musicalrequest.hh"
+#include "paper-def.hh"
+#include "lyric-item.hh"
+#include "stem.hh"
+#include "molecule.hh"
+#include "lookup.hh"
+#include "text-def.hh"
+#include "source-file.hh"
+#include "source.hh"
+#include "debug.hh"
+#include "main.hh"
+
+Lyric_item::Lyric_item(Lyric_req* lreq_l, int voice_count_i)
+    : Text_item(lreq_l,0)
+{
+    pos_i_ = -voice_count_i * 4 ;      // 4 fontsize dependant. TODO
+    dir_i_ = -1;
+}
+
+void
+Lyric_item::do_pre_processing()
+{
+
+    // test context-error
+    if ( tdef_l_->text_str_.index_i( "Gates" ) >=0)// :-)
+       warning( "foul word", tdef_l_->defined_ch_c_l_ );
+}
diff --git a/lily/lyric-staff.cc b/lily/lyric-staff.cc
new file mode 100644 (file)
index 0000000..8414f4e
--- /dev/null
@@ -0,0 +1,22 @@
+#include "musicalrequest.hh"
+#include "voice.hh"
+#include "staff-walker.hh"
+#include "debug.hh"
+#include "staff.hh"
+#include "lyric-staff.hh"
+#include "lyric-walker.hh"
+#include "pscore.hh"
+
+void
+Lyric_staff::set_output(PScore*pscore_l)
+{
+    pstaff_l_ = new PStaff(pscore_l);
+    pscore_l_ = pscore_l;
+    pscore_l_->add(pstaff_l_);
+}
+
+Staff_walker*
+Lyric_staff::get_walker_p()
+{
+    return new Lyric_walker(this);
+}
diff --git a/lily/lyric-walker.cc b/lily/lyric-walker.cc
new file mode 100644 (file)
index 0000000..614e258
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+  lyricwalker.cc -- implement Lyric_walker
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
+#include "musicalrequest.hh"
+#include "voice.hh"
+#include "pscore.hh"
+#include "lyric-staff.hh"
+#include "lyric-walker.hh"
+#include "debug.hh"
+#include "lyric-item.hh"
+#include "staff-column.hh"
+
+void
+Lyric_walker::process_requests()
+{
+    allow_break();
+    
+    int req_count=0;
+    for (int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++)  {
+       Lyric_req * lreq_l = ptr()->musicalreq_l_arr_[i]->lreq_l();
+       if (!lreq_l)
+           continue;
+       Item *lp = new Lyric_item(lreq_l,req_count++);
+       ptr()->typeset_musical_item( lp);
+    }
+}
+
+Lyric_walker::Lyric_walker(Lyric_staff* lstaff_l)
+    : Staff_walker(lstaff_l, lstaff_l->pstaff_l_->pscore_l_)
+{
+
+}
+
+
diff --git a/lily/stem-beam-reg.cc b/lily/stem-beam-reg.cc
new file mode 100644 (file)
index 0000000..54579d3
--- /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 "text-spanner.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_;
+}
diff --git a/lily/text-spanner.cc b/lily/text-spanner.cc
new file mode 100644 (file)
index 0000000..3f23122
--- /dev/null
@@ -0,0 +1,71 @@
+#include "molecule.hh"
+#include "boxes.hh"
+#include "text-spanner.hh"
+#include "text-def.hh"
+#include "debug.hh"
+#include "paper-def.hh"
+
+
+
+void
+Text_spanner::set_support(Directional_spanner*d)
+{
+    support = d;
+    add_dependency(d);
+}
+
+Text_spanner::Text_spanner()
+{
+    support = 0;
+}
+
+void
+Text_spanner::do_print() const
+{
+    spec.print();
+}
+
+void
+Text_spanner::do_post_processing()
+{
+    switch(spec.align_i_) {
+    case 0:
+       text_off_ = support->center() +
+           Offset(0,support->dir_i_ * paper()->internote() * 4); // todo
+       break;
+    default:
+       assert(false);
+       break;
+    }    
+}
+
+Molecule*
+Text_spanner::brew_molecule_p() const
+{
+    Atom tsym (spec.create_atom(paper()));
+    tsym.translate(text_off_);
+
+    Molecule*output = new Molecule;
+    output->add( tsym );
+    return output;
+}
+
+void
+Text_spanner::do_pre_processing()
+{
+    right = support->right;
+    left = support->left;
+    assert(left && right);
+}
+
+Interval
+Text_spanner::height()const
+{
+    return brew_molecule_p()->extent().y;
+}
+
+Spanner*
+Text_spanner::do_break_at(PCol*c1, PCol*c2)const
+{
+    return new Text_spanner(*this); // todo
+}
diff --git a/lily/walk-regs.cc b/lily/walk-regs.cc
new file mode 100644 (file)
index 0000000..0c40802
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+  walkregs.cc -- implement Walker_registers
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "debug.hh"
+#include "clef-reg.hh"
+#include "local-key-reg.hh"
+#include "key-reg.hh"
+#include "meter-reg.hh"
+#include "bar-reg.hh"
+#include "bar.hh"
+#include "walk-regs.hh"
+#include "staff-elem.hh"
+#include "staff.hh"
+#include "complex-walker.hh"
+#include "staff-column.hh"
+#include "voice-group-regs.hh"
+#include "voice-regs.hh"
+#include "commandrequest.hh"
+
+
+Walker_registers::Walker_registers(Complex_walker *w)
+{
+    walk_l_ = w;
+    add( new Bar_register);
+    add( new Clef_register);
+    add( new Key_register);
+    add( new Meter_register);
+    add( new Local_key_register);
+}
+
+void
+Walker_registers::announce_element(Staff_elem_info info)
+{
+    if (info.elem_p_->name() == Bar::static_name()) {
+       walk_l_->allow_break();
+    }
+    announce_info_arr_.push(info);
+}
+
+void
+Walker_registers::acknowledge_element(Staff_elem_info )
+{
+    assert(false);
+}
+
+void
+Walker_registers::do_announces()
+{
+    Request dummy_req;
+    for (int i = 0; i < announce_info_arr_.size(); i++){
+       Staff_elem_info info = announce_info_arr_[i];
+
+       if (!info.req_l_)
+           info.req_l_ = &dummy_req;
+       Register_group_register::acknowledge_element(info);
+    }
+    announce_info_arr_.set_size(0);
+}
+
+void
+Walker_registers::typeset_element(Staff_elem *elem_p)
+{
+    typeset_musical_item(elem_p);
+}
+
+void
+Walker_registers::typeset_musical_item(Staff_elem * elem_p)
+{
+    walk_l_->typeset_element(elem_p);
+}
+
+void
+Walker_registers::typeset_breakable_item(Item * pre_p , Item * nobreak_p,
+                                      Item * post_p)
+{
+    if (pre_p)
+       prebreak_item_p_arr_.push(pre_p);
+    if (nobreak_p)
+       nobreak_item_p_arr_.push(nobreak_p);
+    if (post_p)
+       postbreak_item_p_arr_.push(post_p);
+}
+
+void
+Walker_registers::pre_move_processing()
+{
+    // this generates all items.
+    Register_group_register::pre_move_processing();
+    walk_l_->ptr()->typeset_breakable_items(prebreak_item_p_arr_,
+                                           nobreak_item_p_arr_,
+                                           postbreak_item_p_arr_);
+}
+void
+Walker_registers::post_move_processing()
+{
+    Register_group_register::post_move_processing();
+}
+
+void
+Walker_registers::change_group(Group_change_req * greq_l,
+                              Voice_registers *voice_regs_l,
+                              Voice_group_registers * old_group)
+{
+    Voice_registers *regs_p = (old_group)
+       ? (Voice_registers*) old_group->get_register_p(voice_regs_l)
+       : new Voice_registers(greq_l->voice_l());
+    Voice_group_registers * new_group_l = get_group(greq_l->newgroup_str_);
+    new_group_l->add(regs_p);
+    
+    mtor << "processed change request";
+    print();
+}
+
+Voice_group_registers *
+Walker_registers::get_group(String id)
+{
+    for (int i=0; i < group_l_arr_.size(); i++) {
+       if (group_l_arr_[i]->group_id_str_ == id)
+           return group_l_arr_[i];
+    }
+    Voice_group_registers *group_p = new Voice_group_registers(id);
+    group_l_arr_.push(group_p);
+    add(group_p);
+    return group_p;
+}
+
+void
+Walker_registers::terminate_register(Request_register * reg)
+{
+    for (int i=0; i < group_l_arr_.size(); i++) {
+       if (group_l_arr_[i] == reg) {
+           group_l_arr_.del(i);
+           Register_group_register::terminate_register(reg);
+           return;
+       }
+    }
+    assert(false);
+}
+
+bool
+Walker_registers::try_request(Request * r)
+{
+    bool b = Register_group_register::try_request(r);
+    if (!b) {
+       Command_req * cr_l = r->command() ;
+       
+       if (cr_l && cr_l->groupchange()) {
+           change_group(cr_l->groupchange(), 0, 0);
+       } else 
+           warning("junking request: "  + String(r->name()),
+                   r->defined_ch_c_l_);
+    }
+    return b;
+}
+
+
+Staff_info
+Walker_registers::get_staff_info() return inf;
+{
+    inf.c0_position_i_ = &walk_l_->c0_position_i_;
+    inf.walk_l_ = walk_l_;
+    inf.time_c_l_ = &walk_l_->time_;
+    inf.rhythmic_c_l_ = walk_l_->default_grouping;
+}
+Paper_def*
+Walker_registers::paper()const
+{
+    return walk_l_->staff_l_->paper();
+}