mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-06 01:21:38 -05:00
-Updated Looper and LooperClip to be consistent in ClipState
This commit is contained in:
parent
32674a703a
commit
e5dd3bea0d
7 changed files with 67 additions and 83 deletions
|
@ -16,6 +16,7 @@ class AudioBuffer
|
||||||
AudioBuffer(unsigned long size)
|
AudioBuffer(unsigned long size)
|
||||||
{
|
{
|
||||||
//ID = id;
|
//ID = id;
|
||||||
|
numBeats = 4;
|
||||||
buffer.resize(size);
|
buffer.resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,22 +80,19 @@ void GridLogic::bar()
|
||||||
if ( state[i] == STATE_PLAY_QUEUED )
|
if ( state[i] == STATE_PLAY_QUEUED )
|
||||||
{
|
{
|
||||||
state[i] = STATE_PLAYING;
|
state[i] = STATE_PLAYING;
|
||||||
jack->getLooper( track )->setRecord( scene, false);
|
jack->getLooper( track )->getClip( scene )->play();
|
||||||
jack->getLooper( track )->play( scene, true);
|
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
else if ( state[i] == STATE_STOP_QUEUED )
|
else if ( state[i] == STATE_STOP_QUEUED )
|
||||||
{
|
{
|
||||||
state[i] = STATE_LOADED;
|
state[i] = STATE_LOADED;
|
||||||
jack->getLooper( track )->setRecord( scene, false);
|
jack->getLooper( track )->getClip( scene )->stop();
|
||||||
jack->getLooper( track )->play( scene, false);
|
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
else if ( state[i] == STATE_RECORD_QUEUED )
|
else if ( state[i] == STATE_RECORD_QUEUED )
|
||||||
{
|
{
|
||||||
state[i] = STATE_RECORDING;
|
state[i] = STATE_RECORDING;
|
||||||
jack->getLooper( track )->setRecord( scene, true);
|
jack->getLooper( track )->getClip( scene )->record();
|
||||||
jack->getLooper( track )->play( scene, false);
|
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,33 +48,13 @@ void Logic::looperClipLenght(int t, int s, int l)
|
||||||
|
|
||||||
void Logic::looperUseAsTempo(int t, int s)
|
void Logic::looperUseAsTempo(int t, int s)
|
||||||
{
|
{
|
||||||
size_t l = jack->getLooper( t )->getClip( s )->getBufferLenght();
|
size_t clipBeats = jack->getLooper( t )->getClip( s )->getBeats();
|
||||||
printf("lenght = %zu\n", l );
|
size_t clipFrames = jack->getLooper( t )->getClip( s )->getBufferLenght();
|
||||||
|
|
||||||
int beats = 1;
|
if ( clipBeats > 0 )
|
||||||
|
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
res = l / beats;
|
size_t framesPerBeat = clipFrames / clipBeats;
|
||||||
|
jack->getTimeManager()->setFpb( framesPerBeat );
|
||||||
if ( res - 22050 < jack->getTimeManager()->getFpb() / 2.f )
|
|
||||||
{
|
|
||||||
printf("using beats %i\n", beats);
|
|
||||||
jack->getTimeManager()->setFpb(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
beats = beats + beats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,39 +44,6 @@ Looper::Looper(int t) :
|
||||||
crossfadeSize = 1000;
|
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)
|
LooperClip* Looper::getClip(int scene)
|
||||||
{
|
{
|
||||||
return &clips[scene];
|
return &clips[scene];
|
||||||
|
@ -100,8 +67,6 @@ void Looper::setSample(int scene, AudioBuffer* ab)
|
||||||
|
|
||||||
void Looper::process(unsigned int nframes, Buffers* buffers)
|
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,
|
// process each clip individually: this allows for playback of one clip,
|
||||||
// while another clip records.
|
// while another clip records.
|
||||||
for ( int clip = 0; clip < NSCENES; clip++ )
|
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
|
// copy data from input buffer to recording buffer
|
||||||
float* input = buffers->audio[Buffers::MASTER_INPUT];
|
float* input = buffers->audio[Buffers::MASTER_INPUT];
|
||||||
clips[clip].record( nframes, input, 0 );
|
clips[clip].record( nframes, input, 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( clips[clip].playing() )
|
else if ( clips[clip].playing() )
|
||||||
{
|
{
|
||||||
|
@ -135,6 +99,8 @@ void Looper::process(unsigned int nframes, Buffers* buffers)
|
||||||
playSpeed = float(actualFrames) / targetFrames;
|
playSpeed = float(actualFrames) / targetFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float* out = buffers->audio[Buffers::TRACK_0 + track];
|
||||||
|
|
||||||
for(unsigned int i = 0; i < nframes; i++ )
|
for(unsigned int i = 0; i < nframes; i++ )
|
||||||
{
|
{
|
||||||
out[i] = clips[clip].getSample(playSpeed);
|
out[i] = clips[clip].getSample(playSpeed);
|
||||||
|
|
|
@ -30,13 +30,13 @@ class Looper : public AudioProcessor, public TimeObserver
|
||||||
/// Used for infinite lenght recording
|
/// Used for infinite lenght recording
|
||||||
void setRequestedBuffer(int s, AudioBuffer* ab);
|
void setRequestedBuffer(int s, AudioBuffer* ab);
|
||||||
|
|
||||||
|
/// stores the framesPerBeat from TimeManager. Used to stretch audio
|
||||||
void setFpb(int f) { fpb = f; }
|
void setFpb(int f) { fpb = f; }
|
||||||
|
|
||||||
void play(int scene, bool r);
|
/// Retrieve a clip from the Looper
|
||||||
void setRecord(int scene, bool r);
|
|
||||||
|
|
||||||
LooperClip* getClip(int scene);
|
LooperClip* getClip(int scene);
|
||||||
|
|
||||||
|
/// Process nframes of audio
|
||||||
void process(unsigned int nframes, Buffers* buffers);
|
void process(unsigned int nframes, Buffers* buffers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -111,18 +111,52 @@ long LooperClip::getBufferLenght()
|
||||||
return _recordhead;
|
return _recordhead;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LooperClip::loaded(){return _loaded;}
|
bool LooperClip::loaded()
|
||||||
void LooperClip::playing(bool p){_playing = p; _playhead = 0; }
|
{
|
||||||
bool LooperClip::playing(){return _playing;}
|
return _loaded;
|
||||||
bool LooperClip::recording(){return _recording;}
|
}
|
||||||
void LooperClip::recording(bool r) {_recording = r;}
|
|
||||||
|
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;}
|
void LooperClip::newBufferInTransit(bool n){_newBufferInTransit = n;}
|
||||||
bool LooperClip::newBufferInTransit(){return _newBufferInTransit;}
|
bool LooperClip::newBufferInTransit(){return _newBufferInTransit;}
|
||||||
|
|
||||||
float LooperClip::getSample(float playSpeed)
|
float LooperClip::getSample(float playSpeed)
|
||||||
{
|
{
|
||||||
if ( _buffer )
|
if ( _buffer && _buffer->getData().size() > 0 )
|
||||||
{
|
{
|
||||||
if ( _playhead >= _recordhead ||
|
if ( _playhead >= _recordhead ||
|
||||||
_playhead >= _buffer->getData().size() ||
|
_playhead >= _buffer->getData().size() ||
|
||||||
|
|
|
@ -40,19 +40,25 @@ class LooperClip
|
||||||
|
|
||||||
unsigned long recordSpaceAvailable();
|
unsigned long recordSpaceAvailable();
|
||||||
|
|
||||||
size_t audioBufferSize();
|
|
||||||
|
|
||||||
void setBeats(int beats);
|
void setBeats(int beats);
|
||||||
|
|
||||||
int getBeats();
|
|
||||||
|
|
||||||
long getBufferLenght();
|
|
||||||
|
|
||||||
|
/// get clip state
|
||||||
bool loaded();
|
bool loaded();
|
||||||
void playing(bool p);
|
|
||||||
bool playing();
|
bool playing();
|
||||||
bool recording();
|
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);
|
void newBufferInTransit(bool n);
|
||||||
bool newBufferInTransit();
|
bool newBufferInTransit();
|
||||||
|
@ -63,8 +69,8 @@ class LooperClip
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
bool _recording;
|
|
||||||
bool _playing;
|
bool _playing;
|
||||||
|
bool _recording;
|
||||||
|
|
||||||
bool _newBufferInTransit;
|
bool _newBufferInTransit;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue