substantial overhaul of MCU code - no more separate thread, just connect to signals...
[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 #ifdef DEBUG
18         cout << "Surface::init" << endl;
19 #endif
20         init_controls();
21         init_strips( _max_strips, _unit_strips );
22 #ifdef DEBUG
23         cout << "Surface::init finish" << endl;
24 #endif
25 }
26
27 Surface::~Surface()
28 {
29         // delete groups
30         for( Groups::iterator it = groups.begin(); it != groups.end(); ++it )
31         {
32                 delete it->second;
33         }
34         
35         // delete controls
36         for( Controls::iterator it = controls.begin(); it != controls.end(); ++it )
37         {
38                 delete *it;
39         }
40 }
41
42 // Mackie-specific, because of multiple devices on separate ports
43 // add the strips from 9..max_strips
44 // unit_strips is the number of strips for additional units.
45 void Surface::init_strips( uint32_t max_strips, uint32_t unit_strips )
46 {
47         if ( strips.size() < max_strips )
48         {
49                 strips.resize( max_strips );
50                 for ( uint32_t i = strips.size(); i < max_strips; ++i )
51                 {
52                         // because I can't find itoa
53                         ostringstream os;
54                         os << "strip_" << i + 1;
55                         string name = os.str();
56                         
57                         // shallow copy existing strip
58                         // which works because the controls
59                         // have the same ids across units
60                         // TODO this needs to be a deep copy because
61                         // controls hold state now - in_use
62                         Strip * strip = new Strip( *strips[i % unit_strips] );
63                         
64                         // update the relevant values
65                         strip->index( i );
66                         strip->name( name );
67                         
68                         // add to data structures
69                         groups[name] = strip;
70                         strips[i] = strip;
71                 }
72         }
73 }