From 1fbf9addb3f58a88468f3ae50da7035980fbeb6f Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Mon, 20 May 2013 01:08:10 +0100 Subject: [PATCH] -Loop loading working, needs some cleaning up --- src/event.hxx | 10 ++++++---- src/eventhandlerdsp.cxx | 5 +++-- src/gtrack.hxx | 3 ++- src/looper.cxx | 25 ++++++++++++++++++++----- src/looper.hxx | 4 +++- src/worker.hxx | 2 +- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/event.hxx b/src/event.hxx index f8a677a..02ff07d 100644 --- a/src/event.hxx +++ b/src/event.hxx @@ -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 diff --git a/src/eventhandlerdsp.cxx b/src/eventhandlerdsp.cxx index 58975f6..a645633 100644 --- a/src/eventhandlerdsp.cxx +++ b/src/eventhandlerdsp.cxx @@ -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) ) { diff --git a/src/gtrack.hxx b/src/gtrack.hxx index bac61a8..2986ba7 100644 --- a/src/gtrack.hxx +++ b/src/gtrack.hxx @@ -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 ) { diff --git a/src/looper.cxx b/src/looper.cxx index 606bd51..1c24547 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -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& 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) diff --git a/src/looper.hxx b/src/looper.hxx index 6feae56..52c2c76 100644 --- a/src/looper.hxx +++ b/src/looper.hxx @@ -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); diff --git a/src/worker.hxx b/src/worker.hxx index e3dcb55..87549cc 100644 --- a/src/worker.hxx +++ b/src/worker.hxx @@ -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 buf( infile.frames(), 0.f );