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"
|
|
|
|
|
2013-08-05 14:56:38 +02:00
|
|
|
#include "logic.hxx"
|
|
|
|
|
2013-04-20 12:37:36 +02:00
|
|
|
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() )
|
|
|
|
{
|
2013-09-21 00:28:59 +02:00
|
|
|
case Event::QUIT: {
|
|
|
|
if ( availableRead >= sizeof(EventQuit) ) {
|
|
|
|
EventQuit ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventQuit) );
|
|
|
|
jack->quit();
|
|
|
|
} break; }
|
|
|
|
|
|
|
|
// ========= SAVE =====
|
2013-09-06 01:28:11 +02:00
|
|
|
case Event::STATE_SAVE: {
|
|
|
|
if ( availableRead >= sizeof(EventStateSave) ) {
|
|
|
|
EventStateSave ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventStateSave) );
|
|
|
|
jack->getState()->save();
|
2013-09-03 19:05:57 +02:00
|
|
|
} break; }
|
2013-09-06 01:28:11 +02:00
|
|
|
case Event::STATE_RESET: {
|
|
|
|
if ( availableRead >= sizeof(EventStateReset) ) {
|
|
|
|
EventStateReset ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventStateReset) );
|
|
|
|
jack->getState()->reset();
|
2013-09-06 01:10:33 +02:00
|
|
|
} break; }
|
2013-09-03 19:05:57 +02:00
|
|
|
|
2013-09-20 11:29:05 +02:00
|
|
|
// ========= MASTER ===
|
2013-04-20 12:37:36 +02:00
|
|
|
case Event::MASTER_VOL: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterVol) ) {
|
|
|
|
EventMasterVol ev(0);
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMasterVol) );
|
2013-09-20 11:29:05 +02:00
|
|
|
jack->masterVolume( ev.vol );
|
|
|
|
} break; }
|
|
|
|
case Event::MASTER_RETURN: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterReturn) ) {
|
|
|
|
EventMasterReturn ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMasterReturn) );
|
|
|
|
//jack->getLogic()->trackSend( ev.track, ev.send, ev.value );
|
2013-04-20 12:37:36 +02:00
|
|
|
} break; }
|
2013-09-20 14:11:47 +02:00
|
|
|
case Event::MASTER_INPUT_VOL: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterVol) ) {
|
|
|
|
EventMasterVol ev(0);
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMasterVol) );
|
|
|
|
jack->getLogic()->masterInputVol( ev.vol );
|
|
|
|
} break; }
|
2013-09-20 13:40:50 +02:00
|
|
|
case Event::MASTER_INPUT_TO: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterInputTo) ) {
|
|
|
|
EventMasterInputTo ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMasterInputTo) );
|
|
|
|
jack->getLogic()->masterInputTo( ev.place, ev.value );
|
|
|
|
} break; }
|
2013-09-20 14:02:27 +02:00
|
|
|
case Event::MASTER_INPUT_TO_ACTIVE: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterInputToActive) ) {
|
|
|
|
EventMasterInputToActive ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventMasterInputToActive) );
|
|
|
|
jack->getLogic()->masterInputToActive( ev.place, ev.active );
|
|
|
|
} break; }
|
2013-08-06 23:42:04 +02:00
|
|
|
|
|
|
|
// ========= GRID =====
|
|
|
|
case Event::GRID_EVENT: {
|
|
|
|
if ( availableRead >= sizeof(EventGridEvent) ) {
|
|
|
|
EventGridEvent ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventGridEvent) );
|
|
|
|
if ( ev.pressed )
|
|
|
|
jack->getGridLogic()->pressed( ev.track, ev.scene );
|
|
|
|
else
|
|
|
|
jack->getGridLogic()->released( ev.track, ev.scene );
|
|
|
|
} break; }
|
|
|
|
|
2013-08-22 06:48:59 +02:00
|
|
|
case Event::GRID_LAUNCH_SCENE: {
|
|
|
|
EventGridLaunchScene ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventGridLaunchScene) );
|
|
|
|
jack->getGridLogic()->launchScene( ev.scene );
|
|
|
|
break; }
|
|
|
|
|
2013-05-20 00:57:12 +02:00
|
|
|
case Event::LOOPER_LOAD: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperLoad) ) {
|
|
|
|
EventLooperLoad ev;
|
2013-05-20 02:08:10 +02:00
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperLoad) );
|
2013-08-22 01:05:00 +02:00
|
|
|
jack->getGridLogic()->load( ev.track, ev.clip, (AudioBuffer*)ev.audioBuffer );
|
2013-04-20 12:37:36 +02:00
|
|
|
} 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) );
|
2013-09-18 11:09:26 +02:00
|
|
|
jack->getLogic()->metronomeEnable(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-07-27 19:24:04 +02:00
|
|
|
//jack->setLooperState( ev.track, ev.scene, 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) );
|
2013-08-13 18:03:33 +02:00
|
|
|
jack->getLogic()->looperClipLenght( ev.track, ev.scene, ev.beats );
|
2013-05-16 02:38:11 +02:00
|
|
|
} break; }
|
2013-08-13 19:34:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
case Event::LOOPER_LOOP_USE_AS_TEMPO: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperUseAsTempo) ) {
|
|
|
|
EventLooperUseAsTempo ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperUseAsTempo) );
|
|
|
|
jack->getLogic()->looperUseAsTempo( ev.track, ev.scene );
|
|
|
|
} 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-07-28 15:56:34 +02:00
|
|
|
|
2013-07-31 12:34:28 +02:00
|
|
|
// ======== FX ===========
|
2013-09-20 12:23:59 +02:00
|
|
|
|
|
|
|
case Event::FX_REVERB: break;
|
|
|
|
/*{
|
2013-07-31 12:34:28 +02:00
|
|
|
if ( availableRead >= sizeof(EventFxReverb) ) {
|
|
|
|
EventFxReverb ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventFxReverb) );
|
2013-09-11 02:32:58 +02:00
|
|
|
// TODO implement reverb
|
2013-07-31 12:34:28 +02:00
|
|
|
break; }
|
|
|
|
}
|
2013-09-20 12:23:59 +02:00
|
|
|
*/
|
2013-07-28 17:00:17 +02:00
|
|
|
case Event::TRACK_VOLUME: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackVol) ) {
|
|
|
|
EventTrackVol ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventTrackVol) );
|
2013-08-05 14:56:38 +02:00
|
|
|
jack->getLogic()->trackVolume( ev.track, ev.vol );
|
2013-07-28 17:00:17 +02:00
|
|
|
break; }
|
|
|
|
}
|
2013-09-20 13:40:50 +02:00
|
|
|
|
2013-07-28 15:56:34 +02:00
|
|
|
case Event::TRACK_SEND: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackSend) ) {
|
|
|
|
EventTrackSend ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventTrackSend) );
|
2013-08-05 14:56:38 +02:00
|
|
|
jack->getLogic()->trackSend( ev.track, ev.send, ev.value );
|
2013-07-28 15:56:34 +02:00
|
|
|
} break; }
|
2013-09-20 11:29:05 +02:00
|
|
|
|
2013-08-06 23:20:37 +02:00
|
|
|
|
|
|
|
// ========= LUPPP INTERNAL =====
|
|
|
|
case Event::LOOPER_REQUEST_BUFFER: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperClipRequestBuffer) ) {
|
|
|
|
EventLooperClipRequestBuffer ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperClipRequestBuffer) );
|
|
|
|
jack->getLooper( ev.track )->setRequestedBuffer( ev.scene, ev.ab );
|
|
|
|
} break; }
|
|
|
|
|
2013-09-03 20:35:02 +02:00
|
|
|
case Event::REQUEST_SAVE_BUFFER: {
|
|
|
|
if ( availableRead >= sizeof(EventRequestSaveBuffer) ) {
|
|
|
|
EventRequestSaveBuffer ev;
|
|
|
|
jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventRequestSaveBuffer) );
|
|
|
|
cout << "Save buffer sent with t s ab* " << ev.track << " " << ev.scene << " " << ev.ab << endl;
|
|
|
|
jack->getLooper( ev.track )->getClip(ev.scene)->recieveSaveBuffer( ev.ab );
|
|
|
|
} break; }
|
|
|
|
|
2013-04-20 12:37:36 +02:00
|
|
|
default:
|
|
|
|
{
|
2013-07-28 17:00:17 +02:00
|
|
|
cout << "DSP: Unkown message!! Will clog ringbuffer" << endl;
|
2013-04-20 12:37:36 +02:00
|
|
|
// 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
|
|
|
|
|