fix crash when copy'ing latent plugins
[ardour.git] / libs / ardour / midi_automation_list_binder.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
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         XMLProperty const * source = node->property ("source-id");
39         assert (source);
40
41         XMLProperty const * parameter = node->property ("parameter");
42         assert (parameter);
43
44         Session::SourceMap::const_iterator i = sources.find (PBD::ID (source->value()));
45         assert (i != sources.end());
46         _source = boost::dynamic_pointer_cast<MidiSource> (i->second);
47
48         _parameter = EventTypeMap::instance().from_symbol (parameter->value());
49 }
50
51 AutomationList*
52 MidiAutomationListBinder::get () const
53 {
54         boost::shared_ptr<MidiModel> model = _source->model ();
55         assert (model);
56
57         boost::shared_ptr<AutomationControl> control = model->automation_control (_parameter);
58         assert (control);
59
60         return control->alist().get();
61 }
62
63 void
64 MidiAutomationListBinder::add_state (XMLNode* node)
65 {
66         node->add_property ("source-id", _source->id().to_s());
67         node->add_property ("parameter", EventTypeMap::instance().to_symbol (_parameter));
68 }