]> git.donarmstrong.com Git - lilypond.git/commitdiff
(class Music): include SCM init argument.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 14 Jan 2005 12:31:04 +0000 (12:31 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 14 Jan 2005 12:31:04 +0000 (12:31 +0000)
19 files changed:
lily/event.cc
lily/grace-music.cc
lily/include/event.hh
lily/include/grace-music.hh
lily/include/lyric-combine-music.hh
lily/include/music-list.hh
lily/include/music-sequence.hh
lily/include/music-wrapper.hh
lily/include/music.hh
lily/include/time-scaled-music.hh
lily/lyric-combine-music.cc
lily/music-constructor.cc
lily/music-sequence.cc
lily/music-wrapper.cc
lily/music.cc
lily/sequential-music.cc
lily/simultaneous-music.cc
lily/time-scaled-music.cc
scm/define-music-types.scm

index 5e93cb84c9ee15e12afa10cb770ab89623f80444..271f1b6ed794e83d9ebce194b1c288c755ebbcf1 100644 (file)
@@ -9,16 +9,19 @@
 #include "event.hh"
 #include "warn.hh"
 
-Moment
-Event::get_length () const
+MAKE_SCHEME_CALLBACK(Event,length_callback,1);
+SCM
+Event::length_callback (SCM m)
 {
-  Duration *d = unsmob_duration (get_property ("duration"));
-  if (!d)
+  Music* me = unsmob_music (m);
+  Duration *d = unsmob_duration (me->get_property ("duration"));
+
+  Moment mom;
+  if (d)
     {
-      Moment m ;
-      return m;
+      mom = d->get_length ();
     }
-  return d->get_length ();
+  return mom.smobbed_copy();
 }
 
 void
@@ -62,6 +65,10 @@ Event::to_relative_octave (Pitch last)
 Event::Event (SCM i)
   : Music (i)
 {
+  if (!ly_c_procedure_p (length_callback_))
+    {
+      length_callback_ = length_callback_proc;
+    }
 }
 
 ADD_MUSIC (Event);
index 8acff1974740e96e0ca539f4a92f672504c590d5..02abe88c6046575af8250607f835ebcb9ed76d05 100644 (file)
@@ -8,22 +8,14 @@
 */
 
 #include "grace-music.hh"
-
 #include "grace-iterator.hh"
 
-Moment
-Grace_music::get_length () const
-{
-  Moment m;
-  return m;
-}
-
 Moment
 Grace_music::start_mom () const
 {
-  Moment l = Music_wrapper::get_length ();
+  Moment *l = unsmob_moment (Music_wrapper::length_callback (self_scm ()));
   Moment gl;
-  gl.grace_part_ = -(l.main_part_ + l.grace_part_ );
+  gl.grace_part_ = -(l->main_part_ + l->grace_part_ );
   return gl;
 }
 
index a50e397c4c2988d3696fb50ff214fa5077e7f27b..f282eb941896ee89583206417bbfdce5d8f29c68 100644 (file)
@@ -23,7 +23,7 @@ public:
   Event (SCM);
   VIRTUAL_COPY_CONSTRUCTOR (Music, Event);
   virtual void compress (Moment);
-  virtual Moment get_length () const;
+  DECLARE_SCHEME_CALLBACK(length_callback,(SCM));
   virtual Pitch to_relative_octave (Pitch);
 };
 
index ea1eaf34143d8fcebb86df5734e8680ac9abb34f..9ddb705b9cd49325ba487394d5d15ecbe8e8a80e 100644 (file)
@@ -18,7 +18,6 @@ public:
   VIRTUAL_COPY_CONSTRUCTOR (Music, Grace_music);
   Grace_music (SCM);
 protected:
-  virtual Moment get_length () const;
   virtual Moment start_mom () const;
 };
 
