From 0e6352c54a7f6f5cab7b34ada03ba4b39f7d1775 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Fri, 22 Feb 2008 05:44:35 -0600 Subject: [PATCH] Make loggables more uniform. --- Loggable.C | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Loggable.H | 20 ++++++++++++++++++++ Makefile | 2 +- Region.H | 13 +++++++++---- Tempo_Point.H | 9 ++++++--- Time_Point.H | 12 +++++++++--- 6 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 Loggable.C diff --git a/Loggable.C b/Loggable.C new file mode 100644 index 0000000..44f9839 --- /dev/null +++ b/Loggable.C @@ -0,0 +1,46 @@ + +/*******************************************************************************/ +/* Copyright (C) 2008 Jonathan Moore Liles */ +/* */ +/* This program is free software; you can redistribute it and/or modify it */ +/* under the terms of the GNU General Public License as published by the */ +/* Free Software Foundation; either version 2 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, but WITHOUT */ +/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ +/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */ +/* more details. */ +/* */ +/* You should have received a copy of the GNU General Public License along */ +/* with This program; see the file COPYING. If not,write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/*******************************************************************************/ + +#define _LOGGABLE_C +#include "Loggable.H" +#undef _LOGABLE_C + +#include +#include + +int Loggable::_log_id = 0; + +void +Loggable::log ( const char *module, const char *action, const char *fmt, ... ) +{ + va_list args; + + /* FIXME: log all this stuff to someplace meaningful */ + + printf( "%s %s %p ", module, action, _id ); + + if ( fmt ) + { + va_start( args, fmt ); + vfprintf( stdout, fmt, args ); + va_end( args ); + } + + printf( "\n" ); +} diff --git a/Loggable.H b/Loggable.H index 7a6fae6..554f4f2 100644 --- a/Loggable.H +++ b/Loggable.H @@ -19,14 +19,34 @@ /* Master class for journaling. */ +#pragma once + + class Loggable { + static int _log_id; + +private: + int _id; + public: + Loggable ( ) + { + _id = ++_log_id; + } + /* log messages for journal */ virtual void log_create ( void ) = 0; virtual void log_destroy ( void ) = 0; virtual void log_move ( void ) = 0; virtual void log_change ( void ) = 0; + + void log ( const char *module, const char *action, const char *fmt, ... ); + }; + +#ifndef _LOGGABLE_C +#define log( act, fmt, args... ) log( __CLASS__, act, fmt, ## args ) +#endif diff --git a/Makefile b/Makefile index 85efb3d..2df4eea 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CXXFLAGS=-ggdb -Wall -O0 LIBS=-lsndfile `fltk-config --ldflags` # CXXFLAGS=`fltk-config -cxxflags` -SRCS= Waveform.C Region.C Peaks.C main.C Track.C Timeline.C Audio_File.C Audio_File_SF.C +SRCS= Waveform.C Region.C Peaks.C main.C Track.C Timeline.C Audio_File.C Audio_File_SF.C Loggable.C OBJS=$(SRCS:.C=.o) diff --git a/Region.H b/Region.H index 57a276c..59bd01c 100644 --- a/Region.H +++ b/Region.H @@ -35,6 +35,9 @@ using namespace std; #include "Track_Widget.H" +/* got I hate C++ */ +#define __CLASS__ "Region" + class Region : public Track_Widget { @@ -56,22 +59,22 @@ protected: /* general */ void log_create ( void ) { - printf( "region create %p %lu \"%s\" %d %f %lu %lu\n", this, _offset, _clip->name(), _selected, _scale, _start, _end ); + log( "create", "%lu \"%s\" %d %f %lu %lu", _offset, _clip->name(), _selected, _scale, _start, _end ); } void log_destroy ( void ) { - printf( "region destroy %p\n", this ); + log( "destroy", NULL ); } void log_move ( void ) { - printf( "region move %p %lu\n", this, _offset ); + log( "move", "%lu", _offset ); } void log_change ( void ) { - printf( "region change %p %d %f %lu %lu\n", this, _selected, _scale, _start, _end ); + log( "change", "%d %f %lu %lu", _selected, _scale, _start, _end ); } public: @@ -92,3 +95,5 @@ public: void dump ( void ); }; + +#undef __CLASS__ diff --git a/Tempo_Point.H b/Tempo_Point.H index 29b4583..f5bca12 100644 --- a/Tempo_Point.H +++ b/Tempo_Point.H @@ -21,6 +21,8 @@ #include "Track_Point.H" +#define __CLASS__ "Tempo_Point" + class Tempo_Point : public Track_Point { float _tempo; @@ -36,9 +38,9 @@ class Tempo_Point : public Track_Point protected: - void log_create ( void ) { printf( "tempo-point create %p %lu %f\n", this, _offset, _tempo ); } - void log_destroy ( void ) { printf( "tempo-point destroy %p\n", this ); } - void log_move ( void ) { printf( "tempo-point move %p %lu\n", this, _offset ); } + void log_create ( void ) { log( "create", "%lu %f", _offset, _tempo ); } + void log_destroy ( void ) { log( "destroy", NULL ); } + void log_move ( void ) { log( "move", "%lu", _offset ); } public: @@ -73,3 +75,4 @@ public: } }; +#undef __CLASS__ diff --git a/Time_Point.H b/Time_Point.H index ea67f9c..acba05f 100644 --- a/Time_Point.H +++ b/Time_Point.H @@ -20,6 +20,7 @@ #pragma once #include "Track_Point.H" +#include "Loggable.H" struct time_sig { @@ -33,6 +34,9 @@ struct time_sig } }; + +#define __CLASS__ "Time_Point" + class Time_Point : public Track_Point { time_sig _time; @@ -48,9 +52,9 @@ class Time_Point : public Track_Point protected: - void log_create ( void ) { printf( "time-point create %p %lu %d %d\n", this, _offset, _time.beats_per_bar, _time.note_type ); } - void log_destroy ( void ) { printf( "time-point destroy %p\n", this ); } - void log_move ( void ) { printf( "time-point move %p %lu\n", this, _offset ); } + void log_create ( void ) { log( "create", "%lu %d %d", _offset, _time.beats_per_bar, _time.note_type ); } + void log_destroy ( void ) { log( "destroy", NULL ); } + void log_move ( void ) { log( "move", "%lu", _offset ); } public: @@ -85,3 +89,5 @@ public: } }; + +#undef __CLASS__