Fix up Mackie control surface to cope with changes to midi++ midi ports from a while...
[ardour.git] / libs / surfaces / mackie / mackie_control_protocol_poll.cc
1 #include "mackie_control_protocol.h"
2
3 #include "midi_byte_array.h"
4 #include "surface_port.h"
5
6 #include "pbd/pthread_utils.h"
7 #include "pbd/error.h"
8
9 #include "midi++/types.h"
10 #include "midi++/port.h"
11 #include "midi++/manager.h"
12 #include "i18n.h"
13
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <poll.h>
17 #include <errno.h>
18 #include <string.h>
19
20 #include <iostream>
21 #include <string>
22 #include <vector>
23
24 using namespace std;
25 using namespace Mackie;
26 using namespace PBD;
27
28 const char * MackieControlProtocol::default_port_name = "mcu";
29
30 bool MackieControlProtocol::probe()
31 {
32         return true;
33 }
34
35 void MackieControlProtocol::handle_port_inactive( SurfacePort * port )
36 {
37         // port gone away. So stop polling it ASAP
38         {
39                 // delete the port instance
40                 Glib::Mutex::Lock lock( update_mutex );
41                 MackiePorts::iterator it = find( _ports.begin(), _ports.end(), port );
42                 if ( it != _ports.end() )
43                 {
44                         delete *it;
45                         _ports.erase( it );
46                 }
47         }
48
49         // TODO all the rebuilding of surfaces and so on
50 }
51
52 void MackieControlProtocol::handle_port_active (SurfacePort *)
53 {
54         // no need to re-add port because it was already added
55         // during the init phase. So just update the local surface
56         // representation and send the representation to 
57         // all existing ports
58         
59         // TODO update bank size
60         
61         // TODO rebuild surface, to have new units
62         
63         // finally update session state to the surface
64         // TODO but this is also done in set_active, and
65         // in fact update_surface won't execute unless
66 #ifdef DEBUG
67         cout << "update_surface in handle_port_active" << endl;
68 #endif
69         // _active == true
70         update_surface();
71 }
72
73 void MackieControlProtocol::handle_port_init (Mackie::SurfacePort *)
74 {
75 #ifdef DEBUG
76         cout << "MackieControlProtocol::handle_port_init" << endl;
77 #endif
78 #ifdef DEBUG
79         cout << "MackieControlProtocol::handle_port_init finish" << endl;
80 #endif
81 }