allow surface to work with linked panners on stereo input tracks/busses
[ardour.git] / libs / surfaces / mackie / surface.cc
1 #include "surface.h"
2
3 #include <sstream>
4 #include <iomanip>
5 #include <iostream>
6
7 using namespace std;
8 using namespace Mackie;
9
10 Surface::Surface( uint32_t max_strips, uint32_t unit_strips )
11 : _max_strips( max_strips ), _unit_strips( unit_strips )
12 {
13 }
14
15 void Surface::init()
16 {
17         init_controls();
18         init_strips( _max_strips, _unit_strips );
19 }
20
21 Surface::~Surface()
22 {
23         // delete groups
24         for( Groups::iterator it = groups.begin(); it != groups.end(); ++it )
25         {
26                 delete it->second;
27         }
28         
29         // delete controls
30         for( Controls::iterator it = controls.begin(); it != controls.end(); ++it )
31         {
32                 delete *it;
33         }
34 }
35
36 // Mackie-specific, because of multiple devices on separate ports
37 // add the strips from 9..max_strips
38 // unit_strips is the number of strips for additional units.
39 void Surface::init_strips( uint32_t max_strips, uint32_t unit_strips )
40 {
41         if ( strips.size() < max_strips )
42         {
43                 strips.resize( max_strips );
44                 for ( uint32_t i = strips.size(); i < max_strips; ++i )
45                 {
46                         // because I can't find itoa
47                         ostringstream os;
48                         os << "strip_" << i + 1;
49                         string name = os.str();
50                         
51                         // shallow copy existing strip
52                         // which works because the controls
53                         // have the same ids across units
54                         Strip * strip = new Strip( *strips[i % unit_strips] );
55                         
56                         // update the relevant values
57                         strip->index( i );
58                         strip->name( name );
59                         
60                         // add to data structures
61                         groups[name] = strip;
62                         strips[i] = strip;
63                 }
64         }
65 }
66
67 /**
68         TODO could optimise this to use enum, but it's only
69         called during the protocol class instantiation.
70
71         generated using
72
73         irb -r controls.rb
74         sf=Surface.new
75         sf.parse
76         controls = sf.groups.find{|x| x[0] =~ /strip/}.each{|x| puts x[1]}
77         controls[1].each {|x| puts "\telse if ( control.name() == \"#{x.name}\" )\n\t{\n\t\t_#{x.name} = reinterpret_cast<#{x.class.name}*>(&control);\n\t}\n"}
78 */
79 void Strip::add( Control & control )
80 {
81         Group::add( control );
82         if ( control.name() == "gain" )
83         {
84                 _gain = reinterpret_cast<Fader*>(&control);
85         }
86         else if ( control.name() == "vpot" )
87         {
88                 _vpot = reinterpret_cast<Pot*>(&control);
89         }
90         else if ( control.name() == "recenable" )
91         {
92                 _recenable = reinterpret_cast<Button*>(&control);
93         }
94         else if ( control.name() == "solo" )
95         {
96                 _solo = reinterpret_cast<Button*>(&control);
97         }
98         else if ( control.name() == "mute" )
99         {
100                 _mute = reinterpret_cast<Button*>(&control);
101         }
102         else if ( control.name() == "select" )
103         {
104                 _select = reinterpret_cast<Button*>(&control);
105         }
106         else if ( control.name() == "vselect" )
107         {
108                 _vselect = reinterpret_cast<Button*>(&control);
109         }
110         else if ( control.name() == "fader_touch" )
111         {
112                 _fader_touch = reinterpret_cast<Button*>(&control);
113         }
114         else if ( control.type() == Control::type_led || control.type() == Control::type_led_ring )
115         {
116                 // do nothing
117                 cout << "Strip::add not adding " << control << endl;
118         }
119         else
120         {
121                 ostringstream os;
122                 os << "Strip::add: unknown control type " << control;
123                 throw MackieControlException( os.str() );
124         }
125 }
126