]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
add 2007 to (c) year.
[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--2007 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.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 class Staff_performer : public Performer
20 {
21 public:
22   TRANSLATOR_DECLARATIONS (Staff_performer);
23   ~Staff_performer ();
24
25   string new_instrument_string ();
26   string instrument_string_;
27
28 protected:
29   virtual void acknowledge_audio_element (Audio_element_info info);
30   virtual void finalize ();
31   virtual void initialize ();
32   void process_music ();
33   void stop_translation_timestep ();
34
35 private:
36   Audio_staff *audio_staff_;
37   Audio_instrument *instrument_;
38   Audio_text *instrument_name_;
39   Audio_text *name_;
40   Audio_tempo *tempo_;
41 };
42
43 #include "translator.icc"
44
45 ADD_TRANSLATOR (Staff_performer, "", "",
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   name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
66
67   audio_staff_->add_audio_item (name_);
68   
69   announce_element (Audio_element_info (audio_staff_, 0));
70   announce_element (Audio_element_info (name_, 0));
71 }
72
73 void
74 Staff_performer::process_music ()
75 {
76   string str = new_instrument_string ();
77   if (str.length ())
78     {
79       instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
80       announce_element (Audio_element_info (instrument_name_, 0));
81       instrument_ = new Audio_instrument (str);
82       announce_element (Audio_element_info (instrument_, 0));
83
84       audio_staff_->add_audio_item (instrument_);
85       audio_staff_->add_audio_item (instrument_name_);
86      
87       /*
88         Have to be here before notes arrive into the staff.
89       */
90     }
91 }
92
93 void
94 Staff_performer::stop_translation_timestep ()
95 {
96   SCM proc = ly_lily_module_constant ("percussion?");
97
98   SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.c_str ()));
99   audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1);
100   if (name_)
101     {
102       name_ = 0;
103     }
104   if (tempo_)
105     {
106       tempo_ = 0;
107     }
108   instrument_name_ = 0;
109   instrument_ = 0;
110 }
111
112 void
113 Staff_performer::finalize ()
114 {
115   audio_staff_ = 0;
116 }
117
118 string
119 Staff_performer::new_instrument_string ()
120 {
121   // mustn't ask Score for instrument: it will return piano!
122   SCM minstr = get_property ("midiInstrument");
123
124   if (!scm_is_string (minstr)
125       || ly_scm2string (minstr) == instrument_string_)
126     return "";
127
128   instrument_string_ = ly_scm2string (minstr);
129
130   return instrument_string_;
131 }
132
133 void
134 Staff_performer::acknowledge_audio_element (Audio_element_info inf)
135 {
136   if (Audio_item *ai = dynamic_cast<Audio_item *> (inf.elem_))
137     audio_staff_->add_audio_item (ai);
138 }
139