]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-cc-performer.cc
PO: fetch eo form FTP
[lilypond.git] / lily / midi-cc-performer.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2013--2016 by Heikki Tauriainen <g034737@welho.com>.
5   Adapted from performer implementations
6   Copyright (C) 1996--2015 Jan Nieuwenhuizen <janneke@gnu.org>,
7   Han-Wen Nienhyus <hanwen@xs4all.nl> and others.
8
9   LilyPond is free software: you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation, either version 3 of the License, or
12   (at your option) any later version.
13
14   LilyPond is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19   You should have received a copy of the GNU General Public License
20   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "performer.hh"
24
25 #include "audio-item.hh"
26 #include "context.hh"
27 #include "dispatcher.hh"
28 #include "international.hh"
29 #include "listener.hh"
30 #include "midi-cc-announcer.hh"
31 #include "stream-event.hh"
32
33 #include "translator.icc"
34
35 /**
36    MIDI control change performer.  Announces "set property" events on MIDI
37    context properties.
38 */
39 class Midi_control_change_performer : public Performer
40 {
41 public:
42   TRANSLATOR_DECLARATIONS (Midi_control_change_performer);
43   void announce_control_change (SCM);
44   ~Midi_control_change_performer ();
45
46   void connect_to_context (Context *c);
47   void disconnect_from_context (Context *c);
48
49 private:
50   class Control_change_announcer : public Midi_control_change_announcer
51   {
52   public:
53     Control_change_announcer (Midi_control_change_performer *p,
54                               Stream_event *ev, const string &s);
55
56     SCM get_property_value (const char *property_name);
57     void do_announce (Audio_control_change *item);
58
59   private:
60     Midi_control_change_performer *performer_;
61     Stream_event *event_;
62     string symbol_;
63   };
64 };
65
66 Midi_control_change_performer::Midi_control_change_performer (Context *c)
67   : Performer (c)
68 {
69 }
70
71 Midi_control_change_performer::~Midi_control_change_performer ()
72 {
73 }
74
75 void
76 Midi_control_change_performer::connect_to_context (Context *c)
77 {
78   c->events_below ()->
79   add_listener (GET_LISTENER (Midi_control_change_performer,
80                               announce_control_change),
81                 ly_symbol2scm ("SetProperty"));
82 }
83
84 void
85 Midi_control_change_performer::disconnect_from_context (Context *c)
86 {
87   c->events_below ()->
88   remove_listener (GET_LISTENER (Midi_control_change_performer,
89                                  announce_control_change),
90                    ly_symbol2scm ("SetProperty"));
91 }
92
93 void
94 Midi_control_change_performer::announce_control_change (SCM sev)
95 {
96   Stream_event *ev = unsmob<Stream_event> (sev);
97   SCM sym = ev->get_property ("symbol");
98   if (!scm_is_symbol (sym))
99     return;
100
101   Control_change_announcer a (this, ev, ly_symbol2string (sym));
102   a.announce_control_changes ();
103 }
104
105 Midi_control_change_performer::Control_change_announcer::Control_change_announcer
106 (Midi_control_change_performer *p, Stream_event *ev, const string &s)
107   : Midi_control_change_announcer (ev->origin ()),
108     performer_ (p),
109     event_ (ev),
110     symbol_ (s)
111 {
112 }
113
114 SCM
115 Midi_control_change_performer::Control_change_announcer::get_property_value
116 (const char *property_name)
117 {
118   return symbol_ == property_name ? event_->get_property ("value") : SCM_EOL;
119 }
120
121 void Midi_control_change_performer::Control_change_announcer::do_announce
122 (Audio_control_change *item)
123 {
124   performer_->announce_element (Audio_element_info (item, 0));
125 }
126
127 void
128 Midi_control_change_performer::boot ()
129 {
130
131 }
132
133 ADD_TRANSLATOR (Midi_control_change_performer,
134                 /* doc */
135                 "This performer listens to SetProperty events on context "
136                 "properties for generating MIDI control changes and "
137                 "prepares them for MIDI output.",
138
139                 /* create */
140                 "",
141
142                 /* read */
143                 "midiBalance "
144                 "midiPanPosition "
145                 "midiExpression "
146                 "midiReverbLevel "
147                 "midiChorusLevel ",
148
149                 /* write */
150                 ""
151                );