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

« back to all changes in this revision

Viewing changes to lily/key-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) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
 
6
  (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
7
7
*/
8
8
 
9
 
#include "lily-guile.hh"
10
 
 
 
9
#include "music-sequence.hh"
11
10
#include "audio-item.hh"
12
11
#include "performer.hh"
13
12
#include "warn.hh"
14
13
 
15
 
 
16
14
class Key_performer : public Performer
17
15
{
18
16
public:
20
18
  ~Key_performer ();
21
19
 
22
20
protected:
23
 
  virtual bool try_music (Music* req);
24
 
  virtual void create_audio_elements ();
25
 
  virtual void stop_translation_timestep ();
 
21
  virtual bool try_music (Music *ev);
 
22
  void process_music ();
 
23
  void stop_translation_timestep ();
26
24
 
27
25
private:
28
 
  Key_change_ev* key_req_;
29
 
  Audio_key* audio_;
 
26
  Music *key_ev_;
 
27
  Audio_key *audio_;
30
28
};
31
29
 
32
30
Key_performer::Key_performer ()
33
31
{
34
 
  key_req_ = 0;
 
32
  key_ev_ = 0;
35
33
  audio_ = 0;
36
34
}
37
35
 
40
38
}
41
39
 
42
40
void
43
 
Key_performer::create_audio_elements ()
 
41
Key_performer::process_music ()
44
42
{
45
 
  if (key_req_) 
 
43
  if (key_ev_)
46
44
    {
47
 
      SCM pitchlist = key_req_->get_property ("pitch-alist");
48
 
      SCM proc = ly_scheme_function ("alterations-in-key");
49
 
      
50
 
      SCM acc = gh_call1 (proc, pitchlist);
51
 
      
52
 
      Pitch key_do (0, 
53
 
                    gh_scm2int (ly_caar (pitchlist)),
54
 
                    gh_scm2int (ly_cdar (pitchlist)));
 
45
      SCM pitchlist = key_ev_->get_property ("pitch-alist");
 
46
      SCM proc = ly_lily_module_constant ("alterations-in-key");
 
47
 
 
48
      SCM acc = scm_call_1 (proc, pitchlist);
 
49
 
 
50
      Pitch key_do (0,
 
51
                    scm_to_int (scm_caar (pitchlist)),
 
52
                    scm_to_int (scm_cdar (pitchlist)));
55
53
 
56
54
      Pitch c_do (0, 0, 0);
57
 
                  
 
55
 
58
56
      SCM c_pitchlist
59
57
        = ly_transpose_key_alist (pitchlist,
60
 
                                  interval (key_do, c_do).smobbed_copy ());
 
58
                                  pitch_interval (key_do, c_do).smobbed_copy ());
61
59
 
62
60
      /* MIDI keys are too limited for lilypond scales.
63
61
         We check for minor scale and assume major otherwise.  */
64
 
      SCM minor = scm_c_eval_string ("minor");
65
 
      audio_ = new Audio_key (gh_scm2int (acc),
66
 
                              SCM_BOOL_T != scm_equal_p (minor, c_pitchlist));
67
 
 
68
 
      Audio_element_info info (audio_, key_req_);
 
62
 
 
63
      SCM third = scm_assoc (scm_from_int (2),
 
64
                             c_pitchlist);
 
65
      bool minor = (scm_is_pair (third)
 
66
                    && scm_is_integer (scm_cdr (third))
 
67
                    && scm_to_int (scm_cdr (third)) == FLAT);
 
68
 
 
69
      audio_ = new Audio_key (scm_to_int (acc),
 
70
                              !minor);
 
71
 
 
72
      Audio_element_info info (audio_, key_ev_);
69
73
      announce_element (info);
70
 
      key_req_ = 0;
 
74
      key_ev_ = 0;
71
75
    }
72
76
}
73
77
 
82
86
}
83
87
 
84
88
bool
85
 
Key_performer::try_music (Music* req)
 
89
Key_performer::try_music (Music *ev)
86
90
{
87
 
  if (Key_change_ev *kc = dynamic_cast <Key_change_ev *> (req))
88
 
    {
89
 
      if (key_req_)
90
 
        warning (_ ("FIXME: key change merge"));
91
 
 
92
 
      key_req_ = kc;
93
 
      return true;
94
 
    }
95
 
 
96
 
  return false;
 
91
  if (!key_ev_)
 
92
    key_ev_ = ev;
 
93
 
 
94
  return true;
97
95
}
98
96
 
99
 
ENTER_DESCRIPTION (Key_performer,
100
 
                  "","",
101
 
                  "key-change-event",
102
 
                  "","","");
 
97
#include "translator.icc"
 
98
 
 
99
ADD_TRANSLATOR (Key_performer,
 
100
                "", "",
 
101
                "key-change-event",
 
102
                "", "");