]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/parser.yy (command_element): reverse setting of
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 2 Oct 2004 10:12:09 +0000 (10:12 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 2 Oct 2004 10:12:09 +0000 (10:12 +0000)
instrumentTransposition

* lily/pitch.cc (pitch_interval): rename.

* lily/recording-group-engraver.cc (stop_translation_timestep):
remove macrameing of accumulator and set_car/cdr.

* lily/music.cc (transpose): fold Event::transpose() in.

* lily/event.cc: remove Transpose.

* lily/recording-group-engraver.cc: cleanup.

* ly/music-functions-init.ly (displayMusic): add function.

24 files changed:
ChangeLog
Documentation/user/programming-interface.itely
lily/context.cc
lily/duration.cc
lily/event.cc
lily/grob.cc
lily/include/event.hh
lily/include/pitch.hh
lily/key-performer.cc
lily/lily-parser.cc
lily/moment.cc
lily/music.cc
lily/note-performer.cc
lily/paper-book.cc
lily/paper-system.cc
lily/parser.yy
lily/pitch.cc
lily/quote-iterator.cc
lily/recording-group-engraver.cc
lily/translator-scheme.cc
ly/music-functions-init.ly
scm/define-context-properties.scm
scm/music-functions.scm
scm/part-combiner.scm

index 1136bf08504c7d915c8e8042835cb340939c928e..6be1337a5381d2c63edef7b42a425a372de626d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2004-10-02  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * scm/define-music-properties.scm (all-music-properties): change
+       meaning of instrumentTransposition.  It is now the pitch played
+       that sounds as middle C. This means that instrumentTransposition
+       can be \transposed. 
+
+       * lily/parser.yy (command_element): reverse setting of
+       instrumentTransposition
+
+       * lily/pitch.cc (pitch_interval): rename.
+
+       * lily/recording-group-engraver.cc (stop_translation_timestep):
+       remove macrameing of accumulator and set_car/cdr.
+
+       * lily/music.cc (transpose): fold Event::transpose() in.
+
+       * lily/event.cc: remove Transpose. 
+
+       * lily/recording-group-engraver.cc: cleanup.
+
+       * ly/music-functions-init.ly (displayMusic): add function.
+
        * make/lilypond.fedora.spec.in: rename file.
 
        * lily/lily-lexer.cc (mark_smob): don't use ly_cdr() for getting
index 6a2dae83c2a44ee0a7776081e281f57d73391f19..b5b6686270e54945149a2e8fe95ad621506dce03 100644 (file)
@@ -298,6 +298,12 @@ saving keystrokes (@inputfileref{input/test,music-box.ly}) and
 exporting LilyPond input to other formats
 (@inputfileref{input/test,to-xml.ly})
 
+@cindex internal storage
+@cindex @code{\displayMusic}
+When writing a music function, it is often instructive to inspect how
+a music expression is stored internally. This can be done with the
+music function @code{\displayMusic}
+
 @seealso
 
 @file{scm/music-functions.scm}, @file{scm/music-types.scm},
index 6b539519e1629af16abbb30e92071835a17ba6e0..fff7d6c74944a9a732b754fc684a46158571e4e0 100644 (file)
@@ -364,7 +364,7 @@ Context::now_mom () const
 int
 Context::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Context *sc = (Context *) ly_cdr (s);
+  Context *sc = (Context *) SCM_CELL_WORD_1 (s);
      
   scm_puts ("#<", port);
   scm_puts (classname (sc), port);
index fc52de448163daf0af269f886d71811ea3f8e085..bf4e97bf730c35d878a0fc5494ac196ce9cca877 100644 (file)
@@ -93,7 +93,7 @@ IMPLEMENT_SIMPLE_SMOBS (Duration);
 int
 Duration::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Duration  *r = (Duration *) ly_cdr (s);
+  Duration  *r = (Duration *) SCM_CELL_WORD_1 (s);
 
   scm_puts ("#<Duration ", port);
   scm_display (scm_makfrom0str (r->to_string ().to_str0 ()), port);
@@ -105,8 +105,8 @@ Duration::print_smob (SCM s, SCM port, scm_print_state *)
 SCM
 Duration::equal_p (SCM a , SCM b)
 {
-  Duration  *p = (Duration *) ly_cdr (a);
-  Duration  *q = (Duration *) ly_cdr (b);
+  Duration  *p = (Duration *) SCM_CELL_WORD_1 (a);
+  Duration  *q = (Duration *) SCM_CELL_WORD_1 (b);
 
   bool eq = p->dots_ == q->dots_
     && p->durlog_ == q->durlog_
index aad0bd21101ca3e36e560acb41b0784651dfe641..f47e335ace6614894934ccfecc567253d6aba057 100644 (file)
@@ -30,27 +30,6 @@ Event::compress (Moment m)
     set_property ("duration", d ->compressed (m.main_part_).smobbed_copy ());
 }
 
-void
-Event::transpose (Pitch delta)
-{
-  for (SCM s = this->get_property_alist (true); scm_is_pair (s); s = ly_cdr (s))
-    {
-      SCM entry = ly_car (s);
-      SCM val = ly_cdr (entry);
-
-      if (Pitch * p = unsmob_pitch (val))
-       {
-         Pitch transposed =  p->transposed (delta);
-         scm_set_cdr_x (entry, transposed.smobbed_copy ());
-
-         if (abs (transposed.get_alteration ()) > DOUBLE_SHARP)
-           {
-             warning (_f ("Transposition by %s makes alteration larger than two",
-                          delta.to_string ()));
-           }
-       }
-    }
-}
 
 Pitch
 Event::to_relative_octave (Pitch last)
index 8e79dc76c69321b425f4fb6366ef474222353700..a39ac0f4126fd851679aefc2d95b5b0ff95adc67 100644 (file)
@@ -617,7 +617,7 @@ Grob::mark_smob (SCM ses)
 int
 Grob::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Grob *sc = (Grob *) ly_cdr (s);
+  Grob *sc = (Grob *) SCM_CELL_WORD_1 (s);
 
   scm_puts ("#<Grob ", port);
   scm_puts ((char *) sc->name ().to_str0 (), port);
index 25e5210adc611bfb58290746d778e438dc2848d6..0cf7b8f3b24e44ccb0435f314ab58b64508cbf05 100644 (file)
@@ -26,7 +26,6 @@ public:
   Event ();
   VIRTUAL_COPY_CONSTRUCTOR (Music, Event);
   virtual void compress (Moment);
-  virtual void transpose (Pitch);
   virtual Moment get_length () const;
   virtual Pitch to_relative_octave (Pitch);
 };
