]> git.donarmstrong.com Git - lilypond.git/blob - lily/midi-cc-performer.cc
Issue 4989/1: Fix Type1 (PFA) font embedding
[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 ()
67 {
68 }
69
70 Midi_control_change_performer::~Midi_control_change_performer ()
71 {
72 }
73
74 void
75 Midi_control_change_performer::connect_to_context (Context *c)
76 {
77   c->events_below ()->
78   add_listener (GET_LISTENER (Midi_control_change_performer,
79                               announce_control_change),
80                 ly_symbol2scm ("SetProperty"));
81 }
82
83 void
84 Midi_control_change_performer::disconnect_from_context (Context *c)
85 {
86   c->events_below ()->
87   remove_listener (GET_LISTENER (Midi_control_change_performer,
88                                  announce_control_change),
89                    ly_symbol2scm ("SetProperty"));
90 }
91
92 void
93 Midi_control_change_performer::announce_control_change (SCM sev)
94 {
95   Stream_event *ev = unsmob<Stream_event> (sev);
96   SCM sym = ev->get_property ("symbol");
97   if (!scm_is_symbol (sym))
98     return;
99
100   Control_change_announcer a (this, ev, ly_symbol2string (sym));
101   a.announce_control_changes ();
102 }
103
104 Midi_control_change_performer::Control_change_announcer::Control_change_announcer
105 (Midi_control_change_performer *p, Stream_event *ev, const string &s)
106   : Midi_control_change_announcer (ev->origin ()),
107     performer_ (p),
108     event_ (ev),
109     symbol_ (s)
110 {
111 }
112
113 SCM
114 Midi_control_change_performer::Control_change_announcer::get_property_value
115 (const char *property_name)
116 {
117   return symbol_ == property_name ? event_->get_property ("value") : SCM_EOL;
118 }
119
120 void Midi_control_change_performer::Control_change_announcer::do_announce
121 (Audio_control_change *item)
122 {
123   performer_->announce_element (Audio_element_info (item, 0));
124 }
125
126 void
127 Midi_control_change_performer::boot ()
128 {
129
130 }
131
132 ADD_TRANSLATOR (Midi_control_change_performer,
133                 /* doc */
134                 "This performer listens to SetProperty events on context "
135                 "properties for generating MIDI control changes and "
136                 "prepares them for MIDI output.",
137
138                 /* create */
139                 "",
140
141                 /* read */
142                 "midiBalance "
143                 "midiPanPosition "
144                 "midiExpression "
145                 "midiReverbLevel "
146                 "midiChorusLevel ",
147
148                 /* write */
149                 ""
150                );