-Refactoring, working on State::reset()

main
Harry van Haaren 2013-09-06 01:28:14 +01:00
parent d01530b21e
commit a0fb8cb5b5
10 changed files with 88 additions and 70 deletions

View File

@ -16,16 +16,20 @@ class AudioBuffer
AudioBuffer()
{
ID = privateID++;
numBeats = 0;
audioFrames = 0;
init();
}
AudioBuffer(unsigned long size)
{
// FIXME recorded buffers don't get an ID, using garbage IDs
/// no ID assigned: it *takes* the one from the previous buffer!
init();
buffer.resize(size);
}
void init()
{
numBeats = 0;
audioFrames = 0;
buffer.resize(size);
}
/// this function is used for "resizing" an exisiting buffer, and should

View File

@ -64,28 +64,12 @@ void ClipSelector::setID( int id )
/** converts the Looper::State into the UI represnted ClipSelector state.
* It puts some of the data into clips[], and stores unique state into the class.
**/
void ClipSelector::setState( int clipNum, GridLogic::State s )
{
#ifdef DEBUG_CLIP
cout << "setState clipNum = " << clipNum << " state = " << s << endl;
cout << "ClipSelector::setState() t = " << ID << " clipNum = " << clipNum << " state = " << s << endl;
#endif
switch(s)
{
case GridLogic::STATE_RECORDING:
case GridLogic::STATE_STOPPED:
case GridLogic::STATE_EMPTY:
case GridLogic::STATE_PLAYING:
case GridLogic::STATE_PLAY_QUEUED:
case GridLogic::STATE_RECORD_QUEUED:
case GridLogic::STATE_STOP_QUEUED:
default: break;
}
clips[clipNum].setState( s );
redraw();
}

View File

@ -36,7 +36,7 @@ void DiskReader::loadSample( int track, int scene, string path )
ab->setAudioFrames( infile.frames() );
ab->nonRtSetSample( buf );
cout << "Worker: loadSample() " << path << " size: " << infile.frames() << endl;
//cout << "DiskReader::loadSample() " << path << " size: " << infile.frames() << endl;
if ( infile.frames() > 0 )
@ -46,58 +46,62 @@ void DiskReader::loadSample( int track, int scene, string path )
base << dirname( basePath ) << "/sample.cfg";
// open sample, read all
#ifdef DEBUG_STATE
cout << "loading sample metadata file " << base.str().c_str() << endl;
#endif
std::ifstream sampleFile( base.str().c_str(), std::ios_base::in|std::ios_base::ate);
long file_length = sampleFile.tellg();
sampleFile.seekg(0, std::ios_base::beg);
sampleFile.clear();
char *sampleString = new char[file_length];
sampleFile.read(sampleString, file_length);
cout << "Sample file:" << endl << sampleString << endl;
cout << "Sample file (parsed):" << endl << cJSON_Parse( sampleString ) << endl;
cJSON* sampleJson = cJSON_Parse( sampleString );
if (!sampleJson) {
printf("Error in Sample JSON before: [%s]\n",cJSON_GetErrorPtr());
return;
}
cout << "sampleJson OK" << endl;
// retrieve sample metadata from sample.cfg using filename as key
char* tmp = strdup( path.c_str() );
char* baseName = basename( tmp );
cout << "tmp " << tmp << " baseName " << baseName << endl;
cJSON* sample = cJSON_GetObjectItem( sampleJson, baseName );
if ( sample )
if ( file_length > 0 )
{
cJSON* beats = cJSON_GetObjectItem( sample, "beats" );
sampleFile.seekg(0, std::ios_base::beg);
sampleFile.clear();
char *sampleString = new char[file_length];
sampleFile.read(sampleString, file_length);
cout << "Clip @ " << track << " " << scene << " gets " << beats->valuedouble << " beats."<< endl;
ab->setBeats( beats->valuedouble );
//cout << "Sample file:" << endl << sampleString << endl;
//cout << "Sample file (parsed):" << endl << cJSON_Parse( sampleString ) << endl;
cJSON* sampleJson = cJSON_Parse( sampleString );
if (!sampleJson) {
printf("Error in Sample JSON before: [%s]\n",cJSON_GetErrorPtr());
return;
}
// retrieve sample metadata from sample.cfg using filename as key
char* tmp = strdup( path.c_str() );
char* baseName = basename( tmp );
//cout << "tmp " << tmp << " baseName " << baseName << endl;
cJSON* sample = cJSON_GetObjectItem( sampleJson, baseName );
if ( sample )
{
cJSON* beats = cJSON_GetObjectItem( sample, "beats" );
//cout << "Clip @ " << track << " " << scene << " gets " << beats->valuedouble << " beats."<< endl;
ab->setBeats( beats->valuedouble );
}
else
{
cout << "Wanring: sample.cfg has no entry for beats." << endl;
}
cJSON_Delete( sampleJson );
free ( sampleString );
free ( tmp );
}
else
{
cout << "Wanring: sample.cfg has no entry for beats." << endl;
#ifdef DEBUG_STATE
cout << "DiskReader::loadSample() empty or no sample.cfg found" << endl;
#endif
}
free( basePath );
// write audioBuffer to DSP
EventLooperLoad e = EventLooperLoad( track, scene, ab );
writeToDspRingbuffer( &e );
cJSON_Delete( sampleJson );
free ( sampleString );
free ( tmp );
free( basePath );
}
}

