X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fclef-engraver.cc;h=00c345771728f4e46a06ed75ce08c023b0740f1c;hb=53da8b7d3773da804e79fd455d168efd9475d2f9;hp=0e0c79cc84ecd06f0953cf1c2496af2fb1a77049;hpb=862cb234ae538fec06672800f2bd776afc50e6a8;p=lilypond.git diff --git a/lily/clef-engraver.cc b/lily/clef-engraver.cc index 0e0c79cc84..00c3457717 100644 --- a/lily/clef-engraver.cc +++ b/lily/clef-engraver.cc @@ -1,252 +1,221 @@ /* - clef.cc -- implement Clef_engraver + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 1997--2012 Han-Wen Nienhuys + Mats Bengtsson - (c) 1997--1999 Han-Wen Nienhuys , + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - Mats Bengtsson + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ -#include -#include "bar.hh" -#include "clef-engraver.hh" -#include "clef-item.hh" -#include "debug.hh" -#include "command-request.hh" -#include "time-description.hh" -#include "note-head.hh" -#include "key-item.hh" -#include "local-key-item.hh" - -Clef_engraver::Clef_engraver() -{ - clef_p_ = 0; - clef_req_l_ = 0; - clef_type_str_ = ""; - c0_position_i_ = 0; - clef_position_i_ = 0; - octave_dir_ = CENTER; -} +#include +using namespace std; -/* - PUT THIS IN GUILE! - */ -struct Clef_settings { - char const *name; - char const *cleftype; - int position; -} clef_settings[] = { - {"treble", "treble", -2}, - {"violin", "treble", -2}, - {"G", "treble", -2}, - {"G2", "treble", -2}, - {"french", "treble",-4 }, - {"soprano", "alto",-4 }, - {"mezzosoprano", "alto",-2 }, - {"alto", "alto",0 }, - {"tenor", "alto",2 }, - {"baritone", "alto",4 }, - {"varbaritone", "bass",0 }, - {"bass" , "bass",2 }, - {"F", "bass", 2}, - {"subbass", "bass",4}, - {0,0,0} -}; +#include "item.hh" +#include "context.hh" +#include "staff-symbol-referencer.hh" +#include "engraver.hh" +#include "direction.hh" +#include "side-position-interface.hh" -bool -Clef_engraver::set_type (String s) -{ - if (s.right_str(2) == "_8") // Down one octave - { - octave_dir_ = DOWN; - s = s.left_str(s.length_i() - 2); - } - else if (s.right_str(2) == "^8") // Up one octave - { - octave_dir_ = UP; - s = s.left_str(s.length_i() - 2); - } - else - octave_dir_ = CENTER; +#include "translator.icc" - bool found = 0; - for (Clef_settings *c = clef_settings; !found && c->name; c++) - { - if (c->name == s) - { - clef_type_str_ = c->cleftype; - clef_position_i_ = c->position; - found = 1; - } - } - - if (!found) - { - switch(toupper (s[0])) - { - case 'F': - clef_type_str_ = "bass"; - break; - case 'G': - clef_type_str_ = "treble"; - break; - case 'C': - clef_type_str_ = "alto"; - break; - default: - return false; - } - clef_position_i_ = 2 * (s[1] - '0') - 6; - } +class Clef_engraver : public Engraver +{ +public: + TRANSLATOR_DECLARATIONS (Clef_engraver); + +protected: + void stop_translation_timestep (); + void process_music (); + DECLARE_ACKNOWLEDGER (bar_line); + + virtual void derived_mark () const; +private: + Item *clef_; + Item *octavate_; + + SCM prev_glyph_; + SCM prev_cpos_; + SCM prev_octavation_; + void create_clef (); + void set_glyph (); + void inspect_clef_properties (); +}; - if (clef_type_str_ == "treble") - c0_position_i_ = clef_position_i_ - 4; - else if (clef_type_str_ == "alto") - c0_position_i_ = clef_position_i_; - else if (clef_type_str_ == "bass") - c0_position_i_ = clef_position_i_ + 4; - else - assert (false); - - c0_position_i_ -= (int) octave_dir_ * 7; - - return true; +void +Clef_engraver::derived_mark () const +{ + scm_gc_mark (prev_octavation_); + scm_gc_mark (prev_cpos_); + scm_gc_mark (prev_glyph_); } +Clef_engraver::Clef_engraver () +{ + clef_ = 0; + octavate_ = 0; -/** - Generate a clef at the start of a measure. (when you see a Bar, - ie. a breakpoint) + /* + will trigger a clef at the start since #f != ' () */ + prev_octavation_ = prev_cpos_ = prev_glyph_ = SCM_BOOL_F; +} + void -Clef_engraver::acknowledge_element (Score_element_info info) +Clef_engraver::set_glyph () { - if (dynamic_cast(info.elem_l_) - && clef_type_str_.length_i()) - { - bool def = !clef_p_; - create_clef(); - if(def) - clef_p_->set_elt_property(visibility_lambda_scm_sym, - gh_eval_str ("postbreak_only_visibility")); - } + SCM glyph_sym = ly_symbol2scm ("glyph"); + SCM basic = ly_symbol2scm ("Clef"); - /* ugh; should make Clef_referenced baseclass */ - Item * it_l =dynamic_cast (info.elem_l_); - if (it_l) - { - if (Note_head * h = dynamic_cast(it_l)) - { - // h->position_i_ += c0_position_i_; - h->position_i_ += c0_position_i_; - } - else if (Local_key_item *i = dynamic_cast (it_l)) - { - i->c0_position_i_ =c0_position_i_; - } - else if (Key_item *k = dynamic_cast(it_l)) - { - k-> set_c_position (c0_position_i_); - } - } + execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED); + execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph")); } +/** + Generate a clef at the start of a measure. (when you see a Bar, + ie. a breakpoint) +*/ void -Clef_engraver::do_creation_processing() +Clef_engraver::acknowledge_bar_line (Grob_info info) { - create_default_b_ = true; // should read property. - Scalar def = get_property ("createInitdefaultClef", 0); - if (def.to_bool ()) // egcs: Scalar to bool is ambiguous - set_type (def); - - if (clef_type_str_.length_i ()) - { - create_clef(); - clef_p_->set_elt_property (non_default_scm_sym, SCM_BOOL_T); - } + Item *item = info.item (); + if (item && scm_is_string (get_property ("clefGlyph"))) + create_clef (); } -bool -Clef_engraver::do_try_music (Music * r_l) +void +Clef_engraver::create_clef () { - if (Clef_change_req *cl = dynamic_cast (r_l)) + if (!clef_) { - clef_req_l_ = cl; - if (!set_type (cl->clef_str_)) - cl->error (_ ("unknown clef type ")); + Item *c = make_item ("Clef", SCM_EOL); - return true; - } - else - return false; + clef_ = c; + SCM cpos = get_property ("clefPosition"); -} + if (scm_is_number (cpos)) + clef_->set_property ("staff-position", cpos); + + SCM oct = get_property ("clefOctavation"); + if (scm_is_number (oct) && scm_to_int (oct)) + { + Item *g = make_item ("OctavateEight", SCM_EOL); + + int abs_oct = scm_to_int (oct); + int dir = sign (abs_oct); + abs_oct = abs (abs_oct) + 1; + + SCM txt = scm_number_to_string (scm_from_int (abs_oct), + scm_from_int (10)); + g->set_property ("text", + scm_list_n (ly_lily_module_constant ("vcenter-markup"), + txt, SCM_UNDEFINED)); + Side_position_interface::add_support (g, clef_); + + g->set_parent (clef_, Y_AXIS); + g->set_parent (clef_, X_AXIS); + g->set_property ("direction", scm_from_int (dir)); + octavate_ = g; + } + } +} void -Clef_engraver::create_clef() +Clef_engraver::process_music () { - if (!clef_p_) - { - Clef_item *c= new Clef_item; - c->set_elt_property (break_priority_scm_sym, gh_int2scm (-2)); // ugh - String clefstyle = get_property ("clefStyle", 0); - if (clefstyle.length_i ()) - c->set_elt_property (style_scm_sym, - gh_str02scm (clefstyle.ch_C())); - - announce_element (Score_element_info (c, clef_req_l_)); - clef_p_ = c; - } - - clef_p_->symbol_ = clef_type_str_; - clef_p_->y_position_i_ = clef_position_i_; - if (octave_dir_) - { - clef_p_->set_elt_property (octave_dir_scm_sym, gh_int2scm (octave_dir_)); - } + inspect_clef_properties (); } +static void apply_on_children (Context *context, SCM fun) +{ + scm_call_1 (fun, context->self_scm ()); + for (SCM s = context->children_contexts (); + scm_is_pair (s); s = scm_cdr (s)) + apply_on_children (unsmob_context (scm_car (s)), fun); +} void -Clef_engraver::do_process_requests() +Clef_engraver::inspect_clef_properties () { - if (clef_req_l_) - { - create_clef(); - } - else if (create_default_b_) + SCM glyph = get_property ("clefGlyph"); + SCM clefpos = get_property ("clefPosition"); + SCM octavation = get_property ("clefOctavation"); + SCM force_clef = get_property ("forceClef"); + + if (clefpos == SCM_EOL + || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F + || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F + || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F + || to_boolean (force_clef)) { - String type = get_property ("defaultClef", 0); - set_type (type.length_i () ? type : "treble"); - create_clef (); - create_default_b_ =0; + apply_on_children (context (), + ly_lily_module_constant ("invalidate-alterations")); + + set_glyph (); + if (prev_cpos_ != SCM_BOOL_F || to_boolean (get_property ("firstClef"))) + create_clef (); + + if (clef_) + clef_->set_property ("non-default", SCM_BOOL_T); + + prev_cpos_ = clefpos; + prev_glyph_ = glyph; + prev_octavation_ = octavation; } -} -void -Clef_engraver::do_pre_move_processing() -{ - if (clef_p_) + if (to_boolean (force_clef)) { - typeset_element (clef_p_); - clef_p_ =0; + SCM prev; + Context *w = context ()->where_defined (ly_symbol2scm ("forceClef"), &prev); + w->set_property ("forceClef", SCM_EOL); } - create_default_b_ = false; } void -Clef_engraver::do_post_move_processing() +Clef_engraver::stop_translation_timestep () { - clef_req_l_ = 0; -} + if (clef_) + { + SCM vis = 0; + if (to_boolean (clef_->get_property ("non-default"))) + vis = get_property ("explicitClefVisibility"); -void -Clef_engraver::do_removal_processing() -{ - assert (!clef_p_); -} + if (vis) + clef_->set_property ("break-visibility", vis); + clef_ = 0; + octavate_ = 0; + } +} -ADD_THIS_TRANSLATOR(Clef_engraver); +ADD_ACKNOWLEDGER (Clef_engraver, bar_line); +ADD_TRANSLATOR (Clef_engraver, + /* doc */ + "Determine and set reference point for pitches.", + + /* create */ + "Clef " + "OctavateEight ", + + /* read */ + "clefGlyph " + "clefOctavation " + "clefPosition " + "explicitClefVisibility " + "forceClef ", + + /* write */ + "" + );