-Implementing TimeManager class, using Observer pattern for updates
This commit is contained in:
parent
24bf134736
commit
7061eaa173
4 changed files with 93 additions and 9 deletions
|
@ -2,6 +2,8 @@
|
|||
#ifndef LUPPP_BUFFERS_H
|
||||
#define LUPPP_BUFFERS_H
|
||||
|
||||
#include <jack/transport.h>
|
||||
|
||||
class Buffers
|
||||
{
|
||||
public:
|
||||
|
@ -15,6 +17,15 @@ class Buffers
|
|||
MASTER_OUTPUT = 0,
|
||||
MASTER_INPUT,
|
||||
};
|
||||
|
||||
// Jack details
|
||||
jack_nframes_t nframes;
|
||||
jack_nframes_t samplerate;
|
||||
|
||||
jack_nframes_t transportFrame;
|
||||
jack_position_t transportPosition;
|
||||
jack_transport_state_t transportState;
|
||||
|
||||
};
|
||||
|
||||
#endif // LUPPP_BUFFERS_H
|
||||
|
|
35
src/jack.cxx
35
src/jack.cxx
|
@ -17,8 +17,8 @@ Jack::Jack()
|
|||
// open the client
|
||||
client = jack_client_open ( "Luppp", JackNullOption , 0 , 0 );
|
||||
|
||||
nframes = jack_get_buffer_size( client );
|
||||
samplerate = jack_get_sample_rate( client );
|
||||
buffers.nframes = jack_get_buffer_size( client );
|
||||
buffers.samplerate = jack_get_sample_rate( client );
|
||||
|
||||
masterOutput = jack_port_register( client,
|
||||
"master_out",
|
||||
|
@ -33,12 +33,21 @@ Jack::Jack()
|
|||
0 );
|
||||
|
||||
if ( jack_set_process_callback( client,
|
||||
static_process,
|
||||
static_cast<void*>(this)) )
|
||||
static_process,
|
||||
static_cast<void*>(this)) )
|
||||
{
|
||||
cerr << "Jack() error setting process callback" << endl;
|
||||
}
|
||||
|
||||
if ( jack_set_timebase_callback(client,
|
||||
0,
|
||||
(JackTimebaseCallback)static_timebase,
|
||||
static_cast<void*>(this)) )
|
||||
{
|
||||
cerr << "Jack() error setting timebase callback" << endl;
|
||||
}
|
||||
|
||||
|
||||
loopers.push_back( new Looper() );
|
||||
}
|
||||
|
||||
|
@ -61,6 +70,7 @@ int Jack::process (jack_nframes_t nframes)
|
|||
// pre-zero output buffers
|
||||
memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes );
|
||||
|
||||
|
||||
loopers.at(0)->process(nframes, &buffers );
|
||||
|
||||
/*
|
||||
|
@ -86,11 +96,19 @@ int Jack::getSamplerate()
|
|||
return jack_get_sample_rate( client );
|
||||
}
|
||||
|
||||
int Jack::timebase(jack_transport_state_t,
|
||||
jack_nframes_t,
|
||||
jack_position_t*,
|
||||
int)
|
||||
int Jack::timebase(jack_transport_state_t state,
|
||||
jack_nframes_t nframes,
|
||||
jack_position_t* pos,
|
||||
int newPos)
|
||||
{
|
||||
// fill buffers with data, then pass to timeManager
|
||||
buffers.transportFrame = jack_get_current_transport_frame(client);
|
||||
buffers.transportPosition = *pos;
|
||||
buffers.transportState = state;
|
||||
|
||||
// update "time" from JACK master, or write master?
|
||||
timeManager.process( &buffers );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -107,4 +125,3 @@ int Jack::static_timebase(jack_transport_state_t state,
|
|||
{
|
||||
return static_cast<Jack*>(instance)->timebase(state,nframes, pos, newPos );
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
#include <cstring>
|
||||
#include <jack/jack.h>
|
||||
#include <jack/midiport.h>
|
||||
#include <jack/transport.h>
|
||||
|
||||
#include "looper.hxx"
|
||||
#include "timemanager.hxx"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -36,6 +38,7 @@ class Jack
|
|||
|
||||
private:
|
||||
Buffers buffers;
|
||||
TimeManager timeManager;
|
||||
|
||||
vector<Looper*> loopers;
|
||||
|
||||
|
|
53
src/timemanager.hxx
Normal file
53
src/timemanager.hxx
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
#ifndef LUPPP_TIME_H
|
||||
#define LUPPP_TIME_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "buffers.hxx"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// inherits from ObserverSubject
|
||||
class TimeManager
|
||||
{
|
||||
public:
|
||||
TimeManager()
|
||||
{
|
||||
}
|
||||
|
||||
void process(Buffers* buffers)
|
||||
{
|
||||
float bpm = 120;
|
||||
int framesPerBeat = (int) samplerate / (bpm / 60.0);
|
||||
|
||||
// divide by zero errors!
|
||||
if ( framesPerBeat > 0 )
|
||||
{
|
||||
int newBeat = buffers->transportFrame / framesPerBeat;
|
||||
}
|
||||
//cout << buffers->transportPosition.frame << endl;
|
||||
}
|
||||
|
||||
private:
|
||||
int samplerate;
|
||||
|
||||
// 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…
Reference in a new issue