/*******************************************************************************/ /* 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 "const.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Thread.H" #include "debug.h" #include "Mixer.H" #include "Project.H" #include "Loggable.H" /* for registration */ #include "Module.H" #include "Gain_Module.H" #include "Plugin_Module.H" #include "JACK_Module.H" #include "Meter_Module.H" #include "Meter_Indicator_Module.H" #include "Controller_Module.H" #include "Mono_Pan_Module.H" #include "Chain.H" #include "Mixer_Strip.H" #include "NSM.H" #include #ifdef HAVE_XPM #include "FL/Fl.H" #include "FL/x.H" #include #include "../icons/icon-16x16.xpm" #endif /* TODO: put these in a header */ #define USER_CONFIG_DIR ".non-mixer/" const double NSM_CHECK_INTERVAL = 0.25f; const char COPYRIGHT[] = "Copyright (c) 2008-2012 Jonathan Moore Liles"; char *user_config_dir; Mixer *mixer; NSM_Client *nsm; char *instance_name; #include static int ensure_dirs ( void ) { asprintf( &user_config_dir, "%s/%s", getenv( "HOME" ), USER_CONFIG_DIR ); int r = mkdir( user_config_dir, 0777 ); return r == 0 || errno == EEXIST; } #include static void cb_main ( Fl_Double_Window *, void *) { if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape ) return; mixer->command_quit(); } void check_nsm ( void * v ) { nsm->check(); Fl::repeat_timeout( NSM_CHECK_INTERVAL, check_nsm, v ); } 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..." ); mixer->quit(); } } int main ( int argc, char **argv ) { printf( "%s %s %s -- %s\n", APP_TITLE, VERSION, "", COPYRIGHT ); if ( ! Fl::visual( FL_DOUBLE | FL_RGB ) ) { WARNING( "Xdbe not supported, FLTK will fake double buffering." ); } #ifdef HAVE_XPM fl_open_display(); Pixmap p, mask; XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), (char**)icon_16x16, &p, &mask, NULL); #endif Thread::init(); Thread thread( "UI" ); thread.set(); ensure_dirs(); signal( SIGTERM, sigterm_handler ); signal( SIGHUP, sigterm_handler ); signal( SIGINT, sigterm_handler ); Fl_Tooltip::color( FL_BLACK ); Fl_Tooltip::textcolor( FL_YELLOW ); Fl_Tooltip::size( 14 ); Fl_Tooltip::hoverdelay( 0.1f ); Fl::visible_focus( 0 ); fl_register_images(); LOG_REGISTER_CREATE( Mixer_Strip ); LOG_REGISTER_CREATE( Chain ); LOG_REGISTER_CREATE( Plugin_Module ); LOG_REGISTER_CREATE( Gain_Module ); LOG_REGISTER_CREATE( Meter_Module ); LOG_REGISTER_CREATE( JACK_Module ); LOG_REGISTER_CREATE( Mono_Pan_Module ); LOG_REGISTER_CREATE( Meter_Indicator_Module ); LOG_REGISTER_CREATE( Controller_Module ); init_crystal_boxtypes(); init_gleam_boxtypes(); signal( SIGPIPE, SIG_IGN ); Fl::get_system_colors(); Fl::scheme( "gtk+" ); Fl::lock(); Fl_Double_Window *main_window; { Fl_Double_Window *o = main_window = new Fl_Double_Window( 800, 600, "Non-DAW : Mixer" ); { main_window->xclass( APP_NAME ); { Fl_Widget *o = mixer = new Mixer( 0, 0, main_window->w(), main_window->h(), NULL ); Fl_Group::current()->resizable(o); } } o->end(); o->size_range( main_window->w(), mixer->min_h(), 0, 0 ); o->callback( (Fl_Callback*)cb_main, main_window ); #ifdef HAVE_XPM o->icon((char *)p); #endif o->show( 0, 0 ); } const char *osc_port = NULL; nsm = new NSM_Client; instance_name = strdup( APP_NAME ); bool instance_override = false; static struct option long_options[] = { { "help", no_argument, 0, '?' }, { "instance", required_argument, 0, 'i' }, { "osc-port", required_argument, 0, 'p' }, { 0, 0, 0, 0 } }; int option_index = 0; int c = 0; while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 ) { switch ( c ) { case 'p': DMESSAGE( "Using OSC port %s", optarg ); osc_port = optarg; break; case 'i': DMESSAGE( "Using OSC port %s", optarg ); free( instance_name ); instance_name = strdup( optarg ); instance_override = true; break; case '?': printf( "\nUsage: %s [--instance instance_name] [--osc-port portnum] [path_to_project]\n\n", argv[0] ); exit(0); break; } } Plugin_Module::spawn_discover_thread(); mixer->init_osc( osc_port ); char *nsm_url = getenv( "NSM_URL" ); if ( nsm_url ) { if ( ! nsm->init( nsm_url ) ) { 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." ); nsm->announce( APP_NAME, ":switch:dirty:", argv[0] ); // 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 ); } } else { if ( optind < argc ) { MESSAGE( "Waiting for plugins..." ); Plugin_Module::join_discover_thread(); MESSAGE( "Loading \"%s\"", argv[optind] ); if ( ! mixer->command_load( argv[optind] ) ) { fl_alert( "Error opening project specified on commandline" ); } } } Fl::add_check( check_sigterm ); Fl::run(); delete main_window; main_window = NULL; MESSAGE( "Your fun is over" ); }