index 0643f820de7352986a78b4bc9d6e14ca6a0012ce..b2489c0e1d4f4c66a71b464d113edf5d652e9427 100644 (file)
@@ -17,10 +17,10 @@ class Lyric_combine_music : public Music
 public:
   Lyric_combine_music (SCM);
   VIRTUAL_COPY_CONSTRUCTOR (Music, Lyric_combine_music);
+  DECLARE_SCHEME_CALLBACK(length_callback,(SCM));
 
   Music *get_music () const;
   Music *get_lyrics () const;
-  virtual Moment get_length () const;
 };
 
 #endif /* LYRIC_COMBINE_MUSIC_HH */
index 523fef4464d9ee1377748579c90dcaa94e4e4fd9..fcbcb78e934e4375c74a2426d2bd6788ef00b15d 100644 (file)
@@ -22,7 +22,6 @@ public:
   VIRTUAL_COPY_CONSTRUCTOR (Music, Simultaneous_music);
 
   virtual Pitch to_relative_octave (Pitch);
-  virtual Moment get_length () const;
   virtual Moment start_mom () const;
 };
 
@@ -44,7 +43,6 @@ class Sequential_music : public Music_sequence
 {
 public:
   VIRTUAL_COPY_CONSTRUCTOR (Music, Sequential_music);
-  virtual Moment get_length () const;
   virtual Moment start_mom () const;
   
   Sequential_music (SCM);
index c1c307b1ec36ebfd63fd45530a6286d7054f84f6..34e69c16b98641aa85bef9d44381eebb40c26556 100644 (file)
@@ -9,16 +9,16 @@
 
 #ifndef MUSIC_SEQUENCE_HH
 #define MUSIC_SEQUENCE_HH
+
 #include "music.hh"
-/**
-  Music can be a list of other "Music" elements
- */
+
 class Music_sequence : public Music
 {
 public:
   Music_sequence (SCM h);
   VIRTUAL_COPY_CONSTRUCTOR (Music, Music_sequence);
-
+  DECLARE_SCHEME_CALLBACK(cumulative_length_callback, (SCM));
+  DECLARE_SCHEME_CALLBACK(maximum_length_callback, (SCM));
   SCM music_list () const;
   
   Pitch do_relative_octave (Pitch p, bool b);
index 4d9c2924383d45674da7152b9c0d858bf52587e6..74030955624b98c9384d4aef6d89a318511dbd12 100644 (file)
@@ -24,9 +24,8 @@ class Music_wrapper : public Music
 public:
   Music_wrapper (SCM);
   VIRTUAL_COPY_CONSTRUCTOR (Music, Music_wrapper);
-
+  DECLARE_SCHEME_CALLBACK(length_callback,(SCM));
   Music *element () const;
-  virtual Moment get_length () const;
   virtual Moment start_mom () const;
 };
 
index a9a60cbe6bbf66f7521441128991948cdb84ee12..82de70454b5c5ee21055b136f1789a3bbf7eaf57 100644 (file)
@@ -46,8 +46,7 @@ public:
   
   virtual Pitch to_relative_octave (Pitch);
   String name () const;
-  /// The duration of this piece of music
-  virtual Moment get_length () const;
+  Moment get_length () const;
   virtual Moment start_mom () const;
   void print () const;
   /// Transpose, with the interval central C to #p#
@@ -60,6 +59,8 @@ protected:
   DECLARE_SMOBS (Music,);
   SCM immutable_property_alist_;
   SCM mutable_property_alist_;
+protected:
+  SCM length_callback_;
   friend SCM ly_extended_make_music (SCM, SCM);
 };
 
index efc62bb1bde168a55278a7a2f86c8f38463747c0..18eda762e7deca4f7727761f62bf42e1dbebad84 100644 (file)
@@ -17,7 +17,6 @@
 class Time_scaled_music : public Music_wrapper
 {
 public:
-  Time_scaled_music ();
   Time_scaled_music (SCM);
   VIRTUAL_COPY_CONSTRUCTOR (Music, Time_scaled_music);
 };
