substantial overhaul of MCU code - no more separate thread, just connect to signals...
[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         if ( MIDI::Manager::instance()->port(default_port_name)  == 0 ) {
33                 info << "Mackie: No MIDI port called " << default_port_name << endmsg;
34                 return false;
35         } else {
36                 return true;
37         }
38 }
39
40 void MackieControlProtocol::handle_port_inactive( SurfacePort * port )
41 {
42         // port gone away. So stop polling it ASAP
43         {
44                 // delete the port instance
45                 Glib::Mutex::Lock lock( update_mutex );
46                 MackiePorts::iterator it = find( _ports.begin(), _ports.end(), port );
47                 if ( it != _ports.end() )
48                 {
49                         delete *it;
50                         _ports.erase( it );
51                 }
52         }
53
54         // TODO all the rebuilding of surfaces and so on
55 }
56
57 void MackieControlProtocol::handle_port_active (SurfacePort *)
58 {
59         // no need to re-add port because it was already added
60         // during the init phase. So just update the local surface
61         // representation and send the representation to 
62         // all existing ports
63         
64         // TODO update bank size
65         
66         // TODO rebuild surface, to have new units
67         
68         // finally update session state to the surface
69         // TODO but this is also done in set_active, and
70         // in fact update_surface won't execute unless
71 #ifdef DEBUG
72         cout << "update_surface in handle_port_active" << endl;
73 #endif
74         // _active == true
75         update_surface();
76 }
77
78 void MackieControlProtocol::handle_port_init (Mackie::SurfacePort *)
79 {
80 #ifdef DEBUG
81         cout << "MackieControlProtocol::handle_port_init" << endl;
82 #endif
83 #ifdef DEBUG
84         cout << "MackieControlProtocol::handle_port_init finish" << endl;
85 #endif
86 }