]> git.donarmstrong.com Git - lilypond.git/commitdiff
Revert "Make EventClass hierarchy a property of Global context"
authorDavid Kastrup <dak@gnu.org>
Thu, 4 Jul 2013 12:06:35 +0000 (14:06 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 12 Jul 2013 07:41:56 +0000 (09:41 +0200)
This reverts commit ae2db5b21bf232f5145f3a3e091689c8fc7247e9.

Conflicts:
lily/context-scheme.cc
lily/global-context.cc
lily/music.cc
lily/part-combine-iterator.cc
scm/define-event-classes.scm
scm/document-music.scm

Independently introduced conflict:
lily/footnote-engraver.cc

Also fix tabs reintroduced by revert

16 files changed:
input/regression/scheme-text-spanner.ly
lily/context-scheme.cc
lily/context.cc
lily/engraver.cc
lily/footnote-engraver.cc
lily/global-context.cc
lily/include/context.hh
lily/include/music.hh
lily/music.cc
lily/part-combine-iterator.cc
lily/rhythmic-music-iterator.cc
ly/engraver-init.ly
ly/performer-init.ly
scm/define-context-properties.scm
scm/define-event-classes.scm
scm/document-music.scm

index 6a26177850485c28644c927dbc2275638c4b600c..e4d84a1cbb8166c62358a59fd2eaba3b904d7f27 100644 (file)
@@ -6,27 +6,11 @@ and grob creation methods to create a fully functional text spanner
 in scheme."
 }
 
