From a4c526c11257b68cb7f1945400524bfaa86d05ee Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Thu, 1 Aug 2013 19:58:26 +0100 Subject: [PATCH] -Refactoring Controller grid logic into GridLogic class, updated State enum from Controller to GridLogic --- src/controller/apc.cxx | 18 +++++------ src/controller/apc.hxx | 2 +- src/controller/controller.hxx | 4 ++- src/controllerupdater.hxx | 6 ++-- src/gridlogic.cxx | 26 ++++++++++++++++ src/gridlogic.hxx | 57 +++++++++++++++++++++++++++++++++++ src/looper.cxx | 7 ++--- src/looper.hxx | 6 +++- 8 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 src/gridlogic.cxx create mode 100644 src/gridlogic.hxx diff --git a/src/controller/apc.cxx b/src/controller/apc.cxx index d297ec8..decaede 100644 --- a/src/controller/apc.cxx +++ b/src/controller/apc.cxx @@ -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] ); diff --git a/src/controller/apc.hxx b/src/controller/apc.hxx index ef47199..5a17744 100644 --- a/src/controller/apc.hxx +++ b/src/controller/apc.hxx @@ -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); diff --git a/src/controller/controller.hxx b/src/controller/controller.hxx index dc27552..c5c270c 100644 --- a/src/controller/controller.hxx +++ b/src/controller/controller.hxx @@ -5,6 +5,8 @@ #include +#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 diff --git a/src/controllerupdater.hxx b/src/controllerupdater.hxx index db9c023..a235d48 100644 --- a/src/controllerupdater.hxx +++ b/src/controllerupdater.hxx @@ -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) diff --git a/src/gridlogic.cxx b/src/gridlogic.cxx new file mode 100644 index 0000000..4fb9bce --- /dev/null +++ b/src/gridlogic.cxx @@ -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() +{ + +} diff --git a/src/gridlogic.hxx b/src/gridlogic.hxx new file mode 100644 index 0000000..20a49c3 --- /dev/null +++ b/src/gridlogic.hxx @@ -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 diff --git a/src/looper.cxx b/src/looper.cxx index bb8fab2..85d9e6d 100644 --- a/src/looper.cxx +++ b/src/looper.cxx @@ -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) { diff --git a/src/looper.hxx b/src/looper.hxx index 046f8a3..2c3f75f 100644 --- a/src/looper.hxx +++ b/src/looper.hxx @@ -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];