MCP: try to fix madness with extender strip indices
[ardour.git] / libs / surfaces / mackie / surface.cc
1 #include "ardour/debug.h"
2 #include "surface.h"
3
4 #include <sstream>
5 #include <iomanip>
6 #include <iostream>
7
8 using namespace std;
9 using namespace PBD;
10 using namespace Mackie;
11
12 Surface::Surface( uint32_t max_strips, uint32_t unit_strips )
13 : _max_strips( max_strips ), _unit_strips( unit_strips )
14 {
15 }
16
17 void Surface::init()
18 {
19         DEBUG_TRACE (DEBUG::MackieControl, "Surface::init\n");
20         init_controls();
21         init_strips( _max_strips, _unit_strips );
22         DEBUG_TRACE (DEBUG::MackieControl, "Surface::init finish\n");
23 }
24
25 Surface::~Surface()
26 {
27         // delete groups
28         for( Groups::iterator it = groups.begin(); it != groups.end(); ++it )
29         {
30                 delete it->second;
31         }
32         
33         // delete controls
34         for( Controls::iterator it = controls.begin(); it != controls.end(); ++it )
35         {
36                 delete *it;
37         }
38 }
39
40 // Mackie-specific, because of multiple devices on separate ports
41 // add the strips from 9..max_strips
42 // unit_strips is the number of strips for additional units.
43 void Surface::init_strips (uint32_t max_strips, uint32_t unit_strips)
44 {
45         if ( strips.size() < max_strips ) {
46
47                 uint32_t const old_size = strips.size();
48                 strips.resize (max_strips);
49                 
50                 for (uint32_t i = old_size; i < max_strips; ++i) {
51                         // because I can't find itoa
52                         ostringstream os;
53                         os << "strip_" << i + 1;
54                         string name = os.str();
55                         
56                         // shallow copy existing strip
57                         // which works because the controls
58                         // have the same ids across units
59                         // TODO this needs to be a deep copy because
60                         // controls hold state now - in_use
61                         Strip * strip = new Strip( *strips[i % unit_strips] );
62                         
63                         // update the relevant values
64                         strip->index (i);
65                         strip->name (name);
66                         
67                         // add to data structures
68                         groups[name] = strip;
69                         strips[i] = strip;
70                 }
71         }
72 }