-#(define my-grob-descriptions '())
-
-#(define my-event-classes (ly:make-context-mod))
-
-defineEventClass =
-#(define-void-function (parser location class parent)
-   (symbol? symbol?)
-   (ly:add-context-mod
-    my-event-classes
-    `(apply
-      ,(lambda (context class parent)
-        (ly:context-set-property!
-         context
-         'EventClasses
-         (event-class-cons
-          class
-          parent
-          (ly:context-property context 'EventClasses '()))))
-      ,class ,parent)))
-
-\defineEventClass #'scheme-text-span-event #'span-event
+#(define-event-class 'scheme-text-span-event
+   '(scheme-text-span-event
+     span-event
+     music-event
+     StreamEvent))
 
 #(define (add-grob-definition grob-name grob-entry)
    (let* ((meta-entry   (assoc-get 'meta grob-entry))
@@ -49,9 +33,9 @@ defineEventClass =
      (set! meta-entry (assoc-set! meta-entry 'interfaces
                                   ifaces-entry))
      (set! grob-entry (assoc-set! grob-entry 'meta meta-entry))
-     (set! my-grob-descriptions
+     (set! all-grob-descriptions
            (cons (cons grob-name grob-entry)
-                 my-grob-descriptions))))
+                 all-grob-descriptions))))
 
 #(add-grob-definition
   'SchemeTextSpanner
@@ -197,8 +181,7 @@ schemeTextSpannerEnd =
 \layout {
   \context {
     \Global
-    \grobdescriptions #my-grob-descriptions
-    #my-event-classes
+    \grobdescriptions #all-grob-descriptions
   }
   \context {
     \Voice
index 64f8dd8e15a0fdb3fbf9d2f8fd1821188395c231..f58a793ed4ef805fcbcf4cd47435e88de47edf82 100644 (file)
@@ -211,15 +211,3 @@ LY_DEFINE (ly_context_events_below, "ly:context-events-below",
   Context *ctx = unsmob_context (context);
   return ctx->events_below ()->self_scm ();
 }
-
-LY_DEFINE (ly_make_event_class, "ly:make-event-class",
-           2, 0, 0, (SCM context, SCM type),
-           "Make an event class (a list of types) from the given @var{type}"
-           " within the global context containing @var{context}.")
-{
-  LY_ASSERT_SMOB (Context, context, 1);
-  LY_ASSERT_TYPE (ly_is_symbol, type, 2);
-
-  Context *ctx = unsmob_context (context);
-  return ctx->make_event_class (type);
-}
index 3da638fe557922cdee4817b22d98e937f6ba38a5..3453284cd8c75455787aebcb47252e4ea94b6779 100644 (file)
@@ -92,7 +92,6 @@ Context::Context ()
   definition_mods_ = SCM_EOL;
   event_source_ = 0;
   events_below_ = 0;
-  ancestor_lookup_ = SCM_UNDEFINED;
 
   smobify_self ();
 
@@ -479,7 +478,9 @@ be called from any other place than the send_stream_event macro.
 void
 Context::internal_send_stream_event (SCM type, Input *origin, SCM props[])
 {
-  Stream_event *e = new Stream_event (make_event_class (type), origin);
+  Stream_event *e = new Stream_event
+    (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"), type),
+     origin);
   for (int i = 0; props[i]; i += 2)
     {
       e->set_property (props[i], props[i + 1]);
@@ -619,14 +620,6 @@ Context::get_score_context () const
     return 0;
 }
 
-SCM
-Context::make_event_class (SCM event_type)
-{
-  if (SCM_UNBNDP (ancestor_lookup_))
-    ancestor_lookup_ = get_global_context ()->ancestor_lookup_;
-  return scm_hashq_ref (ancestor_lookup_, event_type, SCM_EOL);
-}
-
 Output_def *
 Context::get_output_def () const
 {
@@ -696,8 +689,6 @@ Context::mark_smob (SCM sm)
   if (me->events_below_)
     scm_gc_mark (me->events_below_->self_scm ());
 
-  scm_gc_mark (me->ancestor_lookup_);
-
   return me->properties_scm_;
 }
 
index db1303d63ce3b918f95e5d9f254c589a84bf89ea..b8bf1234c04d625fe36c635c38aa3bad1a24c85b 100644 (file)
@@ -53,7 +53,7 @@ Engraver::make_grob_info (Grob *e, SCM cause)
   /* TODO: Remove Music code when it's no longer needed */
   if (Music *m = unsmob_music (cause))
     {
-      cause = m->to_event (context ())->unprotect ();
+      cause = m->to_event ()->unprotect ();
     }
   if (e->get_property ("cause") == SCM_EOL
       && (unsmob_stream_event (cause) || unsmob_grob (cause)))
index 39e18cd57c897db66fb029fdd4bf7d4f5e375664..20ee7c149fba5eb80f000c94f95b3a6e5f2ab565 100644 (file)
@@ -88,7 +88,7 @@ Footnote_engraver::acknowledge_grob (Grob_info info)
           return;
         }
 
-      footnotify (info.grob (), mus->to_event (context ())->unprotect ());
+      footnotify (info.grob (), mus->to_event ()->unprotect ());
 
       // This grob has exhausted its footnote
       info.grob ()->set_property ("footnote-music", SCM_EOL);
index 8f22b943effe787d69033023ce8196d99486cafb..49bfff6e19248326c4347662fd6249559dea617d 100644 (file)
@@ -52,12 +52,6 @@ Global_context::Global_context (Output_def *o)
   else
     globaldef->apply_default_property_operations (this);
 
-  SCM p = get_property ("EventClasses");
-
-  ancestor_lookup_ = scm_make_hash_table (scm_length (p));
-  for (; scm_is_pair (p); p = scm_cdr (p))
-    scm_hashq_set_x (ancestor_lookup_, scm_caar (p), scm_car (p));
-
   default_child_ = ly_symbol2scm ("Score");
   accepts_list_ = scm_list_1 (default_child_);
 }
index 794f275287e1f9fcbe404d22c44dfc731c782e6d..14c348f6e4a91c658f30ec36d1570a5b93609ed2 100644 (file)
@@ -118,13 +118,6 @@ public:
   virtual Moment now_mom () const;
   virtual Context *get_default_interpreter (string context_id = "");
 
-  // It would make some sense to have the following just available in
-  // a global context.  It would be decidedly tricky, however, to have
-  // it initialized before the constructor of its Context base class
-  // was able to trigger garbage collection.
-  SCM ancestor_lookup_;
-  SCM make_event_class (SCM);
-
   bool is_alias (SCM) const;
   void add_alias (SCM);
   void add_context (Context *trans);
index b0f48371048a50bc6f4a3d953d89fc20828a88da..83cc5ff4c3148a4add8d1c7b165bc46a0bfe8829 100644 (file)
@@ -24,7 +24,6 @@
 #include "moment.hh"
 #include "pitch.hh"
 #include "prob.hh"
-#include "context.hh"
 
 #define is_mus_type(x) internal_is_music_type (ly_symbol2scm (x))
 
@@ -40,7 +39,7 @@ public:
 
   bool internal_is_music_type (SCM) const;
 
-  Stream_event *to_event (Context *) const;
+  Stream_event *to_event () const;
 
   DECLARE_SCHEME_CALLBACK (relative_callback, (SCM, SCM));
   Pitch to_relative_octave (Pitch);
index be1fb2ed131cb0451ab4e373db8e46d52dd9982a..eea6a9ca818a58552a5d4cdda7a159754696d186 100644 (file)
@@ -275,7 +275,7 @@ Music::origin () const
   ES TODO: This method should probably be reworked or junked.
 */
 Stream_event *
-Music::to_event (Context *c) const
+Music::to_event () const
 {
   SCM class_name = ly_camel_case_2_lisp_identifier (get_property ("name"));
 
@@ -283,8 +283,9 @@ Music::to_event (Context *c) const
   if (!internal_is_music_type (class_name))
     programming_error ("Not a music type");
 
-  Stream_event *e = new Stream_event (c->make_event_class (class_name),
-                                      mutable_property_alist_);
+  Stream_event *e = new Stream_event
+    (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"), class_name),
+     mutable_property_alist_);
   Moment length = get_length ();
   if (length.to_bool ())
     e->set_property ("length", length.smobbed_copy ());
@@ -297,7 +298,7 @@ Music::to_event (Context *c) const
       for (; scm_is_pair (art_mus); art_mus = scm_cdr (art_mus))
         {
           Music *m = unsmob_music (scm_car (art_mus));
-          art_ev = scm_cons (m->to_event (c)->unprotect (), art_ev);
+          art_ev = scm_cons (m->to_event ()->unprotect (), art_ev);
         }
       e->set_property ("articulations", scm_reverse_x (art_ev, SCM_EOL));
     }
@@ -314,7 +315,7 @@ Music::to_event (Context *c) const
 void
 Music::send_to_context (Context *c)
 {
-  Stream_event *ev = to_event (c);
+  Stream_event *ev = to_event ();
   c->event_source ()->broadcast (ev);
   ev->unprotect ();
 }
index c0c9acc89306268535dca2c3a13b2fc56e0b4d54..69c7857b7eeec1ff7098baff288f5ccf080c0fbb 100644 (file)
@@ -224,8 +224,8 @@ Part_combine_iterator::kill_mmrest (int in)
   if (!mmrest_event_)
     {
       mmrest_event_ = new Stream_event
-      (handles_[in].get_context ()->make_event_class
-       (ly_symbol2scm ("multi-measure-rest-event")));
+        (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
+                     ly_symbol2scm ("multi-measure-rest-event")));
       mmrest_event_->set_property ("duration", SCM_EOL);
       mmrest_event_->unprotect ();
     }
@@ -256,15 +256,16 @@ Part_combine_iterator::unisono (bool silent)
       if (playing_state_ != UNISONO
           && newstate == UNISONO)
         {
-          Context *out = (last_playing_ == SOLO2 ? second_iter_ : first_iter_)
-                         ->get_outlet ();
           if (!unisono_event_)
             {
               unisono_event_ = new Stream_event
-              (out->make_event_class (ly_symbol2scm ("unisono-event")));
+                (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
+                             ly_symbol2scm ("unisono-event")));
               unisono_event_->unprotect ();
             }
 
+          Context *out = (last_playing_ == SOLO2 ? second_iter_ : first_iter_)
+                         ->get_outlet ();
           out->event_source ()->broadcast (unisono_event_);
           playing_state_ = UNISONO;
         }
@@ -290,8 +291,8 @@ Part_combine_iterator::solo1 ()
           if (!solo_one_event_)
             {
               solo_one_event_ = new Stream_event
-              (first_iter_->get_outlet ()->make_event_class
-               (ly_symbol2scm ("solo-one-event")));
+                (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
+                             ly_symbol2scm ("solo-one-event")));
               solo_one_event_->unprotect ();
             }
 
@@ -317,8 +318,8 @@ Part_combine_iterator::solo2 ()
           if (!solo_two_event_)
             {
               solo_two_event_ = new Stream_event
-              (second_iter_->get_outlet ()->make_event_class
-               (ly_symbol2scm ("solo-two-event")));
+                (scm_call_1 (ly_lily_module_constant ("ly:make-event-class"),
+                             ly_symbol2scm ("solo-two-event")));
               solo_two_event_->unprotect ();
             }
 
index c1edba9702eb5476335adeb867db71a7a2e4de5c..64daa8ea5b615be924c82bf08cf37d9d5619c315 100644 (file)
@@ -47,7 +47,7 @@ Rhythmic_music_iterator::process (Moment m)
       descend_to_bottom_context ();
 
       Context *c = get_outlet ();
-      Stream_event *ev = get_music ()->to_event (c);
+      Stream_event *ev = get_music ()->to_event ();
       SCM arts = ev->get_property ("articulations");
 
       if (scm_is_pair (arts))
index 2541163a7651de2c352be99c544f147351b4a66b..99647c75d03182f2ab159a44d4a86c9264d50149 100644 (file)
@@ -26,7 +26,6 @@
   \defaultchild "Score"
   \description "Hard coded entry point for LilyPond.  Cannot be tuned."
   \grobdescriptions #all-grob-descriptions
-  EventClasses = #all-event-classes
 }
 
 \context {
index a108212eae4a800bc32eb8de2af269085d74b057..8e3ef0e7ef10ffa3ac1a0538b92bb69bf2fd431a 100644 (file)
@@ -37,7 +37,6 @@
   \accepts Score
   \defaultchild Score
   \description "Hard coded entry point for LilyPond.  Cannot be tuned."
-  EventClasses = #all-event-classes
 }
 
 \context {
index 180675e2f8a4a616b91f9bd1a757bddee7f5a20c..1cbd9fb8b276a74577f53a6b9361d020577f2738 100644 (file)
@@ -641,7 +641,6 @@ are described in @file{scm/bar-line.scm}.")
      (apply translator-property-description x))
 
    `(
-     (EventClasses ,cheap-list? "The initial list of event classes.")
 
      (associatedVoiceContext ,ly:context? "The context object of the
 @code{Voice} that has the melody for this @code{Lyrics}.")
index fb790a591fd562d0fd4b85199a6daad9698f0fbe..05d8542b003272b9df481b0f9435da0fddec4b34 100644 (file)
                 (acons elt lineage alist))
               classlist class))))
 
