diff --git a/src/audiobuffer.hxx b/src/audiobuffer.hxx index f7f58b4..25c85af 100644 --- a/src/audiobuffer.hxx +++ b/src/audiobuffer.hxx @@ -16,6 +16,7 @@ class AudioBuffer AudioBuffer(unsigned long size) { //ID = id; + numBeats = 4; buffer.resize(size); } diff --git a/src/gridlogic.cxx b/src/gridlogic.cxx index 96375f1..efce448 100644 --- a/src/gridlogic.cxx +++ b/src/gridlogic.cxx @@ -80,22 +80,19 @@ void GridLogic::bar() if ( state[i] == STATE_PLAY_QUEUED ) { state[i] = STATE_PLAYING; - jack->getLooper( track )->setRecord( scene, false); - jack->getLooper( track )->play( scene, true); + jack->getLooper( track )->getClip( scene )->play(); change = true; } else if ( state[i] == STATE_STOP_QUEUED ) { state[i] = STATE_LOADED; - jack->getLooper( track )->setRecord( scene, false); - jack->getLooper( track )->play( scene, false); + jack->getLooper( track )->getClip( scene )->stop(); change = true; } else if ( state[i] == STATE_RECORD_QUEUED ) { state[i] = STATE_RECORDING; - jack->getLooper( track )->setRecord( scene, true); - jack->getLooper( track )->play( scene, false); + jack->getLooper( track )->getClip( scene )->record(); change = true; } diff --git a/src/logic.cxx b/src/logic.cxx index 858d13e..9638eb8 100644 --- a/src/logic.cxx +++ b/src/logic.cxx @@ -48,33 +48,13 @@ void Logic::looperClipLenght(int t, int s, int l) void Logic::looperUseAsTempo(int t, int s) { - size_t l = jack->getLooper( t )->getClip( s )->getBufferLenght(); - printf("lenght = %zu\n", l ); + size_t clipBeats = jack->getLooper( t )->getClip( s )->getBeats(); + size_t clipFrames = jack->getLooper( t )->getClip( s )->getBufferLenght(); - int beats = 1; - - int four = l / 4; - int eight = l / 8; - int sixteen = l / 16; - int tirty2 = l / 32; - int sixty4 = l / 64; - - printf("%i\n%i\n%i\n%i\n", four, eight, sixteen, tirty2 ); - - size_t res = l; - - while ( res > 22050 / 2 ) + if ( clipBeats > 0 ) { - res = l / beats; - - if ( res - 22050 < jack->getTimeManager()->getFpb() / 2.f ) - { - printf("using beats %i\n", beats); - jack->getTimeManager()->setFpb(res); - } - - beats = beats + beats; + size_t framesPerBeat = clipFrames / clipBeats; + jack->getTimeManager()->setFpb( framesPerBeat ); } - } diff --git a/src/looper.cxx b/src/looper.cxx index 6340363..158cafa 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -44,39 +44,6 @@ Looper::Looper(int t) : crossfadeSize = 1000; } -void Looper::setRecord(int scene, bool r) -{ - clips[scene].recording(r); - - /* - if ( !r ) - { - // set beats based on recording duration - int beats = (clips[scene].getBufferLenght() / fpb) + 1; - clips[scene].setBeats( beats ); - printf("stop record, has %i beats\n", beats ); - } - */ -} - -void Looper::play(int scene, bool r) -{ - for(int i = 0; i < NSCENES; i++) - { - clips[i].playing(false); - } - - - if ( r ) - { - clips[scene].playing(true); - } - else - { - jack->getControllerUpdater()->setTrackSceneProgress(track, scene, 0.f ); - } -} - LooperClip* Looper::getClip(int scene) { return &clips[scene]; @@ -100,8 +67,6 @@ void Looper::setSample(int scene, AudioBuffer* ab) void Looper::process(unsigned int nframes, Buffers* buffers) { - float* out = buffers->audio[Buffers::TRACK_0 + track]; - // process each clip individually: this allows for playback of one clip, // while another clip records. for ( int clip = 0; clip < NSCENES; clip++ ) @@ -121,7 +86,6 @@ void Looper::process(unsigned int nframes, Buffers* buffers) // copy data from input buffer to recording buffer float* input = buffers->audio[Buffers::MASTER_INPUT]; clips[clip].record( nframes, input, 0 ); - } else if ( clips[clip].playing() ) { @@ -135,6 +99,8 @@ void Looper::process(unsigned int nframes, Buffers* buffers) playSpeed = float(actualFrames) / targetFrames; } + float* out = buffers->audio[Buffers::TRACK_0 + track]; + for(unsigned int i = 0; i < nframes; i++ ) { out[i] = clips[clip].getSample(playSpeed); diff --git a/src/looper.hxx b/src/looper.hxx index 70f1e20..9368c56 100644 --- a/src/looper.hxx +++ b/src/looper.hxx @@ -30,13 +30,13 @@ class Looper : public AudioProcessor, public TimeObserver /// Used for infinite lenght recording void setRequestedBuffer(int s, AudioBuffer* ab); + /// stores the framesPerBeat from TimeManager. Used to stretch audio void setFpb(int f) { fpb = f; } - void play(int scene, bool r); - void setRecord(int scene, bool r); - + /// Retrieve a clip from the Looper LooperClip* getClip(int scene); + /// Process nframes of audio void process(unsigned int nframes, Buffers* buffers); private: diff --git a/src/looperclip.cxx b/src/looperclip.cxx index 1e6770f..2dff79f 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -111,18 +111,52 @@ long LooperClip::getBufferLenght() return _recordhead; } -bool LooperClip::loaded(){return _loaded;} -void LooperClip::playing(bool p){_playing = p; _playhead = 0; } -bool LooperClip::playing(){return _playing;} -bool LooperClip::recording(){return _recording;} -void LooperClip::recording(bool r) {_recording = r;} +bool LooperClip::loaded() +{ + return _loaded; +} + +void LooperClip::play() +{ + _playing = true; + _playhead = 0; +} +void LooperClip::stop() +{ + _playing = false; + _playhead = 0; +} + +bool LooperClip::playing() +{ + return _playing; +} + +bool LooperClip::recording() +{ + return _recording; +} + + +void LooperClip::record() +{ + /* + if ( !r && duration ) + { + setBeats( duration ); + } + */ + _recording = true; + _playing = false; +} + void LooperClip::newBufferInTransit(bool n){_newBufferInTransit = n;} bool LooperClip::newBufferInTransit(){return _newBufferInTransit;} float LooperClip::getSample(float playSpeed) { - if ( _buffer ) + if ( _buffer && _buffer->getData().size() > 0 ) { if ( _playhead >= _recordhead || _playhead >= _buffer->getData().size() || diff --git a/src/looperclip.hxx b/src/looperclip.hxx index e89e7e0..be9eba5 100644 --- a/src/looperclip.hxx +++ b/src/looperclip.hxx @@ -40,19 +40,25 @@ class LooperClip unsigned long recordSpaceAvailable(); - size_t audioBufferSize(); + void setBeats(int beats); - int getBeats(); - - long getBufferLenght(); + /// get clip state bool loaded(); - void playing(bool p); bool playing(); bool recording(); - void recording(bool r); + + /// get buffer details + int getBeats(); + long getBufferLenght(); + size_t audioBufferSize(); + + /// set clip state + void play(); + void stop(); + void record(); void newBufferInTransit(bool n); bool newBufferInTransit(); @@ -63,8 +69,8 @@ class LooperClip private: bool _loaded; - bool _recording; bool _playing; + bool _recording; bool _newBufferInTransit;