]> git.donarmstrong.com Git - lilypond.git/commitdiff
* input/regression/instrument-switch.ly: new file.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 27 Jul 2006 15:52:40 +0000 (15:52 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 27 Jul 2006 15:52:40 +0000 (15:52 +0000)
* 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

ChangeLog
input/regression/instrument-switch.ly [new file with mode: 0644]
lily/instrument-name-engraver.cc
lily/instrument-switch-engraver.cc [new file with mode: 0644]
lily/lily-lexer.cc
lily/parser.yy
ly/engraver-init.ly
ly/music-functions-init.ly
scm/define-context-properties.scm
scm/define-grobs.scm

index b4d20731a2f73ccf4ddd7b81c1ec77a6f4dac6c4..e1c3ed326fcb8608ee6d7bbb5393ac96dbdf6371 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
+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.
 
diff --git a/input/regression/instrument-switch.ly b/input/regression/instrument-switch.ly
new file mode 100644 (file)
index 0000000..73f6dff
--- /dev/null
@@ -0,0 +1,31 @@
+
+\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
+}
index 76e0a88e33dca6ca44535e889f230ed91aa0fe43..4746d4a09d0553facca835899f7e2294b30ed15d 100644 (file)
@@ -34,6 +34,7 @@ protected:
   DECLARE_ACKNOWLEDGER (axis_group);
   void process_music ();
   void start_spanner ();
+  void consider_start_spanner ();
   void stop_spanner ();
 };
 
@@ -48,11 +49,11 @@ Instrument_name_engraver::Instrument_name_engraver ()
 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");
@@ -72,19 +73,27 @@ Instrument_name_engraver::start_spanner ()
     {
       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)
 {
diff --git a/lily/instrument-switch-engraver.cc b/lily/instrument-switch-engraver.cc
new file mode 100644 (file)
index 0000000..67a6803
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+  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",
+                       
+              "");
index e677b9e5c51bcef8a5763f1aa7139be8cbaa5d90..2392f47b363d63917061b20583dd43ec9a18b01b 100644 (file)
@@ -74,7 +74,6 @@ static Keyword_ent the_key_tab[]
   {"time", TIME_T},
   {"times", TIMES},
   {"transpose", TRANSPOSE},
-  {"transposition", TRANSPOSITION},
   {"type", TYPE},
   {"unset", UNSET},
   {"with", WITH},
index a970e8be884ccc63d474b920b4356efd9acb1dd5..d0109edac543f80487894843f6c18e2297b23c63 100644 (file)
@@ -206,7 +206,6 @@ void set_music_properties (Music *p, SCM a);
 %token TEMPO "\\tempo"
 %token TIMES "\\times"
 %token TRANSPOSE "\\transpose"
-%token TRANSPOSITION "\\transposition"
 %token TYPE "\\type"
 %token UNSET "\\unset"
 %token WITH "\\with"
@@ -1470,11 +1469,6 @@ command_element:
                        $$ = 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 ());
index 7e51f515750493d91456316e05593ff117fd3d6b..cba936c6f9bdb1d19336d2188d93bcba44f43639 100644 (file)
@@ -222,7 +222,7 @@ contained staves are not connected vertically."
   \consists "Tie_engraver"
   \consists "Tuplet_engraver"
   \consists "Grace_engraver"
-
+  \consists "Instrument_switch_engraver"
   \consists "Skip_event_swallow_translator"
 }
 
index 141d107cd688f4aa2e2f7a31514ac0e0684afaad..8ff3e6285131fd8359796d63398ad1b7e2be344a 100644 (file)
@@ -201,6 +201,39 @@ acceleration/deceleration. "
 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?)
@@ -290,7 +323,6 @@ removeWithTag =
 %% doing
 %% define-music-function in a .scm causes crash.
 
-
 octave =
 #(define-music-function (parser location pitch-note) (ly:music?)
    "octave check"
@@ -480,8 +512,8 @@ spacingTweaks =
    (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?)
 
@@ -502,7 +534,15 @@ as a first or second voice."
 
 
 
+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?)
index b97a71dbf4041ef70d464b397091a58ecc9790ce..837238ab58433a5abf65ac338acf99a47be108d9 100644 (file)
@@ -253,6 +253,7 @@ selector for tab notation.")
 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.")
index d4c363604361eadeca8ca4065d954aa52aa52646..856ed8226e886d5bbbfcd57d2594aeabdd7654a9 100644 (file)
                                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)