+#include <pthread.h>
+#include <unistd.h>
+#include <AXE/button.h>
+
+#define CMD_QUIT 1
+#define CMD_FASTER 2
+#define CMD_SLOWER 3
+
+class xapp: public xapplication
+{
+ window *main_frame;
+ window *flash;
+
+ pthread_t beat;
+
+ virtual void SetupResources(void);
+
+ virtual int DoCommand(int code);
+
+public:
+
+
+};
+
+xapp Application;
+unsigned BPM = 80;
+
+void * heartbeat(void *v)
+{
+ unsigned long period;
+ unsigned long flash_time = 200000;
+ int count = 0;
+ color forebeat("red");
+ color afterbeat("blue");
+ color idle("white");
+ window *w = (window *)v;
+
+
+ for (;;)
+ {
+ period = 1000000 * 60 / BPM;
+ if (count == 0)
+ w->Background(forebeat);
+ else
+ w->Background(afterbeat);
+
+ w->Clear();
+ XFlush(stddpy.Dpy());
+ usleep(flash_time);
+
+ w->Background(idle);
+ w->Clear();
+ XFlush(stddpy.Dpy());
+ usleep(period - flash_time);
+
+ count++;
+ if (count == 4)
+ count = 0;
+ }
+
+}
+
+void xapp::SetupResources()
+{
+ command_button *btn;
+
+ main_frame = new managed_window;
+
+ main_frame->Resize(700, 500);
+ flash = new window(*main_frame, 92, 2, 606, 496, 1);
+
+ btn = new command_button(*main_frame, 2, 2, "QUIT", CMD_QUIT);
+ btn = new command_button(*main_frame, 2, 42, "++", CMD_FASTER);
+ btn = new command_button(*main_frame, 2, 82, "--", CMD_SLOWER);
+ main_frame->Realize();
+
+ pthread_create(&beat, NULL, heartbeat, flash);
+}
+
+int xapp::DoCommand(int code)
+{
+ switch (code)
+ {
+ case CMD_FASTER:
+ if (BPM < 200)
+ {
+ BPM += 10;
+ }
+ cout << BPM << "beats per minute\n";
+ return 1;
+
+ case CMD_SLOWER:
+ if (BPM > 20)
+ {
+ BPM -= 10;
+ }
+ cout << BPM << "beats per minute\n";
+ return 1;
+
+ case CMD_QUIT:
+ return 0;
+
+ default:
+ return 1;
+ }
+}