]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
release: 1.3.131
[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--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "audio-staff.hh"
14 #include "performer-group-performer.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   VIRTUAL_COPY_CONS(Translator);
24   
25
26   Staff_performer ();
27   ~Staff_performer ();
28
29   String new_instrument_str ();
30   String instrument_str_;
31
32 protected:
33   virtual void play_element (Audio_element* p);
34   virtual void finalize ();
35   virtual void initialize ();
36   virtual void create_audio_elements ();
37   virtual void stop_translation_timestep ();
38
39 private:
40   Audio_staff* audio_staff_p_;
41   Audio_instrument* instrument_p_;
42   Audio_text* instrument_name_p_;
43   Audio_text* name_p_;
44   Audio_tempo* tempo_p_;
45 };
46
47 ADD_THIS_TRANSLATOR (Staff_performer);
48
49 Staff_performer::Staff_performer ()
50 {
51   audio_staff_p_ = 0;
52   instrument_p_ = 0;
53   instrument_name_p_ = 0;
54   name_p_ = 0;
55   tempo_p_ = 0;
56 }
57
58 Staff_performer::~Staff_performer ()
59 {
60 }
61
62 void
63 Staff_performer::initialize ()
64 {
65   audio_staff_p_ = new Audio_staff;
66   announce_element (Audio_element_info (audio_staff_p_, 0));
67
68   name_p_ = new Audio_text (Audio_text::TRACK_NAME, id_str_);
69   announce_element (Audio_element_info (name_p_, 0));
70
71   tempo_p_ = new Audio_tempo (get_tempo_i ());
72   announce_element (Audio_element_info (tempo_p_, 0));
73
74   Performer_group_performer::initialize ();
75 }
76
77 void
78 Staff_performer::create_audio_elements ()
79 {
80   String str = new_instrument_str ();
81   if (str.length_i ())
82     {
83       instrument_name_p_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
84       announce_element (Audio_element_info (instrument_name_p_, 0));
85       instrument_p_ = new Audio_instrument (str);
86       announce_element (Audio_element_info (instrument_p_, 0));
87     }
88 }
89
90 void
91 Staff_performer::stop_translation_timestep ()
92 {
93   if (name_p_)
94     {
95       play_element (name_p_);
96       name_p_ = 0;
97     }
98   if (tempo_p_)
99     {
100       play_element (tempo_p_);
101       tempo_p_ = 0;
102     }
103   if (instrument_name_p_)
104     {
105       play_element (instrument_name_p_);
106       instrument_name_p_ = 0;
107     }
108   if (instrument_p_)
109     {
110       play_element (instrument_p_);
111       instrument_p_ = 0;
112     }
113   Performer_group_performer::stop_translation_timestep ();
114 }
115
116 void
117 Staff_performer::finalize ()
118 {
119   Performer_group_performer::finalize ();
120   Performer::play_element (audio_staff_p_);
121   audio_staff_p_ = 0;
122 }
123
124 String 
125 Staff_performer::new_instrument_str () 
126
127   // mustn't ask Score for instrument: it will return piano!
128   SCM minstr = get_property (ly_symbol2scm ("midiInstrument"));
129
130   if (!gh_string_p(minstr))
131     minstr = get_property (ly_symbol2scm ("instrument"));
132
133   if (!gh_string_p (minstr)
134       || ly_scm2string (minstr) == instrument_str_)
135     return "";
136
137   instrument_str_ = ly_scm2string (minstr);
138
139   return instrument_str_;
140 }
141
142 void 
143 Staff_performer::play_element (Audio_element* p)
144 {
145   if (Audio_item *ai = dynamic_cast<Audio_item *> (p)) 
146     {
147       audio_staff_p_->add_audio_item (ai);
148     }
149   Performer::play_element (p);
150 }
151