Make LooperClip a Time Observer and reset playhead after all beats are played back

main
Georg Krause 2019-05-21 13:20:32 +02:00
parent d3dfa921c7
commit 40035dee3c
3 changed files with 42 additions and 40 deletions

View File

@ -247,24 +247,24 @@ void GridLogic::updateState()
void GridLogic::bar() void GridLogic::bar()
{ {
#ifdef DEBUG_CLIP // #ifdef DEBUG_CLIP
EventGuiPrint e( "GridLogic::bar()" ); // EventGuiPrint e( "GridLogic::bar()" );
//writeToGuiRingbuffer( &e ); // //writeToGuiRingbuffer( &e );
#endif // #endif
/// iterate over all clips, if they're set to QUEUED, set to the next state /// iterate over all clips, if they're set to QUEUED, set to the next state
for( int i = 0; i < NTRACKS*NSCENES; i++ ) { // for( int i = 0; i < NTRACKS*NSCENES; i++ ) {
int track = i / NSCENES; // int track = i / NSCENES;
int scene = i - track * NSCENES; // int scene = i - track * NSCENES;
jack->getLooper( track )->getClip(scene)->bar(); // jack->getLooper( track )->getClip(scene)->bar();
#ifdef DEBUG_CLIP // #ifdef DEBUG_CLIP
GridLogic::State s = jack->getLooper( track )->getClip( scene )->getState(); // GridLogic::State s = jack->getLooper( track )->getClip( scene )->getState();
if ( s != STATE_EMPTY ) { // if ( s != STATE_EMPTY ) {
//printf("%i, %i:after bar() state = %s\n", track, scene, StateString[ int(s) ] ); // //printf("%i, %i:after bar() state = %s\n", track, scene, StateString[ int(s) ] );
} // }
#endif // #endif
} // }
} }

View File

@ -35,7 +35,8 @@ extern Jack* jack;
LooperClip::LooperClip(int t, int s) : LooperClip::LooperClip(int t, int s) :
Stately(), Stately(),
track(t), track(t),
scene(s) scene(s),
TimeObserver()
{ {
_buffer = new AudioBuffer(LOOPER_SAMPLES_UPDATE_SIZE); _buffer = new AudioBuffer(LOOPER_SAMPLES_UPDATE_SIZE);
init(); init();
@ -66,7 +67,7 @@ void LooperClip::init()
_nextPlaybackSpeed = 1; _nextPlaybackSpeed = 1;
_playbackSpeedChange = false; _playbackSpeedChange = false;
_barsPlayed = 0; _beatsPlayed = 0;
updateController(); updateController();
} }
@ -170,7 +171,7 @@ void LooperClip::resetPlayHead()
if (!_recording) if (!_recording)
{ {
_playhead = 0; _playhead = 0;
_barsPlayed = 0; _beatsPlayed = 0;
updateController(); updateController();
} }
} }
@ -255,28 +256,11 @@ long LooperClip::getActualAudioLength()
void LooperClip::bar() void LooperClip::bar()
{ {
// first update the buffer, as time has passed
if ( _recording ) {
// FIXME: assumes 4 beats in a bar
_buffer->setBeats( _buffer->getBeats() + 4 );
_buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() );
}
if(_playbackSpeedChange) { if(_playbackSpeedChange) {
_playbackSpeed = _nextPlaybackSpeed; _playbackSpeed = _nextPlaybackSpeed;
_playbackSpeedChange = false; _playbackSpeedChange = false;
} }
if ( _playing ) {
_barsPlayed++;
}
// FIXME assumes 4 beats in a bar
if((_playing && _barsPlayed >= (getBeats() / 4 / _playbackSpeed)) ||
(_playing && _playhead >= _recordhead)) {
resetPlayHead();
}
if ( _queuePlay ) { if ( _queuePlay ) {
setPlaying(); setPlaying();
} }
@ -287,7 +271,23 @@ void LooperClip::bar()
else if ( _queueRecord ) else if ( _queueRecord )
{ {
setRecording(); setRecording();
} }
if(_recording) {
// FIXME: assumes 4 beats in a bar
_buffer->setBeats(_buffer->getBeats() + 4);
_buffer->setAudioFrames(
jack->getTimeManager()->getFpb() * _buffer->getBeats());
}
}
void LooperClip::beat() {
if(_playing) {
_beatsPlayed++;
}
if(_playing && _beatsPlayed >= (getBeats() / _playbackSpeed)) {
resetPlayHead();
}
} }
void LooperClip::resetQueues() void LooperClip::resetQueues()
@ -363,7 +363,7 @@ void LooperClip::setPlaying()
resetQueues(); resetQueues();
_barsPlayed = 0; _beatsPlayed = 0;
_playhead = 0; _playhead = 0;
} else { } else {
resetQueues(); resetQueues();
@ -379,7 +379,7 @@ void LooperClip::setStopped()
resetQueues(); resetQueues();
_barsPlayed = 0; _beatsPlayed = 0;
_playhead = 0; _playhead = 0;
// set "progress" to zero, as we're stopped! // set "progress" to zero, as we're stopped!

View File

@ -44,7 +44,7 @@ class AudioBuffer;
* *
* This class inherits from Stately to save its state. * This class inherits from Stately to save its state.
**/ **/
class LooperClip : public Stately class LooperClip : public Stately, public TimeObserver
{ {
public: public:
LooperClip(int track, int scene); LooperClip(int track, int scene);
@ -62,6 +62,8 @@ public:
/// TimeObserver override /// TimeObserver override
void bar(); void bar();
void
beat();
/// Start process of saving the clip /// Start process of saving the clip
void save(); void save();
@ -151,7 +153,7 @@ private:
long double _nextPlaybackSpeed; long double _nextPlaybackSpeed;
bool _playbackSpeedChange; bool _playbackSpeedChange;
unsigned int _barsPlayed; unsigned int _beatsPlayed;
AudioBuffer* _buffer; AudioBuffer* _buffer;
/// Request new internal Buffer /// Request new internal Buffer