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

View File

@ -35,7 +35,8 @@ extern Jack* jack;
LooperClip::LooperClip(int t, int s) :
Stately(),
track(t),
scene(s)
scene(s),
TimeObserver()
{
_buffer = new AudioBuffer(LOOPER_SAMPLES_UPDATE_SIZE);
init();
@ -66,7 +67,7 @@ void LooperClip::init()
_nextPlaybackSpeed = 1;
_playbackSpeedChange = false;
_barsPlayed = 0;
_beatsPlayed = 0;
updateController();
}
@ -170,7 +171,7 @@ void LooperClip::resetPlayHead()
if (!_recording)
{
_playhead = 0;
_barsPlayed = 0;
_beatsPlayed = 0;
updateController();
}
}
@ -255,28 +256,11 @@ long LooperClip::getActualAudioLength()
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) {
_playbackSpeed = _nextPlaybackSpeed;
_playbackSpeedChange = false;
}
if ( _playing ) {
_barsPlayed++;
}
// FIXME assumes 4 beats in a bar
if((_playing && _barsPlayed >= (getBeats() / 4 / _playbackSpeed)) ||
(_playing && _playhead >= _recordhead)) {
resetPlayHead();
}
if ( _queuePlay ) {
setPlaying();
}
@ -287,7 +271,23 @@ void LooperClip::bar()
else if ( _queueRecord )
{
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()
@ -363,7 +363,7 @@ void LooperClip::setPlaying()
resetQueues();
_barsPlayed = 0;
_beatsPlayed = 0;
_playhead = 0;
} else {
resetQueues();
@ -379,7 +379,7 @@ void LooperClip::setStopped()
resetQueues();
_barsPlayed = 0;
_beatsPlayed = 0;
_playhead = 0;
// 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.
**/
class LooperClip : public Stately
class LooperClip : public Stately, public TimeObserver
{
public:
LooperClip(int track, int scene);
@ -62,6 +62,8 @@ public:
/// TimeObserver override
void bar();
void
beat();
/// Start process of saving the clip
void save();
@ -151,7 +153,7 @@ private:
long double _nextPlaybackSpeed;
bool _playbackSpeedChange;
unsigned int _barsPlayed;
unsigned int _beatsPlayed;
AudioBuffer* _buffer;
/// Request new internal Buffer