2013-04-20 12:37:36 +02:00
|
|
|
|
|
|
|
#ifndef LUPPP_EVENT_HANDLER_DSP_H
|
|
|
|
#define LUPPP_EVENT_HANDLER_DSP_H
|
|
|
|
|
|
|
|
|
|
|
|
// Library
|
|
|
|
#include <cstring>
|
|
|
|
#include <iostream>
|
|
|
|
#include <jack/ringbuffer.h>
|
|
|
|
|
|
|
|
// Internal
|
|
|
|
#include "jack.hxx"
|
|
|
|
#include "event.hxx"
|
|
|
|
#include "eventhandler.hxx"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
extern Jack* jack;
|
|
|
|
|
2013-04-20 12:54:16 +02:00
|
|
|
void handleDspEvents()
|
2013-04-20 12:37:36 +02:00
|
|
|
{
|
|
|
|
uint availableRead = jack_ringbuffer_read_space( rbToDsp );
|
|
|
|
|
|
|
|
while ( availableRead >= sizeof(EventBase) )
|
|
|
|
{
|
|
|
|
jack_ringbuffer_peek( rbToDsp, (char*)processDspMem, sizeof(EventBase) );
|
|
|
|
|
|
|
|
EventBase* e = (EventBase*)processDspMem;
|
|
|
|
|
|
|
|
// recheck the size against the actual event size
|
|
|
|
if ( availableRead >= e->size() )
|
|
|
|
{
|
|
|
|
switch ( e->type() )
|
|
|
|
{
|
|
|
|
case Event::MASTER_VOL: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterVol) ) {
|
|
|
|
EventMasterVol ev(0);
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMasterVol) );
|
|
|
|
//jack->masterVolume = ev.vol;
|
|
|
|
} break; }
|
2013-05-20 00:57:12 +02:00
|
|
|
case Event::LOOPER_LOAD: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperLoad) ) {
|
|
|
|
EventLooperLoad ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperLoad) );
|
|
|
|
Looper* l = jack->getLooper( ev.track );
|
|
|
|
|
2013-04-20 12:37:36 +02:00
|
|
|
} break; }
|
|
|
|
case Event::PLAY_SAMPLE: {
|
|
|
|
if ( availableRead >= sizeof(EventPlaySample) ) {
|
|
|
|
EventPlaySample ev(0,0);
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventPlaySample) );
|
|
|
|
//jack->setPlayBuffer( ev.track, ev.bufferID );
|
|
|
|
} break; }
|
2013-05-16 00:27:31 +02:00
|
|
|
case Event::METRONOME_ACTIVE: {
|
|
|
|
if ( availableRead >= sizeof(EventMetronomeActive) ) {
|
|
|
|
EventMetronomeActive ev(false);
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMetronomeActive) );
|
|
|
|
jack->getMetronome()->setActive(ev.active);
|
2013-04-20 12:37:36 +02:00
|
|
|
} break; }
|
2013-05-13 23:04:12 +02:00
|
|
|
case Event::LOOPER_STATE: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperState) ) {
|
|
|
|
EventLooperState ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperState) );
|
2013-05-15 03:17:08 +02:00
|
|
|
jack->setLooperState( ev.track, ev.state );
|
2013-05-13 23:04:12 +02:00
|
|
|
} break; }
|
2013-05-16 02:38:11 +02:00
|
|
|
case Event::LOOPER_LOOP_LENGTH: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperLoopLength) ) {
|
|
|
|
EventLooperLoopLength ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperLoopLength) );
|
|
|
|
jack->setLooperLoopLength( ev.track, ev.scale );
|
|
|
|
} break; }
|
2013-05-16 18:16:18 +02:00
|
|
|
case Event::TIME_BPM: {
|
|
|
|
if ( availableRead >= sizeof(EventTimeBPM) ) {
|
|
|
|
EventTimeBPM ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventTimeBPM) );
|
|
|
|
jack->getTimeManager()->setBpm(ev.bpm);
|
|
|
|
} break; }
|
2013-05-16 18:45:46 +02:00
|
|
|
case Event::TIME_TEMPO_TAP: {
|
|
|
|
if ( availableRead >= sizeof(EventTimeTempoTap) ) {
|
|
|
|
EventTimeTempoTap ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventTimeTempoTap) );
|
|
|
|
jack->getTimeManager()->tap();
|
|
|
|
} break; }
|
2013-04-20 12:37:36 +02:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
// just do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// next call will get the half-written event
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update available read, and loop over events
|
|
|
|
availableRead = jack_ringbuffer_read_space( rbToDsp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeToDspRingbuffer(EventBase* e)
|
|
|
|
{
|
|
|
|
if ( jack_ringbuffer_write_space(rbToDsp) >= e->size() )
|
|
|
|
{
|
|
|
|
jack_ringbuffer_write( rbToDsp, (const char*)e, e->size() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "->DSP ringbuffer full!" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LUPPP_EVENT_HANDLER_DSP_H
|
|
|
|
|