]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
``slikken kreng''
[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--2002 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
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 ENTER_DESCRIPTION (Staff_performer, "","","","","" );
45
46 Staff_performer::Staff_performer ()
47 {
48   audio_staff_ = 0;
49   instrument_ = 0;
50   instrument_name_ = 0;
51   name_ = 0;
52   tempo_ = 0;
53 }
54
55 Staff_performer::~Staff_performer ()
56 {
57 }
58
59 void
60 Staff_performer::initialize ()
61 {
62   audio_staff_ = new Audio_staff;
63   announce_element (Audio_element_info (audio_staff_, 0));
64
65   name_ = new Audio_text (Audio_text::TRACK_NAME, id_string_);
66   announce_element (Audio_element_info (name_, 0));
67
68   tempo_ = new Audio_tempo (get_tempo ());
69   announce_element (Audio_element_info (tempo_, 0));
70
71   Performer_group_performer::initialize ();
72 }
73
74 void
75 Staff_performer::create_audio_elements ()
76 {
77   String str = new_instrument_string ();
78   if (str.length ())
79     {
80       instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
81       announce_element (Audio_element_info (instrument_name_, 0));
82       instrument_ = new Audio_instrument (str);
83       announce_element (Audio_element_info (instrument_, 0));
84     }
85   Performer_group_performer::create_audio_elements ();
86 }
87
88 void
89 Staff_performer::stop_translation_timestep ()
90 {
91   SCM proc = scm_primitive_eval (ly_symbol2scm ("percussion-p")); 
92   SCM drums = gh_call1 (proc, ly_symbol2scm (instrument_string_.to_str0 ()));
93   audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1 );
94   if (name_)
95     {
96       play_element (name_);
97       name_ = 0;
98     }
99   if (tempo_)
100     {
101       play_element (tempo_);
102       tempo_ = 0;
103     }
104   if (instrument_name_)
105     {
106       play_element (instrument_name_);
107       instrument_name_ = 0;
108     }
109   if (instrument_)
110     {
111       play_element (instrument_);
112       instrument_ = 0;
113     }
114   Performer_group_performer::stop_translation_timestep ();
115 }
116
117 void
118 Staff_performer::finalize ()
119 {
120   Performer_group_performer::finalize ();
121   Performer::play_element (audio_staff_);
122   audio_staff_ = 0;
123 }
124
125 String 
126 Staff_performer::new_instrument_string () 
127
128   // mustn't ask Score for instrument: it will return piano!
129   SCM minstr = get_property ("midiInstrument");
130
131   if (!gh_string_p (minstr))
132     minstr = get_property ("instrument");
133
134   if (!gh_string_p (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::play_element (Audio_element* p)
145 {
146   if (Audio_item *ai = dynamic_cast<Audio_item *> (p)) 
147     {
148       audio_staff_->add_audio_item (ai);
149     }
150   Performer::play_element (p);
151 }
152