]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
(DECLARE_EVENT_SWALLOWER): ENTER_DESCRIPTION -> ADD_TRANSLATOR
[lilypond.git] / lily / staff-performer.cc
1 /*
2   staff-performer.cc -- implement Staff_performer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "warn.hh"
10 #include "audio-column.hh"
11 #include "audio-item.hh"
12 #include "audio-staff.hh"
13 #include "performer-group-performer.hh"
14 #include "context.hh"
15
16 /** Perform a staff. Individual notes should have their instrument
17  (staff-wide) set, so we override play_element ()
18
19   */
20 class Staff_performer : public Performer_group_performer 
21 {
22 public:
23   TRANSLATOR_DECLARATIONS (Staff_performer);
24   ~Staff_performer ();
25
26   String new_instrument_string ();
27   String instrument_string_;
28
29 protected:
30   virtual void play_element (Audio_element* p);
31   virtual void finalize ();
32   virtual void initialize ();
33   virtual void create_audio_elements ();
34   virtual void stop_translation_timestep ();
35
36 private:
37   Audio_staff* audio_staff_;
38   Audio_instrument* instrument_;
39   Audio_text* instrument_name_;
40   Audio_text* name_;
41   Audio_tempo* tempo_;
42 };
43
44 ADD_TRANSLATOR (Staff_performer, "", "",
45                    "",
46                    "", "", "");
47
48 Staff_performer::Staff_performer ()
49 {
50   audio_staff_ = 0;
51   instrument_ = 0;
52   instrument_name_ = 0;
53   name_ = 0;
54   tempo_ = 0;
55 }
56
57 Staff_performer::~Staff_performer ()
58 {
59 }
60
61 void
62 Staff_performer::initialize ()
63 {
64   audio_staff_ = new Audio_staff;
65   announce_element (Audio_element_info (audio_staff_, 0));
66
67   name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
68   announce_element (Audio_element_info (name_, 0));
69
70   tempo_ = new Audio_tempo (get_tempo ());
71   announce_element (Audio_element_info (tempo_, 0));
72
73   Performer_group_performer::initialize ();
74 }
75
76 void
77 Staff_performer::create_audio_elements ()
78 {
79   String str = new_instrument_string ();
80   if (str.length ())
81     {
82       instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
83       announce_element (Audio_element_info (instrument_name_, 0));
84       instrument_ = new Audio_instrument (str);
85       announce_element (Audio_element_info (instrument_, 0));
86
87       /*
88         Have to be here before notes arrive into the staff.
89        */
90       play_element (instrument_);
91       play_element (instrument_name_);
92     }
93   Performer_group_performer::create_audio_elements ();
94 }
95
96 void
97 Staff_performer::stop_translation_timestep ()
98 {
99   SCM proc = ly_scheme_function ("percussion?");
100   
101   SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.to_str0 ()));
102   audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1 );
103   if (name_)
104     {
105       play_element (name_);
106       name_ = 0;
107     }
108   if (tempo_)
109     {
110       play_element (tempo_);
111       tempo_ = 0;
112     }
113   instrument_name_ = 0;
114   instrument_ = 0;
115   Performer_group_performer::stop_translation_timestep ();
116 }
117
118 void
119 Staff_performer::finalize ()
120 {
121   Performer_group_performer::finalize ();
122   Performer::play_element (audio_staff_);
123   audio_staff_ = 0;
124 }
125
126 String 
127 Staff_performer::new_instrument_string () 
128
129   // mustn't ask Score for instrument: it will return piano!
130   SCM minstr = get_property ("midiInstrument");
131
132   if (!scm_is_string (minstr)
133       || ly_scm2string (minstr) == instrument_string_)
134     return "";
135
136   instrument_string_ = ly_scm2string (minstr);
137
138   return instrument_string_;
139 }
140
141 void 
142 Staff_performer::play_element (Audio_element* p)
143 {
144   if (Audio_item *ai = dynamic_cast<Audio_item *> (p)) 
145     {
146       audio_staff_->add_audio_item (ai);
147     }
148   Performer::play_element (p);
149 }
150