use a note tracker to resolve notes cut off during render by the end of the region
[ardour.git] / libs / ardour / midi_automation_list_binder.cc
1 /*
2  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2011-2014 David Robillard <d@drobilla.net>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include "ardour/midi_automation_list_binder.h"
21 #include "ardour/automation_list.h"
22 #include "ardour/automation_control.h"
23 #include "ardour/midi_source.h"
24 #include "ardour/midi_model.h"
25
26 using namespace ARDOUR;
27
28 MidiAutomationListBinder::MidiAutomationListBinder (boost::shared_ptr<MidiSource> s, Evoral::Parameter p)
29         : _source (s)
30         , _parameter (p)
31 {
32
33 }
34
35 MidiAutomationListBinder::MidiAutomationListBinder (XMLNode* node, Session::SourceMap const & sources)
36         : _parameter (0, 0, 0)
37 {
38         std::string id_str;
39         std::string parameter_str;
40         if (!node->get_property ("source-id", id_str) ||
41             !node->get_property ("parameter", parameter_str)) {
42                 assert (false);
43         }
44
45         Session::SourceMap::const_iterator i = sources.find (PBD::ID (id_str));
46         assert (i != sources.end());
47         _source = boost::dynamic_pointer_cast<MidiSource> (i->second);
48
49         _parameter = EventTypeMap::instance().from_symbol (parameter_str);
50 }
51
52 AutomationList*
53 MidiAutomationListBinder::get () const
54 {
55         boost::shared_ptr<MidiModel> model = _source->model ();
56         assert (model);
57
58         boost::shared_ptr<AutomationControl> control = model->automation_control (_parameter);
59         assert (control);
60
61         return control->alist().get();
62 }
63
64 void
65 MidiAutomationListBinder::add_state (XMLNode* node)
66 {
67         node->set_property ("source-id", _source->id().to_s());
68         node->set_property ("parameter", EventTypeMap::instance().to_symbol (_parameter));
69 }