+(define all-event-classes
+  (fold (lambda (elt classlist)
+          (event-class-cons (cdr elt) (car elt) classlist))
+        '() event-classes))
+
+;; Maps event-class to a list of ancestors (inclusive)
+(define-public ancestor-lookup
+  (let ((h (make-hash-table (length all-event-classes))))
+    (for-each (lambda (ent) (hashq-set! h (car ent) ent))
+              all-event-classes)
+    h))
+
+
 ;; Each class will be defined as
 ;; (class parent grandparent .. )
 ;; so that (eq? (cdr class) parent) holds.
 
+(define-public (define-event-class leaf heritage)
+  (cond
+   ((not (eq? leaf (car heritage)))
+    (ly:warning (_ "All classes must be the last in their matrilineal line.")))
+   ((not (equal? (cdr heritage)
+                 (list-head (hashq-ref ancestor-lookup (cadr heritage) '())
+                            (length (cdr heritage)))))
+    (ly:warning (_ "All classes must have a well-defined pedigree in the existing class hierarchy.")))
+   (else (hashq-set! ancestor-lookup
+                     leaf
+                     (cons leaf
+                           (hashq-ref ancestor-lookup
+                                      (cadr heritage)
+                                      '())))))
+  *unspecified*)
+
+;; TODO: Allow entering more complex classes, by taking unions.
+(define-public (ly:make-event-class leaf)
+  (hashq-ref ancestor-lookup leaf))
+
 (define-public (ly:in-event-class? ev cl)
   "Does event @var{ev} belong to event class @var{cl}?"
   (memq cl (ly:event-property ev 'class)))
 
-(define-public all-event-classes
-  (fold (lambda (elt classlist)
-          (event-class-cons (cdr elt) (car elt) classlist))
-        '() event-classes))
-
 ;; does this exist in guile already?
 (define (map-tree f t)
   (cond
index 92c2b5248705177f9d09072a182dae97a465b4cf..ef31ec1f6aa3c809deaf8515dbf0271b7b30966c 100644 (file)
@@ -16,8 +16,6 @@
 ;;;; You should have received a copy of the GNU General Public License
 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 
-(define doc-context (ly:make-global-context $defaultlayout))
-
 (define (music-props-doc)
   (make <texi-node>
     #:name "Music properties"
@@ -33,7 +31,7 @@
 (define music-types->names (make-hash-table 61))
 (filter-map (lambda (entry)
               (let* ((class (ly:camel-case->lisp-identifier (car entry)))
-                     (classes (ly:make-event-class doc-context class)))
+                     (classes (ly:make-event-class class)))
                 (if classes
                     (map
                      (lambda (cl)
@@ -90,7 +88,7 @@
   (let* ((namesym  (car obj))
          (props (cdr obj))
          (class (ly:camel-case->lisp-identifier namesym))
-         (classes (ly:make-event-class doc-context class))
+         (classes (ly:make-event-class class))
          (accept-list (if classes
                           (human-listify
                            (map ref-ify