Loopp/src/gui.cxx

369 lines
7.9 KiB
C++
Raw Normal View History

2013-04-20 12:50:30 +02:00
#include "gui.hxx"
#include "avtk/avtk_image.h"
#include "avtk/avtk_button.h"
#include <sstream>
// ONLY to be used for QUIT!
#include "jack.hxx"
extern Jack* jack;
#include "audiobuffer.hxx"
2013-10-01 17:04:59 +02:00
#include "controller/genericmidi.hxx"
2013-09-25 13:49:12 +02:00
#include <stdlib.h>
#include <FL/Fl.H>
#include <FL/fl_ask.H>
2013-09-25 13:49:12 +02:00
#include <FL/Fl_Window.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Wizard.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Multiline_Output.H>
// include the header.c file in the planning dir:
// its the GIMP .c export of the LUPPP header image
#include "../planning/header.c"
// Hack, move to gtrack.cpp
int GTrack::privateID = 0;
int GMasterTrack::privateID = 0;
//int AudioBuffer::privateID = 0;
using namespace std;
2013-04-20 12:50:30 +02:00
2013-07-25 00:23:30 +02:00
extern Gui* gui;
extern int signalHanlderInt;
2013-07-25 00:23:30 +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
}
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();
}
else
{
2013-09-21 02:10:01 +02:00
gui->quit();
}
}
static void gui_static_read_rb(void* inst)
{
handleGuiEvents();
Fl::repeat_timeout( 1 / 30.f, &gui_static_read_rb, inst);
}
void option_controller_cb(Fl_Widget*,void* data)
{
LUPPP_NOTE("%s","Controller cb");
}
2013-09-25 13:49:12 +02:00
static void gui_header_callback(Fl_Widget *w, void *data)
{
Gui* g = (Gui*)data;
if ( Fl::event_x() > 130 )
{
return;
}
Fl_Menu_Item rclick_menu[] =
{
{ "New Session" },
{ "Load Session" },
{ "Save Session ", 0, 0, 0, FL_MENU_DIVIDER},
2013-09-25 13:49:12 +02:00
{ "Options", 0, 0, 0, FL_MENU_DIVIDER},
{ "Quit" },
{ 0 }
};
Fl_Menu_Item *m = (Fl_Menu_Item*) rclick_menu->popup( 10, 38, 0, 0, 0);
if ( !m )
{
return;
}
else if ( strcmp(m->label(), "New Session") == 0 )
{
int yes = fl_choice("Start a new session?","Cancel","Yes",0);
if ( yes )
{
gui->reset();
}
}
else if ( strcmp(m->label(), "Load Session") == 0 )
{
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;
}
}
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() );
if ( name )
{
gui->getDiskWriter()->initialize( getenv("HOME"), name );
LUPPP_NOTE("%s %s","Saving session as ", name );
EventStateSave e;
writeToDspRingbuffer( &e );
}
}
2013-09-25 13:49:12 +02:00
else if ( strcmp(m->label(), "Options") == 0 )
{
g->showOptions();
2013-09-25 13:49:12 +02:00
}
else if ( strcmp(m->label(), "Quit") == 0 )
{
g->askQuit();
}
}
void Gui::showOptions()
{
optionWindow->show();
}
void Gui::selectLoadController(Fl_Widget* w, void*)
{
// FIXME: refactor
string path;
Fl_Native_File_Chooser fnfc;
fnfc.title("Pick a controller definition");
fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
fnfc.filter("Controllers\t*.ctlr");
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 controller at %s\n", fnfc.filename());
path = fnfc.filename();
break;
}
if ( strcmp( path.c_str(), "" ) == 0 )
return;
2013-10-01 17:04:59 +02:00
LUPPP_NOTE("%s","ADD Controller cb");
Controller* c = new GenericMIDI( path );
if ( c->status() == Controller::CONTROLLER_OK )
{
EventControllerInstance e(c);
writeToDspRingbuffer( &e );
}
else
{
LUPPP_ERROR("Controller initialization failed!");
}
}
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;
// diskReader loads sample, and parses for sample.cfg
diskReader->loadSample( track, scene, path );
}
void Gui::openAudioEditor(AudioBuffer* ab)
{
LUPPP_WARN("Gui::openAudioEditor() %i", audioEditor );
audioEditor->show(0);
}
Gui::Gui() :
samplerate( 0 ),
window(1110,650),
diskReader( new DiskReader() ),
diskWriter( new DiskWriter() )
{
2013-09-17 12:00:12 +02:00
LUPPP_NOTE( "%s", "Gui()" );
// setup callback to signalChecker()
Fl::add_timeout( 0.1, (Fl_Timeout_Handler)&signalChecker, 0 );
window.color(FL_BLACK);
2013-07-25 18:20:54 +02:00
window.label("Luppp");
window.callback( close_cb, 0 );
2013-07-25 18:20:54 +02:00
Avtk::Image* headerImage = new Avtk::Image(0,0,1110,36,"header.png");
headerImage->setPixbuf( header.pixel_data, 4 );
headerImage->callback( gui_header_callback, this );
/*
tooltipLabel = new Fl_2(130, 25, 500, 20, "");
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-26 01:56:06 +02:00
window.resizable( headerImage );
2013-07-24 20:09:35 +02:00
int i = 0;
for (; i < NTRACKS; i++ )
{
stringstream s;
s << "Track " << i+1;
//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-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");
window.end();
// setup Options dialog
optionWindow = new Fl_Double_Window(400,300,"Options");
Avtk::Button* ctlrButton = new Avtk::Button(5, 25, 200, 20, "Add Controller");
ctlrButton->callback( selectLoadController );
optionWindow->end();
// Create AudioEditor after window.end() has been called
audioEditor = new AudioEditor();
// default controller for testing
LUPPP_NOTE("Adding APC40 Controller cb");
Controller* c = new GenericMIDI( "akai_apc.ctlr" );
if ( c->status() == Controller::CONTROLLER_OK )
{
EventControllerInstance e(c);
writeToDspRingbuffer( &e );
}
else
{
LUPPP_ERROR("Controller initialization failed!");
}
2013-04-20 12:50:30 +02:00
}
void Gui::reset()
{
// signal to DSP to reset state
EventStateReset ev;
writeToDspRingbuffer( &ev );
// clear UI state: track names / scene names
for(unsigned int i = 0; i < NTRACKS; i++)
{
stringstream s;
s << "Track " << i+1;
tracks.at(i)->bg.setLabel( s.str().c_str() );
for(unsigned int s = 0; s < NSCENES; s++)
{
tracks.at(i)->getClipSelector()->clipName( s, "" );
}
}
for(unsigned int i = 0; i < NSCENES; i++)
{
stringstream s;
s << "Scene " << i+1;
master->getClipSelector()->clipName( i, s.str() );
}
}
GTrack* Gui::getTrack(int id)
{
return tracks.at(id);
}
2013-04-20 12:50:30 +02:00
int Gui::show()
{
window.show();
gui_static_read_rb( this );
2013-04-20 12:50:30 +02:00
return Fl::run();
}
2013-07-24 20:09:35 +02:00
int Gui::quit()
{
2013-09-21 02:10:01 +02:00
jack->quit();
window.hide();
2013-09-21 02:10:01 +02:00
exit(0);
}
2013-09-21 02:10:01 +02:00
void Gui::askQuit()
{
2013-09-21 02:10:01 +02:00
int quit = fl_choice("Really Quit?","Cancel","Quit",0);
if ( quit ) // JUST QUIT
{
2013-09-21 02:10:01 +02:00
gui->quit();
}
}
Gui::~Gui()
{
delete optionWindow;
delete audioEditor;
delete diskReader;
delete diskWriter;
delete master;
for(unsigned int i = 0; i < tracks.size(); i++)
{
delete tracks.at(i);
}
}