mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-04 16:51:37 -05:00
-DSP EventsGuiPrint added, updated looper code, metronome queues start tick
This commit is contained in:
parent
238ff21d70
commit
a55800115e
7 changed files with 119 additions and 78 deletions
|
@ -26,6 +26,8 @@ namespace Event
|
|||
LOOPER_LOOP_LENGTH,
|
||||
|
||||
METRONOME_ACTIVE,
|
||||
|
||||
GUI_PRINT,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -133,5 +135,36 @@ class EventMetronomeActive : public EventBase
|
|||
};
|
||||
|
||||
|
||||
// prints the string S in the GUI console
|
||||
class EventGuiPrint : public EventBase
|
||||
{
|
||||
public:
|
||||
int type() { return int(GUI_PRINT); }
|
||||
uint32_t size() { return sizeof(EventGuiPrint); }
|
||||
|
||||
char stringArray[50];
|
||||
|
||||
EventGuiPrint(){}
|
||||
EventGuiPrint(const char* s)
|
||||
{
|
||||
if ( strlen( s ) > 50 )
|
||||
{
|
||||
// this will be called from an RT context, and should be removed from
|
||||
// production code. It is here for the programmer to notice when they
|
||||
// are using code which causes too long a message.
|
||||
cout << "EventGuiPrint() error! Size of string too long!" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// move the sting into this event
|
||||
strcpy( &stringArray[0], s );
|
||||
}
|
||||
}
|
||||
char* getMessage()
|
||||
{
|
||||
return &stringArray[0];
|
||||
}
|
||||
};
|
||||
|
||||
#endif // LUPPP_EVENT_H
|
||||
|
||||
|
|
|
@ -77,6 +77,12 @@ void handleGuiEvents()
|
|||
gui->getTrack(ev.track)->progress.value(ev.progress);
|
||||
//jack->setLooperLoopLength( ev.track, ev.scale );
|
||||
} break; }
|
||||
case Event::GUI_PRINT: {
|
||||
if ( availableRead >= sizeof(EventGuiPrint) ) {
|
||||
EventGuiPrint ev;
|
||||
jack_ringbuffer_read( rbToGui, (char*)&ev, sizeof(EventGuiPrint) );
|
||||
cout << "DSP: " << ev.getMessage() << endl;
|
||||
} break; }
|
||||
default:
|
||||
{
|
||||
cout << "Unkown message!! Will clog ringbuffer" << endl;
|
||||
|
|
|
@ -20,7 +20,7 @@ using namespace std;
|
|||
|
||||
static void gtrack_button_callback(Fl_Widget *w, void *data) {
|
||||
int track = *(int*)data;
|
||||
cout << "Button " << *(int*)data << " " << w->label() << " clicked" << endl;
|
||||
//cout << "Button " << *(int*)data << " " << w->label() << " clicked" << endl;
|
||||
|
||||
if ( strcmp( w->label() , "Rec" ) == 0 )
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ class GTrack : public Fl_Group
|
|||
dial2(x+45, y +155, 24, 24, "B"),
|
||||
dial3(x+75, y +155, 24, 24, "C"),
|
||||
|
||||
progress(x, y, 100, 20, "prog")
|
||||
progress(x+5, y+3, 100, 15, "prog")
|
||||
{
|
||||
ID = privateID++;
|
||||
|
||||
|
|
|
@ -32,14 +32,12 @@ void Looper::process(int nframes, Buffers* buffers)
|
|||
}
|
||||
}
|
||||
|
||||
// update UI
|
||||
EventLooperProgress e(track, float(playPoint) / endPoint );
|
||||
writeToGuiRingbuffer( &e );
|
||||
}
|
||||
|
||||
else if ( state == STATE_RECORDING )
|
||||
{
|
||||
cout << "recording " << endl;
|
||||
for(int i = 0; i < nframes; i++)
|
||||
{
|
||||
if ( lastWrittenSampleIndex < 44100 * 60 )
|
||||
|
@ -49,3 +47,56 @@ void Looper::process(int nframes, Buffers* buffers)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Looper::bar()
|
||||
{
|
||||
// only reset if we're on the last beat of a loop
|
||||
if ( playedBeats >= numBeats )
|
||||
{
|
||||
//cout << "Looper " << track << " restting to 0 " << endl;
|
||||
playPoint = 0;
|
||||
playedBeats = 0;
|
||||
}
|
||||
|
||||
if ( state == STATE_PLAY_QUEUED )
|
||||
{
|
||||
EventGuiPrint e( "Looper Q->Playing" );
|
||||
writeToGuiRingbuffer( &e );
|
||||
state = STATE_PLAYING;
|
||||
playPoint = 0;
|
||||
endPoint = lastWrittenSampleIndex;
|
||||
}
|
||||
if ( state == STATE_RECORD_QUEUED && state != STATE_RECORDING )
|
||||
{
|
||||
EventGuiPrint e( "Looper Q->Recording" );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
state = STATE_RECORDING;
|
||||
playPoint = 0;
|
||||
endPoint = 0;
|
||||
lastWrittenSampleIndex = 0;
|
||||
}
|
||||
if ( state == STATE_PLAY_QUEUED && state != STATE_STOPPED )
|
||||
{
|
||||
EventGuiPrint e( "Looper Q->Stopped" );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
state = STATE_STOPPED;
|
||||
endPoint = lastWrittenSampleIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void Looper::setLoopLength(float l)
|
||||
{
|
||||
numBeats *= l;
|
||||
|
||||
// avoid the 0 * 2 problem
|
||||
if ( numBeats < 1 )
|
||||
numBeats = 1;
|
||||
|
||||
char buffer [50];
|
||||
sprintf (buffer, "Looper loop lenght = %i", numBeats );
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
}
|
||||
|
|
|
@ -29,67 +29,15 @@ class Looper : public Observer // for notifications
|
|||
endPoint (0),
|
||||
playPoint (0),
|
||||
lastWrittenSampleIndex(0)
|
||||
{
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
void bar()
|
||||
{
|
||||
// only reset if we're on the last beat of a loop
|
||||
if ( playedBeats >= numBeats + 1 )
|
||||
{
|
||||
//cout << "Looper " << track << " restting to 0 " << endl;
|
||||
playPoint = 0;
|
||||
playedBeats = 0;
|
||||
}
|
||||
|
||||
if ( state == STATE_PLAY_QUEUED )
|
||||
{
|
||||
cout << " Q->Playing endpoint = " << endPoint << endl;
|
||||
state = STATE_PLAYING;
|
||||
playPoint = 0;
|
||||
endPoint = lastWrittenSampleIndex;
|
||||
}
|
||||
if ( state == STATE_RECORD_QUEUED && state != STATE_RECORDING )
|
||||
{
|
||||
cout << " Q->Recording " << endl;
|
||||
state = STATE_RECORDING;
|
||||
playPoint = 0;
|
||||
endPoint = 0;
|
||||
lastWrittenSampleIndex = 0;
|
||||
}
|
||||
if ( state == STATE_PLAY_QUEUED && state != STATE_STOPPED )
|
||||
{
|
||||
cout << " Q->Stopped " << endl;
|
||||
state = STATE_STOPPED;
|
||||
endPoint = lastWrittenSampleIndex;
|
||||
}
|
||||
}
|
||||
void bar();
|
||||
|
||||
void setLoopLength(float l)
|
||||
{
|
||||
numBeats *= l;
|
||||
|
||||
// avoid the 0 * 2 problem
|
||||
if ( numBeats < 1 )
|
||||
numBeats = 1;
|
||||
|
||||
cout << "Looper " << track << " loop lenght now " << numBeats << endl;
|
||||
}
|
||||
|
||||
void beat()
|
||||
{
|
||||
playedBeats++;
|
||||
//cout << "Looper " << track << " got beat()" << flush;
|
||||
}
|
||||
|
||||
void setFpb(int f)
|
||||
{
|
||||
fpb = f;
|
||||
//cout << "Looper " << track << " got fpb of " << fpb << endl;
|
||||
}
|
||||
void beat() { playedBeats++; }
|
||||
void setFpb(int f) { fpb = f; }
|
||||
|
||||
void setState(State s);
|
||||
void setLoopLength(float l);
|
||||
|
||||
void process(int nframes, Buffers* buffers);
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ class Metronome : public Observer
|
|||
void setActive(bool a)
|
||||
{
|
||||
active = a;
|
||||
// don't play immidiatly
|
||||
playPoint = endPoint + 1;
|
||||
}
|
||||
|
||||
void bar()
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
#define LUPPP_TIME_H
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
#include "buffers.hxx"
|
||||
#include "eventhandler.hxx"
|
||||
|
||||
#include "observer/observer.hxx"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
// inherits from ObserverSubject
|
||||
class TimeManager
|
||||
{
|
||||
|
@ -22,6 +25,13 @@ class TimeManager
|
|||
|
||||
void setBpm(int b)
|
||||
{
|
||||
char buffer [50];
|
||||
sprintf (buffer, "%d", b);
|
||||
//printf ("[%s] is a string %d chars long\n",buffer,n);
|
||||
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
bpm = b;
|
||||
for(uint i = 0; i < observers.size(); i++)
|
||||
{
|
||||
|
@ -32,6 +42,14 @@ class TimeManager
|
|||
void registerObserver(Observer* o)
|
||||
{
|
||||
observers.push_back(o);
|
||||
int fpb = 44100 / bpm * 60;
|
||||
char buffer [50];
|
||||
sprintf (buffer, "TM, bpm = %i, fpb = %i", int(bpm), fpb );
|
||||
EventGuiPrint e( buffer );
|
||||
writeToGuiRingbuffer( &e );
|
||||
|
||||
// triggers newly registered object to have bpm set
|
||||
o->setFpb( fpb );
|
||||
}
|
||||
|
||||
void process(Buffers* buffers)
|
||||
|
@ -80,23 +98,6 @@ class TimeManager
|
|||
int oldBeat;
|
||||
|
||||
std::vector<Observer*> observers;
|
||||
|
||||
// list of Observers of this TimeManager Subject, "beat", "bar" updates?
|
||||
/*
|
||||
for(int i = 0; i < numObservers; i++ )
|
||||
{
|
||||
observers[i]->notifyNewBeat(int beat);
|
||||
}
|
||||
|
||||
if ( bar != oldBar )
|
||||
{
|
||||
for(int i = 0; i < numObservers; i++ )
|
||||
{
|
||||
observers[i]->notifyNewBar(int bar);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
#endif // LUPPP_TIME_H
|
||||
|
|
Loading…
Add table
Reference in a new issue