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"
|
2013-08-06 23:10:27 +02:00
|
|
|
#include "audiobuffer.hxx"
|
2013-05-16 14:38:46 +02:00
|
|
|
#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() )
|
|
|
|
{
|
2013-09-21 01:52:29 +02:00
|
|
|
case Event::QUIT: {
|
|
|
|
if ( availableRead >= sizeof(EventQuit) ) {
|
|
|
|
EventQuit ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventQuit) );
|
|
|
|
LUPPP_NOTE("%s","GUI QUIT");
|
2013-09-23 11:53:58 +02:00
|
|
|
gui->quit();
|
|
|
|
} break; }
|
|
|
|
|
|
|
|
case Event::SAMPLERATE: {
|
|
|
|
if ( availableRead >= sizeof(EventSamplerate) ) {
|
|
|
|
EventSamplerate ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventSamplerate) );
|
|
|
|
gui->samplerate = ev.samplerate;
|
2013-10-03 03:10:35 +02:00
|
|
|
//LUPPP_NOTE("%s %i","Gui Samplerate: ", gui->samplerate);
|
2013-09-21 01:52:29 +02:00
|
|
|
} break; }
|
|
|
|
|
2013-05-16 14:38:46 +02:00
|
|
|
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) );
|
2013-10-09 01:15:31 +02:00
|
|
|
gui->getMasterTrack()->metronomeEnable(ev.active);
|
2013-05-16 14:38:46 +02:00
|
|
|
} 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-08-22 00:51:26 +02:00
|
|
|
|
|
|
|
// only update if significant change
|
|
|
|
//if ( ev.progress - gui->getTrack(ev.track)->radial.value() >= 0.05 ||
|
|
|
|
// ev.progress > 0.9 )
|
|
|
|
gui->getTrack(ev.track)->radial.value(ev.progress);
|
|
|
|
|
2013-05-16 14:38:46 +02:00
|
|
|
} break; }
|
2013-07-27 22:59:20 +02:00
|
|
|
|
2013-10-11 22:33:20 +02:00
|
|
|
|
|
|
|
// FIXME: reset signal level to 0
|
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-09-19 11:44:12 +02:00
|
|
|
if ( ev.track == -2 ) {
|
2013-09-10 22:44:47 +02:00
|
|
|
gui->getMasterTrack()->getInputVolume()->amplitude( ev.left, ev.right );
|
|
|
|
} else if ( ev.track == -1 ) {
|
2013-07-28 15:20:54 +02:00
|
|
|
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 )
|
|
|
|
{
|
2013-08-27 01:14:16 +02:00
|
|
|
gui->getMasterTrack()->getVolume()->fader( ev.vol );
|
2013-07-28 15:20:54 +02:00
|
|
|
}
|
|
|
|
else
|
2013-08-27 01:14:16 +02:00
|
|
|
gui->getTrack(ev.track)->getVolume()->fader( ev.vol );
|
2013-07-27 22:59:20 +02:00
|
|
|
} break; }
|
2013-09-23 13:51:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
case Event::TRACK_RECORD_ARM: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackRecordArm) ) {
|
|
|
|
EventTrackRecordArm ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTrackRecordArm) );
|
2013-10-03 02:50:16 +02:00
|
|
|
gui->getTrack(ev.track)->setRecordActive( ev.recordArm );
|
2013-09-23 13:51:41 +02:00
|
|
|
break; }
|
|
|
|
}
|
2013-09-05 23:35:48 +02:00
|
|
|
|
|
|
|
case Event::TIME_BPM: {
|
|
|
|
if ( availableRead >= sizeof(EventTimeBPM) ) {
|
|
|
|
EventTimeBPM ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTimeBPM) );
|
2013-09-11 00:09:45 +02:00
|
|
|
gui->getMasterTrack()->setBpm( ev.bpm );
|
2013-09-05 23:35:48 +02:00
|
|
|
} break; }
|
2013-08-07 00:19:56 +02:00
|
|
|
|
|
|
|
|
2013-09-06 01:28:11 +02:00
|
|
|
case Event::STATE_SAVE_BUFFER: {
|
|
|
|
if ( availableRead >= sizeof(EventStateSaveBuffer) ) {
|
|
|
|
EventStateSaveBuffer ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventStateSaveBuffer) );
|
2013-09-03 21:06:11 +02:00
|
|
|
#ifdef DEBUG_SAVE
|
2013-09-03 20:35:02 +02:00
|
|
|
cout << "EventSaveBuffer: " << ev.track << " " << ev.scene << " " << ev.ab->getID() << endl;
|
2013-09-03 21:06:11 +02:00
|
|
|
#endif
|
|
|
|
gui->getDiskWriter()->writeAudioBuffer( ev.track, ev.scene, ev.ab );
|
2013-09-17 13:07:25 +02:00
|
|
|
// de allocate the AudioBuffer
|
|
|
|
delete ev.ab;
|
2013-09-03 21:06:11 +02:00
|
|
|
} break; }
|
|
|
|
|
2013-09-06 01:28:11 +02:00
|
|
|
case Event::STATE_SAVE_FINISH: {
|
|
|
|
if ( availableRead >= sizeof(EventStateSaveFinish) ) {
|
|
|
|
EventStateSaveFinish ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventStateSaveFinish) );
|
2013-09-03 21:06:11 +02:00
|
|
|
#ifdef DEBUG_SAVE
|
|
|
|
cout << "EventSaveFinish!" << endl;
|
|
|
|
#endif
|
2013-09-18 10:34:49 +02:00
|
|
|
gui->getDiskWriter()->writeSession();
|
2013-09-03 20:35:02 +02:00
|
|
|
} break; }
|
|
|
|
|
|
|
|
|
2013-08-07 00:19:56 +02:00
|
|
|
case Event::GRID_STATE: {
|
|
|
|
if ( availableRead >= sizeof(EventGridState) ) {
|
|
|
|
EventGridState ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventGridState) );
|
|
|
|
gui->getTrack(ev.track)->getClipSelector()->setState( ev.scene, ev.state );
|
2013-08-22 06:10:30 +02:00
|
|
|
if ( ev.state == GridLogic::STATE_RECORDING )
|
|
|
|
gui->getTrack(ev.track)->getRadialStatus()->recording( true );
|
|
|
|
else
|
|
|
|
gui->getTrack(ev.track)->getRadialStatus()->recording( false );
|
2013-08-07 00:19:56 +02:00
|
|
|
} break; }
|
2013-08-27 19:05:21 +02:00
|
|
|
case Event::GRID_LAUNCH_SCENE: {
|
|
|
|
if ( availableRead >= sizeof(EventGridLaunchScene) ) {
|
|
|
|
EventGridLaunchScene ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventGridLaunchScene) );
|
|
|
|
for(int i = 0; i < NSCENES; i++)
|
|
|
|
gui->getMasterTrack()->getClipSelector()->setState( i, GridLogic::STATE_EMPTY );
|
|
|
|
gui->getMasterTrack()->getClipSelector()->setState( ev.scene, GridLogic::STATE_PLAYING );
|
|
|
|
} break; }
|
2013-08-07 00:19:56 +02:00
|
|
|
|
2013-08-04 19:49:27 +02:00
|
|
|
case Event::TRACK_SEND: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackSend) ) {
|
|
|
|
EventTrackSend ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTrackSend) );
|
2013-10-03 02:18:06 +02:00
|
|
|
if ( ev.send == SEND_POSTFADER )
|
2013-08-05 16:27:29 +02:00
|
|
|
if ( ev.track < NTRACKS )
|
|
|
|
{
|
2013-10-03 02:50:16 +02:00
|
|
|
gui->getTrack(ev.track)->setSend(ev.value );
|
2013-08-05 16:27:29 +02:00
|
|
|
}
|
2013-10-03 02:18:06 +02:00
|
|
|
if ( ev.send == SEND_XSIDE )
|
2013-09-24 19:30:29 +02:00
|
|
|
if ( ev.track < NTRACKS )
|
2013-08-05 16:27:29 +02:00
|
|
|
{
|
2013-10-03 02:50:16 +02:00
|
|
|
gui->getTrack(ev.track)->setXSide( ev.value );
|
2013-08-05 16:27:29 +02:00
|
|
|
}
|
2013-08-04 19:49:27 +02:00
|
|
|
} break; }
|
|
|
|
|
2013-09-24 19:30:29 +02:00
|
|
|
case Event::TRACK_SEND_ACTIVE: {
|
|
|
|
if ( availableRead >= sizeof(EventTrackSendActive) ) {
|
|
|
|
EventTrackSendActive ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTrackSendActive) );
|
2013-10-03 02:18:06 +02:00
|
|
|
if ( ev.send == SEND_POSTFADER )
|
2013-09-24 19:30:29 +02:00
|
|
|
if ( ev.track < NTRACKS )
|
|
|
|
{
|
2013-10-03 02:50:16 +02:00
|
|
|
gui->getTrack(ev.track)->setSendActive(ev.active );
|
2013-09-24 19:30:29 +02:00
|
|
|
}
|
2013-10-03 02:18:06 +02:00
|
|
|
if ( ev.send == SEND_KEY )
|
2013-09-24 19:30:29 +02:00
|
|
|
{
|
|
|
|
if ( ev.track < NTRACKS )
|
|
|
|
{
|
2013-10-03 02:50:16 +02:00
|
|
|
gui->getTrack(ev.track)->setKeyActive( ev.active );
|
2013-09-24 19:30:29 +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) );
|
2013-09-25 19:21:05 +02:00
|
|
|
//cout << "DSP: " << ev.getMessage() << endl;
|
|
|
|
LUPPP_DSP("%s", ev.getMessage() );
|
2013-05-16 16:17:49 +02:00
|
|
|
} 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-08-05 18:52:53 +02:00
|
|
|
case Event::TIME_TEMPO_TAP: {
|
|
|
|
if ( availableRead >= sizeof(EventTimeTempoTap) ) {
|
|
|
|
EventTimeTempoTap ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventTimeTempoTap) );
|
|
|
|
gui->getMasterTrack()->setTapTempo( ev.pressed );
|
|
|
|
} break; }
|
2013-08-06 23:10:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
case Event::LOOPER_REQUEST_BUFFER: {
|
|
|
|
if ( availableRead >= sizeof(EventLooperClipRequestBuffer) ) {
|
|
|
|
EventLooperClipRequestBuffer ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperClipRequestBuffer) );
|
|
|
|
|
|
|
|
/// allocate a new AudioBuffer with ev.numElements, pass back to DSP
|
|
|
|
AudioBuffer* ab = new AudioBuffer(ev.numElements);
|
2013-08-06 23:20:37 +02:00
|
|
|
EventLooperClipRequestBuffer returnEvent(ev.track, ev.scene, ab);
|
|
|
|
writeToDspRingbuffer( &returnEvent );
|
2013-08-22 15:36:56 +02:00
|
|
|
#ifdef DEBUG_BUFFER
|
2013-08-07 01:16:27 +02:00
|
|
|
printf("new buffer going to track %i, scene %i\n",ev.track, ev.scene);
|
2013-08-22 15:36:56 +02:00
|
|
|
#endif
|
2013-08-07 01:16:27 +02:00
|
|
|
} break; }
|
2013-09-03 20:35:02 +02:00
|
|
|
|
|
|
|
case Event::REQUEST_SAVE_BUFFER: {
|
|
|
|
if ( availableRead >= sizeof(EventRequestSaveBuffer) ) {
|
|
|
|
EventRequestSaveBuffer ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventRequestSaveBuffer) );
|
|
|
|
#ifdef DEBUG_BUFFER
|
|
|
|
printf("Save buffer to track %i, scene %i\n",ev.track, ev.scene);
|
|
|
|
#endif
|
|
|
|
/// allocate a new AudioBuffer with ev.numElements, pass back to DSP
|
|
|
|
AudioBuffer* ab = new AudioBuffer(ev.bufferSize);
|
|
|
|
|
|
|
|
if ( ab )
|
|
|
|
{
|
|
|
|
cout << "Save buffer sent with t s ab* " << ev.track << " " << ev.scene << " " << ab << endl;
|
|
|
|
EventRequestSaveBuffer returnEvent( ev.track, ev.scene, ab);
|
|
|
|
writeToDspRingbuffer( &returnEvent );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "error allocating save buffer!" << endl;
|
|
|
|
}
|
|
|
|
} break; }
|
|
|
|
|
2013-08-07 01:16:27 +02:00
|
|
|
case Event::DEALLOCATE_BUFFER: {
|
|
|
|
if ( availableRead >= sizeof(EventDeallocateBuffer) ) {
|
|
|
|
EventDeallocateBuffer ev;
|
|
|
|
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventDeallocateBuffer) );
|
|
|
|
delete ev.ab;
|
2013-08-06 23:10:27 +02:00
|
|
|
} 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
|
|
|
|
|