From 8cf5e19848e406b64b0d8558f5574b5fb89bc261 Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Tue, 27 Mar 2018 17:52:41 +0200 Subject: [PATCH] Some tweaks + Display number of bars recorded (and to be recorded)! --- src/avtk/clipselector.cxx | 19 ++++++++++++++++++- src/avtk/clipselector.hxx | 23 ++++++++++++++++++++++- src/event.hxx | 33 +++++++++++++++++++++++++++++---- src/eventhandlerdsp.cxx | 18 ++++++++++++++---- src/eventhandlergui.cxx | 7 +++++++ src/logic.cxx | 16 ++++++++++++++-- src/logic.hxx | 2 ++ 7 files changed, 106 insertions(+), 12 deletions(-) diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index 82e0e21..b56e55b 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -45,7 +45,7 @@ ClipSelector::ClipSelector( int _x, int _y, int _w, int _h, _master = master; if ( _master ) { - for(int i = 0; i < 10; i++ ) { + for(int i = 0; i < numClips; i++ ) { stringstream s; s << "Scene " << i + 1; clips[i].setName( s.str() ); @@ -62,6 +62,10 @@ ClipSelector::ClipSelector( int _x, int _y, int _w, int _h, void ClipSelector::setID( int id ) { ID = id; + if(!_master){ + EventGridInit e (clips, numClips, ID); + writeToDspRingbuffer( &e ); + } } @@ -205,6 +209,19 @@ void ClipSelector::draw() cairo_show_text( cr, tmp.c_str() ); + // clip bars + if(!_master) { + int bars = clips[i].getBeats() / 4; + int barsToRecord = clips[i].getBarsToRecord(); + bars = (bars == 0) ? barsToRecord : bars; + if(bars > 0) { + cairo_move_to( cr, x + clipHeight + 5, drawY + textHeight + 8); + cairo_set_source_rgba( cr, 255 / 255.f, 255 / 255.f , 255 / 255.f , 0.9 ); + cairo_set_font_size( cr, 8 ); + cairo_show_text( cr, std::to_string(bars).c_str()); + } + } + // special indicator? if ( i == special ) { cairo_rectangle( cr, x+2, drawY, clipWidth -1, clipHeight - 3 ); diff --git a/src/avtk/clipselector.hxx b/src/avtk/clipselector.hxx index b5eecd4..5c7caa2 100644 --- a/src/avtk/clipselector.hxx +++ b/src/avtk/clipselector.hxx @@ -41,7 +41,8 @@ class ClipState public: ClipState() : state(GridLogic::STATE_EMPTY), - name("") + name(""), + lclip(0) // I would use nullptr, but thats not common here... {} void setName(std::string n) @@ -64,9 +65,29 @@ public: return state; } + void setLooperClip(LooperClip* lc){ + lclip = lc; + } + + // we wrap it here, so there may be no + // fuzz with the looperclip + int getBeats(){ + if(!lclip) + return 0; + + return lclip->getBeats(); + } + + int getBarsToRecord(){ + if(!lclip) + return 0; + return lclip->getBarsToRecord(); + } + private: GridLogic::State state; std::string name; + LooperClip* lclip; }; class ClipSelector : public Fl_Button diff --git a/src/event.hxx b/src/event.hxx index 45ba507..03d15bf 100644 --- a/src/event.hxx +++ b/src/event.hxx @@ -1,4 +1,4 @@ -/* +/* * Author: Harry van Haaren 2013 * harryhaaren@gmail.com * @@ -31,11 +31,14 @@ #include "looper.hxx" #include "gridlogic.hxx" #include "transport.hxx" - #pragma GCC diagnostic ignored "-Wunused-parameter" using namespace std; +namespace Avtk { + class ClipState; +} + namespace Event { enum SEND_TYPE { @@ -79,7 +82,7 @@ enum EVENT_TYPE { GRID_SELECT_CLIP_ENABLE, // enable selecting a clip from the grid GRID_SELECT_CLIP_EVENT, // a press / release on the selected clip GRID_SELECT_NEW_CHOSEN, // a different clip is now "special" - EVENT_LOOPER_BARS_TO_RECORD, // choose how many bars to record + GRID_INIT, // init the cells with references to the looper clips /// Track TRACK_JACKSEND, @@ -98,6 +101,7 @@ enum EVENT_TYPE { LOOPER_PROGRESS, LOOPER_LOOP_LENGTH, LOOPER_LOOP_USE_AS_TEMPO, + LOOPER_BARS_TO_RECORD, // choose how many bars to record /// Transport etc METRONOME_ACTIVE, @@ -273,7 +277,7 @@ class EventLooperBarsToRecord : public EventBase public: int type() { - return int(EVENT_LOOPER_BARS_TO_RECORD); + return int(LOOPER_BARS_TO_RECORD); } uint32_t size() { @@ -600,6 +604,26 @@ public: EventStateSaveFinish() {}; }; +class EventGridInit : public EventBase +{ +public: + int type() + { + return int(GRID_INIT); + } + uint32_t size() + { + return sizeof(EventGridInit); + } + + int numClips; + int track; + Avtk::ClipState *clips; + + EventGridInit() {}; + EventGridInit(Avtk::ClipState * c, int n, int t): clips(c), numClips(n), track(t) {} +}; + class EventGridEvent : public EventBase { public: @@ -625,6 +649,7 @@ public: EventGridEvent(int t, int s, bool p): track(t), scene(s), pressed(p) {} }; + class EventGridState : public EventBase { public: diff --git a/src/eventhandlerdsp.cxx b/src/eventhandlerdsp.cxx index 64a9c09..c4a6aaa 100644 --- a/src/eventhandlerdsp.cxx +++ b/src/eventhandlerdsp.cxx @@ -172,6 +172,14 @@ void handleDspEvents() } // ========= GRID ===== + case Event::GRID_INIT: { + if ( availableRead >= sizeof(EventGridInit) ) { + EventGridInit ev; + jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventGridInit) ); + jack->getLogic()->setupClips( ev.clips, ev.numClips, ev.track ); + } + break; + } case Event::GRID_STATE: { if ( availableRead >= sizeof(EventGridState) ) { EventGridState ev; @@ -265,10 +273,12 @@ void handleDspEvents() } break; } - case Event::EVENT_LOOPER_BARS_TO_RECORD: { - EventLooperBarsToRecord ev; - jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperBarsToRecord) ); - jack->getLogic()->looperBarsToRecord( ev.track, ev.scene, ev.bars ); + case Event::LOOPER_BARS_TO_RECORD: { + if ( availableRead >= sizeof(EventLooperBarsToRecord) ) { + EventLooperBarsToRecord ev; + jack_ringbuffer_read( rbToDsp, (char*)&ev, sizeof(EventLooperBarsToRecord) ); + jack->getLogic()->looperBarsToRecord( ev.track, ev.scene, ev.bars ); + } break; } case Event::LOOPER_LOOP_USE_AS_TEMPO: { diff --git a/src/eventhandlergui.cxx b/src/eventhandlergui.cxx index e0c836f..80dee54 100644 --- a/src/eventhandlergui.cxx +++ b/src/eventhandlergui.cxx @@ -140,6 +140,13 @@ void handleGuiEvents() //jack->setLooperLoopLength( ev.track, ev.scale ); } break; } + case Event::LOOPER_BARS_TO_RECORD: { + if ( availableRead >= sizeof(EventLooperLoopLength) ) { + EventLooperBarsToRecord ev; + jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventLooperBarsToRecord) ); + } + break; + } case Event::LOOPER_PROGRESS: { if ( availableRead >= sizeof(EventLooperProgress) ) { EventLooperProgress ev; diff --git a/src/logic.cxx b/src/logic.cxx index dd9f583..f00a42a 100644 --- a/src/logic.cxx +++ b/src/logic.cxx @@ -156,8 +156,20 @@ void Logic::looperBarsToRecord(int t, int s, int b) { if ( t >= 0 && t < NTRACKS ) { jack->getLooper( t )->getClip( s )->setBarsToRecord(b); - } else { - LUPPP_WARN("invalid track number %i: check controller map has \"track\" field.", t ); + } else { LUPPP_WARN("invalid track number %i: check controller map has \"track\" field.", t ); + } +} + +void Logic::setupClips(Avtk::ClipState clips[], int clipNum, int t) +{ + if(!clips) + return; + + Looper * looper = jack->getLooper( t ); + for(int i = 0; i < clipNum; i++){ + LooperClip * tmp = looper->getClip(i); + if(tmp) + clips[i].setLooperClip(tmp); } } diff --git a/src/logic.hxx b/src/logic.hxx index 19a645b..81a536b 100644 --- a/src/logic.hxx +++ b/src/logic.hxx @@ -20,6 +20,7 @@ #define LUPPP_LOGIC_H #include "event.hxx" +#include "avtk/clipselector.hxx" /** Logic * This class contains an interface exposing most functionality in Luppp. The @@ -63,6 +64,7 @@ public: void looperUseAsTempo(int track, int scene); void looperClipLenght(int track, int scene, int lenght); void looperBarsToRecord(int track, int scene, int bars); + void setupClips(Avtk::ClipState clips[], int clipNum, int t); }; #endif // LUPPP_LOGIC_H