2013-08-01 20:58:26 +02:00
|
|
|
|
|
|
|
#include "gridlogic.hxx"
|
|
|
|
|
2013-08-02 04:16:56 +02:00
|
|
|
#include "jack.hxx"
|
2013-08-22 01:05:00 +02:00
|
|
|
#include "audiobuffer.hxx"
|
2013-08-02 04:16:56 +02:00
|
|
|
|
2013-09-11 13:57:31 +02:00
|
|
|
extern Jack* jack;
|
2013-08-13 17:35:27 +02:00
|
|
|
|
2013-08-22 02:19:22 +02:00
|
|
|
const char* GridLogic::StateString[8] = {
|
2013-08-13 17:35:27 +02:00
|
|
|
"empty",
|
|
|
|
"playing",
|
|
|
|
"play queued",
|
2013-08-22 01:46:58 +02:00
|
|
|
"stopped",
|
2013-08-13 17:35:27 +02:00
|
|
|
"stop queued",
|
|
|
|
"recording",
|
|
|
|
"record queued"
|
|
|
|
};
|
|
|
|
|
2013-08-01 20:58:26 +02:00
|
|
|
GridLogic::GridLogic()
|
|
|
|
{
|
2013-08-26 00:36:08 +02:00
|
|
|
sceneLaunch = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GridLogic::getLaunchedScene()
|
|
|
|
{
|
|
|
|
return sceneLaunch;
|
2013-08-01 20:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-22 06:48:59 +02:00
|
|
|
void GridLogic::launchScene( int scene )
|
|
|
|
{
|
|
|
|
for(unsigned int t = 0; t < NTRACKS; t++ )
|
|
|
|
{
|
2013-08-22 16:00:57 +02:00
|
|
|
for(int s = 0; s < NSCENES; s++ )
|
2013-08-22 06:48:59 +02:00
|
|
|
{
|
|
|
|
LooperClip* lc = jack->getLooper( t )->getClip( s );
|
|
|
|
if ( s == scene )
|
2013-08-22 16:00:57 +02:00
|
|
|
{
|
2013-08-22 06:48:59 +02:00
|
|
|
lc->queuePlay();
|
2013-08-22 16:00:57 +02:00
|
|
|
jack->getControllerUpdater()->setSceneState( t, s, lc->getState() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-06 13:13:15 +02:00
|
|
|
if ( lc->somethingQueued() )
|
2013-08-22 16:00:57 +02:00
|
|
|
{
|
2013-09-06 13:13:15 +02:00
|
|
|
lc->neutralize();
|
|
|
|
jack->getControllerUpdater()->setSceneState( t, s, lc->getState() );
|
|
|
|
}
|
|
|
|
else if ( lc->playing() )
|
|
|
|
{
|
|
|
|
lc->queueStop();
|
2013-08-22 16:00:57 +02:00
|
|
|
jack->getControllerUpdater()->setSceneState( t, s, lc->getState() );
|
|
|
|
}
|
|
|
|
}
|
2013-08-22 06:48:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 00:36:08 +02:00
|
|
|
sceneLaunch = scene;
|
|
|
|
|
|
|
|
jack->getControllerUpdater()->launchScene( scene );
|
2013-08-22 06:48:59 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 20:58:26 +02:00
|
|
|
void GridLogic::pressed( int track, int scene )
|
|
|
|
{
|
2013-08-22 16:00:57 +02:00
|
|
|
// get the clip, do the "press" action based on current state.
|
2013-08-27 19:05:21 +02:00
|
|
|
LooperClip* lc = jack->getLooper( track )->getClip( scene );
|
|
|
|
TrackOutput* to = jack->getTrackOutput( track );
|
2013-08-22 02:19:22 +02:00
|
|
|
GridLogic::State s = lc->getState();
|
2013-08-22 15:36:56 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_CLIP
|
2013-08-26 00:36:08 +02:00
|
|
|
printf("GridLogic::pressed() before press state = %s\n", StateString[ int(scene) ] );
|
2013-08-22 15:36:56 +02:00
|
|
|
#endif
|
2013-08-22 02:19:22 +02:00
|
|
|
|
2013-08-27 19:05:21 +02:00
|
|
|
if ( to->recordArm() && !lc->recording() )
|
|
|
|
{
|
|
|
|
lc->queueRecord();
|
|
|
|
to->recordArm(false);
|
2013-09-08 01:37:47 +02:00
|
|
|
jack->getControllerUpdater()->recordArm( track, false );
|
2013-08-27 19:05:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( s == STATE_EMPTY )
|
|
|
|
lc->queueRecord();
|
|
|
|
|
|
|
|
if ( s == STATE_STOPPED )
|
|
|
|
lc->queuePlay();
|
|
|
|
|
|
|
|
if ( s == STATE_PLAYING )
|
|
|
|
lc->queueStop();
|
|
|
|
|
|
|
|
if ( s == STATE_RECORDING )
|
|
|
|
lc->queuePlay();
|
|
|
|
|
|
|
|
if ( s == STATE_PLAY_QUEUED )
|
|
|
|
lc->queueStop();
|
|
|
|
|
|
|
|
if ( s == STATE_STOP_QUEUED )
|
|
|
|
lc->queuePlay();
|
|
|
|
}
|
2013-08-27 01:23:11 +02:00
|
|
|
|
2013-09-06 13:20:14 +02:00
|
|
|
// check state of new clip, if getQueuePlay() == true, queueStop() all other scenes
|
|
|
|
if ( lc->getQueuePlay() )
|
|
|
|
{
|
|
|
|
for(int i = 0; i < NSCENES; i++)
|
|
|
|
{
|
2013-09-08 01:37:47 +02:00
|
|
|
// exclude current scene
|
|
|
|
if ( i != scene )
|
2013-09-06 13:20:14 +02:00
|
|
|
{
|
2013-09-08 01:37:47 +02:00
|
|
|
LooperClip* ilc = jack->getLooper( track )->getClip( i );
|
|
|
|
if ( ilc->somethingQueued() )
|
|
|
|
{
|
|
|
|
ilc->neutralize();
|
|
|
|
jack->getControllerUpdater()->setSceneState(track, i, ilc->getState() );
|
|
|
|
}
|
|
|
|
else if ( ilc->playing() )
|
|
|
|
{
|
|
|
|
ilc->queueStop();
|
|
|
|
jack->getControllerUpdater()->setSceneState(track, i, ilc->getState() );
|
|
|
|
}
|
2013-09-06 13:20:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-22 02:19:22 +02:00
|
|
|
s = lc->getState();
|
2013-08-22 15:36:56 +02:00
|
|
|
#ifdef DEBUG_CLIP
|
|
|
|
printf("GridLogic::pressed() after press state = %s\n", StateString[ int(s) ] );
|
|
|
|
#endif
|
2013-08-22 02:19:22 +02:00
|
|
|
jack->getControllerUpdater()->setSceneState(track, scene, s );
|
2013-08-01 20:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GridLogic::released( int track, int scene )
|
|
|
|
{
|
2013-08-27 01:23:11 +02:00
|
|
|
GridLogic::State s = jack->getLooper( track )->getClip( scene )->getState();
|
|
|
|
jack->getControllerUpdater()->setSceneState(track, scene, s );
|
2013-08-01 20:58:26 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 01:05:00 +02:00
|
|
|
void GridLogic::load(int track, int scene, AudioBuffer* ab)
|
2013-08-13 01:41:17 +02:00
|
|
|
{
|
2013-08-22 01:05:00 +02:00
|
|
|
jack->getLooper( track )->getClip( scene )->load( ab );
|
2013-09-05 00:00:08 +02:00
|
|
|
GridLogic::State s = jack->getLooper( track )->getClip( scene )->getState();
|
|
|
|
jack->getControllerUpdater()->setSceneState(track, scene, s );
|
2013-08-13 01:41:17 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 20:58:26 +02:00
|
|
|
|
2013-08-02 04:16:56 +02:00
|
|
|
void GridLogic::updateState()
|
2013-08-01 20:58:26 +02:00
|
|
|
{
|
2013-08-16 14:14:47 +02:00
|
|
|
//printf("GridLogic::updateState() stub" );
|
2013-09-06 02:28:14 +02:00
|
|
|
for(int t = 0; t < NTRACKS; t++)
|
|
|
|
{
|
|
|
|
for(int s = 0; s < NSCENES; s++)
|
|
|
|
{
|
|
|
|
GridLogic::State st = jack->getLooper( t )->getClip( s )->getState();
|
|
|
|
EventGuiPrint e( GridLogic::StateString[st] );
|
|
|
|
writeToGuiRingbuffer( &e );
|
|
|
|
jack->getControllerUpdater()->setSceneState(t, s, st );
|
|
|
|
}
|
|
|
|
}
|
2013-08-04 19:04:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GridLogic::bar()
|
|
|
|
{
|
2013-08-22 15:36:56 +02:00
|
|
|
#ifdef DEBUG_CLIP
|
2013-08-16 14:14:47 +02:00
|
|
|
EventGuiPrint e( "GridLogic::bar()\n" );
|
|
|
|
writeToGuiRingbuffer( &e );
|
2013-08-22 15:36:56 +02:00
|
|
|
#endif
|
2013-08-04 19:04:26 +02:00
|
|
|
|
2013-08-06 23:42:04 +02:00
|
|
|
/// iterate over all clips, if they're set to QUEUED, set to the next state
|
2013-08-04 19:04:26 +02:00
|
|
|
for( int i = 0; i < NTRACKS*NSCENES; i++ )
|
|
|
|
{
|
2013-08-07 01:16:27 +02:00
|
|
|
int track = i / NSCENES;
|
|
|
|
int scene = i - track * NSCENES;
|
2013-08-22 02:19:22 +02:00
|
|
|
jack->getLooper( track )->getClip( scene )->bar();
|
2013-08-22 15:36:56 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_CLIP
|
2013-08-22 02:19:22 +02:00
|
|
|
GridLogic::State s = jack->getLooper( track )->getClip( scene )->getState();
|
|
|
|
if ( s != STATE_EMPTY )
|
|
|
|
{
|
2013-08-27 19:05:21 +02:00
|
|
|
//printf("%i, %i:after bar() state = %s\n", track, scene, StateString[ int(s) ] );
|
2013-08-22 02:19:22 +02:00
|
|
|
}
|
2013-08-22 15:36:56 +02:00
|
|
|
#endif
|
2013-08-04 19:04:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GridLogic::beat()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-09-11 13:57:31 +02:00
|
|
|
|