Display more useful error messages when project loading fails.

This commit is contained in:
Jonathan Moore Liles 2008-06-21 18:46:11 -05:00
parent 621e278f38
commit fd747b235f
6 changed files with 56 additions and 63 deletions

View File

@ -296,6 +296,8 @@ Engine::init ( void )
_sample_rate = frame_rate();
MESSAGE( "Jack sample rate is %lu", (unsigned long)_sample_rate );
timeline->_sample_rate = frame_rate();
/* we don't need to create any ports until tracks are created */

View File

@ -33,8 +33,8 @@
#include "Loggable.H"
#include "Project.H"
#include "Timeline.H" // for sample_rate();
#include "Timeline.H" // for sample_rate()
#include "Engine/Engine.H" // for sample_rate()
#include "TLE.H" // all this just for load and save...
#include <FL/filename.H>
@ -51,6 +51,15 @@ const int PROJECT_VERSION = 1;
const char *Project::_errstr[] =
{
"Not a Non-DAW project",
"Locked by another process",
"Access denied",
"Samplerate mismatch",
"Incompatible project version"
};
char Project::_name[256];
char Project::_path[512];
bool Project::_is_open = false;
@ -107,7 +116,7 @@ Project::write_info ( void )
}
bool
Project::read_info ( void )
Project::read_info ( int *version, nframes_t *sample_rate )
{
FILE *fp;
@ -124,27 +133,9 @@ Project::read_info ( void )
MESSAGE( "Info: %s = %s", name, value );
if ( ! strcmp( name, "sample rate" ) )
{
nframes_t rate = atoll( value );
if ( rate != timeline->sample_rate() )
WARNING( "incorrect samplerate" );
}
*sample_rate = atoll( value );
else if ( ! strcmp( name, "version" ) )
{
int version = atoi( value );
if ( version < PROJECT_VERSION )
{
WARNING( "Incompatible project version. You must to use \"non-project-convert %d-%d\" to update this project's version", version, PROJECT_VERSION );
return false;
}
else if ( version > PROJECT_VERSION )
{
WARNING( "Incompatible project version (%d).", version );
return false;
}
}
*version = atoi( value );
free( name );
free( value );
@ -224,16 +215,21 @@ Project::open ( const char *name )
chdir( name );
if ( ! acquire_lock( &_lockfd, ".lock" ) )
{
WARNING( "Could not open project: locked by another process!" );
return Project::E_LOCKED;
}
return E_LOCKED;
if ( ! read_info() )
int version;
nframes_t rate;
if ( ! read_info( &version, &rate ) )
return E_INVALID;
if ( version != PROJECT_VERSION )
return E_VERSION;
if ( ! Loggable::open( "history" ) )
FATAL( "error opening journal" );
return E_INVALID;
timeline->sample_rate( rate );
set_name( name );

View File

@ -20,6 +20,8 @@
const char template_dir[] = "share/non-daw/templates";
const char user_template_dir[] = "~/.non-daw/templates";
#include "types.h"
class Project
{
@ -29,9 +31,11 @@ class Project
static char _path[512];
static bool write_info ( void );
static bool read_info ( void );
static bool read_info ( int *version, nframes_t *sample_rate );
static void set_name ( const char *name );
static const char *_errstr[];
public:
enum
@ -39,8 +43,12 @@ public:
E_INVALID = -1,
E_LOCKED = -2,
E_PERM = -3,
E_SAMPLERATE = -4,
E_VERSION = -5
};
static const char *errstr ( int n ) { return _errstr[ ( 0 - n ) - 1 ]; }
static const char *name ( void ) { return Project::_name; }
static void compact ( void );
static bool close ( void );

View File

@ -161,7 +161,7 @@ Loggable::progress_callback( &TLE::progress_cb, this );} {}
} {
Fl_Window main_window {
label Timeline open
xywh {174 117 1025 770} type Double resizable xclass Non_DAW visible
xywh {279 117 1025 770} type Double resizable xclass Non_DAW visible
} {
Fl_Menu_Bar menubar {open
xywh {0 0 1024 25}
@ -194,33 +194,7 @@ main_window->redraw();}
label {&Open}
callback {const char *name = fl_dir_chooser( "Open Project", NULL, NULL );
if ( ! name )
return;
int r = Project::open( name );
if ( r < 0 )
{
const char *s = "";
switch ( r )
{
case Project::E_LOCKED:
s = "Locked by another process";
break;
case Project::E_PERM:
s = "Access denied";
break;
case Project::E_INVALID:
s = "Not a Non-DAW project";
break;
}
fl_alert( "Could not open project \\"%s\\":\\n\\n\\t%s", name, s );
// we are in a somewhar ambiguous state now with no project open.
}}
open( name );}
xywh {10 10 40 25}
}
MenuItem {} {
@ -230,7 +204,7 @@ if ( r < 0 )
if ( n != 2 )
return;
Project::compact();} selected
Project::compact();}
xywh {20 20 40 25}
}
Submenu {} {
@ -850,6 +824,21 @@ progress->redraw();
Fl::check();} {}
}
Function {open( const char *name )} {open
} {
code {if ( ! name )
return;
int r = Project::open( name );
if ( r < 0 )
{
const char *s = Project::errstr( r );
fl_alert( "Could not open project \\"%s\\":\\n\\n\\t%s", name, s );
}} {selected
}
}
}
class New_Project_Dialog {open

View File

@ -146,6 +146,7 @@ public:
nframes_t fpp ( void ) const { return 1 << _fpp; }
nframes_t length ( void ) const;
void sample_rate ( nframes_t r ) { _sample_rate = r; }
nframes_t sample_rate ( void ) const { return _sample_rate; }
int ts_to_x( nframes_t ts ) const { return ts >> _fpp; }
nframes_t x_to_ts ( int x ) const { return x << _fpp; }

View File

@ -140,10 +140,7 @@ main ( int argc, char **argv )
tle->run();
if ( argc > 1 )
if ( Project::open( argv[ 1 ] ) != 0 )
FATAL( "Could not open project specified on command line" );
/* FIXME: open project in /tmp if none is given? */
tle->open( argv[ 1 ] );
Fl::run();