]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
0b138701c391d30fb5ac89e63885bcfc4f9e6128
[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                 /* doc */
47                 "",
48
49                 /* create */
50                 "",
51
52                 /* read */
53                 "",
54
55                 /* write */
56                 "");
57
58 Staff_performer::Staff_performer ()
59 {
60   audio_staff_ = 0;
61   instrument_ = 0;
62   instrument_name_ = 0;
63   name_ = 0;
64   tempo_ = 0;
65 }
66
67 Staff_performer::~Staff_performer ()
68 {
69 }
70
71 void
72 Staff_performer::initialize ()
73 {
74   audio_staff_ = new Audio_staff;
75   name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
76
77   audio_staff_->add_audio_item (name_);
78   
79   announce_element (Audio_element_info (audio_staff_, 0));
80   announce_element (Audio_element_info (name_, 0));
81 }
82
83 void
84 Staff_performer::process_music ()
85 {
86   string str = new_instrument_string ();
87   if (str.length ())
88     {
89       instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
90       announce_element (Audio_element_info (instrument_name_, 0));
91       instrument_ = new Audio_instrument (str);
92       announce_element (Audio_element_info (instrument_, 0));
93
94       audio_staff_->add_audio_item (instrument_);
95       audio_staff_->add_audio_item (instrument_name_);
96      
97       /*
98         Have to be here before notes arrive into the staff.
99       */
100     }
101 }
102
103 void
104 Staff_performer::stop_translation_timestep ()
105 {
106   SCM proc = ly_lily_module_constant ("percussion?");
107
108   SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.c_str ()));
109   audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1);
110   if (name_)
111     {
112       name_ = 0;
113     }
114   if (tempo_)
115     {
116       tempo_ = 0;
117     }
118   instrument_name_ = 0;
119   instrument_ = 0;
120 }
121
122 void
123 Staff_performer::finalize ()
124 {
125   audio_staff_ = 0;
126 }
127
128 string
129 Staff_performer::new_instrument_string ()
130 {
131   // mustn't ask Score for instrument: it will return piano!
132   SCM minstr = get_property ("midiInstrument");
133
134   if (!scm_is_string (minstr)
135       || ly_scm2string (minstr) == instrument_string_)
136     return "";
137
138   instrument_string_ = ly_scm2string (minstr);
139
140   return instrument_string_;
141 }
142
143 void
144 Staff_performer::acknowledge_audio_element (Audio_element_info inf)
145 {
146   if (Audio_item *ai = dynamic_cast<Audio_item *> (inf.elem_))
147     audio_staff_->add_audio_item (ai);
148 }
149