mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-04 16:51:37 -05:00
-Loop loading working, needs some cleaning up
This commit is contained in:
parent
8eec3e1426
commit
1fbf9addb3
6 changed files with 35 additions and 14 deletions
|
@ -16,7 +16,6 @@
|
|||
namespace Event
|
||||
{
|
||||
enum {
|
||||
LOAD_SAMPLE = 0,
|
||||
PLAY_SAMPLE,
|
||||
MASTER_VOL,
|
||||
RECORD,
|
||||
|
@ -100,15 +99,18 @@ class EventLooperLoopLength : public EventBase
|
|||
class EventLooperLoad : public EventBase
|
||||
{
|
||||
public:
|
||||
int type() { return int(LOAD_SAMPLE); }
|
||||
int type() { return int(LOOPER_LOAD); }
|
||||
uint32_t size() { return sizeof(EventLooperLoad); }
|
||||
|
||||
int track;
|
||||
int clip;
|
||||
AudioBuffer* audioBuffer;
|
||||
void* audioBuffer;
|
||||
|
||||
EventLooperLoad(){}
|
||||
EventLooperLoad(int t, int c, AudioBuffer* ab) : track(t), clip(c), audioBuffer(ab) {}
|
||||
EventLooperLoad(int t, int c, void* ab) : track(t), clip(c), audioBuffer(ab)
|
||||
{
|
||||
cout << "ab ptr = " << audioBuffer << endl;
|
||||
}
|
||||
};
|
||||
|
||||
class EventPlaySample : public EventBase
|
||||
|
|
|
@ -41,9 +41,10 @@ void handleDspEvents()
|
|||
case Event::LOOPER_LOAD: {
|
||||
if ( availableRead >= sizeof(EventLooperLoad) ) {
|
||||
EventLooperLoad ev;
|
||||
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperLoad) );
|
||||
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperLoad) );
|
||||
Looper* l = jack->getLooper( ev.track );
|
||||
|
||||
//assert(l);
|
||||
l->setSample( ev.clip, (AudioBuffer*)ev.audioBuffer );
|
||||
} break; }
|
||||
case Event::PLAY_SAMPLE: {
|
||||
if ( availableRead >= sizeof(EventPlaySample) ) {
|
||||
|
|
|
@ -77,9 +77,10 @@ static void gtrack_button_callback(Fl_Widget *w, void *data) {
|
|||
else if ( strcmp( w->label() , "Load" ) == 0 )
|
||||
{
|
||||
AudioBuffer* ab = Worker::loadSample( choose_file() );
|
||||
|
||||
EventLooperLoad e = EventLooperLoad( track, 0 , ab );
|
||||
cout << "writing event ab ptr = " << ab << endl;
|
||||
writeToDspRingbuffer( &e );
|
||||
cout << "writing event done" << endl;
|
||||
}
|
||||
else if ( strcmp( w->label() , "Vol" ) == 0 )
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "looper.hxx"
|
||||
|
||||
#include "jack.hxx"
|
||||
#include "audiobuffer.hxx"
|
||||
#include "eventhandler.hxx"
|
||||
#include "controllerupdater.hxx"
|
||||
|
||||
|
@ -122,15 +123,29 @@ void Looper::updateControllers()
|
|||
}
|
||||
}
|
||||
|
||||
void Looper::setSample(int c, int nB, int bS, float* bP)
|
||||
void Looper::setSample(int c, AudioBuffer* ab)
|
||||
{
|
||||
if ( bS > SAMPLE_SIZE )
|
||||
vector<float>& buf = ab->get();
|
||||
if ( buf.size() > SAMPLE_SIZE )
|
||||
{
|
||||
EventGuiPrint e( "Looper setSample() size > incoming sample" );
|
||||
EventGuiPrint e( "Looper setSample() ERROR size > incoming sample" );
|
||||
writeToGuiRingbuffer( &e );
|
||||
}
|
||||
numBeats = nB;
|
||||
memcpy( &sample[0], bP, bS ); // copy sample data to pre-allocated buffer
|
||||
else
|
||||
{
|
||||
numBeats = ab->getBeats();
|
||||
float* s = &sample[0];
|
||||
float* b = &buf[0];
|
||||
for (int i = 0; i < buf.size(); i++)
|
||||
{
|
||||
*s++ = *b++;
|
||||
}
|
||||
|
||||
endPoint = buf.size();
|
||||
lastWrittenSampleIndex = buf.size();
|
||||
|
||||
//memcpy( &sample[0], &buf[0], buf.size() ); // copy sample data to pre-allocated buffer
|
||||
}
|
||||
}
|
||||
|
||||
void Looper::process(int nframes, Buffers* buffers)
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#define SAMPLE_SIZE 44100*60
|
||||
|
||||
class AudioBuffer;
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Looper : public Observer // for notifications
|
||||
|
@ -26,7 +28,7 @@ class Looper : public Observer // for notifications
|
|||
|
||||
Looper(int t);
|
||||
|
||||
void setSample(int c, int nB, int bS, float* bP);
|
||||
void setSample(int c, AudioBuffer* ab);
|
||||
|
||||
void midi(unsigned char* data);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Worker
|
|||
{
|
||||
SndfileHandle infile( path, SFM_READ );
|
||||
|
||||
|
||||
cout << "Worker: loadSample() TODO: fix memory leak using Shared()" << endl;
|
||||
AudioBuffer* ab = new AudioBuffer();
|
||||
|
||||
std::vector<float> buf( infile.frames(), 0.f );
|
||||
|
|
Loading…
Add table
Reference in a new issue