Fix MIDI monitoring while recording.
[ardour.git] / libs / ardour / midi_track.cc
1 /*
2     Copyright (C) 2006 Paul Davis 
3         By Dave Robillard, 2006
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 #include "pbd/error.h"
20 #include <sigc++/retype.h>
21 #include <sigc++/retype_return.h>
22 #include <sigc++/bind.h>
23
24 #include "pbd/enumwriter.h"
25 #include "midi++/events.h"
26 #include "evoral/midi_util.h"
27
28 #include "ardour/midi_track.h"
29 #include "ardour/midi_diskstream.h"
30 #include "ardour/session.h"
31 #include "ardour/io_processor.h"
32 #include "ardour/midi_region.h"
33 #include "ardour/midi_source.h"
34 #include "ardour/route_group_specialized.h"
35 #include "ardour/processor.h"
36 #include "ardour/midi_playlist.h"
37 #include "ardour/panner.h"
38 #include "ardour/utils.h"
39 #include "ardour/buffer_set.h"
40 #include "ardour/meter.h"
41
42
43 #include "i18n.h"
44
45 using namespace std;
46 using namespace ARDOUR;
47 using namespace PBD;
48
49 MidiTrack::MidiTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
50         : Track (sess, name, flag, mode, DataType::MIDI)
51         , _immediate_events(1024) // FIXME: size?
52         , _note_mode(Sustained)
53 {
54         use_new_diskstream ();
55
56         _declickable = true;
57         _freeze_record.state = NoFreeze;
58         _saved_meter_point = _meter_point;
59         _mode = mode;
60
61         set_input_minimum(ChanCount(DataType::MIDI, 1));
62         set_input_maximum(ChanCount(DataType::MIDI, 1));
63         set_output_minimum(ChanCount(DataType::MIDI, 1));
64         set_output_maximum(ChanCount(DataType::MIDI, 1));
65
66         PortCountChanged(ChanCount(DataType::MIDI, 2)); /* EMIT SIGNAL */
67 }
68
69 MidiTrack::MidiTrack (Session& sess, const XMLNode& node)
70         : Track (sess, node, DataType::MIDI )
71         , _immediate_events(1024) // FIXME: size?
72         , _note_mode(Sustained)
73 {
74         _set_state(node, false);
75         
76         set_input_minimum(ChanCount(DataType::MIDI, 1));
77         set_input_maximum(ChanCount(DataType::MIDI, 1));
78         set_output_minimum(ChanCount(DataType::MIDI, 1));
79         set_output_maximum(ChanCount(DataType::MIDI, 1));
80         
81         PortCountChanged(ChanCount(DataType::MIDI, 2)); /* EMIT SIGNAL */
82 }
83
84 MidiTrack::~MidiTrack ()
85 {
86 }
87
88 void
89 MidiTrack::use_new_diskstream ()
90 {
91         MidiDiskstream::Flag dflags = MidiDiskstream::Flag (0);
92
93         if (_flags & Hidden) {
94                 dflags = MidiDiskstream::Flag (dflags | MidiDiskstream::Hidden);
95         } else {
96                 dflags = MidiDiskstream::Flag (dflags | MidiDiskstream::Recordable);
97         }
98
99         assert(_mode != Destructive);
100
101         boost::shared_ptr<MidiDiskstream> ds (new MidiDiskstream (_session, name(), dflags));
102         _session.add_diskstream (ds);
103
104         set_diskstream (boost::dynamic_pointer_cast<MidiDiskstream> (ds));
105 }       
106
107 int
108 MidiTrack::set_diskstream (boost::shared_ptr<MidiDiskstream> ds)
109 {
110         _diskstream = ds;
111         _diskstream->set_io (*this);
112         _diskstream->set_destructive (_mode == Destructive);
113
114         _diskstream->set_record_enabled (false);
115         //_diskstream->monitor_input (false);
116
117         ic_connection.disconnect();
118         ic_connection = input_changed.connect (mem_fun (*_diskstream, &MidiDiskstream::handle_input_change));
119
120         DiskstreamChanged (); /* EMIT SIGNAL */
121
122         return 0;
123 }       
124
125 int 
126 MidiTrack::use_diskstream (string name)
127 {
128         boost::shared_ptr<MidiDiskstream> dstream;
129
130         if ((dstream = boost::dynamic_pointer_cast<MidiDiskstream>(_session.diskstream_by_name (name))) == 0) {
131                 error << string_compose(_("MidiTrack: midi diskstream \"%1\" not known by session"), name) << endmsg;
132                 return -1;
133         }
134         
135         return set_diskstream (dstream);
136 }
137
138 int 
139 MidiTrack::use_diskstream (const PBD::ID& id)
140 {
141         boost::shared_ptr<MidiDiskstream> dstream;
142
143         if ((dstream = boost::dynamic_pointer_cast<MidiDiskstream> (_session.diskstream_by_id (id))) == 0) {
144                 error << string_compose(_("MidiTrack: midi diskstream \"%1\" not known by session"), id) << endmsg;
145                 return -1;
146         }
147         
148         return set_diskstream (dstream);
149 }
150
151 boost::shared_ptr<MidiDiskstream>
152 MidiTrack::midi_diskstream() const
153 {
154         return boost::dynamic_pointer_cast<MidiDiskstream>(_diskstream);
155 }
156
157 int
158 MidiTrack::set_state (const XMLNode& node)
159 {
160         return _set_state (node, true);
161 }
162
163 int
164 MidiTrack::_set_state (const XMLNode& node, bool call_base)
165 {
166         const XMLProperty *prop;
167         XMLNodeConstIterator iter;
168
169         if (Route::_set_state (node, call_base)) {
170                 return -1;
171         }
172         
173         // No destructive MIDI tracks (yet?)
174         _mode = Normal;
175         
176         if ((prop = node.property (X_("note-mode"))) != 0) {
177                 _note_mode = NoteMode (string_2_enum (prop->value(), _note_mode));
178         } else {
179                 _note_mode = Sustained;
180         }
181
182         if ((prop = node.property ("diskstream-id")) == 0) {
183                 
184                 /* some old sessions use the diskstream name rather than the ID */
185
186                 if ((prop = node.property ("diskstream")) == 0) {
187                         fatal << _("programming error: MidiTrack given state without diskstream!") << endmsg;
188                         /*NOTREACHED*/
189                         return -1;
190                 }
191
192                 if (use_diskstream (prop->value())) {
193                         return -1;
194                 }
195
196         } else {
197                 
198                 PBD::ID id (prop->value());
199                 PBD::ID zero ("0");
200                 
201                 /* this wierd hack is used when creating tracks from a template. there isn't
202                    a particularly good time to interpose between setting the first part of
203                    the track state (notably Route::set_state() and the track mode), and the
204                    second part (diskstream stuff). So, we have a special ID for the diskstream
205                    that means "you should create a new diskstream here, not look for
206                    an old one.
207                 */
208                 
209                 if (id == zero) {
210                         use_new_diskstream ();
211                 } else if (use_diskstream (id)) {
212                         return -1;
213                 }
214         }
215
216         XMLNodeList nlist;
217         XMLNodeConstIterator niter;
218         XMLNode *child;
219
220         nlist = node.children();
221         for (niter = nlist.begin(); niter != nlist.end(); ++niter){
222                 child = *niter;
223
224                 if (child->name() == X_("recenable")) {
225                         _rec_enable_control->set_state (*child);
226                         _session.add_controllable (_rec_enable_control);
227                 }
228         }
229
230         pending_state = const_cast<XMLNode*> (&node);
231
232         if (_session.state_of_the_state() & Session::Loading) {
233                 _session.StateReady.connect (mem_fun (*this, &MidiTrack::set_state_part_two));
234         } else {
235                 set_state_part_two ();
236         }
237
238         return 0;
239 }
240
241 XMLNode& 
242 MidiTrack::state(bool full_state)
243 {
244         XMLNode& root (Route::state(full_state));
245         XMLNode* freeze_node;
246         char buf[64];
247
248         if (_freeze_record.playlist) {
249                 XMLNode* inode;
250
251                 freeze_node = new XMLNode (X_("freeze-info"));
252                 freeze_node->add_property ("playlist", _freeze_record.playlist->name());
253                 freeze_node->add_property ("state", enum_2_string (_freeze_record.state));
254
255                 for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
256                         inode = new XMLNode (X_("processor"));
257                         (*i)->id.print (buf, sizeof(buf));
258                         inode->add_property (X_("id"), buf);
259                         inode->add_child_copy ((*i)->state);
260                 
261                         freeze_node->add_child_nocopy (*inode);
262                 }
263
264                 root.add_child_nocopy (*freeze_node);
265         }
266
267         /* Alignment: act as a proxy for the diskstream */
268         
269         XMLNode* align_node = new XMLNode (X_("Alignment"));
270         AlignStyle as = _diskstream->alignment_style ();
271         align_node->add_property (X_("style"), enum_2_string (as));
272         root.add_child_nocopy (*align_node);
273
274         root.add_property (X_("note-mode"), enum_2_string (_note_mode));
275         
276         /* we don't return diskstream state because we don't
277            own the diskstream exclusively. control of the diskstream
278            state is ceded to the Session, even if we create the
279            diskstream.
280         */
281
282         _diskstream->id().print (buf, sizeof(buf));
283         root.add_property ("diskstream-id", buf);
284         
285         root.add_child_nocopy (_rec_enable_control->get_state());
286
287         return root;
288 }
289
290 void
291 MidiTrack::set_state_part_two ()
292 {
293         XMLNode* fnode;
294         XMLProperty* prop;
295         LocaleGuard lg (X_("POSIX"));
296
297         /* This is called after all session state has been restored but before
298            have been made ports and connections are established.
299         */
300
301         if (pending_state == 0) {
302                 return;
303         }
304
305         if ((fnode = find_named_node (*pending_state, X_("freeze-info"))) != 0) {
306
307                 _freeze_record.state = Frozen;
308                 
309                 for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
310                         delete *i;
311                 }
312                 _freeze_record.processor_info.clear ();
313                 
314                 if ((prop = fnode->property (X_("playlist"))) != 0) {
315                         boost::shared_ptr<Playlist> pl = _session.playlist_by_name (prop->value());
316                         if (pl) {
317                                 _freeze_record.playlist = boost::dynamic_pointer_cast<MidiPlaylist> (pl);
318                         } else {
319                                 _freeze_record.playlist.reset();
320                                 _freeze_record.state = NoFreeze;
321                         return;
322                         }
323                 }
324                 
325                 if ((prop = fnode->property (X_("state"))) != 0) {
326                         _freeze_record.state = FreezeState (string_2_enum (prop->value(), _freeze_record.state));
327                 }
328                 
329                 XMLNodeConstIterator citer;
330                 XMLNodeList clist = fnode->children();
331                 
332                 for (citer = clist.begin(); citer != clist.end(); ++citer) {
333                         if ((*citer)->name() != X_("processor")) {
334                                 continue;
335                         }
336                         
337                         if ((prop = (*citer)->property (X_("id"))) == 0) {
338                                 continue;
339                         }
340                         
341                         FreezeRecordProcessorInfo* frii = new FreezeRecordProcessorInfo (*((*citer)->children().front()),
342                                                                                    boost::shared_ptr<Processor>());
343                         frii->id = prop->value ();
344                         _freeze_record.processor_info.push_back (frii);
345                 }
346         }
347
348         /* Alignment: act as a proxy for the diskstream */
349
350         if ((fnode = find_named_node (*pending_state, X_("Alignment"))) != 0) {
351
352                 if ((prop = fnode->property (X_("style"))) != 0) {
353
354                         /* fix for older sessions from before EnumWriter */
355
356                         string pstr;
357
358                         if (prop->value() == "capture") {
359                                 pstr = "CaptureTime";
360                         } else if (prop->value() == "existing") {
361                                 pstr = "ExistingMaterial";
362                         } else {
363                                 pstr = prop->value();
364                         }
365
366                         AlignStyle as = AlignStyle (string_2_enum (pstr, as));
367                         _diskstream->set_persistent_align_style (as);
368                 }
369         }
370         return;
371 }       
372
373 int 
374 MidiTrack::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, 
375                     bool session_state_changing, bool can_record, bool rec_monitors_input)
376 {
377         if (n_outputs().n_midi() == 0) {
378                 return 0;
379         }
380
381         if (!_active) {
382                 silence (nframes);
383         }
384
385         if (session_state_changing) {
386
387                 /* XXX is this safe to do against transport state changes? */
388
389                 passthru_silence (start_frame, end_frame, nframes, 0, false);
390                 return 0;
391         }
392
393         midi_diskstream()->check_record_status (start_frame, nframes, can_record);
394
395         bool send_silence;
396         
397         if (_have_internal_generator) {
398                 /* since the instrument has no input streams,
399                    there is no reason to send any signal
400                    into the route.
401                 */
402                 send_silence = true;
403         } else {
404
405                 if (Config->get_auto_input()) {
406                         if (Config->get_monitoring_model() == SoftwareMonitoring) {
407                                 send_silence = false;
408                         } else {
409                                 send_silence = true;
410                         }
411                 } else {
412                         if (_diskstream->record_enabled()) {
413                                 if (Config->get_monitoring_model() == SoftwareMonitoring) {
414                                         send_silence = false;
415                                 } else {
416                                         send_silence = true;
417                                 }
418                         } else {
419                                 send_silence = true;
420                         }
421                 }
422         }
423
424         apply_gain_automation = false;
425
426         if (send_silence) {
427                 
428                 /* if we're sending silence, but we want the meters to show levels for the signal,
429                    meter right here.
430                 */
431                 
432                 if (_have_internal_generator) {
433                         passthru_silence (start_frame, end_frame, nframes, 0, true);
434                 } else {
435                         if (_meter_point == MeterInput) {
436                                 just_meter_input (start_frame, end_frame, nframes);
437                         }
438                         passthru_silence (start_frame, end_frame, nframes, 0, false);
439                 }
440
441         } else {
442         
443                 /* we're sending signal, but we may still want to meter the input. 
444                  */
445
446                 passthru (start_frame, end_frame, nframes, 0, (_meter_point == MeterInput));
447         }
448         
449         flush_outputs (nframes);
450
451         return 0;
452 }
453
454 int
455 MidiTrack::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, int declick,
456                  bool can_record, bool rec_monitors_input)
457 {
458         int dret;
459         boost::shared_ptr<MidiDiskstream> diskstream = midi_diskstream();
460         
461         prepare_inputs (nframes);
462
463         {
464                 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
465                 if (lm.locked()) {
466                         // automation snapshot can also be called from the non-rt context
467                         // and it uses the redirect list, so we take the lock out here
468                         automation_snapshot (start_frame);
469                 }
470         }
471
472         if (n_outputs().n_total() == 0 && _processors.empty()) {
473                 return 0;
474         }
475
476         if (!_active) {
477                 silence (nframes);
478                 return 0;
479         }
480
481         nframes_t transport_frame = _session.transport_frame();
482
483         
484         if ((nframes = check_initial_delay (nframes, transport_frame)) == 0) {
485                 /* need to do this so that the diskstream sets its
486                    playback distance to zero, thus causing diskstream::commit
487                    to do nothing.
488                    */
489                 return diskstream->process (transport_frame, 0, can_record, rec_monitors_input);
490         } 
491
492         _silent = false;
493
494         if ((dret = diskstream->process (transport_frame, nframes, can_record, rec_monitors_input)) != 0) {
495
496                 silence (nframes);
497                 return dret;
498         }
499
500         /* special condition applies */
501
502         if (_meter_point == MeterInput) {
503                 just_meter_input (start_frame, end_frame, nframes);
504         }
505
506         if (diskstream->record_enabled() && !can_record && !Config->get_auto_input()) {
507
508                 /* not actually recording, but we want to hear the input material anyway,
509                    at least potentially (depending on monitoring options)
510                    */
511
512                 passthru (start_frame, end_frame, nframes, 0, true);
513
514         } else {
515                 /*
516                    XXX is it true that the earlier test on n_outputs()
517                    means that we can avoid checking it again here? i think
518                    so, because changing the i/o configuration of an IO
519                    requires holding the AudioEngine lock, which we hold
520                    while in the process() tree.
521                    */
522
523
524                 /* copy the diskstream data to all output buffers */
525
526                 //const size_t limit = n_process_buffers().n_audio();
527                 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
528
529                 diskstream->get_playback(bufs.get_midi(0), start_frame, end_frame);
530
531                 process_output_buffers (bufs, start_frame, end_frame, nframes,
532                                         (!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick, (_meter_point != MeterInput));
533         
534         }
535
536         flush_outputs (nframes);
537
538         return 0;
539 }
540
541 int
542 MidiTrack::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,  
543                         bool can_record, bool rec_monitors_input)
544 {
545         if (n_outputs().n_midi() == 0 && _processors.empty()) {
546                 return 0;
547         }
548
549         if (!_active) {
550                 silence (nframes);
551                 return 0;
552         }
553
554         _silent = true;
555         apply_gain_automation = false;
556
557         silence (nframes);
558
559         return midi_diskstream()->process (_session.transport_frame(), nframes, can_record, rec_monitors_input);
560 }
561
562 void
563 MidiTrack::process_output_buffers (BufferSet& bufs,
564                                    nframes_t start_frame, nframes_t end_frame, 
565                                    nframes_t nframes, bool with_processors, int declick,
566                                    bool meter)
567 {
568         /* There's no such thing as a MIDI bus for the time being.
569          * We'll do all the MIDI route work here for now, but the long-term goal is to have
570          * Route::process_output_buffers handle everything */
571         
572         if (meter && (_meter_point == MeterInput || _meter_point == MeterPreFader)) {
573                 _meter->run_in_place(bufs, start_frame, end_frame, nframes);
574         }
575
576         // Run all processors
577         if (with_processors) {
578                 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
579                 if (rm.locked()) {
580                         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
581                                 bufs.set_count(ChanCount::max(bufs.count(), (*i)->output_streams()));
582                                 (*i)->run_in_place (bufs, start_frame, end_frame, nframes);
583                         }
584                 } 
585         }
586         
587         if (meter && (_meter_point == MeterPostFader)) {
588                 _meter->run_in_place(bufs, start_frame, end_frame, nframes);
589         }
590         
591         // Main output stage
592         if (muted()) {
593                 IO::silence (nframes);
594         } else {
595
596                 // Write 'automation' controllers (e.g. CC events from a UI slider)
597                 write_controller_messages(bufs.get_midi(0), start_frame, end_frame, nframes);
598                 
599                 deliver_output(bufs, start_frame, end_frame, nframes);
600         }
601 }
602
603 void
604 MidiTrack::write_controller_messages(MidiBuffer& output_buf, nframes_t start, nframes_t end, nframes_t nframes)
605 {
606         // Append immediate events (UI controls)
607
608         // XXX TAKE _port_offset in Port into account???
609
610         _immediate_events.read (output_buf, 0, 0, nframes - 1); // all stamps = 0
611 }
612
613 int
614 MidiTrack::export_stuff (BufferSet& bufs, nframes_t nframes, nframes_t end_frame)
615 {
616         return -1;
617 }
618
619 void
620 MidiTrack::set_latency_delay (nframes_t longest_session_latency)
621 {
622         Route::set_latency_delay (longest_session_latency);
623         _diskstream->set_roll_delay (_roll_delay);
624 }
625
626 boost::shared_ptr<Region>
627 MidiTrack::bounce (InterThreadInfo& itt)
628 {
629         throw;
630         // vector<MidiSource*> srcs;
631         // return _session.write_one_track (*this, 0, _session.current_end_frame(), false, srcs, itt);
632         return boost::shared_ptr<Region> ();
633 }
634
635
636 boost::shared_ptr<Region>
637 MidiTrack::bounce_range (nframes_t start, nframes_t end, InterThreadInfo& itt, bool enable_processing)
638 {
639         throw;
640         //vector<MidiSource*> srcs;
641         //return _session.write_one_track (*this, start, end, false, srcs, itt);
642         return boost::shared_ptr<Region> ();
643 }
644
645 void
646 MidiTrack::freeze (InterThreadInfo& itt)
647 {
648 }
649
650 void
651 MidiTrack::unfreeze ()
652 {
653         _freeze_record.state = UnFrozen;
654         FreezeChange (); /* EMIT SIGNAL */
655 }
656
657 void
658 MidiTrack::set_note_mode (NoteMode m)
659 {
660         _note_mode = m;
661         midi_diskstream()->set_note_mode(m);
662 }
663
664 void
665 MidiTrack::midi_panic() 
666 {
667         for (uint8_t channel = 0; channel <= 0xF; channel++) {
668                 uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
669                 write_immediate_event(3, ev);
670                 ev[1] = MIDI_CTL_ALL_NOTES_OFF;
671                 write_immediate_event(3, ev);
672                 ev[1] = MIDI_CTL_RESET_CONTROLLERS;
673                 write_immediate_event(3, ev);
674         }
675 }
676
677 /** \return true on success, false on failure (no buffer space left)
678  */
679 bool
680 MidiTrack::write_immediate_event(size_t size, const uint8_t* buf)
681 {
682         if (!Evoral::midi_event_is_valid(buf, size)) {
683                 cerr << "WARNING: Ignoring illegal immediate MIDI event" << endl;
684                 return false;
685         }
686         const uint32_t type = EventTypeMap::instance().midi_event_type(buf[0]);
687         return (_immediate_events.write(0, type, size, buf) == size);
688 }
689
690 void
691 MidiTrack::MidiControl::set_value(float val)
692 {
693         bool valid = false;
694         if (isinf(val)) {
695                 cerr << "MIDIControl value is infinity" << endl;
696         } else if (isnan(val)) {
697                 cerr << "MIDIControl value is NaN" << endl;
698         } else if (val < _list->parameter().min()) {
699                 cerr << "MIDIControl value is < " << _list->parameter().min() << endl;
700         } else if (val > _list->parameter().max()) {
701                 cerr << "MIDIControl value is > " << _list->parameter().max() << endl;
702         } else {
703                 valid = true;
704         }
705         
706         if (!valid) {
707                 return;
708         }
709
710         assert(val <= _list->parameter().max());
711         size_t size = 3;
712
713         if ( ! automation_playback()) {
714                 uint8_t ev[3] = { _list->parameter().channel(), int(val), 0 };
715                 switch(_list->parameter().type()) {
716                 case MidiCCAutomation:
717                         ev[0] += MIDI_CMD_CONTROL;
718                         ev[1] = _list->parameter().id();
719                         ev[2] = int(val);
720                         break;
721                         
722                 case MidiPgmChangeAutomation:
723                         size = 2;
724                         ev[0] += MIDI_CMD_PGM_CHANGE;
725                         ev[1] = int(val);
726                         break;
727                         
728                 case MidiChannelPressureAutomation:
729                         size = 2;
730                         ev[0] += MIDI_CMD_CHANNEL_PRESSURE;
731                         ev[1] = int(val);
732                         break;
733                         
734                 case MidiPitchBenderAutomation:
735                         ev[0] += MIDI_CMD_BENDER;
736                         ev[1] = 0x7F & int(val);
737                         ev[2] = 0x7F & (int(val) >> 7);
738                         break;
739                         
740                 default:
741                         assert(false);
742                 }
743                 _route->write_immediate_event(size,  ev);
744         }
745
746         AutomationControl::set_value(val);
747
748