/*******************************************************************************/ /* 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 projects. All the actual project state belongs to Timeline and other classes. */ #include #include #include #include #include #include #include "Loggable.H" #include "Project.H" #include "Timeline.H" // for sample_rate(); /* FIXME: wrong place for this */ #define APP_TITLE "Non-DAW" #define PROJECT_VERSION "0.28.0" #include "debug.h" char Project::_name[256]; bool Project::_is_open = false; void Project::set_name ( const char *name ) { char *s = rindex( name, '/' ); strcpy( Project::_name, s ? s + 1 : name ); for ( s = Project::_name; *s; ++s ) if ( *s == '_' || *s == '-' ) *s = ' '; } static int exists ( const char *name ) { struct stat st; return 0 == stat( name, &st ); } #include bool Project::close ( void ) { Loggable::close(); write_info(); _is_open = false; } bool Project::write_info ( void ) { if ( ! open() ) return true; FILE *fp; if ( ! ( fp = fopen( "info", "w" ) ) ) { WARNING( "could not open project info file for writing." ); return false; } fprintf( fp, "created by\n\t%s\nversion\n\t%s\nsample rate\n\t%lu\n", APP_TITLE " " VERSION, PROJECT_VERSION, timeline->sample_rate() ); fclose( fp ); return true; } bool Project::read_info ( void ) { FILE *fp; if ( ! ( fp = fopen( "info", "r" ) ) ) { WARNING( "could not open project info file for reading." ); return false; } /* TODO: something */ fclose( fp ); return true; } bool Project::open ( const char *name ) { if ( chdir( name ) ) { WARNING( "Cannot change to project dir \"%s\"", name ); return false; } if ( ! exists( "history" ) || ! exists( "sources" ) ) // ! exists( "options" ) ) { WARNING( "Not a Non-DAW project: \"%s\"", name ); return false; } if ( ! Loggable::open( "history" ) ) FATAL( "error opening journal" ); set_name( name ); read_info(); _is_open = true; return true; } bool Project::create ( const char *name, const char *template_name ) { close(); if ( exists( name ) ) { WARNING( "Project already exists" ); return false; } if ( mkdir( name, 0777 ) ) { WARNING( "Cannot create project directory" ); return false; } if ( chdir( name ) ) FATAL( "WTF? Cannot change to new project directory" ); mkdir( "sources", 0777 ); creat( "history", 0666 ); /* TODO: copy template */ return open( name ); }