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"
35 MIDI control function performer. Announces "set property" events on MIDI
38 class Midi_control_function_performer : public Performer
41 TRANSLATOR_DECLARATIONS (Midi_control_function_performer);
42 void announce_function_value_change (SCM);
43 ~Midi_control_function_performer ();
45 void connect_to_context (Context *c);
46 void disconnect_from_context (Context *c);
49 Midi_control_function_performer::Midi_control_function_performer ()
53 Midi_control_function_performer::~Midi_control_function_performer ()
58 Midi_control_function_performer::connect_to_context (Context *c)
61 add_listener (GET_LISTENER (Midi_control_function_performer, announce_function_value_change),
62 ly_symbol2scm ("SetProperty"));
66 Midi_control_function_performer::disconnect_from_context (Context *c)
69 remove_listener (GET_LISTENER (Midi_control_function_performer, announce_function_value_change),
70 ly_symbol2scm ("SetProperty"));
74 Midi_control_function_performer::announce_function_value_change (SCM sev)
76 Stream_event *ev = unsmob<Stream_event> (sev);
77 SCM sym = ev->get_property ("symbol");
78 if (!scm_is_symbol (sym))
81 // Search for a matching context property; if found, check that the value
82 // of the property is within the allowed range, and announce a possible
83 // change in the value of the corresponding control function.
84 string symbol = ly_symbol2string (sym);
85 for (const Audio_control_function_value_change::Context_property *p
86 = Audio_control_function_value_change::context_properties_;
89 if (symbol == p->name_)
91 SCM value = ev->get_property ("value");
92 if (scm_is_number (value))
94 Real val = scm_to_double (value);
95 if (val >= p->range_min_ && val <= p->range_max_)
97 // Normalize the value to the 0.0 to 1.0 range.
98 val = ((val - p->range_min_)
99 / (p->range_max_ - p->range_min_));
100 Audio_control_function_value_change *item
101 = new Audio_control_function_value_change (p->control_,
103 announce_element (Audio_element_info (item, 0));
107 warning (_f ("ignoring out-of-range value change for MIDI "
116 ADD_TRANSLATOR (Midi_control_function_performer,