]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
Update source file headers. Fixes using standard GNU package conventions.
[lilypond.git] / lily / staff-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2009 Jan Nieuwenhuizen <janneke@gnu.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "warn.hh"
21 #include "audio-column.hh"
22 #include "audio-item.hh"
23 #include "audio-staff.hh"
24 #include "performer-group.hh"
25 #include "context.hh"
26
27 /* Perform a staff. Individual notes should have their instrument
28   (staff-wide) set, so we override play_element ()
29 */
30 class Staff_performer : public Performer
31 {
32 public:
33   TRANSLATOR_DECLARATIONS (Staff_performer);
34   ~Staff_performer ();
35
36   string new_instrument_string ();
37   string instrument_string_;
38
39 protected:
40   virtual void acknowledge_audio_element (Audio_element_info info);
41   virtual void finalize ();
42   virtual void initialize ();
43   void process_music ();
44   void stop_translation_timestep ();
45
46 private:
47   Audio_staff *audio_staff_;
48   Audio_instrument *instrument_;
49   Audio_text *instrument_name_;
50   Audio_text *name_;
51   Audio_tempo *tempo_;
52 };
53
54 #include "translator.icc"
55
56 ADD_TRANSLATOR (Staff_performer,
57                 /* doc */
58                 "",
59
60                 /* create */
61                 "",
62
63                 /* read */
64                 "",
65
66                 /* write */
67                 "");
68
69 Staff_performer::Staff_performer ()
70 {
71   audio_staff_ = 0;
72   instrument_ = 0;
73   instrument_name_ = 0;
74   name_ = 0;
75   tempo_ = 0;
76 }
77
78 Staff_performer::~Staff_performer ()
79 {
80 }
81
82 void
83 Staff_performer::initialize ()
84 {
85   audio_staff_ = new Audio_staff;
86   name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
87
88   audio_staff_->add_audio_item (name_);
89   
90   announce_element (Audio_element_info (audio_staff_, 0));
91   announce_element (Audio_element_info (name_, 0));
92 }
93
94 void
95 Staff_performer::process_music ()
96 {
97   string str = new_instrument_string ();
98   if (str.length ())
99     {
100       instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
101       announce_element (Audio_element_info (instrument_name_, 0));
102       instrument_ = new Audio_instrument (str);
103       announce_element (Audio_element_info (instrument_, 0));
104
105       audio_staff_->add_audio_item (instrument_);
106       audio_staff_->add_audio_item (instrument_name_);
107      
108       /*
109         Have to be here before notes arrive into the staff.
110       */
111     }
112 }
113
114 void
115 Staff_performer::stop_translation_timestep ()
116 {
117   SCM proc = ly_lily_module_constant ("percussion?");
118
119   SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.c_str ()));
120   audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1);
121   if (name_)
122     {
123       name_ = 0;
124     }
125   if (tempo_)
126     {
127       tempo_ = 0;
128     }
129   instrument_name_ = 0;
130   instrument_ = 0;
131 }
132
133 void
134 Staff_performer::finalize ()
135 {
136   audio_staff_ = 0;
137 }
138
139 string
140 Staff_performer::new_instrument_string ()
141 {
142   // mustn't ask Score for instrument: it will return piano!
143   SCM minstr = get_property ("midiInstrument");
144
145   if (!scm_is_string (minstr)
146       || ly_scm2string (minstr) == instrument_string_)
147     return "";
148
149   instrument_string_ = ly_scm2string (minstr);
150
151   return instrument_string_;
152 }
153
154 void
155 Staff_performer::acknowledge_audio_element (Audio_element_info inf)
156 {
157   if (Audio_item *ai = dynamic_cast<Audio_item *> (inf.elem_))
158     audio_staff_->add_audio_item (ai);
159 }
160