]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dynamic-performer.cc
2003 -> 2004
[lilypond.git] / lily / dynamic-performer.cc
index 1a7ac9e2c618c3717cf968c2d1f0de98bff4f69a..a00139574cd61e3408f234278512fa81784b9ceb 100644 (file)
@@ -3,78 +3,57 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  2000 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "performer.hh"
-#include "command-request.hh"
-#include "musical-request.hh"
+
+#include "event.hh"
 #include "audio-item.hh"
 
 /*
   TODO:
-    handle multiple requests
- */
+  
+    handle multiple events
 
-/**
-   perform absolute (text) dynamics
+    perform absolute (text) dynamics
  */
 class Dynamic_performer : public Performer
 {
 public:
-  VIRTUAL_COPY_CONS (Translator);
-  
-  Dynamic_performer ();
-  ~Dynamic_performer ();
-
+  TRANSLATOR_DECLARATIONS(Dynamic_performer);
 protected:
-  void do_print () const;
-  virtual bool do_try_music (Music* req_l);
-  virtual void do_process_music ();
-  virtual void do_pre_move_processing ();
+  virtual bool try_music (Music* req);
+  virtual void stop_translation_timestep ();
+  virtual void create_audio_elements ();
 
 private:
-  Text_script_req* text_script_req_l_;
-  Audio_dynamic* audio_p_;
+  Music* script_req_;
+  Audio_dynamic* audio_;
 };
 
-ADD_THIS_TRANSLATOR (Dynamic_performer);
-
 Dynamic_performer::Dynamic_performer ()
 {
-  text_script_req_l_ = 0;
-  audio_p_ = 0;
-}
-
-Dynamic_performer::~Dynamic_performer ()
-{
-}
-
-void
-Dynamic_performer::do_print () const
-{
-#ifndef NPRINT
-  if (text_script_req_l_)
-    text_script_req_l_->print ();
-#endif
+  script_req_ = 0;
+  audio_ = 0;
 }
 
 void
-Dynamic_performer::do_process_music ()
+Dynamic_performer::create_audio_elements ()
 {
-  if (text_script_req_l_)
+  if (script_req_)
     {
-      
-      SCM s = scm_eval2
-       (gh_list
-        (ly_symbol2scm ("dynamic-absolute-volume"),
-         ly_quote_scm (ly_str02scm (text_script_req_l_->text_str_.ch_C ())),
-         SCM_UNDEFINED),
-        SCM_EOL);
-      Real volume = gh_scm2double (scm_eval2 (ly_symbol2scm ("dynamic-default-volume"), SCM_EOL));
-      if (gh_number_p (s))
-       volume = gh_scm2double (s);
-      
+      SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
+
+      SCM svolume  = SCM_EOL;
+      if (gh_procedure_p (proc))
+       {
+         // urg
+         svolume = gh_call1 (proc, script_req_->get_mus_property ("text"));
+       }
+
+      Real volume = robust_scm2double (svolume, 0.5); 
+
       /*
        properties override default equaliser setting
        */
@@ -94,59 +73,63 @@ Dynamic_performer::do_process_music ()
          /*
            urg, code duplication:: staff_performer
          */
-         s = get_property ("midiInstrument");
+         SCM s = get_property ("midiInstrument");
          
-         if (!gh_string_p(s))
+         if (!gh_string_p (s))
            s = get_property ("instrument");
          
-         if (!gh_string_p(s))
-           s = ly_str02scm ("piano");
+         if (!gh_string_p (s))
+           s = scm_makfrom0str ("piano");
          
          
-         s = scm_eval2 (gh_list (ly_symbol2scm ("instrument-equaliser"),
-                                s, SCM_UNDEFINED),
-                        SCM_EOL);
-         if (gh_pair_p (s))
+         SCM eq = get_property ("instrumentEqualizer");
+         if (gh_procedure_p (eq))
+           {
+             s = gh_call1 (eq, s);
+           }
+
+         if (is_number_pair (s))
            {
-             Interval iv;
-             iv[MIN] = gh_scm2double (gh_car (s));
-             iv[MAX] = gh_scm2double (gh_cdr (s));
+             Interval iv = ly_scm2interval (s);
              volume = iv[MIN] + iv.length () * volume;
            }
        }
       
-      audio_p_ = new Audio_dynamic (volume);
-      Audio_element_info info (audio_p_, text_script_req_l_);
+      audio_ = new Audio_dynamic (volume);
+      Audio_element_info info (audio_, script_req_);
       announce_element (info);
-      text_script_req_l_ = 0;
+      script_req_ = 0;
     }
 }
 
 void
-Dynamic_performer::do_pre_move_processing ()
+Dynamic_performer::stop_translation_timestep ()
 {
-  if (audio_p_)
+  if (audio_)
     {
-      play_element (audio_p_);
-      audio_p_ = 0;
+      play_element (audio_);
+      audio_ = 0;
     }
 }
 
 bool
-Dynamic_performer::do_try_music (Music* r)
+Dynamic_performer::try_music (Music* r)
 {
-  if (!text_script_req_l_)
+  if (!script_req_)
     {
-      // urg, text script, style `dynamic' is how absolute dynamics appear
-      if(Text_script_req* t = dynamic_cast <Text_script_req*> (r))
+      if (r->is_mus_type ("absolute-dynamic-event")) // fixme.
        {
-         if (t->style_str_ == "dynamic")
-           {
-             text_script_req_l_ = t;
-             return true;
-           }
+         script_req_ = r;
+         return true;
        }
     }
   return false;
 }
 
+ENTER_DESCRIPTION(Dynamic_performer,
+                 /*descr*/               "",
+                 /* creats*/ "",
+                 /* accepts */     "absolute-dynamic-event",
+                 /* acks */ "",
+                 /*reads */"dynamicAbsoluteVolumeFunction midiMaximumVolume midiMinimumVolume midiInstrument instrumentEqualizer",
+                 /*writes*/"");