mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-06 01:21:38 -05:00
-Refactored metronome
This commit is contained in:
parent
3ab0096371
commit
0b11dd30c8
3 changed files with 89 additions and 67 deletions
82
src/metronome.cxx
Normal file
82
src/metronome.cxx
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
|
||||||
|
#include "metronome.hxx"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "buffers.hxx"
|
||||||
|
|
||||||
|
#include "observer/time.hxx"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Metronome::Metronome() :
|
||||||
|
TimeObserver(),
|
||||||
|
playBar (false),
|
||||||
|
active (false),
|
||||||
|
playPoint (0)
|
||||||
|
{
|
||||||
|
// create beat and bar samples
|
||||||
|
endPoint = (44100.f/441);
|
||||||
|
// samples per cycle of
|
||||||
|
float scale = 2 * 3.1415 / endPoint;
|
||||||
|
|
||||||
|
// And fill it up
|
||||||
|
for(int i=0;i < endPoint*40;i++){
|
||||||
|
beatSample[i]= sin(i*scale);
|
||||||
|
barSample [i]= sin(i*scale*1.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't play after creation
|
||||||
|
playPoint = endPoint + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Metronome::setActive(bool a)
|
||||||
|
{
|
||||||
|
active = a;
|
||||||
|
// don't play immidiatly
|
||||||
|
playPoint = endPoint + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Metronome::bar()
|
||||||
|
{
|
||||||
|
playPoint = 0;
|
||||||
|
playBar = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Metronome::beat()
|
||||||
|
{
|
||||||
|
playPoint = 0;
|
||||||
|
//cout << "Looper " << track << " got beat()" << flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Metronome::setFpb(int f)
|
||||||
|
{
|
||||||
|
fpb = f;
|
||||||
|
|
||||||
|
// disable play until next beat
|
||||||
|
playPoint = endPoint + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Metronome::process(int nframes, Buffers* buffers)
|
||||||
|
{
|
||||||
|
if ( not active )
|
||||||
|
return;
|
||||||
|
|
||||||
|
float* outL = buffers->audio[Buffers::MASTER_OUT_L];
|
||||||
|
float* outR = buffers->audio[Buffers::MASTER_OUT_R];
|
||||||
|
|
||||||
|
float* sample = &beatSample[0];
|
||||||
|
if( playBar ) { sample = &barSample[0]; playBar = false; }
|
||||||
|
|
||||||
|
for(int i = 0; i < nframes; i++)
|
||||||
|
{
|
||||||
|
if ( playPoint < endPoint )
|
||||||
|
{
|
||||||
|
outL[i] += sample[playPoint];
|
||||||
|
outR[i] += sample[playPoint];
|
||||||
|
playPoint++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,79 +11,18 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// simple metronome class
|
|
||||||
class Metronome : public TimeObserver
|
class Metronome : public TimeObserver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Metronome() :
|
Metronome();
|
||||||
TimeObserver(),
|
|
||||||
playBar (false),
|
|
||||||
active (false),
|
|
||||||
playPoint (0)
|
|
||||||
{
|
|
||||||
// create beat and bar samples
|
|
||||||
endPoint = (44100.f/441);
|
|
||||||
// samples per cycle of
|
|
||||||
float scale = 2 * 3.1415 / endPoint;
|
|
||||||
|
|
||||||
// And fill it up
|
void setActive(bool a);
|
||||||
for(int i=0;i < endPoint*40;i++){
|
|
||||||
beatSample[i]= sin(i*scale);
|
|
||||||
barSample [i]= sin(i*scale*1.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't play after creation
|
void bar();
|
||||||
playPoint = endPoint + 1;
|
void beat();
|
||||||
}
|
void setFpb(int f);
|
||||||
|
|
||||||
void setActive(bool a)
|
void process(int nframes, Buffers* buffers);
|
||||||
{
|
|
||||||
active = a;
|
|
||||||
// don't play immidiatly
|
|
||||||
playPoint = endPoint + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bar()
|
|
||||||
{
|
|
||||||
playPoint = 0;
|
|
||||||
playBar = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void beat()
|
|
||||||
{
|
|
||||||
playPoint = 0;
|
|
||||||
//cout << "Looper " << track << " got beat()" << flush;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFpb(int f)
|
|
||||||
{
|
|
||||||
fpb = f;
|
|
||||||
|
|
||||||
// disable play until next beat
|
|
||||||
playPoint = endPoint + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void process(int nframes, Buffers* buffers)
|
|
||||||
{
|
|
||||||
if ( not active )
|
|
||||||
return;
|
|
||||||
|
|
||||||
float* outL = buffers->audio[Buffers::MASTER_OUT_L];
|
|
||||||
float* outR = buffers->audio[Buffers::MASTER_OUT_R];
|
|
||||||
|
|
||||||
float* sample = &beatSample[0];
|
|
||||||
if( playBar ) { sample = &barSample[0]; playBar = false; }
|
|
||||||
|
|
||||||
for(int i = 0; i < nframes; i++)
|
|
||||||
{
|
|
||||||
if ( playPoint < endPoint )
|
|
||||||
{
|
|
||||||
outL[i] += sample[playPoint];
|
|
||||||
outR[i] += sample[playPoint];
|
|
||||||
playPoint++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fpb;
|
int fpb;
|
||||||
|
|
1
wscript
1
wscript
|
@ -28,6 +28,7 @@ def build(bld):
|
||||||
'src/looperclip.cxx',
|
'src/looperclip.cxx',
|
||||||
'src/trackoutput.cxx',
|
'src/trackoutput.cxx',
|
||||||
'src/timemanager.cxx',
|
'src/timemanager.cxx',
|
||||||
|
'src/metronome.cxx',
|
||||||
|
|
||||||
'src/logic.cxx',
|
'src/logic.cxx',
|
||||||
'src/gridlogic.cxx',
|
'src/gridlogic.cxx',
|
||||||
|
|
Loading…
Add table
Reference in a new issue