mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-04 16:51:37 -05:00
An event aproach.
This commit is contained in:
parent
185e842412
commit
6a4188dbb7
10 changed files with 81 additions and 99 deletions
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "audiobuffer.hxx"
|
#include "audiobuffer.hxx"
|
||||||
|
#include "eventhandler.hxx"
|
||||||
#include "config.hxx"
|
#include "config.hxx"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
@ -62,10 +62,6 @@ ClipSelector::ClipSelector( int _x, int _y, int _w, int _h,
|
||||||
void ClipSelector::setID( int id )
|
void ClipSelector::setID( int id )
|
||||||
{
|
{
|
||||||
ID = 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)
|
void ClipSelector::clipName(int clip, std::string name)
|
||||||
{
|
{
|
||||||
clips[clip].setName( 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)
|
void ClipSelector::setSpecial(int scene)
|
||||||
|
@ -423,7 +424,18 @@ int ClipSelector::handle(int event)
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
return Fl_Widget::handle(event);
|
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
|
} // Avtk
|
||||||
|
|
|
@ -41,9 +41,9 @@ class ClipState
|
||||||
public:
|
public:
|
||||||
ClipState() :
|
ClipState() :
|
||||||
state(GridLogic::STATE_EMPTY),
|
state(GridLogic::STATE_EMPTY),
|
||||||
name(""),
|
name(""),
|
||||||
lclip(0) // I would use nullptr, but thats not common here...
|
barsText("")
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void setName(std::string n)
|
void setName(std::string n)
|
||||||
{
|
{
|
||||||
|
@ -65,33 +65,15 @@ public:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLooperClip(LooperClip* lc){
|
void setBeats(int beats, bool isBarsToRecord);
|
||||||
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);
|
|
||||||
|
|
||||||
|
const char * getBarsString(){
|
||||||
return barsText.c_str();
|
return barsText.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GridLogic::State state;
|
GridLogic::State state;
|
||||||
std::string name;
|
std::string name;
|
||||||
LooperClip* lclip;
|
|
||||||
std::string barsText;
|
std::string barsText;
|
||||||
|
|
||||||
// tmp
|
// tmp
|
||||||
|
@ -127,6 +109,8 @@ public:
|
||||||
void setState( int clipNum, GridLogic::State s );
|
void setState( int clipNum, GridLogic::State s );
|
||||||
|
|
||||||
void clipName(int clip, std::string name);
|
void clipName(int clip, std::string name);
|
||||||
|
void setClipBeats(int scene, int beats, bool isBeatsToRecord);
|
||||||
|
|
||||||
std::string clipName(int clip);
|
std::string clipName(int clip);
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
|
@ -35,10 +35,6 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace Avtk {
|
|
||||||
class ClipState;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Event
|
namespace Event
|
||||||
{
|
{
|
||||||
enum SEND_TYPE {
|
enum SEND_TYPE {
|
||||||
|
@ -82,7 +78,6 @@ enum EVENT_TYPE {
|
||||||
GRID_SELECT_CLIP_ENABLE, // enable selecting a clip from the grid
|
GRID_SELECT_CLIP_ENABLE, // enable selecting a clip from the grid
|
||||||
GRID_SELECT_CLIP_EVENT, // a press / release on the selected clip
|
GRID_SELECT_CLIP_EVENT, // a press / release on the selected clip
|
||||||
GRID_SELECT_NEW_CHOSEN, // a different clip is now "special"
|
GRID_SELECT_NEW_CHOSEN, // a different clip is now "special"
|
||||||
GRID_INIT, // init the cells with references to the looper clips
|
|
||||||
|
|
||||||
/// Track
|
/// Track
|
||||||
TRACK_JACKSEND,
|
TRACK_JACKSEND,
|
||||||
|
@ -132,6 +127,9 @@ enum EVENT_TYPE {
|
||||||
|
|
||||||
// for keeping loop index's inside the enum
|
// for keeping loop index's inside the enum
|
||||||
EVENT_TYPE_FINAL,
|
EVENT_TYPE_FINAL,
|
||||||
|
|
||||||
|
// Clip
|
||||||
|
CLIP_BEATS_CHANGED,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// returns the pretty name of an event
|
/// returns the pretty name of an event
|
||||||
|
@ -604,26 +602,6 @@ public:
|
||||||
EventStateSaveFinish() {};
|
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
|
class EventGridEvent : public EventBase
|
||||||
{
|
{
|
||||||
public:
|
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
|
#endif // LUPPP_EVENT_H
|
||||||
|
|
||||||
|
|
|
@ -171,15 +171,7 @@ void handleDspEvents()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========= GRID =====
|
// ========= 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: {
|
case Event::GRID_STATE: {
|
||||||
if ( availableRead >= sizeof(EventGridState) ) {
|
if ( availableRead >= sizeof(EventGridState) ) {
|
||||||
EventGridState ev;
|
EventGridState ev;
|
||||||
|
@ -484,7 +476,7 @@ void handleDspEvents()
|
||||||
cout << "DSP: Unkown message!! Will clog ringbuffer" << endl;
|
cout << "DSP: Unkown message!! Will clog ringbuffer" << endl;
|
||||||
// just do nothing
|
// just do nothing
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// next call will get the half-written event
|
// next call will get the half-written event
|
||||||
|
|
|
@ -140,13 +140,6 @@ void handleGuiEvents()
|
||||||
//jack->setLooperLoopLength( ev.track, ev.scale );
|
//jack->setLooperLoopLength( ev.track, ev.scale );
|
||||||
} break;
|
} 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: {
|
case Event::LOOPER_PROGRESS: {
|
||||||
if ( availableRead >= sizeof(EventLooperProgress) ) {
|
if ( availableRead >= sizeof(EventLooperProgress) ) {
|
||||||
EventLooperProgress ev;
|
EventLooperProgress ev;
|
||||||
|
@ -286,6 +279,14 @@ void handleGuiEvents()
|
||||||
break;
|
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: {
|
case Event::TRACK_SEND: {
|
||||||
if ( availableRead >= sizeof(EventTrackSend) ) {
|
if ( availableRead >= sizeof(EventTrackSend) ) {
|
||||||
|
@ -297,7 +298,7 @@ void handleGuiEvents()
|
||||||
}
|
}
|
||||||
if ( ev.send == SEND_XSIDE )
|
if ( ev.send == SEND_XSIDE )
|
||||||
if ( ev.track < NTRACKS ) {
|
if ( ev.track < NTRACKS ) {
|
||||||
gui->getTrack(ev.track)->setXSide( ev.value );
|
gui->getTrack(ev.track)->setXSide( ev.value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -43,14 +43,14 @@ public:
|
||||||
void sendVolume(float vol);
|
void sendVolume(float vol);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int m_trackid;
|
||||||
|
AudioProcessor* m_previousProcessor;
|
||||||
bool m_active;
|
bool m_active;
|
||||||
float m_sendvol;
|
float m_sendvol;
|
||||||
jack_port_t* m_sendport_l;
|
jack_port_t* m_sendport_l;
|
||||||
jack_port_t* m_sendport_r;
|
jack_port_t* m_sendport_r;
|
||||||
jack_port_t* m_returnport_l;
|
jack_port_t* m_returnport_l;
|
||||||
jack_port_t* m_returnport_r;
|
jack_port_t* m_returnport_r;
|
||||||
int m_trackid;
|
|
||||||
AudioProcessor* m_previousProcessor;
|
|
||||||
int m_counter;
|
int m_counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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)
|
void Logic::looperUseAsTempo(int t, int s)
|
||||||
{
|
{
|
||||||
size_t clipBeats = jack->getLooper( t )->getClip( s )->getBeats();
|
size_t clipBeats = jack->getLooper( t )->getClip( s )->getBeats();
|
||||||
|
|
|
@ -64,7 +64,6 @@ public:
|
||||||
void looperUseAsTempo(int track, int scene);
|
void looperUseAsTempo(int track, int scene);
|
||||||
void looperClipLenght(int track, int scene, int lenght);
|
void looperClipLenght(int track, int scene, int lenght);
|
||||||
void looperBarsToRecord(int track, int scene, int bars);
|
void looperBarsToRecord(int track, int scene, int bars);
|
||||||
void setupClips(Avtk::ClipState clips[], int clipNum, int t);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LUPPP_LOGIC_H
|
#endif // LUPPP_LOGIC_H
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "looperclip.hxx"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "config.hxx"
|
#include "config.hxx"
|
||||||
#include "jack.hxx"
|
#include "jack.hxx"
|
||||||
|
@ -50,8 +48,9 @@ void LooperClip::init()
|
||||||
|
|
||||||
_queuePlay = false;
|
_queuePlay = false;
|
||||||
_queueStop = false;
|
_queueStop = false;
|
||||||
_queueRecord= false;
|
_queueRecord= false;
|
||||||
_wantedBeats= -0;
|
_wantedBeats= -1;
|
||||||
|
setBeats(0);
|
||||||
|
|
||||||
if ( _buffer ) {
|
if ( _buffer ) {
|
||||||
_buffer->init();
|
_buffer->init();
|
||||||
|
@ -115,6 +114,8 @@ void LooperClip::load( AudioBuffer* ab )
|
||||||
}
|
}
|
||||||
|
|
||||||
_buffer = ab;
|
_buffer = ab;
|
||||||
|
EventClipBeatsChanged e( track, scene, _wantedBeats, true );
|
||||||
|
writeToGuiRingbuffer( &e );
|
||||||
|
|
||||||
_playhead = 0;
|
_playhead = 0;
|
||||||
jack->getControllerUpdater()->setTrackSceneProgress(track, scene, 0 );
|
jack->getControllerUpdater()->setTrackSceneProgress(track, scene, 0 );
|
||||||
|
@ -182,13 +183,15 @@ void LooperClip::setPlayHead(float ph)
|
||||||
{
|
{
|
||||||
if(!_recording&&_playing) {
|
if(!_recording&&_playing) {
|
||||||
_playhead = ph;
|
_playhead = ph;
|
||||||
jack->getControllerUpdater()->setTrackSceneProgress(track, scene, getProgress() );
|
jack->getControllerUpdater()->setTrackSceneProgress( track, scene, getProgress() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LooperClip::setBarsToRecord(int bars)
|
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()
|
int LooperClip::getBeatsToRecord()
|
||||||
|
@ -252,7 +255,11 @@ void LooperClip::setBeats(int beats)
|
||||||
{
|
{
|
||||||
if ( _buffer ) {
|
if ( _buffer ) {
|
||||||
_buffer->setBeats( beats );
|
_buffer->setBeats( beats );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Even on Reset!
|
||||||
|
EventClipBeatsChanged e(track, scene, beats, false);
|
||||||
|
writeToGuiRingbuffer(&e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LooperClip::getBeats()
|
int LooperClip::getBeats()
|
||||||
|
@ -284,10 +291,10 @@ void LooperClip::bar()
|
||||||
GridLogic::State s = GridLogic::STATE_EMPTY;
|
GridLogic::State s = GridLogic::STATE_EMPTY;
|
||||||
|
|
||||||
// first update the buffer, as time has passed
|
// first update the buffer, as time has passed
|
||||||
if ( _recording ) {
|
if ( _recording ) {
|
||||||
// FIXME: assumes 4 beats in a bar
|
// FIXME: assumes 4 beats in a bar
|
||||||
_buffer->setBeats( _buffer->getBeats() + 4 );
|
setBeats( _buffer->getBeats() + 4 );
|
||||||
_buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() );
|
_buffer->setAudioFrames( jack->getTimeManager()->getFpb() * _buffer->getBeats() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _playhead >= _recordhead ) {
|
if ( _playhead >= _recordhead ) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue