From 6a4188dbb7d65a22b15afaceb1966b79afc1e4b9 Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Sat, 31 Mar 2018 19:37:44 +0200 Subject: [PATCH] An event aproach. --- src/audiobuffer.cxx | 1 + src/avtk/clipselector.cxx | 24 ++++++++++++++----- src/avtk/clipselector.hxx | 32 +++++++------------------ src/event.hxx | 49 +++++++++++++++++++-------------------- src/eventhandlerdsp.cxx | 12 ++-------- src/eventhandlergui.cxx | 17 +++++++------- src/jacksendreturn.hxx | 4 ++-- src/logic.cxx | 13 ----------- src/logic.hxx | 1 - src/looperclip.cxx | 27 +++++++++++++-------- 10 files changed, 81 insertions(+), 99 deletions(-) diff --git a/src/audiobuffer.cxx b/src/audiobuffer.cxx index 13cb689..172b393 100644 --- a/src/audiobuffer.cxx +++ b/src/audiobuffer.cxx @@ -17,6 +17,7 @@ */ #include "audiobuffer.hxx" +#include "eventhandler.hxx" #include "config.hxx" #include diff --git a/src/avtk/clipselector.cxx b/src/avtk/clipselector.cxx index 90b8b68..bdc3e1d 100644 --- a/src/avtk/clipselector.cxx +++ b/src/avtk/clipselector.cxx @@ -62,10 +62,6 @@ 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 ); - } } @@ -91,7 +87,12 @@ std::string ClipSelector::clipName(int clip) void ClipSelector::clipName(int clip, std::string name) { clips[clip].setName( name ); - redraw(); + redraw(); +} + +void ClipSelector::setClipBeats(int scene, int beats, bool isBeatsToRecord) +{ + clips[scene].setBeats(beats, isBeatsToRecord); } void ClipSelector::setSpecial(int scene) @@ -423,7 +424,18 @@ int ClipSelector::handle(int event) return 0; default: return Fl_Widget::handle(event); - } + } +} + +void ClipState::setBeats(int beats, bool isBarsToRecord) +{ + if(beats > 0) { + barsText = std::to_string(beats/4); + if(isBarsToRecord) + barsText = "(" + barsText + ")"; + } + else + barsText = std::string(""); } } // Avtk diff --git a/src/avtk/clipselector.hxx b/src/avtk/clipselector.hxx index 3194bdf..3b7c47d 100644 --- a/src/avtk/clipselector.hxx +++ b/src/avtk/clipselector.hxx @@ -41,9 +41,9 @@ class ClipState public: ClipState() : state(GridLogic::STATE_EMPTY), - name(""), - lclip(0) // I would use nullptr, but thats not common here... - {} + name(""), + barsText("") + {} void setName(std::string n) { @@ -65,33 +65,15 @@ public: return state; } - void setLooperClip(LooperClip* lc){ - lclip = lc; - } - - // we wrap it here, so there may be no - // fuzz with the looperclip - const char * getBarsString(){ - if(!lclip) - return 0; - - int beats = lclip->getBeats(); - int barsToRecord = lclip->getBarsToRecord(); - int bars = (beats == 0) ? barsToRecord : beats / 4; - - if (bars <= 0) - return 0; - - if(bars != lastBars) - barsText = std::to_string(bars); + void setBeats(int beats, bool isBarsToRecord); + const char * getBarsString(){ return barsText.c_str(); } private: - GridLogic::State state; + GridLogic::State state; std::string name; - LooperClip* lclip; std::string barsText; // tmp @@ -127,6 +109,8 @@ public: void setState( int clipNum, GridLogic::State s ); void clipName(int clip, std::string name); + void setClipBeats(int scene, int beats, bool isBeatsToRecord); + std::string clipName(int clip); void draw(); diff --git a/src/event.hxx b/src/event.hxx index adf5c3b..11053b8 100644 --- a/src/event.hxx +++ b/src/event.hxx @@ -35,10 +35,6 @@ using namespace std; -namespace Avtk { - class ClipState; -} - namespace Event { enum SEND_TYPE { @@ -82,7 +78,6 @@ 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" - GRID_INIT, // init the cells with references to the looper clips /// Track TRACK_JACKSEND, @@ -132,6 +127,9 @@ enum EVENT_TYPE { // for keeping loop index's inside the enum EVENT_TYPE_FINAL, + + // Clip + CLIP_BEATS_CHANGED, }; /// returns the pretty name of an event @@ -604,26 +602,6 @@ public: EventStateSaveFinish() {}; }; -class EventGridInit : public EventBase -{ -public: - int type() - { - return int(GRID_INIT); - } - uint32_t size() - { - return sizeof(EventGridInit); - } - - Avtk::ClipState *clips; - int numClips; - int track; - - EventGridInit() {}; - EventGridInit(Avtk::ClipState * c, int n, int t): clips(c), numClips(n), track(t) {} -}; - class EventGridEvent : public EventBase { public: @@ -1196,6 +1174,27 @@ public: } }; +class EventClipBeatsChanged : public EventBase +{ +public: + int type() + { + return int(CLIP_BEATS_CHANGED); + } + uint32_t size() + { + return sizeof(EventClipBeatsChanged); + } + + int track; + int scene; + int beats; + bool isBeatsToRecord; + + EventClipBeatsChanged() {} + EventClipBeatsChanged(int t, int s, int b, bool i) : track(t), scene(s), beats(b), isBeatsToRecord(i) {} +}; + #endif // LUPPP_EVENT_H diff --git a/src/eventhandlerdsp.cxx b/src/eventhandlerdsp.cxx index c4a6aaa..df9e390 100644 --- a/src/eventhandlerdsp.cxx +++ b/src/eventhandlerdsp.cxx @@ -171,15 +171,7 @@ void handleDspEvents() break; } - // ========= 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; - } + // ========= GRID ===== case Event::GRID_STATE: { if ( availableRead >= sizeof(EventGridState) ) { EventGridState ev; @@ -484,7 +476,7 @@ void handleDspEvents() cout << "DSP: Unkown message!! Will clog ringbuffer" << endl; // just do nothing break; - } + } } } else { // next call will get the half-written event diff --git a/src/eventhandlergui.cxx b/src/eventhandlergui.cxx index 80dee54..cacf847 100644 --- a/src/eventhandlergui.cxx +++ b/src/eventhandlergui.cxx @@ -140,13 +140,6 @@ 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; @@ -286,6 +279,14 @@ void handleGuiEvents() break; } + case Event::CLIP_BEATS_CHANGED: { + if ( availableRead >= sizeof(EventClipBeatsChanged) ) { + EventClipBeatsChanged ev; + jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventClipBeatsChanged) ); + gui->getTrack(ev.track)->getClipSelector()->setClipBeats(ev.scene, ev.beats, ev.isBeatsToRecord); + } + break; + } case Event::TRACK_SEND: { if ( availableRead >= sizeof(EventTrackSend) ) { @@ -297,7 +298,7 @@ void handleGuiEvents() } if ( ev.send == SEND_XSIDE ) if ( ev.track < NTRACKS ) { - gui->getTrack(ev.track)->setXSide( ev.value ); + gui->getTrack(ev.track)->setXSide( ev.value ); } } break; diff --git a/src/jacksendreturn.hxx b/src/jacksendreturn.hxx index e2fc3f6..fc6c6c8 100644 --- a/src/jacksendreturn.hxx +++ b/src/jacksendreturn.hxx @@ -43,14 +43,14 @@ public: void sendVolume(float vol); private: + int m_trackid; + AudioProcessor* m_previousProcessor; bool m_active; float m_sendvol; jack_port_t* m_sendport_l; jack_port_t* m_sendport_r; jack_port_t* m_returnport_l; jack_port_t* m_returnport_r; - int m_trackid; - AudioProcessor* m_previousProcessor; int m_counter; }; diff --git a/src/logic.cxx b/src/logic.cxx index f00a42a..b94b552 100644 --- a/src/logic.cxx +++ b/src/logic.cxx @@ -160,19 +160,6 @@ void Logic::looperBarsToRecord(int t, int s, int b) } } -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); - } -} - void Logic::looperUseAsTempo(int t, int s) { size_t clipBeats = jack->getLooper( t )->getClip( s )->getBeats(); diff --git a/src/logic.hxx b/src/logic.hxx index 81a536b..b4f3af5 100644 --- a/src/logic.hxx +++ b/src/logic.hxx @@ -64,7 +64,6 @@ 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 diff --git a/src/looperclip.cxx b/src/looperclip.cxx index f9882ab..af15cb5 100644 --- a/src/looperclip.cxx +++ b/src/looperclip.cxx @@ -16,8 +16,6 @@ * along with this program. If not, see . */ -#include "looperclip.hxx" - #include #include "config.hxx" #include "jack.hxx" @@ -50,8 +48,9 @@ void LooperClip::init() _queuePlay = false; _queueStop = false; - _queueRecord= false; - _wantedBeats= -0; + _queueRecord= false; + _wantedBeats= -1; + setBeats(0); if ( _buffer ) { _buffer->init(); @@ -115,6 +114,8 @@ void LooperClip::load( AudioBuffer* ab ) } _buffer = ab; + EventClipBeatsChanged e( track, scene, _wantedBeats, true ); + writeToGuiRingbuffer( &e ); _playhead = 0; jack->getControllerUpdater()->setTrackSceneProgress(track, scene, 0 ); @@ -182,13 +183,15 @@ void LooperClip::setPlayHead(float ph) { if(!_recording&&_playing) { _playhead = ph; - jack->getControllerUpdater()->setTrackSceneProgress(track, scene, getProgress() ); + jack->getControllerUpdater()->setTrackSceneProgress( track, scene, getProgress() ); } } void LooperClip::setBarsToRecord(int bars) { - _wantedBeats = bars * 4; // we set bars + _wantedBeats = bars * 4; // we set beats + EventClipBeatsChanged e( track, scene, _wantedBeats, true); + writeToGuiRingbuffer(&e); } int LooperClip::getBeatsToRecord() @@ -252,7 +255,11 @@ void LooperClip::setBeats(int beats) { if ( _buffer ) { _buffer->setBeats( beats ); - } + } + + // Even on Reset! + EventClipBeatsChanged e(track, scene, beats, false); + writeToGuiRingbuffer(&e); } int LooperClip::getBeats() @@ -284,10 +291,10 @@ void LooperClip::bar() GridLogic::State s = GridLogic::STATE_EMPTY; // first update the buffer, as time has passed - if ( _recording ) { + if ( _recording ) { // FIXME: assumes 4 beats in a bar - _buffer->setBeats( _buffer->getBeats() + 4 ); - _buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() ); + setBeats( _buffer->getBeats() + 4 ); + _buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() ); } if ( _playhead >= _recordhead ) {