index 98777b1dd741626aadc52f0d3ea617b157d09288..c4678b60740aef84c256ed56db9df0e097ca97fe 100644 (file)
@@ -16,10 +16,13 @@ Lyric_combine_music::Lyric_combine_music (SCM x)
 {
 }
 
-Moment
-Lyric_combine_music::get_length () const
+MAKE_SCHEME_CALLBACK(Lyric_combine_music,length_callback,1);
+SCM
+Lyric_combine_music::length_callback (SCM m)
 {
-  return get_music ()->get_length ();
+  Music * me = unsmob_music (m);
+  Music *melody = unsmob_music (scm_car (me->get_property ("elements")));
+  return melody->get_length ().smobbed_copy ();
 }
 
 Music*
index 120bfef2368260469227a81897cf16e9c4d8012c..97c295e016fadbbe22a726913faef6abf9105083 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "warn.hh"
 
-typedef Music *(*Music_ctor) ();
-
 static std::map<String,Music_ctor> *ctors_map_;
 
 void
index 35db3471c8a55e058d765973fe2702379e9fe82d..22621393f6a08dd858fa1f9247547d4a6ad39ffc 100644 (file)
@@ -66,6 +66,22 @@ Music_sequence::maximum_length (SCM l)
   return dur;
 }
 
+MAKE_SCHEME_CALLBACK(Music_sequence,maximum_length_callback,1);
+SCM
+Music_sequence::maximum_length_callback (SCM m)
+{
+  Music* me = unsmob_music (m);
+  return maximum_length (me->get_property ("elements")).smobbed_copy();
+}
+
+MAKE_SCHEME_CALLBACK(Music_sequence,cumulative_length_callback,1);
+SCM
+Music_sequence::cumulative_length_callback (SCM m)
+{
+  Music* me = unsmob_music (m);
+  return maximum_length (me->get_property ("elements")).smobbed_copy();
+}
+
 Pitch
 music_list_to_relative (SCM l,Pitch p, bool ret_first)
 {
@@ -124,3 +140,4 @@ Music_sequence::first_start (SCM l)
   return m;
 }
 
+
index d6995ac664988b55182f7cf04e5f3d6a9aa50ea1..939b90db94868a3787bded5602bae54a7345a2e6 100644 (file)
@@ -14,10 +14,14 @@ Music_wrapper::Music_wrapper (SCM x)
 {
 }
 
-Moment
-Music_wrapper::get_length () const
+
+MAKE_SCHEME_CALLBACK(Music_wrapper,length_callback,1);
+SCM
+Music_wrapper::length_callback (SCM m)
 {
-  return element ()->get_length ();
+  Music * me = unsmob_music (m);
+  Music *elt = unsmob_music (me->get_property ("element"));
+  return elt->get_length ().smobbed_copy ();
 }
 
 Music*
index 4e98b61775fb867c4aa4b4111faef2e3d073d197..db31a9aec19a8c03fdf74d84eed4a4a88032dcb5 100644 (file)
@@ -45,6 +45,8 @@ Music::Music (SCM init)
   immutable_property_alist_ = init;
   mutable_property_alist_ = SCM_EOL;
   smobify_self ();
+
+  length_callback_ = get_property ("length-callback");
 }
 
 Music::Music (Music const &m)
@@ -58,6 +60,7 @@ Music::Music (Music const &m)
      that they won't be protected from GC. */
   smobify_self ();
   mutable_property_alist_ = ly_music_deep_copy (m.mutable_property_alist_);
+  length_callback_ = m.length_callback_;
   set_spot (*m.origin ());
 }
 
@@ -89,14 +92,13 @@ Music::get_length () const
   if (unsmob_moment (lst))
     return *unsmob_moment (lst);
 
