]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
* lily/accidental-placement.cc (position_accidentals): bugfix in
[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 "translator-group.hh"
10 #include "warn.hh"
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "audio-staff.hh"
14 #include "performer-group-performer.hh"
15 #include "context.hh"
16
17 /** Perform a staff. Individual notes should have their instrument
18  (staff-wide) set, so we override play_element ()
19
20   */
21 class Staff_performer : public Performer_group_performer 
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Staff_performer);
25   ~Staff_performer ();
26
27   String new_instrument_string ();
28   String instrument_string_;
29
30 protected:
31   virtual void play_element (Audio_element* p);
32   virtual void finalize ();
33   virtual void initialize ();
34   virtual void create_audio_elements ();
35   virtual void stop_translation_timestep ();
36
37 private:
38   Audio_staff* audio_staff_;
39   Audio_instrument* instrument_;
40   Audio_text* instrument_name_;
41   Audio_text* name_;
42   Audio_tempo* tempo_;
43 };
44
45 ENTER_DESCRIPTION (Staff_performer, "", "",
46                    "",
47                    "", "", "");
48
49 Staff_performer::Staff_performer ()
50 {
51   audio_staff_ = 0;
52   instrument_ = 0;
53   instrument_name_ = 0;
54   name_ = 0;
55   tempo_ = 0;
56 }
57
58 Staff_performer::~Staff_performer ()
59 {
60 }
61
62 void
63 Staff_performer::initialize ()
64 {
65   audio_staff_ = new Audio_staff;
66   announce_element (Audio_element_info (audio_staff_, 0));
67
68   name_ = new Audio_text (Audio_text::TRACK_NAME, daddy_context_->id_string_);
69   announce_element (Audio_element_info (name_, 0));
70
71   tempo_ = new Audio_tempo (get_tempo ());
72   announce_element (Audio_element_info (tempo_, 0));
73
74   Performer_group_performer::initialize ();
75 }
76
77 void
78 Staff_performer::create_audio_elements ()
79 {
80   String str = new_instrument_string ();
81   if (str.length ())
82     {
83       instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
84       announce_element (Audio_element_info (instrument_name_, 0));
85       instrument_ = new Audio_instrument (str);
86       announce_element (Audio_element_info (instrument_, 0));
87     }
88   Performer_group_performer::create_audio_elements ();
89 }
90
91 void
92 Staff_performer::stop_translation_timestep ()
93 {
94   /*
95     UGH. -> don't use eval.
96   */
97   static SCM proc;
98   if (!proc)
99     proc = scm_primitive_eval (ly_symbol2scm ("percussion?"));
100   
101   SCM drums = gh_call1 (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   if (instrument_name_)
114     {
115       play_element (instrument_name_);
116       instrument_name_ = 0;
117     }
118   if (instrument_)
119     {
120       play_element (instrument_);
121       instrument_ = 0;
122     }
123   Performer_group_performer::stop_translation_timestep ();
124 }
125
126 void
127 Staff_performer::finalize ()
128 {
129   Performer_group_performer::finalize ();
130   Performer::play_element (audio_staff_);
131   audio_staff_ = 0;
132 }
133
134 String 
135 Staff_performer::new_instrument_string () 
136
137   // mustn't ask Score for instrument: it will return piano!
138   SCM minstr = get_property ("midiInstrument");
139
140   if (!gh_string_p (minstr)
141       || ly_scm2string (minstr) == instrument_string_)
142     return "";
143
144   instrument_string_ = ly_scm2string (minstr);
145
146   return instrument_string_;
147 }
148
149 void 
150 Staff_performer::play_element (Audio_element* p)
151 {
152   if (Audio_item *ai = dynamic_cast<Audio_item *> (p)) 
153     {
154       audio_staff_->add_audio_item (ai);
155     }
156   Performer::play_element (p);
157 }
158