2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2013--2015 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.
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.
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.
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/>.
23 #include "performer.hh"
25 #include "audio-item.hh"
27 #include "dispatcher.hh"
28 #include "international.hh"
29 #include "listener.hh"
30 #include "stream-event.hh"
32 #include "translator.icc"
37 MIDI control function performer. Announces "set property" events on MIDI
40 class Midi_control_function_performer : public Performer
43 TRANSLATOR_DECLARATIONS (Midi_control_function_performer);
44 void announce_function_value_change (SCM);
45 ~Midi_control_function_performer ();
47 void connect_to_context (Context *c);
48 void disconnect_from_context (Context *c);
51 Midi_control_function_performer::Midi_control_function_performer ()
55 Midi_control_function_performer::~Midi_control_function_performer ()
60 Midi_control_function_performer::connect_to_context (Context *c)
63 add_listener (GET_LISTENER (Midi_control_function_performer, announce_function_value_change),
64 ly_symbol2scm ("SetProperty"));
68 Midi_control_function_performer::disconnect_from_context (Context *c)
71 remove_listener (GET_LISTENER (Midi_control_function_performer, announce_function_value_change),
72 ly_symbol2scm ("SetProperty"));
76 Midi_control_function_performer::announce_function_value_change (SCM sev)
78 Stream_event *ev = unsmob<Stream_event> (sev);
79 SCM sym = ev->get_property ("symbol");
80 if (!scm_is_symbol (sym))
83 // Search for a matching context property; if found, check that the value
84 // of the property is within the allowed range, and announce a possible
85 // change in the value of the corresponding control function.
86 string symbol = ly_symbol2string (sym);
87 for (const Audio_control_function_value_change::Context_property *p
88 = Audio_control_function_value_change::context_properties_;
91 if (symbol == p->name_)
93 SCM value = ev->get_property ("value");
94 if (scm_is_number (value))
96 Real val = scm_to_double (value);
97 if (val >= p->range_min_ && val <= p->range_max_)
99 // Normalize the value to the 0.0 to 1.0 range.
100 val = ((val - p->range_min_)
101 / (p->range_max_ - p->range_min_));
102 Audio_control_function_value_change *item
103 = new Audio_control_function_value_change (p->control_,
105 announce_element (Audio_element_info (item, 0));
109 warning (_f ("ignoring out-of-range value change for MIDI "
118 ADD_TRANSLATOR (Midi_control_function_performer,