diff --git a/src/looper.cxx b/src/looper.cxx index 71af0d9..bae7cf1 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -110,6 +110,9 @@ void Looper::process(unsigned int nframes, Buffers* buffers) // handle state of clip, and do what needs doing: // record into buffer, play from buffer, etc if ( clips[clip]->recording() ) { + if(clips[clip]->getWantedBeats() > 0 && clips[clip]->getBeats() >= clips[clip]->getWantedBeats() - 4) + clips[clip]->queuePlay(true); + if ( clips[clip]->recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST && !clips[clip]->newBufferInTransit() ) { EventLooperClipRequestBuffer e( track, clip, clips[clip]->audioBufferSize() + LOOPER_SAMPLES_UPDATE_SIZE); diff --git a/src/looperclip.cxx b/src/looperclip.cxx index e193c6a..328768c 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -51,6 +51,7 @@ void LooperClip::init() _queuePlay = false; _queueStop = false; _queueRecord= false; + _wantedBeats= -0; if ( _buffer ) { _buffer->init(); @@ -184,14 +185,22 @@ void LooperClip::setPlayHead(float ph) if(!_recording&&_playing) { _playhead = ph; jack->getControllerUpdater()->setTrackSceneProgress(track, scene, getProgress() ); - } + } } +void LooperClip::setWantedBeats(int beats) +{ + _wantedBeats = beats; +} +int LooperClip::getWantedBeats() +{ + return _wantedBeats; +} void LooperClip::record(int count, float* L, float* R) { - // write "count" samples into current buffer. + // write "count" samples into current buffer. if ( _buffer ) { size_t size = _buffer->getSize(); @@ -240,8 +249,12 @@ size_t LooperClip::audioBufferSize() void LooperClip::setBeats(int beats) { if ( _buffer ) { + if(_buffer->getBeats() == 0) + setWantedBeats( beats ); _buffer->setBeats( beats ); - } + } else { + setWantedBeats( beats ); + } } int LooperClip::getBeats() diff --git a/src/looperclip.hxx b/src/looperclip.hxx index b6af836..872a84e 100644 --- a/src/looperclip.hxx +++ b/src/looperclip.hxx @@ -116,15 +116,19 @@ public: ///reset the play head to zero. Does nothing when recording void setPlayHead(float ph); + void setWantedBeats(int beats); + + int getWantedBeats(); + #ifdef BUILD_TESTS // used only in test cases void setState( bool load, bool play, bool rec, bool qPlay, bool qStop, bool qRec ); #endif private: - int track, scene; + int track, scene; - /** Luppp needs more than the current state of the clip to accuratly handle + /** Luppp needs more than the current state of the clip to accuratly handle * it. The current state of the grid is kept up-to-date by GridLogic * abstracting detail away, sending GridLogic::State to Controllers. **/ @@ -140,6 +144,7 @@ private: float _playhead; float _recordhead; + int _wantedBeats; AudioBuffer* _buffer; };