2013-05-16 14:38:46 +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 "gui.hxx"
|
|
|
|
#include "event.hxx"
|
|
|
|
#include "eventhandler.hxx"
|
|
|
|
|
|
|
|
extern Gui* gui;
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
void handleGuiEvents()
|
|
|
|
{
|
|
|
|
uint availableRead = jack_ringbuffer_read_space( rbToGui );
|
|
|
|
|
|
|
|
while ( availableRead >= sizeof(EventBase) )
|
|
|
|
{
|
|
|
|
jack_ringbuffer_peek( rbToGui, (char*)processGuiMem, sizeof(EventBase) );
|
|
|
|
|
|
|
|
EventBase* e = (EventBase*)processGuiMem;
|
|
|
|
|
|
|
|
// recheck the size against the actual event size
|
|
|
|
if ( availableRead >= e->size() )
|
|
|
|
{
|
|
|
|
//cout << "reading event type " << e->type() << endl;
|
|
|
|
|
|
|
|
switch ( e->type() )
|
|
|
|
{
|
|
|
|
case Event::MASTER_VOL: {
|
|
|
|
if ( availableRead >= sizeof(EventMasterVol) ) {
|
|
|
|
EventMasterVol ev(0);
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventMasterVol) );
|
|
|
|
//jack->masterVolume = ev.vol;
|
|
|
|
} break; }
|
|
|
|
case Event::METRONOME_ACTIVE: {
|
|
|
|
if ( availableRead >= sizeof(EventMetronomeActive) ) {
|
|
|
|
EventMetronomeActive ev(false);
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventMetronomeActive) );
|
|
|
|
//jack->getMetronome()->setActive(ev.active);
|
|
|
|
} break; }
|
|
|
|
case Event::LOOPER_STATE: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperState) ) {
|
|
|
|
EventLooperState ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperState) );
|
2013-07-27 19:24:04 +02:00
|
|
|
//gui->getTrack(ev.track)->getClipSelector()->setState(ev.scene, ev.state);
|
2013-05-16 14:38:46 +02:00
|
|
|
//jack->setLooperState( ev.track, ev.state );
|
|
|
|
} break; }
|
|
|
|
case Event::LOOPER_LOOP_LENGTH: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperLoopLength) ) {
|
2013-07-27 19:24:04 +02:00
|
|
|
//EventLooperLoopLength ev;
|
|
|
|
//jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperLoopLength) );
|
2013-05-16 14:38:46 +02:00
|
|
|
//jack->setLooperLoopLength( ev.track, ev.scale );
|
|
|
|
} break; }
|
|
|
|
case Event::LOOPER_PROGRESS: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperProgress) ) {
|
|
|
|
EventLooperProgress ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperProgress) );
|
2013-07-31 03:27:27 +02:00
|
|
|
//printf("progress on %i, %f\n", ev.track, ev.progress);
|
2013-07-30 17:15:02 +02:00
|
|
|
gui->getTrack(ev.track)->radial.value(ev.progress);
|
2013-05-16 14:38:46 +02:00
|
|
|
//jack->setLooperLoopLength( ev.track, ev.scale );
|
|
|
|
} break; }
|
2013-07-27 22:59:20 +02:00
|
|
|
|
2013-07-26 02:27:19 +02:00
|
|
|
case Event::TRACK_SIGNAL_LEVEL: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackSignalLevel) ) {
|
|
|
|
EventTrackSignalLevel ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTrackSignalLevel) );
|
2013-07-28 15:20:54 +02:00
|
|
|
if ( ev.track < 0 ) {
|
|
|
|
gui->getMasterTrack()->getVolume()->amplitude( ev.left, ev.right );
|
|
|
|
} else {
|
|
|
|
gui->getTrack(ev.track)->getVolume()->amplitude( ev.left, ev.right ); }
|
2013-07-26 02:27:19 +02:00
|
|
|
} break; }
|
2013-07-27 22:59:20 +02:00
|
|
|
case Event::TRACK_VOLUME: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackVol) ) {
|
|
|
|
EventTrackVol ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTrackVol) );
|
2013-07-28 15:20:54 +02:00
|
|
|
if ( ev.track < 0 )
|
|
|
|
{
|
|
|
|
gui->getMasterTrack()->getVolume()->value( ev.vol );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gui->getTrack(ev.track)->getVolume()->value( ev.vol );
|
2013-07-27 22:59:20 +02:00
|
|
|
} break; }
|
|
|
|
|
2013-05-16 16:17:49 +02:00
|
|
|
case Event::GUI_PRINT: {
|
|
|
|
if ( availableRead >= sizeof(EventGuiPrint) ) {
|
|
|
|
EventGuiPrint ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventGuiPrint) );
|
|
|
|
cout << "DSP: " << ev.getMessage() << endl;
|
|
|
|
} break; }
|
2013-07-27 17:37:54 +02:00
|
|
|
case Event::TIME_BAR_BEAT: {
|
|
|
|
if ( availableRead >= sizeof(EventTimeBarBeat) ) {
|
|
|
|
EventTimeBarBeat ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTimeBarBeat) );
|
|
|
|
gui->getMasterTrack()->setBarBeat( ev.bar, ev.beat);
|
|
|
|
} break; }
|
2013-05-16 14:38:46 +02:00
|
|
|
default:
|
|
|
|
{
|
2013-07-28 17:00:17 +02:00
|
|
|
cout << "GUI: Unkown message!! Will clog ringbuffer" << endl;
|
2013-05-16 14:38:46 +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( rbToGui );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeToGuiRingbuffer(EventBase* e)
|
|
|
|
{
|
|
|
|
if ( jack_ringbuffer_write_space(rbToGui) >= e->size() )
|
|
|
|
{
|
|
|
|
jack_ringbuffer_write( rbToGui, (const char*)e, e->size() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "->GUI ringbuffer full!" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LUPPP_EVENT_HANDLER_DSP_H
|
|
|
|
|