diff --git a/src/audiobuffer.hxx b/src/audiobuffer.hxx index 0189134..a64226b 100644 --- a/src/audiobuffer.hxx +++ b/src/audiobuffer.hxx @@ -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 diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index 875bf58..53cabfd 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -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(); } diff --git a/src/diskreader.cxx b/src/diskreader.cxx index 5466a62..2c093c5 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -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 ); } } diff --git a/src/gridlogic.cxx b/src/gridlogic.cxx index 40c33f1..cfa0752 100644 --- a/src/gridlogic.cxx +++ b/src/gridlogic.cxx @@ -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 diff --git a/src/gridlogic.hxx b/src/gridlogic.hxx index f47aa4b..d270801 100644 --- a/src/gridlogic.hxx +++ b/src/gridlogic.hxx @@ -68,4 +68,6 @@ class GridLogic : public TimeObserver int sceneLaunch; }; + + #endif // LUPPP_GRID_LOGIC_H diff --git a/src/gtrack.hxx b/src/gtrack.hxx index f0a0bc6..7653313 100644 --- a/src/gtrack.hxx +++ b/src/gtrack.hxx @@ -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); diff --git a/src/looperclip.cxx b/src/looperclip.cxx index 7db2f7e..472504e 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -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 ) diff --git a/src/looperclip.hxx b/src/looperclip.hxx index a680a09..f9dfbb7 100644 --- a/src/looperclip.hxx +++ b/src/looperclip.hxx @@ -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 ); diff --git a/src/state/state.cxx b/src/state/state.cxx index 6e0c33f..f270fbf 100644 --- a/src/state/state.cxx +++ b/src/state/state.cxx @@ -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() diff --git a/src/trackoutput.cxx b/src/trackoutput.cxx index ae924a2..ce145c1 100644 --- a/src/trackoutput.cxx +++ b/src/trackoutput.cxx @@ -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; }