mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
Loops get retriggered when setting bpm
This commit is contained in:
parent
eb06f749a5
commit
804bca9135
6 changed files with 66 additions and 5 deletions
|
@ -71,6 +71,27 @@ LooperClip* Looper::getClip(int scene)
|
|||
return clips[scene];
|
||||
}
|
||||
|
||||
void Looper::beat()
|
||||
{
|
||||
//FIXME: Need to keep looperClips in sync when there exists no int N
|
||||
// such that playSpeed*N==1
|
||||
// for(int i=0;i<NSCENES;i++)
|
||||
// {
|
||||
// int iph=clips[i]->getPlayhead()+1.0;
|
||||
// long targetFrames = clips[i]->getBeats() * fpb;
|
||||
// long actualFrames = clips[i]->getActualAudioLength();//getBufferLenght();
|
||||
// float playSpeed = 1.0;
|
||||
|
||||
// if ( targetFrames != 0 && actualFrames != 0 )
|
||||
// {
|
||||
// playSpeed = float(actualFrames) / targetFrames;
|
||||
// }
|
||||
// clips[i]->setPlayHead(iph-(iph%fpb)*playSpeed);
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void Looper::setRequestedBuffer(int s, AudioBuffer* ab)
|
||||
{
|
||||
clips[s]->setRequestedBuffer( ab );
|
||||
|
@ -144,6 +165,12 @@ void Looper::process(unsigned int nframes, Buffers* buffers)
|
|||
|
||||
}
|
||||
|
||||
void Looper::resetTimeState()
|
||||
{
|
||||
for(int i=0;i<NSCENES;i++)
|
||||
clips[i]->setPlayHead(0.0);
|
||||
}
|
||||
|
||||
void Looper::pitchShift(int count, float* input, float* output)
|
||||
{
|
||||
float fSlow0 = windowSize;
|
||||
|
|
|
@ -50,9 +50,16 @@ class Looper : public AudioProcessor, public TimeObserver
|
|||
/// Retrieve a clip from the Looper
|
||||
LooperClip* getClip(int scene);
|
||||
|
||||
/// Override beat(). Resyncs loperclips to beat in case playSpeed is funny fraction
|
||||
/// that doesnt add up to 1 (e.g if playSpeed=3/4 then 3/4+3/4+3/4+3/4=3!=1 bringing
|
||||
/// looperClip out of sync)
|
||||
virtual void beat();
|
||||
/// Process nframes of audio
|
||||
void process(unsigned int nframes, Buffers* buffers);
|
||||
|
||||
/// reset timestate implementation: rest all looperClips
|
||||
virtual void resetTimeState();
|
||||
|
||||
private:
|
||||
const int track;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include "controllerupdater.hxx"
|
||||
#include "timemanager.hxx"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
extern Jack* jack;
|
||||
|
@ -187,6 +187,15 @@ void LooperClip::recieveSaveBuffer( AudioBuffer* saveBuffer )
|
|||
}
|
||||
}
|
||||
|
||||
void LooperClip::setPlayHead(float ph)
|
||||
{
|
||||
if(!_recording&&_playing)
|
||||
{
|
||||
_playhead = ph;
|
||||
jack->getControllerUpdater()->setTrackSceneProgress(track, scene, getProgress() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LooperClip::record(int count, float* L, float* R)
|
||||
|
@ -292,7 +301,7 @@ void LooperClip::bar()
|
|||
_buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() );
|
||||
}
|
||||
|
||||
if ( _playhead == _recordhead )
|
||||
if ( _playhead >= _recordhead )
|
||||
{
|
||||
_playhead = 0.f;
|
||||
}
|
||||
|
@ -457,7 +466,7 @@ float LooperClip::getSample(float playSpeed)
|
|||
|
||||
std::vector<float>& v = _buffer->getData();
|
||||
float tmp = v.at(_playhead);
|
||||
_playhead += playSpeed;
|
||||
_playhead +=playSpeed;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
@ -476,6 +485,11 @@ float LooperClip::getProgress()
|
|||
return 0.f;
|
||||
}
|
||||
|
||||
float LooperClip::getPlayhead()
|
||||
{
|
||||
return _playhead;
|
||||
}
|
||||
|
||||
#ifdef BUILD_TESTS
|
||||
void LooperClip::setState( bool load, bool play, bool rec, bool qPlay, bool qStop, bool qRec )
|
||||
{
|
||||
|
|
|
@ -76,6 +76,7 @@ class LooperClip : public Stately
|
|||
/// get buffer details
|
||||
int getBeats();
|
||||
float getProgress();
|
||||
float getPlayhead();
|
||||
//Return the length of the complete buffer
|
||||
long getBufferLenght();
|
||||
//Return the nr of samples holding actual audio. This is less then getBufferLength();
|
||||
|
@ -107,6 +108,9 @@ class LooperClip : public Stately
|
|||
/// used for saving the contents of this buffer to disk
|
||||
void recieveSaveBuffer( AudioBuffer* ab );
|
||||
|
||||
///reset the play head to zero. Does nothing when recording
|
||||
void setPlayHead(float ph);
|
||||
|
||||
#ifdef BUILD_TESTS
|
||||
// used only in test cases
|
||||
void setState( bool load, bool play, bool rec, bool qPlay, bool qStop, bool qRec );
|
||||
|
|
|
@ -30,6 +30,9 @@ class TimeObserver
|
|||
|
||||
virtual void setFpb(int fpb){};
|
||||
|
||||
//Reset any internal set of this object regarding time. Don't reset/delete any buffers!!
|
||||
//This is not to be confused with Stately::reset()
|
||||
virtual void resetTimeState(){};
|
||||
|
||||
virtual void bar(){};
|
||||
|
||||
|
|
|
@ -71,6 +71,12 @@ void TimeManager::setBpm(float bpm)
|
|||
LUPPP_NOTE("%s %f","setBpm()",bpm);
|
||||
#endif
|
||||
setFpb( samplerate / bpm * 60 );
|
||||
barCounter = 0;
|
||||
beatCounter = 0;
|
||||
beatFrameCountdown = -1;
|
||||
for(int i=0;i<observers.size();i++)
|
||||
observers[i]->resetTimeState();
|
||||
|
||||
}
|
||||
|
||||
void TimeManager::setBpmZeroOne(float b)
|
||||
|
|
Loading…
Add table
Reference in a new issue