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