* python/lilylib.py (setup_temp): temporary directories are mode 700.
[lilypond.git] / lily / staff-performer.cc
blobd8cad9bf98f8c3ea02955bf8be5a521406daa1a2
1 /*
2 staff-performer.cc -- implement Staff_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
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"
16 /** Perform a staff. Individual notes should have their instrument
17 (staff-wide) set, so we override play_element ()
20 class Staff_performer : public Performer_group_performer
22 public:
23 TRANSLATOR_DECLARATIONS(Staff_performer);
24 ~Staff_performer ();
26 String new_instrument_string ();
27 String instrument_string_;
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 ();
36 private:
37 Audio_staff* audio_staff_;
38 Audio_instrument* instrument_;
39 Audio_text* instrument_name_;
40 Audio_text* name_;
41 Audio_tempo* tempo_;
44 ENTER_DESCRIPTION (Staff_performer, "", "",
45 "",
46 "", "", "");
48 Staff_performer::Staff_performer ()
50 audio_staff_ = 0;
51 instrument_ = 0;
52 instrument_name_ = 0;
53 name_ = 0;
54 tempo_ = 0;
57 Staff_performer::~Staff_performer ()
61 void
62 Staff_performer::initialize ()
64 audio_staff_ = new Audio_staff;
65 announce_element (Audio_element_info (audio_staff_, 0));
67 name_ = new Audio_text (Audio_text::TRACK_NAME, id_string_);
68 announce_element (Audio_element_info (name_, 0));
70 tempo_ = new Audio_tempo (get_tempo ());
71 announce_element (Audio_element_info (tempo_, 0));
73 Performer_group_performer::initialize ();
76 void
77 Staff_performer::create_audio_elements ()
79 String str = new_instrument_string ();
80 if (str.length ())
82 instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
83 announce_element (Audio_element_info (instrument_name_, 0));
84 instrument_ = new Audio_instrument (str);
85 announce_element (Audio_element_info (instrument_, 0));
87 Performer_group_performer::create_audio_elements ();
90 void
91 Staff_performer::stop_translation_timestep ()
94 UGH. -> don't use eval.
97 SCM proc = scm_primitive_eval (ly_symbol2scm ("percussion?"));
98 SCM drums = gh_call1 (proc, ly_symbol2scm (instrument_string_.to_str0 ()));
99 audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1 );
100 if (name_)
102 play_element (name_);
103 name_ = 0;
105 if (tempo_)
107 play_element (tempo_);
108 tempo_ = 0;
110 if (instrument_name_)
112 play_element (instrument_name_);
113 instrument_name_ = 0;
115 if (instrument_)
117 play_element (instrument_);
118 instrument_ = 0;
120 Performer_group_performer::stop_translation_timestep ();
123 void
124 Staff_performer::finalize ()
126 Performer_group_performer::finalize ();
127 Performer::play_element (audio_staff_);
128 audio_staff_ = 0;
131 String
132 Staff_performer::new_instrument_string ()
134 // mustn't ask Score for instrument: it will return piano!
135 SCM minstr = get_property ("midiInstrument");
137 if (!gh_string_p (minstr))
138 minstr = get_property ("instrument");
140 if (!gh_string_p (minstr)
141 || ly_scm2string (minstr) == instrument_string_)
142 return "";
144 instrument_string_ = ly_scm2string (minstr);
146 return instrument_string_;
149 void
150 Staff_performer::play_element (Audio_element* p)
152 if (Audio_item *ai = dynamic_cast<Audio_item *> (p))
154 audio_staff_->add_audio_item (ai);
156 Performer::play_element (p);