-Refactoring Controller grid logic into GridLogic class, updated State enum from Controller to GridLogic

This commit is contained in:
Harry van Haaren 2013-08-01 19:58:26 +01:00
parent 6c77081b15
commit a4c526c112
8 changed files with 108 additions and 18 deletions

View file

@ -21,21 +21,21 @@ void AkaiAPC::recordArm(int t, bool enabled)
jack->writeApcOutput( &data[0] );
}
void AkaiAPC::clipSelect(int t, int clip, ClipMode cm)
void AkaiAPC::setSceneState(int t, int clip, GridLogic::State s)
{
unsigned char data[3];
data[0] = 144 + t;
data[1] = 53 + clip;
switch (cm)
switch (s)
{
case CLIP_MODE_EMPTY: data[2] = 0; break;
case CLIP_MODE_PLAYING: data[2] = 1; break;
case CLIP_MODE_PLAY_QUEUED: data[2] = 2; break;
case CLIP_MODE_RECORDING: data[2] = 3; break;
case CLIP_MODE_RECORD_QUEUED: data[2] = 4; break;
case CLIP_MODE_LOADED: data[2] = 5; break;
case CLIP_MODE_STOP_QUEUED: data[2] = 6; break;
case GridLogic::STATE_EMPTY: data[2] = 0; break;
case GridLogic::STATE_PLAYING: data[2] = 1; break;
case GridLogic::STATE_PLAY_QUEUED: data[2] = 2; break;
case GridLogic::STATE_RECORDING: data[2] = 3; break;
case GridLogic::STATE_RECORD_QUEUED: data[2] = 4; break;
case GridLogic::STATE_LOADED: data[2] = 5; break;
case GridLogic::STATE_STOP_QUEUED: data[2] = 6; break;
}
jack->writeApcOutput( &data[0] );

View file

@ -17,7 +17,7 @@ class AkaiAPC : public Controller, public MidiObserver
void mute(int t, bool b);
void volume(int t, float f);
void recordArm(int t, bool b);
void clipSelect(int track, int clip, ClipMode cm);
void setSceneState(int track, int clip, GridLogic::State s);
void midi(unsigned char* data);

View file

@ -5,6 +5,8 @@
#include <string>
#include "../gridlogic.hxx"
class Controller
{
public:
@ -30,7 +32,7 @@ class Controller
virtual void mute(int t, bool b){};
virtual void volume(int t, float f){};
virtual void recordArm(int t, bool r){};
virtual void clipSelect(int track, int clip, ClipMode cm){};
virtual void setSceneState(int track, int scene, GridLogic::State s){};
};
#endif // LUPPP_CONTROLLER_H

View file

@ -8,6 +8,8 @@
#include "controller/apc.hxx"
#include "controller/controller.hxx"
#include "gridlogic.hxx"
using namespace std;
// this is a wrapper class around a vector of Controller instances
@ -31,10 +33,10 @@ class ControllerUpdater
c.at(i)->mute(t,b);
}
void clipSelect(int t, int clip, Controller::ClipMode cm)
void clipSelect(int t, int clip, GridLogic::State s)
{
for(unsigned int i = 0; i < c.size(); i++)
c.at(i)->clipSelect(t,clip,cm);
c.at(i)->setSceneState(t,clip,s);
}
void recordArm(int t, bool r)

26
src/gridlogic.cxx Normal file
View file

@ -0,0 +1,26 @@
#include "gridlogic.hxx"
GridLogic::GridLogic()
{
}
void GridLogic::pressed( int track, int scene )
{
}
void GridLogic::released( int track, int scene )
{
}
void GridLogic::update()
{
}

57
src/gridlogic.hxx Normal file
View file

@ -0,0 +1,57 @@
#ifndef LUPPP_GRID_LOGIC_H
#define LUPPP_GRID_LOGIC_H
#include "config.hxx"
#include "observer/time.hxx"
/** GridLogic
* The logic code for the luppp tracks / grid resides here. This logic is
* separtated from the Looper class so it can be repurposed by different
* controllers and input devices. The UI and eg. APC / Launchpad all have a
* similar grid style interface: implementing the logic in each is not good.
*
* The class sends Looper messages to change its state, thus abstracting away
* the details of the Looper control, and exposing its functionality using a
* convinient API.
*
* When the state of a block changes, it will update the state of the grid on
* the controller.
*
* It inherits from TimeObserver so it can change the state of the clip on the
* bar / beat.
**/
class GridLogic : public TimeObserver
{
public:
/// possible states of each square. Public so Controller subclasses can
/// determine the state of the square
enum State {
STATE_EMPTY = 0,
STATE_PLAYING,
STATE_PLAY_QUEUED,
STATE_LOADED,
STATE_STOP_QUEUED,
STATE_RECORDING,
STATE_RECORD_QUEUED,
};
GridLogic();
/// button press / click event
void pressed( int track, int scene );
/// button release / click-release event
void released( int track, int scene );
/// resend entire grid state to controller
void updateState();
private:
/// contains the current state of each grid square
State state[NTRACKS*NSCENES];
};
#endif // LUPPP_GRID_LOGIC_H

View file

@ -85,11 +85,10 @@ void Looper::midi(unsigned char* data)
*/
}
void Looper::setScene( int sc )
void Looper::queuePlayScene( int sc )
{
// update Looper to play different scene
//scene = sc;
//sample = samples[scene];
//queuedScene = sc;
//jack->getControllerUpdater()->clipSelect(track, scene, Controller::CLIP_MODE_PLAY_QUEUED);
}
//void Looper::setState( State s) {

View file

@ -32,7 +32,7 @@ class Looper : public AudioProcessor, public TimeObserver
void setFpb(int f) { /*fpb = f;*/ }
void setScene( int sc );
void queuePlayScene( int sc );
LooperClip* getClip(int scene);
@ -43,6 +43,10 @@ class Looper : public AudioProcessor, public TimeObserver
private:
const int track;
/// variables used to determing the current actions of the looper
int playingScene;
int queuedScene;
float* tmpRecordBuffer;
LooperClip clips[10];