Loopp/src/gui.cxx

151 lines
3.1 KiB
C++
Raw Normal View History

2013-04-20 12:50:30 +02:00
#include "gui.hxx"
#include "avtk/avtk_image.h"
#include <sstream>
#include "jack.hxx"
#include "audiobuffer.hxx"
#include "worker.hxx"
#include <FL/fl_ask.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;
2013-07-25 18:20:54 +02:00
void luppp_tooltip(std::string s)
2013-07-25 00:23:30 +02:00
{
return;
//gui->setTooltip(s);
2013-07-25 00:23:30 +02:00
}
void Gui::setTooltip( std::string s )
{
tooltip = s;
tooltipLabel->label( tooltip.c_str() );
}
2013-07-24 20:09:35 +02:00
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)
2013-07-25 18:20:54 +02:00
return; // ignore ESC
2013-05-16 19:03:58 +02:00
else o->hide();
}
static void gui_static_read_rb(void* inst)
{
//cout << "read gui" << endl;
handleGuiEvents();
Fl::repeat_timeout( 1 / 30.f, &gui_static_read_rb, inst);
}
static void gui_header_callback(Fl_Widget *w, void *data)
{
if ( Fl::event_x() > 130 )
{
return;
}
Fl_Menu_Item rclick_menu[] =
{
{ "Load" },
{ "Save " },
{ 0 }
};
Fl_Menu_Item *m = (Fl_Menu_Item*) rclick_menu->popup( 10, 38, 0, 0, 0);
if ( !m )
{
return;
}
else if ( strcmp(m->label(), "Load") == 0 )
{
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;
}
}
else if ( strcmp(m->label(), "Save ") == 0 ) {
const char* name = fl_input( "Save session as", "lupppSession" );
cout << "Save clicked, name = " << name << endl;
EventSave e;
//writeToDspRingbuffer( &e );
}
}
Gui::Gui() :
window(1110,650),
diskReader( new DiskReader ),
diskWriter( new DiskWriter )
{
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 );
2013-07-25 19:05:23 +02:00
tooltipLabel = new Fl_Box(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();
2013-04-20 12:50:30 +02:00
}
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