fix issue with initialization of a BBT_Time variable.
[ardour.git] / libs / canvas / debug.cc
1 /*
2     Copyright (C) 2011-2013 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
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 #include <sys/time.h>
21 #include <iostream>
22 #include <gdk/gdk.h>
23 #include "canvas/debug.h"
24
25 using namespace std;
26
27 PBD::DebugBits PBD::DEBUG::CanvasItems = PBD::new_debug_bit ("canvasitems");
28 PBD::DebugBits PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
29 PBD::DebugBits PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
30 PBD::DebugBits PBD::DEBUG::CanvasRender = PBD::new_debug_bit ("canvasrender");
31 PBD::DebugBits PBD::DEBUG::CanvasEnterLeave = PBD::new_debug_bit ("canvasenterleave");
32
33 struct timeval ArdourCanvas::epoch;
34 map<string, struct timeval> ArdourCanvas::last_time;
35 int ArdourCanvas::render_count;
36 int ArdourCanvas::render_depth;
37 int ArdourCanvas::dump_depth;
38
39 void
40 ArdourCanvas::set_epoch ()
41 {
42         gettimeofday (&epoch, 0);
43 }
44
45 void
46 ArdourCanvas::checkpoint (string group, string message)
47 {
48         struct timeval now;
49         gettimeofday (&now, 0);
50
51         now.tv_sec -= epoch.tv_sec;
52         now.tv_usec -= epoch.tv_usec;
53         if (now.tv_usec < 0) {
54                 now.tv_usec += 1e6;
55                 --now.tv_sec;
56         }
57
58         map<string, struct timeval>::iterator last = last_time.find (group);
59
60         if (last != last_time.end ()) {
61 #if 0
62                 time_t seconds = now.tv_sec - last->second.tv_sec;
63                 suseconds_t useconds = now.tv_usec - last->second.tv_usec;
64                 if (useconds < 0) {
65                         useconds += 1e6;
66                         --seconds;
67                 }
68                 cout << (now.tv_sec + ((double) now.tv_usec / 1e6)) << " [" << (seconds + ((double) useconds / 1e6)) << "]: " << message << "\n";
69 #endif
70         } else {
71                 cout << message << "\n";
72         }
73
74         last_time[group] = now;
75 }
76
77 const char*
78 ArdourCanvas::event_type_string (int event_type)
79 {
80         switch (event_type) {
81         case GDK_NOTHING:
82                 return "nothing";
83         case GDK_DELETE:
84                 return "delete";
85         case GDK_DESTROY:
86                 return "destroy";
87         case GDK_EXPOSE:
88                 return "expose";
89         case GDK_MOTION_NOTIFY:
90                 return "motion_notify";
91         case GDK_BUTTON_PRESS:
92                 return "button_press";
93         case GDK_2BUTTON_PRESS:
94                 return "2button_press";
95         case GDK_3BUTTON_PRESS:
96                 return "3button_press";
97         case GDK_BUTTON_RELEASE:
98                 return "button_release";
99         case GDK_KEY_PRESS:
100                 return "key_press";
101         case GDK_KEY_RELEASE:
102                 return "key_release";
103         case GDK_ENTER_NOTIFY:
104                 return "enter_notify";
105         case GDK_LEAVE_NOTIFY:
106                 return "leave_notify";
107         case GDK_FOCUS_CHANGE:
108                 return "focus_change";
109         case GDK_CONFIGURE:
110                 return "configure";
111         case GDK_MAP:
112                 return "map";
113         case GDK_UNMAP:
114                 return "unmap";
115         case GDK_PROPERTY_NOTIFY:
116                 return "property_notify";
117         case GDK_SELECTION_CLEAR:
118                 return "selection_clear";
119         case GDK_SELECTION_REQUEST:
120                 return "selection_request";
121         case GDK_SELECTION_NOTIFY:
122                 return "selection_notify";
123         case GDK_PROXIMITY_IN:
124                 return "proximity_in";
125         case GDK_PROXIMITY_OUT:
126                 return "proximity_out";
127         case GDK_DRAG_ENTER:
128                 return "drag_enter";
129         case GDK_DRAG_LEAVE:
130                 return "drag_leave";
131         case GDK_DRAG_MOTION:
132                 return "drag_motion";
133         case GDK_DRAG_STATUS:
134                 return "drag_status";
135         case GDK_DROP_START:
136                 return "drop_start";
137         case GDK_DROP_FINISHED:
138                 return "drop_finished";
139         case GDK_CLIENT_EVENT:
140                 return "client_event";
141         case GDK_VISIBILITY_NOTIFY:
142                 return "visibility_notify";
143         case GDK_NO_EXPOSE:
144                 return "no_expose";
145         case GDK_SCROLL:
146                 return "scroll";
147         case GDK_WINDOW_STATE:
148                 return "window_state";
149         case GDK_SETTING:
150                 return "setting";
151         case GDK_OWNER_CHANGE:
152                 return "owner_change";
153         case GDK_GRAB_BROKEN:
154                 return "grab_broken";
155         case GDK_DAMAGE:
156                 return "damage";
157         }
158
159         return "unknown";
160 }