2013-04-20 12:50:30 +02:00
|
|
|
|
|
|
|
#include "gui.hxx"
|
2013-05-13 03:43:44 +02:00
|
|
|
#include "avtk/avtk_image.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2013-09-21 01:52:29 +02:00
|
|
|
// ONLY to be used for QUIT!
|
2013-07-30 23:02:14 +02:00
|
|
|
#include "jack.hxx"
|
2013-09-21 01:52:29 +02:00
|
|
|
extern Jack* jack;
|
|
|
|
|
2013-05-20 00:57:12 +02:00
|
|
|
#include "audiobuffer.hxx"
|
|
|
|
|
2013-09-05 00:55:44 +02:00
|
|
|
#include <FL/fl_ask.H>
|
|
|
|
|
2013-07-22 10:13:18 +02:00
|
|
|
// include the header.c file in the planning dir:
|
|
|
|
// its the GIMP .c export of the LUPPP header image
|
|
|
|
#include "../planning/header.c"
|
|
|
|
|
2013-05-13 03:43:44 +02:00
|
|
|
// Hack, move to gtrack.cpp
|
|
|
|
int GTrack::privateID = 0;
|
2013-05-16 02:38:11 +02:00
|
|
|
int GMasterTrack::privateID = 0;
|
2013-08-06 23:10:27 +02:00
|
|
|
//int AudioBuffer::privateID = 0;
|
2013-05-13 03:43:44 +02:00
|
|
|
|
|
|
|
using namespace std;
|
2013-04-20 12:50:30 +02:00
|
|
|
|
2013-07-25 00:23:30 +02:00
|
|
|
extern Gui* gui;
|
2013-09-21 01:52:29 +02:00
|
|
|
extern int signalHanlderInt;
|
2013-07-25 00:23:30 +02:00
|
|
|
|
2013-09-21 01:52:29 +02:00
|
|
|
static void signalChecker(void*)
|
|
|
|
{
|
|
|
|
if ( signalHanlderInt )
|
|
|
|
{
|
|
|
|
// Luppp recieved either a SIGTERM or SIGINT: quit gracefully
|
|
|
|
gui->quit();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Fl::repeat_timeout( 0.1, (Fl_Timeout_Handler)&signalChecker, 0 );
|
|
|
|
}
|
2013-05-16 19:03:58 +02:00
|
|
|
}
|
2013-05-16 14:38:46 +02:00
|
|
|
|
2013-09-21 01:52:29 +02:00
|
|
|
void close_cb(Fl_Widget*o, void*)
|
|
|
|
{
|
|
|
|
if ( (Fl::event() == FL_KEYDOWN || Fl::event() == FL_SHORTCUT) && Fl::event_key() == FL_Escape)
|
|
|
|
{
|
|
|
|
// on excape, as about quitting
|
2013-09-21 02:10:01 +02:00
|
|
|
gui->askQuit();
|
2013-09-21 01:52:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-21 02:10:01 +02:00
|
|
|
gui->quit();
|
2013-09-21 01:52:29 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-16 14:38:46 +02:00
|
|
|
static void gui_static_read_rb(void* inst)
|
|
|
|
{
|
|
|
|
//cout << "read gui" << endl;
|
|
|
|
handleGuiEvents();
|
|
|
|
Fl::repeat_timeout( 1 / 30.f, &gui_static_read_rb, inst);
|
|
|
|
}
|
|
|
|
|
2013-09-05 00:55:44 +02:00
|
|
|
static void gui_header_callback(Fl_Widget *w, void *data)
|
|
|
|
{
|
|
|
|
if ( Fl::event_x() > 130 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Menu_Item rclick_menu[] =
|
|
|
|
{
|
2013-09-06 01:10:33 +02:00
|
|
|
{ "New Session" },
|
|
|
|
{ "Load Session" },
|
|
|
|
{ "Save Session ", 0, 0, 0, FL_MENU_DIVIDER},
|
|
|
|
{ "Quit" },
|
2013-09-05 00:55:44 +02:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Menu_Item *m = (Fl_Menu_Item*) rclick_menu->popup( 10, 38, 0, 0, 0);
|
|
|
|
|
|
|
|
if ( !m )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-09-06 01:10:33 +02:00
|
|
|
else if ( strcmp(m->label(), "New Session") == 0 )
|
|
|
|
{
|
2013-09-17 13:07:25 +02:00
|
|
|
int yes = fl_choice("Start a new session?","Cancel","Yes",0);
|
|
|
|
if ( yes )
|
2013-09-06 01:10:33 +02:00
|
|
|
{
|
2013-09-06 01:28:11 +02:00
|
|
|
EventStateReset ev;
|
2013-09-06 01:10:33 +02:00
|
|
|
writeToDspRingbuffer( &ev );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( strcmp(m->label(), "Load Session") == 0 )
|
2013-09-05 00:55:44 +02:00
|
|
|
{
|
|
|
|
cout << "Load clicked" << endl;
|
|
|
|
Fl_Native_File_Chooser fnfc;
|
|
|
|
fnfc.title("Load Session");
|
|
|
|
fnfc.type(Fl_Native_File_Chooser::BROWSE_DIRECTORY);
|
|
|
|
fnfc.directory( getenv("HOME") );
|
|
|
|
|
|
|
|
switch ( fnfc.show() )
|
|
|
|
{
|
|
|
|
case -1: //printf("ERROR: %s\\n", fnfc.errmsg());
|
|
|
|
break; // ERROR
|
|
|
|
case 1: //printf("CANCEL\\n");
|
|
|
|
break; // CANCEL
|
|
|
|
default: printf("Loading session directory %s\n", fnfc.filename());
|
|
|
|
gui->getDiskReader()->readSession( fnfc.filename() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-06 01:10:33 +02:00
|
|
|
else if ( strcmp(m->label(), "Save Session ") == 0 )
|
2013-09-05 15:42:48 +02:00
|
|
|
{
|
2013-09-18 10:53:15 +02:00
|
|
|
const char* name = fl_input( "Save session as", gui->getDiskWriter()->getLastSaveName().c_str() );
|
2013-09-05 12:36:51 +02:00
|
|
|
if ( name )
|
|
|
|
{
|
|
|
|
cout << "Save clicked, name = " << name << endl;
|
|
|
|
gui->getDiskWriter()->initialize( getenv("HOME"), name );
|
2013-09-06 01:28:11 +02:00
|
|
|
EventStateSave e;
|
2013-09-05 12:36:51 +02:00
|
|
|
writeToDspRingbuffer( &e );
|
|
|
|
}
|
2013-09-05 00:55:44 +02:00
|
|
|
}
|
2013-09-21 00:28:59 +02:00
|
|
|
else if ( strcmp(m->label(), "Quit") == 0 )
|
|
|
|
{
|
2013-09-21 01:52:29 +02:00
|
|
|
gui->askQuit();
|
2013-09-21 00:28:59 +02:00
|
|
|
}
|
2013-09-05 00:55:44 +02:00
|
|
|
}
|
|
|
|
|
2013-09-05 19:33:16 +02:00
|
|
|
void Gui::selectLoadSample( int track, int scene )
|
|
|
|
{
|
|
|
|
// FIXME: refactor
|
|
|
|
string path;
|
|
|
|
Fl_Native_File_Chooser fnfc;
|
|
|
|
fnfc.title("Pick a file");
|
|
|
|
fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
|
|
|
//fnfc.filter("Wav\t*.wav");
|
|
|
|
fnfc.directory( getenv("HOME") ); // default directory to use
|
|
|
|
// Show native chooser
|
|
|
|
switch ( fnfc.show() ) {
|
|
|
|
case -1: printf("ERROR: %s\n", fnfc.errmsg()); break; // ERROR
|
|
|
|
case 1: printf("CANCEL\n"); break; // CANCEL
|
|
|
|
default: printf("Loading directory: %s\n", fnfc.filename());
|
|
|
|
// update path and load it
|
|
|
|
path = fnfc.filename();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcmp( path.c_str(), "" ) == 0 )
|
|
|
|
return;
|
|
|
|
|
2013-09-05 20:18:21 +02:00
|
|
|
// diskReader loads sample, and parses for sample.cfg
|
|
|
|
diskReader->loadSample( track, scene, path );
|
2013-09-05 19:33:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-16 00:27:31 +02:00
|
|
|
Gui::Gui() :
|
2013-09-03 21:06:11 +02:00
|
|
|
window(1110,650),
|
2013-09-17 13:07:25 +02:00
|
|
|
diskReader( new DiskReader() ),
|
2013-09-23 11:53:58 +02:00
|
|
|
diskWriter( new DiskWriter() ),
|
|
|
|
samplerate( 0 )
|
2013-05-16 00:27:31 +02:00
|
|
|
{
|
2013-09-17 12:00:12 +02:00
|
|
|
LUPPP_NOTE( "%s", "Gui()" );
|
2013-09-21 01:52:29 +02:00
|
|
|
|
|
|
|
// setup callback to signalChecker()
|
|
|
|
Fl::add_timeout( 0.1, (Fl_Timeout_Handler)&signalChecker, 0 );
|
|
|
|
|
2013-05-16 00:27:31 +02:00
|
|
|
window.color(FL_BLACK);
|
2013-07-25 18:20:54 +02:00
|
|
|
window.label("Luppp");
|
2013-09-21 01:52:29 +02:00
|
|
|
window.callback( close_cb, 0 );
|
2013-05-13 03:43:44 +02:00
|
|
|
|
2013-07-25 18:20:54 +02:00
|
|
|
Avtk::Image* headerImage = new Avtk::Image(0,0,1110,36,"header.png");
|
2013-07-22 10:13:18 +02:00
|
|
|
headerImage->setPixbuf( header.pixel_data, 4 );
|
2013-09-05 00:55:44 +02:00
|
|
|
headerImage->callback( gui_header_callback, this );
|
2013-05-13 03:43:44 +02:00
|
|
|
|
2013-07-25 19:05:23 +02:00
|
|
|
tooltipLabel = new Fl_Box(130, 25, 500, 20, "");
|
2013-07-25 18:53:59 +02:00
|
|
|
tooltipLabel->labelcolor( FL_LIGHT2 );
|
|
|
|
tooltipLabel->color( FL_DARK2 );
|
2013-07-25 19:05:23 +02:00
|
|
|
tooltipLabel->hide();
|
|
|
|
//tooltipLabel->align( FL_ALIGN_TOP_LEFT );
|
2013-07-25 18:53:59 +02:00
|
|
|
|
2013-07-26 01:56:06 +02:00
|
|
|
window.resizable( headerImage );
|
2013-07-24 20:09:35 +02:00
|
|
|
|
2013-05-16 02:38:11 +02:00
|
|
|
int i = 0;
|
|
|
|
for (; i < NTRACKS; i++ )
|
2013-05-13 03:43:44 +02:00
|
|
|
{
|
|
|
|
stringstream s;
|
|
|
|
s << "Track " << i+1;
|
2013-07-30 04:07:46 +02:00
|
|
|
//printf("track name %s\n", s.str().c_str() );
|
2013-07-25 18:40:25 +02:00
|
|
|
tracks.push_back( new GTrack(8 + i * 118, 40, 110, 600, s.str().c_str() ) );
|
2013-05-13 03:43:44 +02:00
|
|
|
}
|
2013-04-20 13:20:46 +02:00
|
|
|
|
2013-07-25 18:40:25 +02:00
|
|
|
master = new GMasterTrack(8 + i * 118, 40, 150, 600, "Master");
|
2013-07-22 12:53:08 +02:00
|
|
|
|
2013-05-16 00:27:31 +02:00
|
|
|
window.end();
|
2013-04-20 12:50:30 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 14:38:46 +02:00
|
|
|
GTrack* Gui::getTrack(int id)
|
|
|
|
{
|
|
|
|
return tracks.at(id);
|
|
|
|
}
|
|
|
|
|
2013-04-20 12:50:30 +02:00
|
|
|
int Gui::show()
|
|
|
|
{
|
2013-05-16 00:27:31 +02:00
|
|
|
window.show();
|
2013-05-16 14:38:46 +02:00
|
|
|
|
2013-07-30 23:02:14 +02:00
|
|
|
gui_static_read_rb( this );
|
|
|
|
|
2013-04-20 12:50:30 +02:00
|
|
|
return Fl::run();
|
|
|
|
}
|
2013-07-24 20:09:35 +02:00
|
|
|
|
2013-09-21 01:52:29 +02:00
|
|
|
|
|
|
|
int Gui::quit()
|
|
|
|
{
|
2013-09-21 02:10:01 +02:00
|
|
|
jack->quit();
|
2013-09-21 01:52:29 +02:00
|
|
|
window.hide();
|
2013-09-21 02:10:01 +02:00
|
|
|
exit(0);
|
2013-09-21 01:52:29 +02:00
|
|
|
}
|
|
|
|
|
2013-09-21 02:10:01 +02:00
|
|
|
void Gui::askQuit()
|
2013-09-21 01:52:29 +02:00
|
|
|
{
|
2013-09-21 02:10:01 +02:00
|
|
|
int quit = fl_choice("Really Quit?","Cancel","Quit",0);
|
|
|
|
if ( quit ) // JUST QUIT
|
2013-09-21 01:52:29 +02:00
|
|
|
{
|
2013-09-21 02:10:01 +02:00
|
|
|
gui->quit();
|
2013-09-21 01:52:29 +02:00
|
|
|
}
|
|
|
|
}
|