-Refactored ClipSelector and Gclipselectoraction.hxx into one file, removing cruft

This commit is contained in:
Harry van Haaren 2013-09-05 15:06:23 +01:00
parent 15855ad727
commit 8763c3d12d
3 changed files with 38 additions and 58 deletions

View file

@ -33,6 +33,16 @@ class AudioBuffer
return ID;
}
void setName(const char* n)
{
if ( strlen(n) > 19 )
#ifdef DEBUG_BUFFER
printf("AudioBuffer setName too long!\n" );
#endif return;
memcpy( name, n, sizeof(char)* 20 );
}
int getBeats()
{
return numBeats;
@ -62,6 +72,8 @@ class AudioBuffer
int numBeats;
char name[20];
std::vector<float> buffer;
};

View file

@ -29,7 +29,6 @@
#include <sstream>
#include "../gridlogic.hxx"
#include "../gclipselectoraction.hxx"
#include "../worker.hxx"
#include "../looper.hxx"
@ -51,7 +50,7 @@ class ClipState
name("")
{}
void setName(std::string n = "---")
void setName(std::string n)
{
name = n;
}
@ -255,9 +254,9 @@ class ClipSelector : public Fl_Button
cairo_stroke(cr);
// clip name
cairo_move_to( cr, x + clipHeight + 10, drawY + 16 );
cairo_set_source_rgba( cr, 255 / 255.f, 255 / 255.f , 255 / 255.f , 1 );
cairo_set_font_size( cr, 10 );
cairo_move_to( cr, x + clipHeight + 10, drawY + 17 );
cairo_set_source_rgba( cr, 255 / 255.f, 255 / 255.f , 255 / 255.f , 0.9 );
cairo_set_font_size( cr, 11 );
cairo_show_text( cr, clips[i].getName().c_str() );
drawY += clipHeight;
@ -339,12 +338,29 @@ class ClipSelector : public Fl_Button
}
else if ( strcmp(m->label(), "Load") == 0 )
{
int loadFail = clipSelectorLoad( ID, clipNum );
if ( !loadFail )
{
clips[clipNum].setName();
clips[clipNum].setState(GridLogic::STATE_STOPPED);
// 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 0;
AudioBuffer* ab = Worker::loadSample( path );
EventLooperLoad e = EventLooperLoad( ID, clipNum, ab );
writeToDspRingbuffer( &e );
}
else if ( strcmp(m->label(), "1") == 0 ) {
EventLooperLoopLength e = EventLooperLoopLength(ID, clipNum ,1);

View file

@ -1,48 +0,0 @@
#ifndef LUPPP_G_CLIP_SELECTOR_ACTION_H
#define LUPPP_G_CLIP_SELECTOR_ACTION_H
#include "config.hxx"
#include "worker.hxx"
#include "looper.hxx"
#include "audiobuffer.hxx"
#include "eventhandler.hxx"
static string choose_file()
{
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; // FILE CHOSEN
}
return path;
}
static int clipSelectorLoad(int track, int scene)
{
string filePathName = choose_file();
if ( strcmp( filePathName.c_str(), "" ) == 0 )
return -1;
AudioBuffer* ab = Worker::loadSample( filePathName );
EventLooperLoad e = EventLooperLoad( track, scene, ab );
writeToDspRingbuffer( &e );
return 0;
}
#endif // LUPPP_G_CLIP_SELECTOR_ACTION_H