From aa898047c517a5e438228a57c8e7cb6f708f9041 Mon Sep 17 00:00:00 2001 From: fred Date: Wed, 27 Mar 2002 02:02:53 +0000 Subject: [PATCH] lilypond-1.5.10 --- aclocal.m4 | 2 +- flower/include/rational.hh | 8 ++- input/test/figured-bass.ly | 54 +++++++------- lily/beam.cc | 2 +- lily/engraver.cc | 4 +- lily/figured-bass-engraver.cc | 104 +++++++++++++++++++++++++++ lily/grob.cc | 2 + lily/include/main.hh | 1 + lily/include/my-lily-lexer.hh | 3 +- lily/include/untransposable-music.hh | 26 +++++++ lily/lexer.ll | 48 +++++++++---- lily/musical-request.cc | 11 ++- lily/my-lily-lexer.cc | 4 +- lily/parser.yy | 92 ++++++++++++++++++++++-- lily/score.cc | 22 ++++-- lily/untransposable-music.cc | 28 ++++++++ lily/volta-engraver.cc | 2 - ly/engraver-init.ly | 10 +++ stepmake/aclocal.m4 | 2 +- 19 files changed, 357 insertions(+), 68 deletions(-) create mode 100644 lily/figured-bass-engraver.cc create mode 100644 lily/include/untransposable-music.hh create mode 100644 lily/untransposable-music.cc diff --git a/aclocal.m4 b/aclocal.m4 index 720f2db629..fd2b360a3a 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -717,7 +717,7 @@ AC_DEFUN(AC_STEPMAKE_TEXMF, [ # # For now let people define these in their environments # - : ${MFPLAIN_MP=`kpsewhich mp mfplain.mp`} + : ${MFPLAIN_MP=`kpsewhich --format mp mfplain.mp`} AC_MSG_RESULT($MFPLAIN_MP) AC_MSG_CHECKING(for inimetapost flags) diff --git a/flower/include/rational.hh b/flower/include/rational.hh index ab4a3d41cf..995700c55c 100644 --- a/flower/include/rational.hh +++ b/flower/include/rational.hh @@ -35,7 +35,10 @@ class Rational { public: void set_infinite (int sign); - bool infty_b () const; + bool infty_b () const + { + return sign_ == 2 || sign_ == -2; + } void invert (); int num () const { return sign_ * num_; } int den () const { return den_; } @@ -52,7 +55,8 @@ public: Initialize to 0. */ Rational (); - Rational (int, int =1); + Rational (int); + Rational (int, int); Rational (double); Rational (Rational const&r) { copy (r);} diff --git a/input/test/figured-bass.ly b/input/test/figured-bass.ly index 102c7f90b6..9c6b0300be 100644 --- a/input/test/figured-bass.ly +++ b/input/test/figured-bass.ly @@ -1,27 +1,29 @@ -\version "1.3.146" -% Example of figured bass, using text scripts. -% (An alternative is to use a lyrics line if you want the figures -% aligned vertically.) - - - -% Scheme macros for accidentals. Note how they can be combined -% with other strings, for example in: d^#`(columns ,sharp "4") - -#(define sharp '((raise . 0.2) (music (named "accidentals-1")))) -#(define natural '((raise . 0.2) (music (named "accidentals-0")))) -#(define flat '((raise . 0.2) (music (named "accidentals--1")))) - - -\score{ - \notes \relative c'{ - \clef bass - - c^"5" d^#natural g,^"7 6" [a8 e] | - fis4^"7 6" [g8 d] e4^"7 6" [f?8 c] | - [d^#sharp d b g][c^"7" c^"5" a^"6" f] | - [bes^"7" bes^"5" g^"6" e] a4^#sharp d^"6" ~ | - d^#`(columns ,sharp "4") c^"6" d e^#sharp | +\header { +texidoc = "Test figured bass. + +Figured bass is created by the FiguredBass context which eats +note-requests and rest-requests. You can enter these either using +standard @code{< >} notation, or using the special @code{\figures { }} +mode, which allows you to type numbers, like @code{<4 6+>}. + +" } + +\score { \notes < +\context FiguredBass \transpose c'' { + + + \figures { + r + <1 3 5>4 <3- 5+ 6!> <5> + } + } + \context Voice { + c + g8 g + f4 + d + c } -} - + +> + } diff --git a/lily/beam.cc b/lily/beam.cc index 48c81d14cf..df1bf65ffa 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -761,7 +761,7 @@ Beam::set_beaming (Grob*me,Beaming_info_list *beaming) */ Molecule Beam::stem_beams (Grob*me,Item *here, Item *next, Item *prev, - Real dy, Real dydx + Real /* dy */ , Real dydx ) { // ugh -> use commonx diff --git a/lily/engraver.cc b/lily/engraver.cc index 02e683b055..9059624ce6 100644 --- a/lily/engraver.cc +++ b/lily/engraver.cc @@ -10,6 +10,7 @@ #include "engraver.hh" #include "engraver-group-engraver.hh" #include "grob.hh" +#include "main.hh" void @@ -21,7 +22,8 @@ Engraver::announce_grob (Grob_info inf) void Engraver::announce_grob (Grob* e, Music *m) { - if (m && m->origin ()->location_str ().length_i ()) + if (m && store_locations_global_b + && m->origin ()->location_str ().length_i ()) { e->set_grob_property ("origin", m->get_mus_property ("origin")); } diff --git a/lily/figured-bass-engraver.cc b/lily/figured-bass-engraver.cc new file mode 100644 index 0000000000..87894fcdd5 --- /dev/null +++ b/lily/figured-bass-engraver.cc @@ -0,0 +1,104 @@ +#include "engraver.hh" +#include "text-item.hh" +#include "musical-request.hh" +#include "item.hh" + +class Figured_bass_engraver : public Engraver +{ +public: + VIRTUAL_COPY_CONS(Translator); + Figured_bass_engraver(); + +protected: + Link_array figures_; + Rest_req * rest_req_; + + Grob * figure_; + + virtual bool try_music (Music*); + virtual void stop_translation_timestep (); + virtual void process_music (); +}; + + +Figured_bass_engraver::Figured_bass_engraver() +{ + figure_ = 0; + rest_req_ = 0; +} + +void +Figured_bass_engraver::stop_translation_timestep () +{ + if (figure_) + { + typeset_grob (figure_); + figure_ =00; + } + + figures_.clear (); +} + +bool +Figured_bass_engraver::try_music (Music*m) +{ + if (Note_req* n = dynamic_cast (m)) + { + figures_.push (n); + return true; + } + else if (Rest_req * r = dynamic_cast (m)) + { + rest_req_ = r; + return true; + } + return false; +} + +void +Figured_bass_engraver::process_music () +{ + if (rest_req_) + { + figure_ = new Item (get_property ("BassFigure")); + announce_grob (figure_, rest_req_); // todo + figure_->set_grob_property ("text" , gh_str02scm ("-")); + } + else if (figures_.size ()) + { + figure_ = new Item (get_property ("BassFigure")); + announce_grob (figure_, figures_[0]); // todo + SCM flist = SCM_EOL; + for (int i = 0; i < figures_.size (); i++) + { + Note_req * n = figures_[i]; + Pitch *p = unsmob_pitch (n->get_mus_property ("pitch")); + + String fstr = to_str (p->steps ()+ 1); + + SCM one_fig = ly_str02scm(fstr.ch_C ()); + + if (p->alteration_i_ || to_boolean (n->get_mus_property ("force-accidental") )) + { + SCM alter = scm_assoc (gh_int2scm (p->alteration_i_), + figure_->get_grob_property ("accidental-alist")); + if (gh_pair_p (alter)) + { + one_fig = gh_list (ly_symbol2scm ("columns"), + one_fig, + gh_cdr(alter), + SCM_UNDEFINED); + } + } + + flist = gh_cons (one_fig, flist); + } + + flist = gh_cons (ly_symbol2scm ("lines"), flist); + + figure_-> set_grob_property ("text", flist); + } +} + + +ADD_THIS_TRANSLATOR(Figured_bass_engraver); diff --git a/lily/grob.cc b/lily/grob.cc index 0f233e6136..c5cfcbe174 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -351,6 +351,8 @@ Grob::add_dependency (Grob*e) Do break substitution in S, using CRITERION. Return new value. CRITERION is either a SMOB pointer to the desired line, or a number representing the break direction. Do not modify SRC. + + It is rather tightly coded, since it takes a lot of time. */ SCM Grob::handle_broken_grobs (SCM src, SCM criterion) diff --git a/lily/include/main.hh b/lily/include/main.hh index 12d63619c8..7d2f90174f 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -30,6 +30,7 @@ extern String output_format_global; extern String output_name_global; extern bool safe_global_b; extern bool verbose_global_b; +extern bool store_locations_global_b; /* misc */ extern All_font_metrics *all_fonts_global_p; diff --git a/lily/include/my-lily-lexer.hh b/lily/include/my-lily-lexer.hh index a0f6901b1b..2c3d405952 100644 --- a/lily/include/my-lily-lexer.hh +++ b/lily/include/my-lily-lexer.hh @@ -56,6 +56,7 @@ public: SCM lookup_identifier (String s); void push_note_state (); + void push_figuredbass_state (); void push_chord_state (); void push_lyric_state (); void pop_state (); @@ -64,7 +65,7 @@ public: bool note_state_b () const; bool chord_state_b () const; bool lyric_state_b () const; - + bool figure_state_b () const; private: int lookup_keyword (String); int scan_bare_word (String); diff --git a/lily/include/untransposable-music.hh b/lily/include/untransposable-music.hh new file mode 100644 index 0000000000..4f99e41322 --- /dev/null +++ b/lily/include/untransposable-music.hh @@ -0,0 +1,26 @@ + +/* +untransposable-music.hh -- declare + +source file of the GNU LilyPond music typesetter + +(c) 2001 Han-Wen Nienhuys + + */ + +#ifndef UNTRANSPOSABLE_MUSIC_HH +#define UNTRANSPOSABLE_MUSIC_HH +#include "music-wrapper.hh" + +class Untransposable_music : public Music_wrapper +{ +public: + Untransposable_music (); + virtual Pitch to_relative_octave (Pitch); + virtual void transpose (Pitch); + VIRTUAL_COPY_CONS(Music); +}; + + +#endif /* UNTRANSPOSABLE_MUSIC_HH */ + diff --git a/lily/lexer.ll b/lily/lexer.ll index a875cea59e..2bbf7c564c 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -93,6 +93,7 @@ SCM scan_fraction (String); %x incl %x lyrics %x notes +%x figures %x quote %x longcomment @@ -129,7 +130,7 @@ HYPHEN -- // windows-suck-suck-suck } -{ +{ "%{" { yy_push_state (longcomment); } @@ -146,7 +147,7 @@ HYPHEN -- } } -\\version{WHITE}* { +\\version{WHITE}* { yy_push_state (version); } \"[^"]*\" { /* got the version number */ @@ -178,7 +179,7 @@ HYPHEN -- } -\\maininput { +\\maininput { if (!main_input_b_) { start_main_input (); @@ -188,7 +189,7 @@ HYPHEN -- error (_ ("\\maininput disallowed outside init files")); } -\\include { +\\include { yy_push_state (incl); } \"[^"]*\";? { /* got the include file name */ @@ -221,34 +222,34 @@ HYPHEN -- cerr << _ ("Missing end quote") << endl; exit (1); } -{RESTNAME} { +{RESTNAME} { const char *s = YYText (); yylval.scm = ly_str02scm (s); return RESTNAME; } -R { +R { return MULTI_MEASURE_REST; } -\\\${BLACK}*{WHITE} { +\\\${BLACK}*{WHITE} { String s=YYText () + 2; s=s.left_str (s.length_i () - 1); return scan_escaped_word (s); } -\${BLACK}*{WHITE} { +\${BLACK}*{WHITE} { String s=YYText () + 1; s=s.left_str (s.length_i () - 1); return scan_bare_word (s); } -\\\${BLACK}* { // backup rule +\\\${BLACK}* { // backup rule cerr << _ ("white expected") << endl; exit (1); } -\${BLACK}* { // backup rule +\${BLACK}* { // backup rule cerr << _ ("white expected") << endl; exit (1); } -# { //embedded scm +# { //embedded scm //char const* s = YYText () + 1; char const* s = here_ch_C (); int n = 0; @@ -267,7 +268,15 @@ HYPHEN -- return SCM_T; } -{ +{ + \> { + return FIGURE_CLOSE; + } + \< { + return FIGURE_OPEN; + } +} +{ {ALPHAWORD} { return scan_bare_word (YYText ()); } @@ -430,11 +439,11 @@ HYPHEN -- return c; } -. { +. { return YYText ()[0]; } -\\. { +\\. { char c= YYText ()[1]; switch (c) { @@ -467,6 +476,11 @@ My_lily_lexer::push_note_state () yy_push_state (notes); } +void +My_lily_lexer::push_figuredbass_state() +{ + yy_push_state (figures); +} void My_lily_lexer::push_chord_state () { @@ -581,6 +595,12 @@ My_lily_lexer::lyric_state_b () const return YY_START == lyrics; } +bool +My_lily_lexer::figure_state_b () const +{ + return YY_START == figures; +} + /* urg, belong to String (_convert) and should be generalised diff --git a/lily/musical-request.cc b/lily/musical-request.cc index ae24d23a2e..7ed6f00438 100644 --- a/lily/musical-request.cc +++ b/lily/musical-request.cc @@ -52,16 +52,16 @@ Rhythmic_req::do_equal_b (Request const* r) const Moment Rhythmic_req::length_mom () const { - return unsmob_duration (get_mus_property ("duration"))->length_mom (); - + Duration* d = unsmob_duration (get_mus_property ("duration")); + return d ? d->length_mom () : Moment (0); } void Rhythmic_req::compress (Moment m) { Duration *d = unsmob_duration (get_mus_property ("duration")); - - set_mus_property ("duration", d ->compressed (m.main_part_).smobbed_copy ()); + if (d) + set_mus_property ("duration", d ->compressed (m.main_part_).smobbed_copy ()); } bool @@ -109,6 +109,3 @@ Articulation_req::do_equal_b (Request const* r) const - - - diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 9c07514277..54feff2251 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -50,9 +50,8 @@ static Keyword_ent the_key_tab[]={ {"duration", DURATION}, {"dynamicscript", DYNAMICSCRIPT}, {"elementdescriptions", ELEMENTDESCRIPTIONS}, - {"font", FONT}, + {"figures",FIGURES}, {"grace", GRACE}, - {"ngrace", NGRACE}, {"glissando", GLISSANDO}, {"header", HEADER}, {"in", IN_T}, @@ -81,6 +80,7 @@ static Keyword_ent the_key_tab[]={ {"repeat", REPEAT}, {"addlyrics", ADDLYRICS}, {"partcombine", PARTCOMBINE}, + {"porrectus", PORRECTUS}, {"score", SCORE}, {"script", SCRIPT}, {"stylesheet", STYLESHEET}, diff --git a/lily/parser.yy b/lily/parser.yy index c732454e53..c0a6061ddf 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -15,6 +15,14 @@ - */ +/* + +the rules for who is protecting what are very shady. TODO: uniformise +this. + + +*/ + #include #include @@ -45,7 +53,7 @@ #include "transposed-music.hh" #include "time-scaled-music.hh" #include "repeated-music.hh" - +#include "untransposable-music.hh" #include "lilypond-input-version.hh" #include "grace-music.hh" #include "part-combine-music.hh" @@ -186,9 +194,9 @@ yylex (YYSTYPE *s, void * v_l) %token DENIES %token DURATION %token EXTENDER -%token FONT +%token FIGURES FIGURE_OPEN FIGURE_CLOSE %token GLISSANDO -%token GRACE NGRACE +%token GRACE %token HEADER %token HYPHEN %token IN_T @@ -207,6 +215,7 @@ yylex (YYSTYPE *s, void * v_l) %token PAPER %token PARTIAL %token PENALTY +%token PORRECTUS %token PROPERTY %token OVERRIDE SET REVERT %token PT_T @@ -237,6 +246,8 @@ yylex (YYSTYPE *s, void * v_l) %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET %type exclamations questions dots +%type bass_number bass_mod +%type bass_figure figure_list figure_spec %token DIGIT %token NOTENAME_PITCH %token TONICNAME_PITCH @@ -912,6 +923,16 @@ Composite_music: { $$ = $3; THIS->lexer_p_->pop_state (); } + | FIGURES + { THIS->lexer_p_->push_figuredbass_state (); } + Music + { + Music * chm = new Untransposable_music () ; + chm->set_mus_property ("element", $3->self_scm ()); + $$ = chm; + + THIS->lexer_p_->pop_state (); + } | CHORDS { THIS->lexer_p_->push_chord_state (); } Music @@ -1215,6 +1236,9 @@ shorthand_command_req: | BREATHE { $$ = new Breathing_sign_req; } + | PORRECTUS { + $$ = new Porrectus_req; + } ; @@ -1674,6 +1698,56 @@ tremolo_type: ; +bass_number: + DIGIT + | UNSIGNED + ; + +bass_mod: + '-' { $$ = -1; } + | '+' { $$ = 1; } + | '!' { $$ = 0; } + ; + +bass_figure: + bass_number { + Pitch p ; + p .notename_i_ = $1 - 1; + p.normalise(); + + Note_req * nr = new Note_req; + $$ = nr->self_scm (); + nr->set_mus_property ("pitch", p.smobbed_copy ()); + scm_unprotect_object ($$); + } + | bass_figure bass_mod { + if ($2) { + SCM sp = unsmob_music ($1)->get_mus_property ("pitch"); + unsmob_pitch (sp)->alteration_i_ += $2; + } else { + unsmob_music ($1)->set_mus_property ("force-accidental", SCM_BOOL_T); + } + } + ; + +figure_list: + /**/ { + $$ = SCM_EOL; + } + | figure_list bass_figure { + $$ = gh_cons ($2, $1); + } + ; + +figure_spec: + FIGURE_OPEN figure_list FIGURE_CLOSE { + Music * m = new Request_chord (SCM_EOL); + $2 = scm_reverse_x ($2, SCM_EOL); + m->set_mus_property ("elements", $2); + $$ = m->self_scm (); + } + ; + simple_element: pitch exclamations questions optional_notemode_duration { @@ -1698,7 +1772,17 @@ simple_element: n->set_spot (i); $$ = v; } - | RESTNAME optional_notemode_duration { + | figure_spec optional_notemode_duration { + Music * m = unsmob_music ($1); + Input i = THIS->pop_spot (); + m->set_spot (i); + for (SCM s = m->get_mus_property ("elements"); gh_pair_p (s); s = gh_cdr (s)) + { + unsmob_music (gh_car (s))->set_mus_property ("duration", $2); + } + $$ = m; + } + | RESTNAME optional_notemode_duration { Input i = THIS->pop_spot (); SCM e = SCM_UNDEFINED; diff --git a/lily/score.cc b/lily/score.cc index ae6cf4173d..9ab1dbe428 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -35,13 +35,24 @@ Score::Score () smobify_self (); } +/* + store point & click locations. + Global to save some time. (Sue us!) + */ +bool store_locations_global_b; + Score::Score (Score const &s) : Input (s) { music_ = SCM_EOL; header_p_ = 0; smobify_self (); - + + /* + TODO: this is not very elegant.... + */ + store_locations_global_b = (gh_eval_str ("point-and-click") != SCM_BOOL_F); + Music * m =unsmob_music (s.music_); music_ = m?m->clone ()->self_scm () : SCM_EOL; scm_gc_unprotect_object (music_); @@ -50,12 +61,11 @@ Score::Score (Score const &s) def_p_arr_.push (s.def_p_arr_[i]->clone ()); errorlevel_i_ = s.errorlevel_i_; if (s.header_p_) - { - header_p_ = (s.header_p_) ? new Scheme_hash_table (*s.header_p_): 0; + { + header_p_ = (s.header_p_) ? new Scheme_hash_table (*s.header_p_): 0; - scm_gc_unprotect_object (header_p_->self_scm ()); - } - + scm_gc_unprotect_object (header_p_->self_scm ()); + } } Score::~Score () diff --git a/lily/untransposable-music.cc b/lily/untransposable-music.cc new file mode 100644 index 0000000000..d04127f4ac --- /dev/null +++ b/lily/untransposable-music.cc @@ -0,0 +1,28 @@ +/* +untransposable-music.cc -- implement Untransposable_music + +source file of the GNU LilyPond music typesetter + +(c) 2001 Han-Wen Nienhuys + + */ + +#include "untransposable-music.hh" + +void +Untransposable_music::transpose (Pitch ) +{ +} + +Pitch +Untransposable_music::to_relative_octave (Pitch p) +{ + return p; +} + +ADD_MUSIC(Untransposable_music); + +Untransposable_music::Untransposable_music() +{ + +} diff --git a/lily/volta-engraver.cc b/lily/volta-engraver.cc index 1227a9315b..6feb88b12d 100644 --- a/lily/volta-engraver.cc +++ b/lily/volta-engraver.cc @@ -141,8 +141,6 @@ Volta_engraver::acknowledge_grob (Grob_info i) { if (volta_span_p_) Volta_spanner::add_column (volta_span_p_,item); - if (end_volta_span_p_) - Volta_spanner::add_column (end_volta_span_p_,item); } if (Bar::has_interface (item)) { diff --git a/ly/engraver-init.ly b/ly/engraver-init.ly index 9717e3c5e2..01e05e9bcf 100644 --- a/ly/engraver-init.ly +++ b/ly/engraver-init.ly @@ -149,6 +149,7 @@ VoiceContext = \translator { \consists "Phrasing_slur_engraver" \consists "Slur_engraver" \consists "Tie_engraver" + \consists "Porrectus_engraver" \consists "Tuplet_engraver" \consists "A2_engraver" @@ -221,6 +222,7 @@ StaffGroupContext = \translator { \accepts "InnerChoirStaff" \accepts "ChoirStaff" \accepts "InnerStaffGroup" + \accepts "FiguredBass" } @@ -344,6 +346,7 @@ ScoreContext = \translator { \accepts "ChoirStaff" \accepts "PianoStaff" \accepts "NoteNames" + \accepts "FiguredBass" soloText = #"Solo" soloIIText = #"Solo II" @@ -413,3 +416,10 @@ EasyNotation = \translator { GraceContext = \translator { \type "Engraver_group_engraver" } + +FiguredBassContext = \translator { + \type "Engraver_group_engraver" + \name FiguredBass + \consists "Figured_bass_engraver" + \consistsend "Axis_group_engraver" +} diff --git a/stepmake/aclocal.m4 b/stepmake/aclocal.m4 index 720f2db629..fd2b360a3a 100644 --- a/stepmake/aclocal.m4 +++ b/stepmake/aclocal.m4 @@ -717,7 +717,7 @@ AC_DEFUN(AC_STEPMAKE_TEXMF, [ # # For now let people define these in their environments # - : ${MFPLAIN_MP=`kpsewhich mp mfplain.mp`} + : ${MFPLAIN_MP=`kpsewhich --format mp mfplain.mp`} AC_MSG_RESULT($MFPLAIN_MP) AC_MSG_CHECKING(for inimetapost flags) -- 2.39.5