-  lst = get_property ("length-callback");
-  if (ly_c_procedure_p (lst))
+  if (ly_c_procedure_p (length_callback_))
     {
-      SCM res = scm_call_1 (lst, self_scm ());
+      SCM res = scm_call_1 (length_callback_, self_scm ());
       return *unsmob_moment (res);
     }
 
-  return 0;
+  return *unsmob_moment (scm_call_1 (length_callback_, self_scm ()));
 }
 
 Moment
index f250e86e378f5fc96892272c2f026f75ac1c80c4..ada814deb0c737b23882ebcbebd2a2dac1f2b08b 100644 (file)
@@ -1,16 +1,11 @@
 #include "music-list.hh"
 #include "sequential-music-iterator.hh"
 
-Sequential_music::Sequential_music ()
-  : Music_sequence ()
+Sequential_music::Sequential_music (SCM x)
+  : Music_sequence (x)
 {
 }
 
-Moment
-Sequential_music::get_length () const
-{
-  return Music_sequence::cumulative_length (get_property ("elements"));
-}
 ADD_MUSIC (Sequential_music);
 
 Moment
index 58164628636302ba74598dd889d04f273f22825b..04f0506c2beb157e464c10583157fae4898a130f 100644 (file)
 #include "music-list.hh"
 #include "scm-option.hh"
 
-Moment
-Simultaneous_music::get_length () const
-{
-  return Music_sequence::maximum_length (get_property ("elements"));
-}
-
 Moment
 Simultaneous_music::start_mom () const
 {
index c41bb123f0b26283ed77f52342694bf1ce683d79..bfe33e045a03df34ba2d8b94fa67f1ed7594d108 100644 (file)
@@ -11,8 +11,9 @@
 
 #include "time-scaled-music-iterator.hh"
 
-Time_scaled_music::Time_scaled_music ()
+Time_scaled_music::Time_scaled_music (SCM x)
+  : Music_wrapper (x)
 {
-  
 }
+
 ADD_MUSIC (Time_scaled_music);
index c3ac9e8856c058514da0bf82717d73b4b2194b9f..2b52cfd951f204b01c13a4ac60f9adaa4b792fd1 100644 (file)
@@ -199,6 +199,7 @@ Syntax: @var{note}\\cr
      . (
        (description .  "Interpret the argument as grace notes. ")
        (internal-class-name . "Grace_music")
+       (length . ,(ly:make-moment 0 1))
        (iterator-ctor . ,Grace_iterator::constructor)
        (types . (grace-music music-wrapper-music general-music))
        ))
@@ -452,6 +453,7 @@ previously added property from a graphical object definition
 Syntax \\sequential @{..@} or simply @{..@} .")
 
        (internal-class-name . "Sequential_music")
+       (length-callback . ,Music_sequence::cumulative_length_callback)
        (iterator-ctor . ,Sequential_music_iterator::constructor)
        (types . (general-music sequential-music))
        ))
@@ -463,6 +465,7 @@ to group start-mmrest, skip, stop-mmrest sequence.
 
 Syntax @code{R2.*5} for 5 measures in 3/4 time.")
        (internal-class-name . "Sequential_music")
+       (length-callback . ,Music_sequence::cumulative_length_callback)
        (iterator-ctor . ,Sequential_music_iterator::constructor)
        (types . (general-music sequential-music))
        ))
@@ -497,6 +500,7 @@ SYNTAX
 
        (internal-class-name . "Simultaneous_music")
        (iterator-ctor . ,Simultaneous_music_iterator::constructor)
+       (length-callback . ,Music_sequence::maximum_length_callback)
        
        (types . (general-music simultaneous-music))
        ))
@@ -593,6 +597,7 @@ For example, transposed music.")
        (description .  "Internally used to group a set of events.")
        (internal-class-name . "Event_chord")
        (iterator-ctor . ,Event_chord_iterator::constructor)
+       (length-callback . ,Music_sequence::maximum_length_callback)
        (types . (general-music event-chord simultaneous-music))
        )
      )