mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
-Removed State member variable from GridLogic, LooperClip should be analysed for data
This commit is contained in:
parent
96b78f0c5a
commit
8f71d7411b
6 changed files with 96 additions and 69 deletions
|
@ -11,7 +11,7 @@ const char* StateString[8] = {
|
|||
"empty",
|
||||
"playing",
|
||||
"play queued",
|
||||
"loaded",
|
||||
"stopped",
|
||||
"stop queued",
|
||||
"recording",
|
||||
"record queued"
|
||||
|
@ -21,7 +21,7 @@ GridLogic::GridLogic()
|
|||
{
|
||||
for( int i = 0; i < NTRACKS*NSCENES; i++ )
|
||||
{
|
||||
state[i] = STATE_EMPTY;
|
||||
//state[i] = STATE_EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ GridLogic::GridLogic()
|
|||
void GridLogic::pressed( int track, int scene )
|
||||
{
|
||||
//printf("before press state = %s\n", StateString[ int(state[track*NTRACKS + scene]) ] );
|
||||
|
||||
/*
|
||||
if ( state[track*NSCENES + scene] == STATE_EMPTY )
|
||||
state[track*NSCENES + scene] = STATE_RECORD_QUEUED;
|
||||
|
||||
|
@ -45,18 +45,19 @@ void GridLogic::pressed( int track, int scene )
|
|||
//printf("after press state = %s\n", StateString[ int(state[track*NSCENES + scene]) ] );
|
||||
|
||||
jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene]);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void GridLogic::released( int track, int scene )
|
||||
{
|
||||
jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene] );
|
||||
//jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene] );
|
||||
}
|
||||
|
||||
void GridLogic::load(int track, int scene, AudioBuffer* ab)
|
||||
{
|
||||
jack->getLooper( track )->getClip( scene )->load( ab );
|
||||
jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene] );
|
||||
//jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene] );
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,30 +77,6 @@ void GridLogic::bar()
|
|||
{
|
||||
int track = i / NSCENES;
|
||||
int scene = i - track * NSCENES;
|
||||
bool change = false;
|
||||
|
||||
if ( state[i] == STATE_PLAY_QUEUED )
|
||||
{
|
||||
jack->getLooper( track )->getClip( scene )->queuePlay();
|
||||
change = true;
|
||||
}
|
||||
else if ( state[i] == STATE_STOP_QUEUED )
|
||||
{
|
||||
state[i] = STATE_STOPPED;
|
||||
jack->getLooper( track )->getClip( scene )->queueStop();
|
||||
change = true;
|
||||
}
|
||||
else if ( state[i] == STATE_RECORD_QUEUED )
|
||||
{
|
||||
state[i] = STATE_RECORDING;
|
||||
jack->getLooper( track )->getClip( scene )->queueRecord();
|
||||
change = true;
|
||||
}
|
||||
|
||||
if ( change )
|
||||
{
|
||||
jack->getControllerUpdater()->setSceneState(track, scene, state[track*NSCENES + scene] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,10 +56,7 @@ class GridLogic : public TimeObserver
|
|||
void bar();
|
||||
void beat();
|
||||
|
||||
private:
|
||||
/// contains the current state of each grid square
|
||||
State state[NTRACKS*NSCENES];
|
||||
|
||||
/// for debug purposes: use static_cast<int>(GridLogic::State) to access
|
||||
static const char* StateString[8];
|
||||
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@ Looper::Looper(int t) :
|
|||
|
||||
for(int i = 0; i < 10; i++ )
|
||||
{
|
||||
clips[i] = LooperClip();
|
||||
clips[i] = new LooperClip(track, i);
|
||||
}
|
||||
|
||||
fpb = 22050;
|
||||
|
@ -46,23 +46,12 @@ Looper::Looper(int t) :
|
|||
|
||||
LooperClip* Looper::getClip(int scene)
|
||||
{
|
||||
return &clips[scene];
|
||||
return clips[scene];
|
||||
}
|
||||
|
||||
void Looper::setRequestedBuffer(int s, AudioBuffer* ab)
|
||||
{
|
||||
clips[s].setRequestedBuffer( ab );
|
||||
}
|
||||
|
||||
|
||||
void Looper::setSample(int scene, AudioBuffer* ab)
|
||||
{
|
||||
clips[scene].load( ab );
|
||||
|
||||
char buffer [50];
|
||||
sprintf (buffer, "Looper setSample() writing to scene %i",scene);
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
clips[s]->setRequestedBuffer( ab );
|
||||
}
|
||||
|
||||
void Looper::process(unsigned int nframes, Buffers* buffers)
|
||||
|
@ -73,25 +62,25 @@ void Looper::process(unsigned int nframes, Buffers* buffers)
|
|||
{
|
||||
// handle state of clip, and do what needs doing:
|
||||
// record into buffer, play from buffer, etc
|
||||
if ( clips[clip].recording() )
|
||||
if ( clips[clip]->recording() )
|
||||
{
|
||||
if ( clips[clip].recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST &&
|
||||
!clips[clip].newBufferInTransit() )
|
||||
if ( clips[clip]->recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST &&
|
||||
!clips[clip]->newBufferInTransit() )
|
||||
{
|
||||
EventLooperClipRequestBuffer e( track, clip, clips[clip].audioBufferSize() + 44100 * 4);
|
||||
EventLooperClipRequestBuffer e( track, clip, clips[clip]->audioBufferSize() + 44100 * 4);
|
||||
writeToGuiRingbuffer( &e );
|
||||
clips[clip].newBufferInTransit(true);
|
||||
clips[clip]->newBufferInTransit(true);
|
||||
}
|
||||
|
||||
// copy data from input buffer to recording buffer
|
||||
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() )
|
||||
{
|
||||
// copy data into tmpBuffer, then pitch-stretch into track buffer
|
||||
long targetFrames = clips[clip].getBeats() * fpb;
|
||||
long actualFrames = clips[clip].getBufferLenght();
|
||||
long targetFrames = clips[clip]->getBeats() * fpb;
|
||||
long actualFrames = clips[clip]->getBufferLenght();
|
||||
float playSpeed = 1.0;
|
||||
|
||||
if ( targetFrames != 0 && actualFrames != 0 )
|
||||
|
@ -103,7 +92,7 @@ void Looper::process(unsigned int nframes, Buffers* buffers)
|
|||
|
||||
for(unsigned int i = 0; i < nframes; i++ )
|
||||
{
|
||||
out[i] = clips[clip].getSample(playSpeed);
|
||||
out[i] = clips[clip]->getSample(playSpeed);
|
||||
}
|
||||
|
||||
//printf("Looper %i playing(), speed = %f\n", track, playSpeed );
|
||||
|
@ -111,7 +100,7 @@ void Looper::process(unsigned int nframes, Buffers* buffers)
|
|||
if ( uiUpdateCounter > uiUpdateConstant )
|
||||
{
|
||||
|
||||
jack->getControllerUpdater()->setTrackSceneProgress(track, clip, clips[clip].getProgress() );
|
||||
jack->getControllerUpdater()->setTrackSceneProgress(track, clip, clips[clip]->getProgress() );
|
||||
uiUpdateCounter = 0;
|
||||
}
|
||||
uiUpdateCounter += nframes;
|
||||
|
|
|
@ -23,9 +23,6 @@ class Looper : public AudioProcessor, public TimeObserver
|
|||
public:
|
||||
Looper(int t);
|
||||
|
||||
/// *sets* the sample
|
||||
void setSample(int c, AudioBuffer* ab);
|
||||
|
||||
/// *sets* the new audiobuffer, but the content gets copied to the new buffer.
|
||||
/// Used for infinite lenght recording
|
||||
void setRequestedBuffer(int s, AudioBuffer* ab);
|
||||
|
@ -49,7 +46,7 @@ class Looper : public AudioProcessor, public TimeObserver
|
|||
int fpb;
|
||||
|
||||
//vector<float> tmpRecordBuffer;
|
||||
LooperClip clips[10];
|
||||
LooperClip* clips[10];
|
||||
|
||||
// Pitch Shifting
|
||||
void pitchShift(int count, float* input, float* output);
|
||||
|
|
|
@ -3,15 +3,24 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "config.hxx"
|
||||
#include "jack.hxx"
|
||||
#include "event.hxx"
|
||||
#include "eventhandler.hxx"
|
||||
#include "audiobuffer.hxx"
|
||||
|
||||
LooperClip::LooperClip()
|
||||
extern Jack* jack;
|
||||
|
||||
LooperClip::LooperClip(int t, int s) :
|
||||
track(t),
|
||||
scene(s)
|
||||
{
|
||||
_loaded = false;
|
||||
_playing = false;
|
||||
_recording = false;
|
||||
_loaded = false;
|
||||
_playing = false;
|
||||
_recording = false;
|
||||
|
||||
_queuePlay = false;
|
||||
_queueStop = false;
|
||||
_queueRecord= false;
|
||||
|
||||
_buffer = 0; //new AudioBuffer(44100);
|
||||
_newBufferInTransit = false;
|
||||
|
@ -37,6 +46,12 @@ void LooperClip::load( AudioBuffer* ab )
|
|||
|
||||
// set the endpoint to the buffer's size
|
||||
_recordhead = _buffer->getData().size();
|
||||
|
||||
char buffer [50];
|
||||
sprintf (buffer, "LooperClip::load() track %i, scene %i",track, scene);
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
}
|
||||
|
||||
void LooperClip::setRequestedBuffer( AudioBuffer* ab )
|
||||
|
@ -111,11 +126,54 @@ long LooperClip::getBufferLenght()
|
|||
return _recordhead;
|
||||
}
|
||||
|
||||
void LooperClip::bar()
|
||||
{
|
||||
bool change = false;
|
||||
GridLogic::State s = GridLogic::STATE_EMPTY;
|
||||
|
||||
if ( _queuePlay && _loaded )
|
||||
{
|
||||
_playing = true;
|
||||
s = GridLogic::STATE_PLAYING;
|
||||
_recording = false;
|
||||
_queuePlay = false;
|
||||
change = true;
|
||||
|
||||
_playhead = 0;
|
||||
}
|
||||
else if ( _queueStop )
|
||||
{
|
||||
_playing = false;
|
||||
s = GridLogic::STATE_STOPPED;
|
||||
_recording = false;
|
||||
_queueStop = false;
|
||||
change = true;
|
||||
}
|
||||
else if ( _queueRecord )
|
||||
{
|
||||
_recording = true;
|
||||
s = GridLogic::STATE_RECORDING;
|
||||
_playing = false;
|
||||
_queueRecord = false;
|
||||
change = true;
|
||||
|
||||
_recordhead = 0;
|
||||
}
|
||||
|
||||
if ( change )
|
||||
{
|
||||
jack->getControllerUpdater()->setSceneState(track, scene, s );
|
||||
}
|
||||
|
||||
_playhead = 0;
|
||||
}
|
||||
|
||||
|
||||
void LooperClip::queuePlay()
|
||||
{
|
||||
_playing = true;
|
||||
_playhead = 0;
|
||||
_queuePlay = true;
|
||||
_queueStop = false;
|
||||
_queueRecord = false;
|
||||
}
|
||||
void LooperClip::queueStop()
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ class AudioBuffer;
|
|||
class LooperClip
|
||||
{
|
||||
public:
|
||||
LooperClip();
|
||||
LooperClip(int track, int scene);
|
||||
|
||||
/// loads a sample: eg from disk, unloading current sample if necessary
|
||||
void load( AudioBuffer* ab );
|
||||
|
@ -35,6 +35,9 @@ class LooperClip
|
|||
float getSample(float playSpeed);
|
||||
void record(int count, float* L, float* R);
|
||||
|
||||
/// TimeObserver overrides
|
||||
void bar();
|
||||
|
||||
/// get clip state
|
||||
bool loaded();
|
||||
bool playing();
|
||||
|
@ -66,6 +69,8 @@ class LooperClip
|
|||
void setRequestedBuffer( AudioBuffer* ab );
|
||||
|
||||
private:
|
||||
int track, scene;
|
||||
|
||||
/** Luppp needs more than the current state of the clip to accuratly handle
|
||||
* it. The current state of the grid is kept up-to-date by GridLogic
|
||||
* abstracting detail away, sending GridLogic::State to Controllers.
|
||||
|
@ -74,6 +79,10 @@ class LooperClip
|
|||
bool _playing;
|
||||
bool _recording;
|
||||
|
||||
bool _queuePlay;
|
||||
bool _queueStop;
|
||||
bool _queueRecord;
|
||||
|
||||
bool _newBufferInTransit;
|
||||
|
||||
float _playhead;
|
||||
|
|
Loading…
Add table
Reference in a new issue