index db31415fad37d9420cceaa223bf3c97a805486e3..bd0f20918279e9431b984fc0ebe0a75281fa9eb6 100644 (file)
@@ -86,7 +86,7 @@ INSTANTIATE_COMPARE (Pitch, Pitch::compare);
 
 int compare (Array<Pitch>*, Array<Pitch>*);
 extern SCM pitch_less_proc;
-Pitch interval (Pitch const & from , Pitch const & to );
+Pitch pitch_interval (Pitch const & from , Pitch const & to );
 
 #endif /* MUSICAL_PITCH_HH */
 
index f27f0d85f4c3614c9f4b4c51fa488ccf3bb12b54..531e33e8204addfca203865966dbf1b1a7e00de8 100644 (file)
@@ -57,7 +57,7 @@ Key_performer::create_audio_elements ()
                  
       SCM c_pitchlist
        = ly_transpose_key_alist (pitchlist,
-                                 interval (key_do, c_do).smobbed_copy ());
+                                 pitch_interval (key_do, c_do).smobbed_copy ());
 
       /* MIDI keys are too limited for lilypond scales.
         We check for minor scale and assume major otherwise.  */
index 157a76516546d9b4c12086c03461e12d12e61426..aa131151ceeab2a88d40b7831ab40c9efe05c5e3 100644 (file)
@@ -74,7 +74,7 @@ int
 Lily_parser::print_smob (SCM s, SCM port, scm_print_state*)
 {
   scm_puts ("#<my_lily_parser ", port);
-  Lily_parser *parser = (Lily_parser*) ly_cdr (s);
+  Lily_parser *parser = (Lily_parser*) SCM_CELL_WORD_1 (s);
   (void) parser;
   scm_puts (" >", port);
   return 1;
index a7d0e8ddb95d56ea9e05c2249d49d2ac62fceddc..72e138b4a9e0fa012127c9406c95920ea4d0ec09 100644 (file)
@@ -46,7 +46,7 @@ Moment::mark_smob (SCM)
 int
 Moment::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Moment  *r = (Moment *) ly_cdr (s);
+  Moment  *r = (Moment *) SCM_CELL_WORD_1 (s);
      
   scm_puts ("#<Mom ", port);
   String str = r->to_string ();
index 9e980ea8212087afb18158ac463b67d674ba50a6..869bbbe3fd7e69618686f2c98f3fc0a9e317a76a 100644 (file)
@@ -169,6 +169,24 @@ Music::compress (Moment factor)
 void
 Music::transpose (Pitch delta)
 {
+  for (SCM s = this->get_property_alist (true); scm_is_pair (s); s = ly_cdr (s))
+    {
+      SCM entry = ly_car (s);
+      SCM val = ly_cdr (entry);
+
+      if (Pitch * p = unsmob_pitch (val))
+       {
+         Pitch transposed =  p->transposed (delta);
+         scm_set_cdr_x (entry, transposed.smobbed_copy ());
+
+         if (abs (transposed.get_alteration ()) > DOUBLE_SHARP)
+           {
+             warning (_f ("Transposition by %s makes alteration larger than two",
+                          delta.to_string ()));
+           }
+       }
+    }
   SCM elt = get_property ("element");
 
   if (Music* m = unsmob_music (elt))
index 4d938dee650282bf227b8eb9e525f385b28ab7d2..0109b7bb33b36717b5737ddefccf86eed72cbdec 100644 (file)
@@ -50,7 +50,7 @@ Note_performer::create_audio_elements ()
 
          if (Pitch * pitp = unsmob_pitch (pit))
            {
-             Audio_note* p = new Audio_note (*pitp,  n->get_length (), transposing);
+             Audio_note* p = new Audio_note (*pitp,  n->get_length (),  - transposing);
              Audio_element_info info (p, n);
              announce_element (info);
              notes_.push (p);
index 6d2d6b328e4132e0e551b268d2734e0feab8d216..b557c83b924a7d937a6c39bb84c9309b16e2c702 100644 (file)
@@ -53,7 +53,7 @@ Paper_book::mark_smob (SCM smob)
 int
 Paper_book::print_smob (SCM smob, SCM port, scm_print_state*)
 {
-  Paper_book *b = (Paper_book*) ly_cdr (smob);
+  Paper_book *b = (Paper_book*) SCM_CELL_WORD_1 (smob);
      
   scm_puts ("#<", port);
   scm_puts (classname (b), port);
index 455bb9a667957d1b1e1c479572f621e6139d93cc..b4dd9784e411a121049b90778b4f3840d976c13f 100644 (file)
@@ -43,7 +43,7 @@ Paper_system::mark_smob (SCM smob)
 int
 Paper_system::print_smob (SCM smob, SCM port, scm_print_state*)
 {
-  Paper_system *p = (Paper_system*) ly_cdr (smob);
+  Paper_system *p = (Paper_system*) SCM_CELL_WORD_1 (smob);
   scm_puts ("#<", port);
   scm_puts (classname (p), port);
   scm_puts (" ", port);
index 64bccc13f6bad0322b97bbd4d3f09f7a7788390c..6d8d755366ae37cd7805ec5d8df29a7fa44e827f 100644 (file)
@@ -1104,7 +1104,7 @@ Prefix_composite_music:
                Pitch from = *unsmob_pitch ($2);
                Pitch to = *unsmob_pitch ($3);
 
-               p->transpose (interval (from, to));
+               p->transpose (pitch_interval (from, to));
                $$->set_property ("element", p->self_scm ());
                scm_gc_unprotect_object (p->self_scm ());
        }
@@ -1616,8 +1616,10 @@ command_element:
                $$->set_spot (THIS->here_input ());
        }
        | TRANSPOSITION pitch {
+               Pitch middle_c;
+               Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
                $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
-                                       $2);
+                                        sounds_as_c.smobbed_copy());
                $$->set_spot (THIS-> here_input ());
                $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
                        $$, SCM_EOL);
index 5dc46f97e6770f3a68b687418dc08a0d88951656..6613dbdc4925e671b87e347d2dce9285f885cd60 100644 (file)
@@ -149,7 +149,7 @@ Pitch::transpose (Pitch delta)
 }
 
 Pitch
