Fix setting clips individual playspeed

main
Georg Krause 2019-05-20 08:45:18 +02:00
parent 985db72d8d
commit d3dfa921c7
2 changed files with 20 additions and 9 deletions

View File

@ -62,6 +62,10 @@ void LooperClip::init()
_playhead = 0; _playhead = 0;
_recordhead = 0; _recordhead = 0;
_playbackSpeed = 1;
_nextPlaybackSpeed = 1;
_playbackSpeedChange = false;
_barsPlayed = 0; _barsPlayed = 0;
updateController(); updateController();
} }
@ -225,7 +229,9 @@ size_t LooperClip::audioBufferSize()
void LooperClip::setBeats(int beats) void LooperClip::setBeats(int beats)
{ {
if ( _buffer ) { if ( _buffer ) {
_buffer->setBeats( beats ); _nextPlaybackSpeed =
(long double)_buffer->getBeats() / (long double)beats;
_playbackSpeedChange = true;
} }
} }
@ -256,17 +262,19 @@ void LooperClip::bar()
_buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() ); _buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() );
} }
if(_playbackSpeedChange) {
_playbackSpeed = _nextPlaybackSpeed;
_playbackSpeedChange = false;
}
if ( _playing ) { if ( _playing ) {
_barsPlayed++; _barsPlayed++;
} }
// FIXME assumes 4 beats in a bar // FIXME assumes 4 beats in a bar
if ( (_playing && _barsPlayed >= getBeats() / 4) || _playhead >= _recordhead) { if((_playing && _barsPlayed >= (getBeats() / 4 / _playbackSpeed)) ||
_barsPlayed = 0; (_playing && _playhead >= _recordhead)) {
_playhead = 0; resetPlayHead();
#ifdef DEBUG_TIME
cout << "reset: " << _playhead << " - " << _barsPlayed << "\n";
#endif
} }
if ( _queuePlay ) { if ( _queuePlay ) {
@ -444,11 +452,10 @@ bool LooperClip::newBufferInTransit()
void void
LooperClip::getSample(long double playSpeed, float *L, float *R) LooperClip::getSample(long double playSpeed, float *L, float *R)
{ {
playSpeed *= _playbackSpeed;
if(_buffer && (_buffer->getSize() > 0)) { if(_buffer && (_buffer->getSize() > 0)) {
if(_playhead >= _recordhead || if(_playhead >= _recordhead ||
_playhead >= _buffer->getSize() || _playhead < 0) { _playhead >= _buffer->getSize() || _playhead < 0) {
resetPlayHead();
// FIXME is there a better way than just output 0 if frames are missing? // FIXME is there a better way than just output 0 if frames are missing?
*L = 0.f; *L = 0.f;
*R = 0.f; *R = 0.f;

View File

@ -147,6 +147,10 @@ private:
float _recordhead; float _recordhead;
int _recFpb; int _recFpb;
long double _playbackSpeed;
long double _nextPlaybackSpeed;
bool _playbackSpeedChange;
unsigned int _barsPlayed; unsigned int _barsPlayed;
AudioBuffer* _buffer; AudioBuffer* _buffer;