~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/dynamic-performer.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
  source file of the GNU LilyPond music typesetter
5
5
 
6
 
  (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
 
6
  (c) 2000--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7
7
*/
8
8
 
9
9
#include "performer.hh"
10
10
 
11
 
#include "event.hh"
12
11
#include "audio-item.hh"
 
12
#include "music.hh"
 
13
#include "translator.icc"
13
14
 
14
15
/*
15
16
  TODO:
16
 
  
17
 
    handle multiple events
18
 
 
19
 
    perform absolute (text) dynamics
20
 
 */
 
17
 
 
18
  handle multiple events
 
19
 
 
20
  perform absolute (text) dynamics
 
21
*/
21
22
class Dynamic_performer : public Performer
22
23
{
23
24
public:
24
25
  TRANSLATOR_DECLARATIONS (Dynamic_performer);
25
26
protected:
26
 
  virtual bool try_music (Music* req);
27
 
  virtual void stop_translation_timestep ();
28
 
  virtual void create_audio_elements ();
 
27
  virtual bool try_music (Music *event);
 
28
  void stop_translation_timestep ();
 
29
  void process_music ();
29
30
 
30
31
private:
31
 
  Music* script_req_;
32
 
  Audio_dynamic* audio_;
 
32
  Music *script_event_;
 
33
  Audio_dynamic *audio_;
33
34
};
34
35
 
35
36
Dynamic_performer::Dynamic_performer ()
36
37
{
37
 
  script_req_ = 0;
 
38
  script_event_ = 0;
38
39
  audio_ = 0;
39
40
}
40
41
 
41
42
void
42
 
Dynamic_performer::create_audio_elements ()
 
43
Dynamic_performer::process_music ()
43
44
{
44
 
  if (script_req_)
 
45
  if (script_event_)
45
46
    {
46
47
      SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
47
48
 
48
 
      SCM svolume  = SCM_EOL;
49
 
      if (gh_procedure_p (proc))
 
49
      SCM svolume = SCM_EOL;
 
50
      if (ly_is_procedure (proc))
50
51
        {
51
52
          // urg
52
 
          svolume = gh_call1 (proc, script_req_->get_property ("text"));
 
53
          svolume = scm_call_1 (proc, script_event_->get_property ("text"));
53
54
        }
54
55
 
55
 
      Real volume = robust_scm2double (svolume, 0.5); 
 
56
      Real volume = robust_scm2double (svolume, 0.5);
56
57
 
57
58
      /*
58
59
        properties override default equaliser setting
59
 
       */
 
60
      */
60
61
      SCM min = get_property ("midiMinimumVolume");
61
62
      SCM max = get_property ("midiMaximumVolume");
62
 
      if (gh_number_p (min) || gh_number_p (max))
 
63
      if (scm_is_number (min) || scm_is_number (max))
63
64
        {
64
65
          Interval iv (0, 1);
65
 
          if (gh_number_p (min))
66
 
            iv[MIN] = gh_scm2double (min);
67
 
          if (gh_number_p (max))
68
 
            iv[MAX] = gh_scm2double (max);
 
66
          if (scm_is_number (min))
 
67
            iv[MIN] = scm_to_double (min);
 
68
          if (scm_is_number (max))
 
69
            iv[MAX] = scm_to_double (max);
69
70
          volume = iv[MIN] + iv.length () * volume;
70
71
        }
71
72
      else
74
75
            urg, code duplication:: staff_performer
75
76
          */
76
77
          SCM s = get_property ("midiInstrument");
77
 
          
78
 
          if (!gh_string_p (s))
 
78
 
 
79
          if (!scm_is_string (s))
79
80
            s = get_property ("instrument");
80
 
          
81
 
          if (!gh_string_p (s))
 
81
 
 
82
          if (!scm_is_string (s))
82
83
            s = scm_makfrom0str ("piano");
83
 
          
84
 
          
 
84
 
85
85
          SCM eq = get_property ("instrumentEqualizer");
86
 
          if (gh_procedure_p (eq))
87
 
            {
88
 
              s = gh_call1 (eq, s);
89
 
            }
 
86
          if (ly_is_procedure (eq))
 
87
            s = scm_call_1 (eq, s);
90
88
 
91
89
          if (is_number_pair (s))
92
90
            {
94
92
              volume = iv[MIN] + iv.length () * volume;
95
93
            }
96
94
        }
97
 
      
 
95
 
98
96
      audio_ = new Audio_dynamic (volume);
99
 
      Audio_element_info info (audio_, script_req_);
 
97
      Audio_element_info info (audio_, script_event_);
100
98
      announce_element (info);
101
 
      script_req_ = 0;
 
99
      script_event_ = 0;
102
100
    }
103
101
}
104
102
 
113
111
}
114
112
 
115
113
bool
116
 
Dynamic_performer::try_music (Music* r)
 
114
Dynamic_performer::try_music (Music *r)
117
115
{
118
 
  if (!script_req_)
 
116
  if (!script_event_)
119
117
    {
120
118
      if (r->is_mus_type ("absolute-dynamic-event")) // fixme.
121
119
        {
122
 
          script_req_ = r;
 
120
          script_event_ = r;
123
121
          return true;
124
122
        }
125
123
    }
126
124
  return false;
127
125
}
128
126
 
129
 
ENTER_DESCRIPTION (Dynamic_performer,
130
 
                  /*descr*/               "",
131
 
                  /* creats*/ "",
132
 
                  /* accepts */     "absolute-dynamic-event",
133
 
                  /* acks */ "",
134
 
                  /*reads */"dynamicAbsoluteVolumeFunction midiMaximumVolume midiMinimumVolume midiInstrument instrumentEqualizer",
135
 
                  /*writes*/"");
 
127
ADD_TRANSLATOR (Dynamic_performer,
 
128
                /* doc */                "",
 
129
                /* create */ "",
 
130
                /* accept */ "absolute-dynamic-event",
 
131
                /* read */ "dynamicAbsoluteVolumeFunction midiMaximumVolume midiMinimumVolume midiInstrument instrumentEqualizer",
 
132
                /*writes*/"");