-interval (Pitch const & from , Pitch const & to )
+pitch_interval (Pitch const & from , Pitch const & to )
 {
   int sound = to.quartertone_pitch ()  - from.quartertone_pitch ();
   Pitch pt (to.get_octave () - from.get_octave (),
@@ -257,7 +257,7 @@ IMPLEMENT_SIMPLE_SMOBS (Pitch);
 int
 Pitch::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Pitch *r = (Pitch *) ly_cdr (s);
+  Pitch *r = (Pitch *) SCM_CELL_WORD_1 (s);
   scm_puts ("#<Pitch ", port);
   scm_display (scm_makfrom0str (r->to_string ().to_str0 ()), port);
   scm_puts (" >", port);
@@ -267,8 +267,8 @@ Pitch::print_smob (SCM s, SCM port, scm_print_state *)
 SCM
 Pitch::equal_p (SCM a , SCM b)
 {
-  Pitch *p = (Pitch *) ly_cdr (a);
-  Pitch *q = (Pitch *) ly_cdr (b);
+  Pitch *p = (Pitch *) SCM_CELL_WORD_1 (a);
+  Pitch *q = (Pitch *) SCM_CELL_WORD_1 (b);
 
   bool eq = p->notename_ == q->notename_
     && p->octave_ == q->octave_
@@ -394,7 +394,7 @@ LY_DEFINE (ly_pitch_diff, "ly:pitch-diff",
   SCM_ASSERT_TYPE (p, pitch, SCM_ARG1, __FUNCTION__, "Pitch");
   SCM_ASSERT_TYPE (r, root, SCM_ARG2, __FUNCTION__, "Pitch");
 
-  return interval (*r, *p).smobbed_copy ();
+  return pitch_interval (*r, *p).smobbed_copy ();
 }
 
 int
index 961ae02f8140d87ee4bac271d0f108b7e3ab1ce7..2b5fd91b83814f11a92939640850d0c672db9df4 100644 (file)
@@ -164,6 +164,10 @@ Quote_iterator::process (Moment m)
   if (scm_is_pair (entry))
     {
       Pitch * quote_pitch = unsmob_pitch (ly_cdar (entry));
+
+      /*
+       The pitch that sounds like central C
+       */
       Pitch * me_pitch = unsmob_pitch (get_outlet ()->get_property ("instrumentTransposition"));
       
       for (SCM s = ly_cdr (entry); scm_is_pair (s); s = ly_cdr (s))
@@ -183,7 +187,7 @@ Quote_iterator::process (Moment m)
                  if (me_pitch)
                    mp = *me_pitch;
 
-                 Pitch diff = interval (mp, qp);
+                 Pitch diff = pitch_interval (qp, mp);
 
                  SCM copy = ly_deep_mus_copy (mus->self_scm ());
                  mus = unsmob_music (copy);
index 96c0ffc964b5547934c8611b2672c07fcc1d25de..86137b8399ec8825e30e4d737b98ebdc3f91f54a 100644 (file)
 
 class Recording_group_engraver : public Engraver_group_engraver
 {
-  void start ();
 public:
   TRANSLATOR_DECLARATIONS (Recording_group_engraver);
   virtual bool try_music (Music *m);
-  virtual void start_translation_timestep ();
+  void add_music (SCM, SCM);
   virtual void stop_translation_timestep ();
   virtual void finalize ();
   virtual void initialize ();
   virtual void derived_mark () const;
+  SCM now_events_;
   SCM accumulator_;
 };
 
@@ -36,51 +36,31 @@ void
 Recording_group_engraver::initialize ()
 {
   Engraver_group_engraver::initialize ();
-  start ();
 }
 
 Recording_group_engraver::Recording_group_engraver ()
 {
   accumulator_ = SCM_EOL;
+  now_events_ = SCM_EOL;
 }
 
 void
-Recording_group_engraver::start_translation_timestep ()
+Recording_group_engraver::add_music (SCM music, SCM success)
 {
-  Engraver_group_engraver::start_translation_timestep ();
-
-
-  /*
-    We have to do this both in initialize () and
-    start_translation_timestep (), since start_translation_timestep ()
-    isn't called on the first time-step.
-   */
-  start () ;
+  now_events_ = scm_cons (scm_cons (music, success), now_events_);
 }
 
-void
-Recording_group_engraver::start ()
-{
-  if (!scm_is_pair (accumulator_))
-    accumulator_ = scm_cons (SCM_EOL, SCM_EOL);
-  if (!scm_is_pair (ly_car (accumulator_)))
-    {
-      /*
-       Need to store transposition for every moment; transposition changes during pieces.
-       */
-      scm_set_car_x (accumulator_, scm_cons (scm_cons (now_mom ().smobbed_copy (),
-                                                    get_property ("instrumentTransposition")),
-                                                    SCM_EOL));
-    }
-}
 
 void
 Recording_group_engraver::stop_translation_timestep ()
 {
   Engraver_group_engraver::stop_translation_timestep ();
-  scm_set_cdr_x (accumulator_, scm_cons (ly_car (accumulator_), ly_cdr (accumulator_)));
 
-  scm_set_car_x (accumulator_, SCM_EOL);
+  accumulator_ = scm_acons (scm_cons (now_mom ().smobbed_copy (),
+                                    get_property ("instrumentTransposition")),
+                           now_events_,
+                           accumulator_);
+  now_events_ = SCM_EOL;
 }
 
 void
@@ -91,8 +71,6 @@ Recording_group_engraver::finalize ()
 
   if (ly_c_procedure_p (proc))
     scm_call_2  (proc, context ()->self_scm (), ly_cdr (accumulator_));
-
-  accumulator_ = SCM_EOL;
 }
 
 bool
@@ -100,12 +78,7 @@ Recording_group_engraver::try_music (Music  *m)
 {
   bool retval = Translator_group::try_music (m);
 
-  SCM seq = ly_cdar (accumulator_);
-  seq = scm_cons (scm_cons  (m->self_scm (), ly_bool2scm (retval)),
-                seq);
-  
-  scm_set_cdr_x  (ly_car (accumulator_), seq);
-
+  add_music (m->self_scm (), ly_bool2scm (retval));
   return retval;
 }
 
index a80b4c1661bedca200252c6051f340522c4ca218..35054fd0d2f20728d41fdd39bf2ec1e5f7f109eb 100644 (file)
@@ -36,7 +36,7 @@ LY_DEFINE (ly_translator_description, "ly:translator-description",
 int
 Translator::print_smob (SCM s, SCM port, scm_print_state *)
 {
-  Translator *me = (Translator*) ly_cdr (s);
+  Translator *me = (Translator*) SCM_CELL_WORD_1 (s);
   scm_puts ("#<Translator ", port);
   scm_puts (classname (me), port);
   scm_puts (" >", port);
index 70755dff3b2dbc8408f63a47a743483706b751f4..07802d74b20f186c3055452a383c3233f183498e 100644 (file)
@@ -25,6 +25,9 @@ applycontext = #(def-music-function (location proc) (procedure?)
                    'origin location
                    'procedure proc))
 
+displayMusic = #(def-music-function (location music) (ly:music?)
+                (display-music music)
+                music)
 applyoutput = #(def-music-function (location proc) (procedure?)
                 (make-music 'ApplyOutputEvent 
                   'origin location
index 3606f842267581782bddc97548395aea07512a7c..7a9815b7756d75f5d991a3bdfd76560b60e5a370 100644 (file)
@@ -227,7 +227,9 @@ the @code{instr} property labels following lines.")
      (instrumentEqualizer ,procedure? "
 Function taking a string (instrument name), and returning a (@var{min} . @var{max}) pair of numbers for the loudness range of the instrument.
 ")
-     (instrumentTransposition ,ly:pitch? "Define the transposition of the instrument. This is used to transpose the MIDI output, and @code{\\quote}s.")
+     (instrumentTransposition ,ly:pitch? "Defines the transposition of
+the instrument. Its value is the pitch that sounds like middle C. This
+is used to transpose the MIDI output, and @code{\\quote}s.")
 
      (keyAccidentalOrder ,list? " Alist that defines in what order
 alterations should be printed.  The format is (@var{name}
index 3212e52159be43c33c41cda1b55401a3e10d9b43..4f4152a2750c4b31c6ae7940796d95e47af8deab 100644 (file)
@@ -605,6 +605,7 @@ Syntax:
                          ))
 
        )
+
     (if (string? quoted-name)
        (if  (vector? quoted-vector)
             (set! (ly:music-property music 'quoted-events) quoted-vector)
index 5cc2cfb8d21eadf154a9f0729d6346bad3df2f73..e206d0d12111eda12afc5a7544fb22dd4f504337 100644 (file)
@@ -193,6 +193,8 @@ Voice-state objects
   (set! part-combine-listener x))
 
 (define-public (notice-the-events-for-pc context lst)
+  "add CONTEXT-ID, EVENT list to NOTICED variable."
+  
   (set! noticed (acons (ly:context-id context) lst noticed)))
 
 (define-public (make-part-combine-music music-list)
@@ -508,9 +510,11 @@ the mark when there are no spanners active."
   (let* ((tab (eval 'musicQuotes (current-module) ))
         (context (ly:run-translator (context-spec-music mus 'Voice)
                                     part-combine-listener))
-        (evs (last-pair noticed)))
-    (if (pair? evs)
+        (first-voice-handle (last-pair noticed)))
+
+    (if (pair? first-voice-handle)
        (hash-set! tab name
                   ;; cdr : skip name string
-                  (list->vector (reverse! (cdar evs) '()))))))
+                  (list->vector (reverse! (cdar first-voice-handle)
+                                          '()))))))