Loopp/src/looperclip.hxx

136 lines
4.0 KiB
C++
Raw Normal View History

2013-12-08 22:44:43 +01:00
/*
* Author: Harry van Haaren 2013
* harryhaaren@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-07-27 19:34:48 +02:00
#ifndef LUPPP_LOOPER_CLIP_H
#define LUPPP_LOOPER_CLIP_H
2013-07-31 02:05:14 +02:00
#include <stdio.h>
#include "state/stately.hxx"
2013-08-06 22:55:57 +02:00
#include "config.hxx"
#include "gridlogic.hxx"
2013-08-15 18:17:16 +02:00
class AudioBuffer;
2013-07-27 19:34:48 +02:00
/** LooperClip
* Represents each clip that a looper can playback. The core of the audio
* samples is stored in AudioBuffer objects which are dynamically resized. The
* base size of a AudioBuffer is 1 second's worth, after which larger buffers
* will be requested.
* The transition between AudioBuffer instances is seamless: when the clip is
* running out, the new one is requested. Upon its arrival the current data is
* copied, and the old buffer is returned for deallocation.
*
* This system allows for arbitrary length recordings, without huge
* pre-allocated buffers while it is still quite simple.
*
* Each clip has its properties like length and bars/beats, so the Looper knows
* to dynamically stretch / process the audio appropriately. Controllers and the
* UI are updated from this data.
*
* This class inherits from SaveAble to save its state.
2013-07-27 19:34:48 +02:00
**/
class LooperClip : public Stately
2013-07-27 19:34:48 +02:00
{
public:
LooperClip(int track, int scene);
void init();
/// loads a sample: eg from disk, unloading current sample if necessary
2013-08-15 18:17:16 +02:00
void load( AudioBuffer* ab );
2013-07-27 19:34:48 +02:00
2013-08-22 01:26:01 +02:00
/// audio functionality
float getSample(float playSpeed);
2013-08-15 18:17:16 +02:00
void record(int count, float* L, float* R);
/// TimeObserver override
void bar();
/// SaveAble overrides
void save();
2013-09-06 00:54:58 +02:00
void reset();
/// analyses current _playing _recording vars, returns the current State
GridLogic::State getState();
bool playing();
bool getLoaded();
bool getQueueStop();
bool getQueuePlay();
bool recording();
/// get buffer details
2013-08-22 01:26:01 +02:00
int getBeats();
float getProgress();
2013-08-22 01:26:01 +02:00
long getBufferLenght();
size_t audioBufferSize();
/// set clip state
void queuePlay(bool=true);
2013-08-22 01:26:01 +02:00
void queueStop();
void queueRecord();
2013-09-06 13:57:45 +02:00
void neutralize(); // removes all play || record states if on
bool somethingQueued(); // returns true if any state is queued
2013-08-22 01:26:01 +02:00
/// set buffer state
void setBeats(int beats);
2013-08-22 01:26:01 +02:00
/// Luppp internal buffer resizing
2013-08-15 18:17:16 +02:00
void newBufferInTransit(bool n);
bool newBufferInTransit();
2013-10-03 22:34:41 +02:00
unsigned long recordSpaceAvailable();
2013-08-22 01:26:01 +02:00
/** used to update the size of the buffer for this looperclip. The current
* data is copied into the new buffer, then the smaller buffer is sent
* for de-allocation.
**/
void setRequestedBuffer( AudioBuffer* ab );
/// used for saving the contents of this buffer to disk
void recieveSaveBuffer( AudioBuffer* ab );
2013-07-27 19:34:48 +02:00
#ifdef BUILD_TESTS
// used only in test cases
void setState( bool load, bool play, bool rec, bool qPlay, bool qStop, bool qRec );
#endif
2013-07-27 19:34:48 +02:00
private:
int track, scene;
2013-08-22 01:26:01 +02:00
/** 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.
**/
2013-07-27 19:34:48 +02:00
bool _loaded;
bool _playing;
bool _recording;
bool _queuePlay;
bool _queueStop;
bool _queueRecord;
bool _newBufferInTransit;
float _playhead;
float _recordhead;
2013-07-27 19:34:48 +02:00
AudioBuffer* _buffer;
};
#endif // LUPPP_LOOPER_CLIP_H