enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / midi_automation_line.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/midi_region.h"
22
23 #include "midi++/midnam_patch.h"
24
25 #include "midi_automation_line.h"
26 #include "midi_time_axis.h"
27
28 #include "pbd/i18n.h"
29
30 using namespace std;
31
32 MidiAutomationLine::MidiAutomationLine (
33         const std::string&                                      name,
34         TimeAxisView&                                           tav,
35         ArdourCanvas::Item&                                     parent,
36         boost::shared_ptr<ARDOUR::AutomationList>               list,
37         boost::shared_ptr<ARDOUR::MidiRegion>                   region,
38         Evoral::Parameter                                       parameter,
39         Evoral::TimeConverter<double, ARDOUR::framepos_t>*      converter)
40         : AutomationLine (name, tav, parent, list, parameter, converter)
41         , _region (region)
42         , _parameter (parameter)
43 {
44
45 }
46
47 MementoCommandBinder<ARDOUR::AutomationList>*
48 MidiAutomationLine::memento_command_binder ()
49 {
50         return new ARDOUR::MidiAutomationListBinder (_region->midi_source(), _parameter);
51 }
52
53 string
54 MidiAutomationLine::get_verbose_cursor_string (double fraction) const
55 {
56         using namespace MIDI::Name;
57
58         if (_parameter.type() != ARDOUR::MidiCCAutomation) {
59                 return AutomationLine::get_verbose_cursor_string(fraction);
60         }
61
62         MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(trackview.get_parent());
63         if (!mtv) {
64                 return AutomationLine::get_verbose_cursor_string(fraction);
65         }
66
67         boost::shared_ptr<MasterDeviceNames> device_names(mtv->get_device_names());
68         if (!device_names) {
69                 return AutomationLine::get_verbose_cursor_string(fraction);
70         }
71
72         const std::string& device_mode = mtv->gui_property(X_("midnam-custom-device-mode"));
73         const uint8_t      channel     = mtv->get_channel_for_add();
74
75         boost::shared_ptr<const ValueNameList> value_names = device_names->value_name_list_by_control(
76                 device_mode, channel, _parameter.id());
77         if (!value_names) {
78                 return AutomationLine::get_verbose_cursor_string(fraction);
79         }
80
81         const uint16_t cc_value = floor(std::max(std::min(fraction * 127.0, 127.0), 0.0));
82
83         boost::shared_ptr<const Value> value = value_names->max_value_below(cc_value);
84         if (!value) {
85                 return AutomationLine::get_verbose_cursor_string(fraction);
86         }
87
88         return value->name();
89 }
90