a) dynamically loadable control surface support
[ardour.git] / libs / surfaces / generic_midi / generic_midi_control_protocol.cc
1 #include <ardour/route.h>
2 #include <ardour/session.h>
3
4 #include "generic_midi_control_protocol.h"
5
6 using namespace ARDOUR;
7
8 #include "i18n.h"
9
10 GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
11         : ControlProtocol  (s, _("GenericMIDI"))
12 {
13         _port = 0;
14 }
15
16 GenericMidiControlProtocol::~GenericMidiControlProtocol ()
17 {
18 }
19
20 void
21 GenericMidiControlProtocol::set_port (MIDI::Port* p)
22 {
23         _port = p;
24 }
25
26 void 
27 GenericMidiControlProtocol::send_route_feedback (list<Route*>& routes)
28 {
29         if (_port != 0) {
30
31                 const int32_t bufsize = 16 * 1024;
32                 int32_t bsize = bufsize;
33                 MIDI::byte* buf = new MIDI::byte[bufsize];
34                 MIDI::byte* end = buf;
35                 
36                 for (list<Route*>::iterator r = routes.begin(); r != routes.end(); ++r) {
37                 end = (*r)->write_midi_feedback (end, bsize);
38                 }
39                 
40                 if (end == buf) {
41                         delete [] buf;
42                         return;
43                 } 
44                 
45                 session.deliver_midi (_port, buf, (int32_t) (end - buf));
46                 //cerr << "MIDI feedback: wrote " << (int32_t) (end - buf) << " to midi port\n";
47         }
48 }
49
50 bool
51 GenericMidiControlProtocol::active() const
52 {
53         return _port && send();
54 }
55