Fix DSP load sorting with inactive plugins
[ardour.git] / gtk2_ardour / midi_automation_line.cc
1 /*
2  * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2010-2014 David Robillard <d@drobilla.net>
4  * Copyright (C) 2010-2017 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "ardour/midi_automation_list_binder.h"
23 #include "ardour/midi_region.h"
24
25 #include "midi++/midnam_patch.h"
26
27 #include "midi_automation_line.h"
28 #include "midi_time_axis.h"
29
30 #include "pbd/i18n.h"
31
32 using namespace std;
33
34 MidiAutomationLine::MidiAutomationLine (
35         const std::string&                                      name,
36         TimeAxisView&                                           tav,
37         ArdourCanvas::Item&                                     parent,
38         boost::shared_ptr<ARDOUR::AutomationList>               list,
39         boost::shared_ptr<ARDOUR::MidiRegion>                   region,
40         Evoral::Parameter                                       parameter,
41         Evoral::TimeConverter<double, ARDOUR::samplepos_t>*     converter)
42         : AutomationLine (name, tav, parent, list, parameter, converter)
43         , _region (region)
44         , _parameter (parameter)
45 {
46
47 }
48
49 MementoCommandBinder<ARDOUR::AutomationList>*
50 MidiAutomationLine::memento_command_binder ()
51 {
52         return new ARDOUR::MidiAutomationListBinder (_region->midi_source(), _parameter);
53 }
54
55 string
56 MidiAutomationLine::get_verbose_cursor_string (double fraction) const
57 {
58         using namespace MIDI::Name;
59
60         if (_parameter.type() != ARDOUR::MidiCCAutomation) {
61                 return AutomationLine::get_verbose_cursor_string(fraction);
62         }
63
64         MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(trackview.get_parent());
65         if (!mtv) {
66                 return AutomationLine::get_verbose_cursor_string(fraction);
67         }
68
69         boost::shared_ptr<MasterDeviceNames> device_names(mtv->get_device_names());
70         if (!device_names) {
71                 return AutomationLine::get_verbose_cursor_string(fraction);
72         }
73
74         const std::string& device_mode = mtv->gui_property(X_("midnam-custom-device-mode"));
75         const uint8_t      channel     = mtv->get_channel_for_add();
76
77         boost::shared_ptr<const ValueNameList> value_names = device_names->value_name_list_by_control(
78                 device_mode, channel, _parameter.id());
79         if (!value_names) {
80                 return AutomationLine::get_verbose_cursor_string(fraction);
81         }
82
83         const uint16_t cc_value = floor(std::max(std::min(fraction * 127.0, 127.0), 0.0));
84
85         boost::shared_ptr<const Value> value = value_names->max_value_below(cc_value);
86         if (!value) {
87                 return AutomationLine::get_verbose_cursor_string(fraction);
88         }
89
90         return value->name();
91 }
92