From 5ca4efe8372c9de6255c2b86b1d77ef44f36b8d0 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 4 May 2008 02:10:15 -0500 Subject: [PATCH] Break session loading/creation code out into its own file. --- Timeline/Session.C | 113 ++++++++++++++++++++++++++++++++++++++++++ Timeline/Session.H | 34 +++++++++++++ Timeline/TLE.fl | 12 +++-- Timeline/main.C | 75 ++-------------------------- Timeline/makefile.inc | 1 + 5 files changed, 159 insertions(+), 76 deletions(-) create mode 100644 Timeline/Session.C create mode 100644 Timeline/Session.H diff --git a/Timeline/Session.C b/Timeline/Session.C new file mode 100644 index 0000000..53e906a --- /dev/null +++ b/Timeline/Session.C @@ -0,0 +1,113 @@ + +/*******************************************************************************/ +/* 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. */ +/*******************************************************************************/ + +/* Routings for opening/closing/creation of sessions. All the actual +session state belongs to Timeline and other classes. */ + + +#include +#include +#include +#include + +#include "Loggable.H" +#include "Session.H" + +#include "debug.h" +char Session::_name[256]; + +void +Session::set_name ( const char *name ) +{ + char *s = rindex( name, '/' ); + + strcpy( Session::_name, s ? s : name ); + + for ( s = Session::_name; *s; ++s ) + if ( *s == '_' || *s == '-' ) + *s = ' '; +} + +static int +exists ( const char *name ) +{ + struct stat st; + + return 0 == stat( name, &st ); +} + +#include + +bool +Session::close ( void ) +{ + Loggable::close(); +} + +bool +Session::open ( const char *name ) +{ + if ( chdir( name ) ) + { + WARNING( "Cannot change to session dir \"%s\"", name ); + return false; + } + + if ( ! exists( "history" ) || + ! exists( "sources" ) ) +// ! exists( "options" ) ) + { + WARNING( "Not a Non-DAW session: \"%s\"", name ); + return false; + } + + if ( ! Loggable::open( "history" ) ) + FATAL( "error opening journal" ); + + set_name( name ); +} + +bool +Session::create ( const char *name, const char *template_name ) +{ + if ( exists( name ) ) + { + WARNING( "Session already exists" ); + return false; + } + + if ( mkdir( name, 0777 ) ) + { + WARNING( "Cannot create session directory" ); + return false; + } + + if ( chdir( name ) ) + FATAL( "WTF? Cannot change to new session directory" ); + + mkdir( "sources", 0777 ); + + set_name( name ); + + /* TODO: copy template */ + + close(); + + return open( name ); +} diff --git a/Timeline/Session.H b/Timeline/Session.H new file mode 100644 index 0000000..e379bef --- /dev/null +++ b/Timeline/Session.H @@ -0,0 +1,34 @@ + +/*******************************************************************************/ +/* 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. */ +/*******************************************************************************/ + +class Session +{ + + static char _name[256]; + +public: + + + static const char *name ( void ) { return Session::_name; } + static void set_name ( const char *name ); + static bool close ( void ); + static bool open ( const char *name ); + static bool create ( const char *name, const char *template_name ); + +}; diff --git a/Timeline/TLE.fl b/Timeline/TLE.fl index 2de8e1b..3bdd3c6 100644 --- a/Timeline/TLE.fl +++ b/Timeline/TLE.fl @@ -14,6 +14,8 @@ decl {\#include "Transport.H"} {} decl {\#include "Loggable.H"} {} +decl {\#include "Session.H"} {} + decl {\#include "Clock.H"} {public } @@ -117,7 +119,7 @@ free( path );} {} } { Fl_Window main_window { label {Non-DAW - Timeline} open - xywh {129 104 1020 765} type Double resizable xclass {Non-DAW} visible + xywh {174 178 1020 765} type Double resizable xclass {Non-DAW} visible } { Fl_Menu_Bar menubar {open xywh {0 0 1024 25} @@ -546,9 +548,9 @@ delete win;} class Timeline } Fl_Box {} { - label {} + label {} selected xywh {450 0 475 22} labeltype SHADOW_LABEL labelfont 2 - code0 {o->label( session_display_name );} + code0 {o->label( Session::name() );} } Fl_Value_Output xruns_output { label {xruns:} @@ -593,7 +595,7 @@ xruns_output->value( engine->xruns() );} {} } { Fl_Window {} { label About open - xywh {1082 94 495 525} type Double visible + xywh {677 145 495 525} type Double visible } { Fl_Tabs {} {open xywh {-4 122 507 419} @@ -691,7 +693,7 @@ o->hide();} open private xywh {75 110 375 25} labeltype EMBOSSED_LABEL } Fl_Box {} { - label {New Session} selected + label {New Session} xywh {15 8 520 33} box RSHADOW_BOX color 133 labelsize 20 labelcolor 32 } Fl_Choice _template { diff --git a/Timeline/main.C b/Timeline/main.C index 1bd2975..08e23c8 100644 --- a/Timeline/main.C +++ b/Timeline/main.C @@ -49,6 +49,7 @@ #include #include +#include "Session.H" Engine *engine; Timeline *timeline; @@ -69,27 +70,6 @@ const char COPYRIGHT[] = "Copyright (C) 2008 Jonathan Moore Liles"; #include "debug.h" char *user_config_dir; -char session_display_name[256]; - -void -set_display_name ( const char *name ) -{ - char *s = rindex( name, '/' ); - - strcpy( session_display_name, s ? s : name ); - - for ( s = session_display_name; *s; ++s ) - if ( *s == '_' || *s == '-' ) - *s = ' '; -} - -static int -exists ( const char *name ) -{ - struct stat st; - - return 0 == stat( name, &st ); -} #include @@ -103,40 +83,10 @@ ensure_dirs ( void ) return r == 0 || errno == EEXIST; } -bool -create_session ( const char *name ) -{ - if ( exists( name ) ) - { - WARNING( "Session already exists" ); - return false; - } - - if ( mkdir( name, 0777 ) ) - { - WARNING( "Cannot create session directory" ); - return false; - } - - if ( chdir( name ) ) - FATAL( "WTF? Cannot change to new session directory" ); - - mkdir( "sources", 0777 ); - - set_display_name( name ); - - /* TODO: load template */ - - - return true; -} int main ( int argc, char **argv ) { - - *session_display_name = '\0'; - /* welcome to C++ */ LOG_REGISTER_CREATE( Region ); LOG_REGISTER_CREATE( Time_Point ); @@ -154,25 +104,11 @@ main ( int argc, char **argv ) printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT ); - const char *pwd = getenv( "PWD" ); - if ( argc > 1 ) - { - /* FIXME: what about FLTK arguments? */ + if ( ! Session::open( argv[ 1 ] ) ) + FATAL( "Could not open session specified on command line" ); - /* change to session dir */ - if ( chdir( argv[ 1 ] ) ) - FATAL( "Cannot change to session dir \"%s\"", argv[ 1 ] ); - else - pwd = argv[ 1 ]; - } - - if ( ! exists( "history" ) || - ! exists( "sources" ) ) -// ! exists( "options" ) ) - FATAL( "Not a Non-DAW session: \"%s\"", pwd ); - - set_display_name( pwd ); + /* FIXME: open session in /tmp if none is given? */ TLE tle; @@ -186,9 +122,6 @@ main ( int argc, char **argv ) * scenario requiring otherwise */ transport->stop(); - MESSAGE( "Opening session" ); - Loggable::open( "history" ); - MESSAGE( "Starting GUI" ); // tle.main_window->show( argc, argv ); tle.main_window->show(); diff --git a/Timeline/makefile.inc b/Timeline/makefile.inc index 51bd3c6..093c930 100644 --- a/Timeline/makefile.inc +++ b/Timeline/makefile.inc @@ -28,6 +28,7 @@ Timeline/Transport.C \ Timeline/Waveform.C \ Timeline/dsp.C \ Timeline/main.C \ +Timeline/Session.C \ debug.C \ Timeline_OBJS:=$(Timeline_SRCS:.C=.o)