X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdrum-note-engraver.cc;h=73bec0ed9f83f171ea060e9b74a7295ad4cf1c21;hb=a6a51abfd0195a3cf7d6ea095cf69808852f21ce;hp=5adc23d7ebf1a81d9debc91af82b2e70279acf39;hpb=c4c0ba811cd526f047de3f4d3c77abcc32a3e076;p=lilypond.git diff --git a/lily/drum-note-engraver.cc b/lily/drum-note-engraver.cc index 5adc23d7eb..73bec0ed9f 100644 --- a/lily/drum-note-engraver.cc +++ b/lily/drum-note-engraver.cc @@ -1,12 +1,26 @@ /* - drum-note-engraver.cc + This file is part of LilyPond, the GNU music typesetter. - (c) 1997--2006 Han-Wen Nienhuys + Copyright (C) 1997--2015 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. + + 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 using namespace std; +#include "item.hh" #include "duration.hh" #include "engraver.hh" #include "note-column.hh" @@ -21,27 +35,25 @@ using namespace std; class Drum_notes_engraver : public Engraver { - vector notes_; - vector dots_; - vector scripts_; - vector events_; + vector scripts_; + vector events_; public: TRANSLATOR_DECLARATIONS (Drum_notes_engraver); protected: void process_music (); - DECLARE_ACKNOWLEDGER (stem); - DECLARE_ACKNOWLEDGER (note_column); - DECLARE_TRANSLATOR_LISTENER (note); + void acknowledge_stem (Grob_info); + void acknowledge_note_column (Grob_info); + void listen_note (Stream_event *); void stop_translation_timestep (); }; -Drum_notes_engraver::Drum_notes_engraver () +Drum_notes_engraver::Drum_notes_engraver (Context *c) + : Engraver (c) { } -IMPLEMENT_TRANSLATOR_LISTENER (Drum_notes_engraver, note); void Drum_notes_engraver::listen_note (Stream_event *ev) { @@ -51,64 +63,44 @@ Drum_notes_engraver::listen_note (Stream_event *ev) void Drum_notes_engraver::process_music () { - SCM tab = 0; + if (events_.empty ()) + return; + + SCM tab = get_property ("drumStyleTable"); for (vsize i = 0; i < events_.size (); i++) { - if (!tab) - tab = get_property ("drumStyleTable"); - Stream_event *ev = events_[i]; Item *note = make_item ("NoteHead", ev->self_scm ()); - Duration dur = *unsmob_duration (ev->get_property ("duration")); - - note->set_property ("duration-log", scm_from_int (dur.duration_log ())); - - if (dur.dot_count ()) - { - Item *d = make_item ("Dots", ev->self_scm ()); - Rhythmic_head::set_dots (note, d); - - if (dur.dot_count () - != robust_scm2int (d->get_property ("dot-count"), 0)) - d->set_property ("dot-count", scm_from_int (dur.dot_count ())); - - d->set_parent (note, Y_AXIS); - - dots_.push_back (d); - } - SCM drum_type = ev->get_property ("drum-type"); SCM defn = SCM_EOL; - if (scm_hash_table_p (tab) == SCM_BOOL_T) - defn = scm_hashq_ref (tab, drum_type, SCM_EOL); + if (to_boolean (scm_hash_table_p (tab))) + defn = scm_hashq_ref (tab, drum_type, SCM_EOL); if (scm_is_pair (defn)) - { - SCM pos = scm_caddr (defn); - SCM style = scm_car (defn); - SCM script = scm_cadr (defn); - - if (scm_integer_p (pos) == SCM_BOOL_T) - note->set_property ("staff-position", pos); - if (scm_is_symbol (style)) - note->set_property ("style", style); - - if (scm_is_string (script)) - { - Item *p = make_item ("Script", ev->self_scm ()); - make_script_from_event (p, context (), script, - 0); - - p->set_parent (note, Y_AXIS); - Side_position_interface::add_support (p, note); - scripts_.push_back (p); - } - } - - notes_.push_back (note); + { + SCM pos = scm_caddr (defn); + SCM style = scm_car (defn); + SCM script = scm_cadr (defn); + + if (scm_is_integer (pos)) + note->set_property ("staff-position", pos); + if (scm_is_symbol (style)) + note->set_property ("style", style); + + if (scm_is_string (script)) + { + Item *p = make_item ("Script", ev->self_scm ()); + make_script_from_event (p, context (), script, + 0); + + p->set_parent (note, Y_AXIS); + Side_position_interface::add_support (p, note); + scripts_.push_back (p); + } + } } } @@ -120,7 +112,7 @@ Drum_notes_engraver::acknowledge_stem (Grob_info inf) Grob *e = scripts_[i]; if (to_dir (e->get_property ("side-relative-direction"))) - e->set_object ("direction-source", inf.grob ()->self_scm ()); + e->set_object ("direction-source", inf.grob ()->self_scm ()); Side_position_interface::add_support (e, inf.grob ()); } @@ -134,27 +126,40 @@ Drum_notes_engraver::acknowledge_note_column (Grob_info inf) Grob *e = scripts_[i]; if (!e->get_parent (X_AXIS) - && Side_position_interface::get_axis (e) == Y_AXIS) - e->set_parent (inf.grob (), X_AXIS); + && Side_position_interface::get_axis (e) == Y_AXIS) + e->set_parent (inf.grob (), X_AXIS); + + Side_position_interface::add_support (e, inf.grob ()); } } void Drum_notes_engraver::stop_translation_timestep () { - notes_.clear (); - dots_.clear (); scripts_.clear (); - events_.clear (); } -ADD_ACKNOWLEDGER (Drum_notes_engraver, stem); -ADD_ACKNOWLEDGER (Drum_notes_engraver, note_column); + +void +Drum_notes_engraver::boot () +{ + ADD_LISTENER (Drum_notes_engraver, note); + ADD_ACKNOWLEDGER (Drum_notes_engraver, stem); + ADD_ACKNOWLEDGER (Drum_notes_engraver, note_column); +} + ADD_TRANSLATOR (Drum_notes_engraver, - /* doc */ "Generate noteheads.", - /* create */ "NoteHead Dots Script", - /* accept */ "note-event", - /* read */ "drumStyleTable", - /* write */ ""); + /* doc */ + "Generate drum note heads.", + + /* create */ + "NoteHead " + "Script ", + + /* read */ + "drumStyleTable ", + /* write */ + "" + );