]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-performer.cc
release: 1.3.1
[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--1999 Jan Nieuwenhuizen <janneke@gnu.org>
7  */
8
9 #include "staff-performer.hh"
10 #include "translator-group.hh"
11 #include "debug.hh"
12 #include "audio-column.hh"
13 #include "audio-item.hh"
14 #include "audio-staff.hh"
15
16
17 ADD_THIS_TRANSLATOR (Staff_performer);
18
19 Staff_performer::Staff_performer ()
20 {
21   audio_staff_p_ = 0;
22   instrument_p_ = 0;
23   instrument_name_p_ = 0;
24   name_p_ = 0;
25   tempo_p_ = 0;
26 }
27
28 Staff_performer::~Staff_performer ()
29 {
30 }
31
32 void
33 Staff_performer::do_creation_processing ()
34 {
35   audio_staff_p_ = new Audio_staff;
36   announce_element (Audio_element_info (audio_staff_p_, 0));
37
38   name_p_ = new Audio_text (Audio_text::TRACK_NAME, id_str_);
39   announce_element (Audio_element_info (name_p_, 0));
40
41   tempo_p_ = new Audio_tempo (get_tempo_i ());
42   announce_element (Audio_element_info (tempo_p_, 0));
43
44   Performer_group_performer::do_creation_processing ();
45 }
46
47 void
48 Staff_performer::do_process_requests ()
49 {
50   String str = new_instrument_str ();
51   if (str.length_i ())
52     {
53       instrument_name_p_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
54       announce_element (Audio_element_info (instrument_name_p_, 0));
55       instrument_p_ = new Audio_instrument (str);
56       announce_element (Audio_element_info (instrument_p_, 0));
57     }
58   Performer_group_performer::do_process_requests ();
59 }
60
61 void
62 Staff_performer::do_pre_move_processing ()
63 {
64   if (name_p_)
65     {
66       play_element (name_p_);
67       name_p_ = 0;
68     }
69   if (tempo_p_)
70     {
71       play_element (tempo_p_);
72       tempo_p_ = 0;
73     }
74   if (instrument_name_p_)
75     {
76       play_element (instrument_name_p_);
77       instrument_name_p_ = 0;
78     }
79   if (instrument_p_)
80     {
81       play_element (instrument_p_);
82       instrument_p_ = 0;
83     }
84   Performer_group_performer::do_pre_move_processing ();
85 }
86
87 void
88 Staff_performer::do_removal_processing ()
89 {
90   Performer_group_performer::do_removal_processing ();
91   Performer::play_element (audio_staff_p_);
92   audio_staff_p_ = 0;
93 }
94
95 String 
96 Staff_performer::new_instrument_str () 
97
98   // mustn't ask Score for instrument: it will return piano!
99   SCM minstr = get_property (gh_symbol2scm ("midiInstrument"), 0);
100
101   if (!gh_string_p(minstr))
102     minstr = get_property (gh_symbol2scm ("instrument"), 0);
103
104   if (ly_scm2string (minstr) == instrument_str_)
105     return "";
106
107   instrument_str_ = ly_scm2string (minstr);
108
109   return instrument_str_;
110 }
111
112 void 
113 Staff_performer::play_element (Audio_element* p)
114 {
115   if (Audio_item *ai = dynamic_cast<Audio_item *> (p)) 
116     {
117       audio_staff_p_->add_audio_item (ai);
118     }
119   Performer::play_element (p);
120 }
121