View File

@ -119,9 +119,18 @@ void GridLogic::load(int track, int scene, AudioBuffer* ab)
void GridLogic::updateState()
{
//printf("GridLogic::updateState() stub" );
for(int t = 0; t < NTRACKS; t++)
{
for(int s = 0; s < NSCENES; s++)
{
GridLogic::State st = jack->getLooper( t )->getClip( s )->getState();
EventGuiPrint e( GridLogic::StateString[st] );
writeToGuiRingbuffer( &e );
jack->getControllerUpdater()->setSceneState(t, s, st );
}
}
}
void GridLogic::bar()
{
#ifdef DEBUG_CLIP

View File

@ -68,4 +68,6 @@ class GridLogic : public TimeObserver
int sceneLaunch;
};
#endif // LUPPP_GRID_LOGIC_H

View File

@ -67,6 +67,8 @@ class GTrack : public Fl_Group
rev.callback( gtrack_reverb_cb, this );
post.callback( gtrack_post_cb, this );
post.value( 1.0 );
volume.callback( gtrack_vol_cb, this );
volBox.maximum(1.0f);

View File

@ -14,6 +14,12 @@ LooperClip::LooperClip(int t, int s) :
Stately(),
track(t),
scene(s)
{
_buffer = new AudioBuffer(4410);
init();
}
void LooperClip::init()
{
_loaded = false;
_playing = false;
@ -23,14 +29,16 @@ LooperClip::LooperClip(int t, int s) :
_queueStop = false;
_queueRecord= false;
_buffer = new AudioBuffer(4410);
if ( _buffer )
{
_buffer->init();
}
_newBufferInTransit = false;
_playhead = 0;
_recordhead = 0;
}
void LooperClip::save()
{
// ensure there is something in the buffer to be saved
@ -53,22 +61,20 @@ void LooperClip::save()
void LooperClip::reset()
{
// TODO make the LooperClip reset to initial state
/*
if ( _loaded )
{
char buffer [50];
sprintf (buffer, "LC::save() track %i, scene %i", track,scene);
sprintf (buffer, "LC::reset() track %i, scene %i", track,scene);
EventGuiPrint e( buffer );
writeToGuiRingbuffer( &e );
EventRequestSaveBuffer e2( track, scene, _buffer->getAudioFrames() );
writeToGuiRingbuffer( &e2 );
//EventRequestSaveBuffer e2( track, scene, _buffer->getAudioFrames() );
//writeToGuiRingbuffer( &e2 );
}
else
{
SaveAble::done();
//SaveAble::done();
}
*/
}
/// loads a sample: eg from disk, unloading current sample if necessary
@ -93,7 +99,6 @@ void LooperClip::load( AudioBuffer* ab )
sprintf (buffer, "LC::load() t %i, s %i, aF %i",track, scene, int(_buffer->getAudioFrames()) );
EventGuiPrint e( buffer );
writeToGuiRingbuffer( &e );
}
void LooperClip::setRequestedBuffer( AudioBuffer* ab )

View File

@ -32,6 +32,8 @@ class LooperClip : public Stately
public:
LooperClip(int track, int scene);
void init();
/// loads a sample: eg from disk, unloading current sample if necessary
void load( AudioBuffer* ab );

View File

@ -5,6 +5,10 @@
#include "../event.hxx"
#include "../eventhandler.hxx"
#include "../jack.hxx"
extern Jack* jack;
using namespace std;
State::State()
@ -37,6 +41,8 @@ void State::reset()
{
statelys.at(i)->reset();
}
jack->getGridLogic()->updateState();
}
void State::finish()

View File

@ -19,7 +19,7 @@ TrackOutput::TrackOutput(int t, AudioProcessor* ap) :
_toReverb = 0.0;
_toMaster = 0.8;
_toSidechain = 0.0;
_toPostSidechain = 0.0;
_toPostSidechain = 1.0;
}