2008-02-14 06:47:12 +01:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
2008-05-03 06:44:48 +02:00
|
|
|
|
2008-02-14 06:47:12 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-05-22 09:05:49 +02:00
|
|
|
#include <stdlib.h>
|
2012-02-29 07:12:07 +01:00
|
|
|
#include <getopt.h>
|
2008-02-14 06:47:12 +01:00
|
|
|
|
2008-05-22 09:05:49 +02:00
|
|
|
/* for registrations */
|
2008-05-05 02:04:20 +02:00
|
|
|
#include "Audio_Region.H"
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Sequence.H"
|
|
|
|
#include "Audio_Sequence.H"
|
2008-02-16 08:21:15 +01:00
|
|
|
#include "Timeline.H"
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Tempo_Sequence.H"
|
|
|
|
#include "Time_Sequence.H"
|
2008-05-05 00:32:08 +02:00
|
|
|
#include "Annotation_Sequence.H"
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Control_Sequence.H"
|
2012-10-24 07:44:19 +02:00
|
|
|
#include "Cursor_Sequence.H"
|
2008-04-19 06:16:21 +02:00
|
|
|
#include "Track.H"
|
2008-02-17 22:25:02 +01:00
|
|
|
|
2008-04-23 04:22:46 +02:00
|
|
|
#include "TLE.H"
|
2010-01-21 01:33:02 +01:00
|
|
|
#include "Timeline.H"
|
2012-03-02 05:23:23 +01:00
|
|
|
|
2012-04-11 08:59:12 +02:00
|
|
|
#include "FL/themes.H"
|
|
|
|
#include "FL/Fl_Theme.H"
|
2008-04-22 23:23:23 +02:00
|
|
|
|
2008-05-07 01:33:24 +02:00
|
|
|
#include "Project.H"
|
2008-05-22 09:05:49 +02:00
|
|
|
#include "Transport.H"
|
|
|
|
#include "Engine/Engine.H"
|
2008-05-15 03:10:49 +02:00
|
|
|
|
2010-02-01 07:25:16 +01:00
|
|
|
#include "Thread.H"
|
2008-06-02 03:13:18 +02:00
|
|
|
|
2012-05-22 07:04:09 +02:00
|
|
|
#include <nsm.h>
|
|
|
|
|
|
|
|
extern void set_nsm_callbacks ( nsm_client_t *nsm );
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2012-02-29 06:24:51 +01:00
|
|
|
#ifdef HAVE_XPM
|
|
|
|
#include "FL/Fl.H"
|
|
|
|
#include "FL/x.H"
|
|
|
|
#include <X11/xpm.h>
|
|
|
|
#include "../icons/icon-16x16.xpm"
|
|
|
|
#endif
|
|
|
|
|
2008-04-09 02:05:15 +02:00
|
|
|
Engine *engine;
|
2008-02-21 17:20:36 +01:00
|
|
|
Timeline *timeline;
|
2008-04-22 04:47:29 +02:00
|
|
|
Transport *transport;
|
2008-05-15 06:23:16 +02:00
|
|
|
TLE *tle;
|
2012-05-22 07:04:09 +02:00
|
|
|
nsm_client_t *nsm;
|
2010-01-21 01:33:02 +01:00
|
|
|
|
|
|
|
char *instance_name = NULL;
|
2008-02-21 10:35:03 +01:00
|
|
|
|
2008-05-03 06:44:48 +02:00
|
|
|
/* TODO: put these in a header */
|
|
|
|
#define USER_CONFIG_DIR ".non-daw/"
|
|
|
|
|
|
|
|
const char APP_NAME[] = "Non-DAW";
|
2008-05-15 06:23:16 +02:00
|
|
|
const char APP_TITLE[] = "The Non-DAW";
|
2012-03-05 04:01:07 +01:00
|
|
|
const char COPYRIGHT[] = "Copyright (C) 2008-2012 Jonathan Moore Liles";
|
2008-05-03 06:44:48 +02:00
|
|
|
|
2012-02-24 04:46:49 +01:00
|
|
|
const double NSM_CHECK_INTERVAL = 0.25f;
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2008-05-03 06:44:48 +02:00
|
|
|
#define PACKAGE "non"
|
|
|
|
|
|
|
|
|
2008-07-30 04:30:45 +02:00
|
|
|
#include "const.h"
|
2010-02-01 07:25:16 +01:00
|
|
|
#include "debug.h"
|
2008-02-20 07:11:33 +01:00
|
|
|
|
2008-04-25 05:15:17 +02:00
|
|
|
char *user_config_dir;
|
2008-05-03 06:44:48 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
2008-04-22 23:23:23 +02:00
|
|
|
|
2008-04-25 05:15:17 +02:00
|
|
|
static int
|
|
|
|
ensure_dirs ( void )
|
|
|
|
{
|
2008-05-03 06:44:48 +02:00
|
|
|
asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR );
|
2008-04-22 23:23:23 +02:00
|
|
|
|
2008-05-03 06:44:48 +02:00
|
|
|
int r = mkdir( user_config_dir, 0777 );
|
|
|
|
|
|
|
|
return r == 0 || errno == EEXIST;
|
|
|
|
}
|
|
|
|
|
2008-05-16 02:26:51 +02:00
|
|
|
#include <FL/Fl_Shared_Image.H>
|
|
|
|
|
2008-06-05 04:11:17 +02:00
|
|
|
#include <signal.h>
|
|
|
|
|
2009-01-12 04:38:30 +01:00
|
|
|
void
|
|
|
|
shift ( char **argv, int *argc, int n )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0; i < *argc; ++i )
|
|
|
|
argv[ i ] = argv[ i + n ];
|
|
|
|
|
|
|
|
argv[ i ] = 0;
|
|
|
|
argc -= n;
|
|
|
|
}
|
2008-05-17 20:42:50 +02:00
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
extern Timeline *timeline;
|
|
|
|
|
|
|
|
void
|
2012-02-24 03:55:43 +01:00
|
|
|
check_nsm ( void * v )
|
2010-01-21 01:33:02 +01:00
|
|
|
{
|
2012-05-22 07:04:09 +02:00
|
|
|
nsm_check_nowait( nsm );
|
2012-02-24 04:46:49 +01:00
|
|
|
Fl::repeat_timeout( NSM_CHECK_INTERVAL, check_nsm, v );
|
2010-01-21 01:33:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int got_sigterm = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
sigterm_handler ( int )
|
|
|
|
{
|
|
|
|
got_sigterm = 1;
|
|
|
|
Fl::awake();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
check_sigterm ( void * )
|
|
|
|
{
|
|
|
|
if ( got_sigterm )
|
|
|
|
{
|
|
|
|
MESSAGE( "Got SIGTERM, quitting..." );
|
|
|
|
timeline->command_quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-14 06:47:12 +01:00
|
|
|
int
|
|
|
|
main ( int argc, char **argv )
|
|
|
|
{
|
2012-02-29 06:24:51 +01:00
|
|
|
|
2012-03-06 09:59:19 +01:00
|
|
|
printf( "%s %s -- %s\n", APP_TITLE, VERSION, COPYRIGHT );
|
|
|
|
|
|
|
|
if ( ! Fl::visual( FL_DOUBLE | FL_RGB ) )
|
|
|
|
{
|
|
|
|
WARNING( "Xdbe not supported, FLTK will fake double buffering." );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-29 06:24:51 +01:00
|
|
|
#ifdef HAVE_XPM
|
|
|
|
fl_open_display();
|
|
|
|
Pixmap p, mask;
|
|
|
|
|
|
|
|
XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display),
|
|
|
|
(char**)icon_16x16, &p, &mask, NULL);
|
|
|
|
#endif
|
|
|
|
|
2008-06-02 03:13:18 +02:00
|
|
|
Thread::init();
|
|
|
|
|
|
|
|
Thread thread( "UI" );
|
|
|
|
thread.set();
|
2008-05-16 02:26:51 +02:00
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
signal( SIGTERM, sigterm_handler );
|
2012-03-05 04:12:32 +01:00
|
|
|
signal( SIGHUP, sigterm_handler );
|
|
|
|
signal( SIGINT, sigterm_handler );
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2008-05-16 02:26:51 +02:00
|
|
|
fl_register_images();
|
|
|
|
|
2008-03-01 15:23:59 +01:00
|
|
|
/* welcome to C++ */
|
2008-05-06 06:33:41 +02:00
|
|
|
LOG_REGISTER_CREATE( Annotation_Point );
|
|
|
|
LOG_REGISTER_CREATE( Annotation_Region );
|
2008-05-05 01:06:36 +02:00
|
|
|
LOG_REGISTER_CREATE( Annotation_Sequence );
|
2008-05-06 06:33:41 +02:00
|
|
|
LOG_REGISTER_CREATE( Audio_Region );
|
|
|
|
LOG_REGISTER_CREATE( Audio_Sequence );
|
|
|
|
LOG_REGISTER_CREATE( Control_Point );
|
|
|
|
LOG_REGISTER_CREATE( Control_Sequence );
|
|
|
|
LOG_REGISTER_CREATE( Tempo_Point );
|
|
|
|
LOG_REGISTER_CREATE( Time_Point );
|
2012-10-24 07:44:19 +02:00
|
|
|
LOG_REGISTER_CREATE( Cursor_Point );
|
|
|
|
LOG_REGISTER_CREATE( Cursor_Region );
|
2008-05-06 06:33:41 +02:00
|
|
|
LOG_REGISTER_CREATE( Track );
|
2008-02-22 21:20:44 +01:00
|
|
|
|
2008-06-05 04:11:17 +02:00
|
|
|
signal( SIGPIPE, SIG_IGN );
|
|
|
|
|
2008-04-25 05:15:17 +02:00
|
|
|
if ( ! ensure_dirs() )
|
2008-05-03 06:44:48 +02:00
|
|
|
FATAL( "Cannot create required directories" );
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
instance_name = strdup( APP_NAME );
|
2012-02-29 07:12:07 +01:00
|
|
|
bool instance_override = false;
|
2008-05-03 06:44:48 +02:00
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
|
|
|
|
const char *osc_port = NULL;
|
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
2012-03-05 04:01:07 +01:00
|
|
|
{ "help", no_argument, 0, '?' },
|
2012-02-29 07:12:07 +01:00
|
|
|
{ "instance", required_argument, 0, 'i' },
|
|
|
|
{ "osc-port", required_argument, 0, 'p' },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int option_index = 0;
|
|
|
|
int c = 0;
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 )
|
|
|
|
{
|
|
|
|
switch ( c )
|
|
|
|
{
|
2012-03-05 04:01:07 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
case 'p':
|
|
|
|
DMESSAGE( "Using OSC port %s", optarg );
|
|
|
|
osc_port = optarg;
|
|
|
|
break;
|
|
|
|
case 'i':
|
2012-03-05 04:01:07 +01:00
|
|
|
DMESSAGE( "Using instance name %s", optarg );
|
2012-02-29 07:12:07 +01:00
|
|
|
free( instance_name );
|
|
|
|
instance_name = strdup( optarg );
|
|
|
|
instance_override = true;
|
|
|
|
break;
|
|
|
|
case '?':
|
2012-03-05 04:01:07 +01:00
|
|
|
printf( "\nUsage: %s [--instance instance_name] [--osc-port portnum] [path_to_project]\n\n", argv[0] );
|
2012-02-29 07:12:07 +01:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2012-03-05 04:01:07 +01:00
|
|
|
/* we don't really need a pointer for this */
|
|
|
|
// will be created on project new/open
|
|
|
|
engine = NULL;
|
|
|
|
|
|
|
|
tle = new TLE;
|
|
|
|
|
2012-05-22 07:04:09 +02:00
|
|
|
nsm = nsm_new();
|
|
|
|
set_nsm_callbacks( nsm );
|
2012-03-05 04:01:07 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
MESSAGE( "Starting GUI" );
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
tle->run();
|
2012-02-29 06:24:51 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
timeline->init_osc( osc_port );
|
2012-02-20 10:58:46 +01:00
|
|
|
|
2012-02-29 06:24:51 +01:00
|
|
|
#ifdef HAVE_XPM
|
2012-02-29 07:12:07 +01:00
|
|
|
tle->main_window->icon((char *)p);
|
2012-02-29 06:24:51 +01:00
|
|
|
#endif
|
2012-02-29 07:12:07 +01:00
|
|
|
tle->main_window->show( 0, NULL );
|
2012-04-11 08:59:12 +02:00
|
|
|
|
|
|
|
fl_register_themes();
|
|
|
|
|
|
|
|
Fl_Theme::set();
|
2012-02-29 06:24:51 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
char *nsm_url = getenv( "NSM_URL" );
|
2012-02-29 06:24:51 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
if ( nsm_url )
|
|
|
|
{
|
2012-05-22 07:04:09 +02:00
|
|
|
if ( ! nsm_init( nsm, nsm_url ) )
|
2010-01-21 01:33:02 +01:00
|
|
|
{
|
2012-02-29 07:12:07 +01:00
|
|
|
if ( instance_override )
|
|
|
|
WARNING( "--instance option is not available when running under session management, ignoring." );
|
|
|
|
|
|
|
|
if ( optind < argc )
|
|
|
|
WARNING( "Loading files from the command-line is incompatible with session management, ignoring." );
|
|
|
|
|
2012-05-22 07:04:09 +02:00
|
|
|
nsm_send_announce( nsm, APP_NAME, ":progress:switch:", argv[0] );
|
2012-02-24 03:55:43 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
|
|
|
|
Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL );
|
2010-01-21 01:33:02 +01:00
|
|
|
}
|
2012-02-29 07:12:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( optind < argc )
|
2010-01-21 01:33:02 +01:00
|
|
|
{
|
2012-02-29 07:12:07 +01:00
|
|
|
MESSAGE( "Loading \"%s\"", argv[optind] );
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2012-02-29 07:12:07 +01:00
|
|
|
tle->open( argv[optind] );
|
2010-01-21 01:33:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl::add_check( check_sigterm );
|
2008-05-04 09:32:54 +02:00
|
|
|
|
2008-06-06 04:30:34 +02:00
|
|
|
Fl::run();
|
2010-01-21 01:33:02 +01:00
|
|
|
|
2012-02-24 03:55:43 +01:00
|
|
|
/* cleanup for valgrind's sake */
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
if ( engine )
|
|
|
|
{
|
|
|
|
delete engine;
|
|
|
|
engine = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-24 03:55:43 +01:00
|
|
|
delete timeline;
|
|
|
|
timeline = NULL;
|
|
|
|
|
2010-01-21 01:33:02 +01:00
|
|
|
delete tle;
|
|
|
|
tle = NULL;
|
|
|
|
|
2012-05-22 07:04:09 +02:00
|
|
|
nsm_free( nsm );
|
2010-01-21 01:33:02 +01:00
|
|
|
nsm = NULL;
|
|
|
|
|
2008-05-11 19:19:01 +02:00
|
|
|
MESSAGE( "Your fun is over" );
|
2008-02-14 06:47:12 +01:00
|
|
|
}
|