* lily/instrument-switch-engraver.cc (process_music): new file.
* ly/engraver-init.ly: add Instrument_switch_engraver
* ly/music-functions-init.ly: \instrumentSwitch
* scm/define-context-properties.scm
(all-user-translation-properties): add instrumentCueName
* scm/define-grobs.scm (all-grob-descriptions): add InstrumentSwitch
+2006-07-27 Han-Wen Nienhuys <hanwen@lilypond.org>
+
+ * input/regression/instrument-switch.ly: new file.
+
+ * lily/instrument-switch-engraver.cc (process_music): new file.
+
+ * ly/engraver-init.ly: add Instrument_switch_engraver
+
+ * ly/music-functions-init.ly: \instrumentSwitch
+
+ * scm/define-context-properties.scm
+ (all-user-translation-properties): add instrumentCueName
+
+ * scm/define-grobs.scm (all-grob-descriptions): add InstrumentSwitch
+
2006-07-26 Han-Wen Nienhuys <hanwen@lilypond.org>
+ * ly/music-functions-init.ly: music function \transposition.
+
+ * lily/parser.yy (command_element): softcode \transposition.
+
* lily/fall-engraver.cc (process_music): delta-pitch -> delta-step.
(process_music): oops.
--- /dev/null
+
+\header {
+
+ texidoc = "The @code{switchInstrument} music function modifies
+properties for an in staff instrument switch. "
+ }
+
+\version "2.9.13"
+\addInstrumentDefinition #"bassClar"
+ #`((instrumentTransposition . ,(ly:make-pitch -1 6 FLAT))
+ (instrumentName . "bla")
+ (shortInstrumentName . "bl")
+ (clefGlyph . "clefs.F")
+ (middleCPosition . 6)
+ (clefPosition . 2)
+ (instrumentCueName . ,(make-bold-markup "cl. B"))
+ (midiInstrument . "clarinet"))
+
+
+\paper {
+ ragged-right = ##t
+}
+
+\relative
+{
+ c4
+ \instrumentSwitch "bassClar"
+ c2.\break
+ c1\break
+ c
+}
DECLARE_ACKNOWLEDGER (axis_group);
void process_music ();
void start_spanner ();
+ void consider_start_spanner ();
void stop_spanner ();
};
void
Instrument_name_engraver::process_music ()
{
- start_spanner ();
+ consider_start_spanner ();
}
void
-Instrument_name_engraver::start_spanner ()
+Instrument_name_engraver::consider_start_spanner ()
{
SCM long_text = get_property ("instrumentName");
SCM short_text = get_property ("shortInstrumentName");
{
if (text_spanner_)
stop_spanner ();
-
- text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
-
- Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
- text_spanner_->set_bound (LEFT, col);
- text_spanner_->set_property ("text", short_text);
- text_spanner_->set_property ("long-text", long_text);
+
short_text_ = short_text;
long_text_ = long_text;
+
+ start_spanner ();
}
}
+void
+Instrument_name_engraver::start_spanner ()
+{
+ text_spanner_ = make_spanner ("InstrumentName", SCM_EOL);
+
+ Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
+ text_spanner_->set_bound (LEFT, col);
+ text_spanner_->set_property ("text", short_text_);
+ text_spanner_->set_property ("long-text", long_text_);
+}
+
+
void
Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
{
--- /dev/null
+/*
+ instrument-switch-engraver.cc -- implement
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2006 Han-Wen Nienhuys <hanwen@lilypond.org>
+
+*/
+
+#include "engraver.hh"
+#include "item.hh"
+#include "translator.icc"
+
+
+class Instrument_switch_engraver : public Engraver
+{
+
+ TRANSLATOR_DECLARATIONS(Instrument_switch_engraver);
+protected:
+ Grob *text_;
+ SCM cue_name_;
+
+ void stop_translation_time_step ();
+ void process_music ();
+};
+
+
+Instrument_switch_engraver::Instrument_switch_engraver ()
+{
+ cue_name_ = SCM_EOL;
+ text_ = 0;
+}
+
+void
+Instrument_switch_engraver::process_music ()
+{
+ SCM cue_text = get_property ("instrumentCueName");
+
+ if (!scm_is_eq (cue_name_, cue_text))
+ {
+ text_ = make_item ("InstrumentSwitch", SCM_EOL);
+ text_->set_property ("text", cue_text);
+ cue_name_ = cue_text;
+ }
+}
+
+void
+Instrument_switch_engraver::stop_translation_time_step ()
+{
+ text_ = 0;
+}
+
+ADD_TRANSLATOR(Instrument_switch_engraver,
+ "Create a cue text for taking instrument.",
+
+ "InstrumentSwitch ",
+
+ "",
+
+ "instrumentCueName",
+
+ "");
{"time", TIME_T},
{"times", TIMES},
{"transpose", TRANSPOSE},
- {"transposition", TRANSPOSITION},
{"type", TYPE},
{"unset", UNSET},
{"with", WITH},
%token TEMPO "\\tempo"
%token TIMES "\\times"
%token TRANSPOSE "\\transpose"
-%token TRANSPOSITION "\\transposition"
%token TYPE "\\type"
%token UNSET "\\unset"
%token WITH "\\with"
$$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
}
- | TRANSPOSITION pitch {
- Pitch middle_c;
- Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
- $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Staff"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("instrumentTransposition"), sounds_as_c.smobbed_copy ());
- }
| PARTIAL duration_length {
Moment m = - unsmob_duration ($2)->get_length ();
$$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
\consists "Tie_engraver"
\consists "Tuplet_engraver"
\consists "Grace_engraver"
-
+ \consists "Instrument_switch_engraver"
\consists "Skip_event_swallow_translator"
}
grace =
#(def-grace-function startGraceMusic stopGraceMusic)
+
+"instrument-definitions" = #'()
+
+addInstrumentDefinition =
+#(define-music-function
+ (parser location name lst) (string? list?)
+
+ (set! instrument-definitions (acons name lst instrument-definitions))
+
+ (make-music 'SequentialMusic 'void #t))
+
+
+instrumentSwitch =
+#(define-music-function
+ (parser location name) (string?)
+ (let*
+ ((handle (assoc name instrument-definitions))
+ (instrument-def (if handle (cdr handle) '()))
+ )
+
+ (if (not handle)
+ (ly:input-message "No such instrument: ~a" name))
+ (context-spec-music
+ (make-music 'SimultaneousMusic
+ 'elements
+ (map (lambda (kv)
+ (make-property-set
+ (car kv)
+ (cdr kv)))
+ instrument-def))
+ 'Staff)))
+
+
keepWithTag =
#(define-music-function
(parser location tag music) (symbol? ly:music?)
%% doing
%% define-music-function in a .scm causes crash.
-
octave =
#(define-music-function (parser location pitch-note) (ly:music?)
"octave check"
(make-music 'SequentialMusic 'void #t))
-transposedCueDuring = #
-(define-music-function
+transposedCueDuring =
+#(define-music-function
(parser location what dir pitch-note main-music)
(string? ly:dir? ly:music? ly:music?)
+transposition =
+#(define-music-function (parser location pitch-note) (ly:music?)
+ "Set instrument transposition"
+ (context-spec-music
+ (make-property-set 'instrumentTransposition
+ (ly:pitch-diff (ly:make-pitch 0 0 0) (pitch-of-note pitch-note)))
+ 'Staff
+))
tweak = #(define-music-function (parser location sym val arg)
(symbol? scheme? ly:music?)
printed as numbers, but only as extender lines.")
+ (instrumentCueName ,markup? "Name to print if another instrument is to be taken.")
(instrumentName ,markup? "The name to print left of a staff. The
@code{instrument} property labels the staff in the first system, and
the @code{instr} property labels following lines.")
side-position-interface
font-interface))))))
+ (InstrumentSwitch
+ . (
+ (padding . 0.3)
+ (stencil . ,ly:text-interface::print)
+ (Y-offset . ,ly:side-position-interface::y-aligned-side)
+ (X-offset . ,ly:self-alignment-interface::x-aligned-on-self)
+ (staff-padding . 2)
+ (direction . ,UP)
+ (self-alignment-X . ,CENTER)
+ (meta . ((class . Item)
+ (interfaces . (system-start-text-interface
+ side-position-interface
+ font-interface))))))
+
(KeyCancellation
. (
(stencil . ,ly:key-signature-interface::print)