NOOP, remove trailing tabs/whitespace.
[ardour.git] / libs / surfaces / tranzport / io.cc
1 /*
2  *   Copyright (C) 2006 Paul Davis
3  *   Copyright (C) 2007 Michael Taht
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *   */
20
21 /* The routines in here should know absolutely nothing about how io is actually done */
22
23 #include <tranzport_control_protocol.h>
24
25 int
26 TranzportControlProtocol::flush ()
27 {
28         int pending = 0;
29
30 // Always write the lights first
31         if(!(pending = lights_flush())) {
32                 pending = screen_flush();
33         }
34
35 #if DEBUG_TRANZPORT_BITS > 9
36         int s;
37         if(s = (screen_invalid.count())) { //  + lights_invalid.count())) {
38                 printf("VALID  : %s %s\n",
39                        screen_invalid.to_string().c_str(),
40                        lights_invalid.to_string().c_str());
41                 printf("CURR   : %s %s\n",
42                        screen_invalid.to_string().c_str(),
43                        lights_current.to_string().c_str());
44                 printf("PENDING  : %s %s\n",
45                        screen_invalid.to_string().c_str(),
46                        lights_pending.to_string().c_str());
47 #if DEBUG_TRANZPORT_BITS > 10
48                 printf("invalid bits: %d\n",s);
49 #endif
50         }
51 #endif
52         return pending;
53 }
54
55
56 int
57 TranzportControlProtocol::lights_flush ()
58 {
59         std::bitset<LIGHTS> light_state;
60         light_state = lights_pending ^ lights_current;
61         if ( (light_state.none() || lights_invalid.none()))
62         {
63                 return (0);
64         }
65
66 #if DEBUG_TRANZPORT_LIGHTS
67         printf("LPEND   : %s\n", lights_pending.to_string().c_str());
68         printf("LCURR   : %s\n", lights_current.to_string().c_str());
69 #endif
70
71         // if ever we thread reads/writes STATUS_OK will have to move into the loop
72         int i;
73
74         if ( _device_status == STATUS_OK || _device_status == STATUS_ONLINE) {
75                 for (i = 0; i<LIGHTS; i++) {
76                         if(light_state[i]) {
77                                 if(light_set ((LightID)i,lights_pending[i])) {
78 #if DEBUG_TRANZPORT_LIGHTS > 2
79                                         printf("Did %d light writes\n",i);
80 #endif
81                                         return light_state.count();
82                                 } else {
83                                         light_state[i] = 0;
84                                 }
85
86                         }
87                 }
88         }
89         light_state = lights_pending ^ lights_current;
90 #if DEBUG_TRANZPORT_LIGHTS > 2
91         printf("Did %d light writes, left: %d\n",i, light_state.count());
92 #endif
93
94         return light_state.count();
95 }