mirror of
https://github.com/vale981/openAV-Luppp
synced 2025-03-05 09:01:39 -05:00
-Initial APC feedback working
This commit is contained in:
parent
370815e7aa
commit
39d6c6e60f
4 changed files with 30 additions and 28 deletions
|
@ -13,7 +13,7 @@ class Buffers
|
||||||
memset( audio, 0, sizeof(float*)*2);
|
memset( audio, 0, sizeof(float*)*2);
|
||||||
}
|
}
|
||||||
float* audio[32];
|
float* audio[32];
|
||||||
unsigned char* midi [32];
|
void* midi [32];
|
||||||
|
|
||||||
enum BUFFER {
|
enum BUFFER {
|
||||||
MASTER_OUTPUT = 0,
|
MASTER_OUTPUT = 0,
|
||||||
|
|
32
src/jack.cxx
32
src/jack.cxx
|
@ -85,23 +85,25 @@ void Jack::activate()
|
||||||
|
|
||||||
int Jack::process (jack_nframes_t nframes)
|
int Jack::process (jack_nframes_t nframes)
|
||||||
{
|
{
|
||||||
// do events from the ringbuffer
|
|
||||||
handleDspEvents();
|
|
||||||
|
|
||||||
// get buffers
|
// get buffers
|
||||||
buffers.audio[Buffers::MASTER_INPUT] = (float*)jack_port_get_buffer( masterInput , nframes);
|
buffers.audio[Buffers::MASTER_INPUT] = (float*)jack_port_get_buffer( masterInput , nframes);
|
||||||
buffers.audio[Buffers::MASTER_OUTPUT] = (float*)jack_port_get_buffer( masterOutput, nframes);
|
buffers.audio[Buffers::MASTER_OUTPUT] = (float*)jack_port_get_buffer( masterOutput, nframes);
|
||||||
buffers.midi[Buffers::MASTER_MIDI_INPUT]= (unsigned char*) jack_port_get_buffer( masterMidiInput, nframes );
|
buffers.midi[Buffers::MASTER_MIDI_INPUT]= (void*) jack_port_get_buffer( masterMidiInput, nframes );
|
||||||
buffers.midi[Buffers::APC_INPUT] = (unsigned char*) jack_port_get_buffer( apcMidiInput , nframes );
|
buffers.midi[Buffers::APC_INPUT] = (void*) jack_port_get_buffer( apcMidiInput , nframes );
|
||||||
buffers.midi[Buffers::APC_OUTPUT] = (unsigned char*) jack_port_get_buffer( apcMidiOutput , nframes );
|
buffers.midi[Buffers::APC_OUTPUT] = (void*) jack_port_get_buffer( apcMidiOutput , nframes );
|
||||||
|
|
||||||
// pre-zero output buffers
|
// pre-zero output buffers
|
||||||
memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes );
|
memset( buffers.audio[Buffers::MASTER_OUTPUT], 0, sizeof(float) * nframes );
|
||||||
jack_midi_clear_buffer( buffers.midi[Buffers::APC_OUTPUT] );
|
jack_midi_clear_buffer( buffers.midi[Buffers::APC_OUTPUT] );
|
||||||
|
|
||||||
|
|
||||||
|
// do events from the ringbuffer
|
||||||
|
handleDspEvents();
|
||||||
|
|
||||||
// process incoming MIDI
|
// process incoming MIDI
|
||||||
jack_midi_event_t in_event;
|
jack_midi_event_t in_event;
|
||||||
|
|
||||||
|
|
||||||
int masterMidiInputIndex = 0;
|
int masterMidiInputIndex = 0;
|
||||||
int event_count = (int) jack_midi_get_event_count( buffers.midi[Buffers::MASTER_MIDI_INPUT] );
|
int event_count = (int) jack_midi_get_event_count( buffers.midi[Buffers::MASTER_MIDI_INPUT] );
|
||||||
|
|
||||||
|
@ -109,7 +111,7 @@ int Jack::process (jack_nframes_t nframes)
|
||||||
{
|
{
|
||||||
jack_midi_event_get(&in_event, buffers.midi[Buffers::MASTER_MIDI_INPUT], masterMidiInputIndex);
|
jack_midi_event_get(&in_event, buffers.midi[Buffers::MASTER_MIDI_INPUT], masterMidiInputIndex);
|
||||||
|
|
||||||
cout << int(in_event.buffer[0]) << int(in_event.buffer[1]) << int(in_event.buffer[2]) << endl;
|
cout << "Frame: " << in_event.time << " " << int(in_event.buffer[0]) << " " << int(in_event.buffer[1]) << " " << int(in_event.buffer[2]) << endl;
|
||||||
|
|
||||||
// check each looper for MIDI match
|
// check each looper for MIDI match
|
||||||
for(int i = 0; i < loopers.size(); i++)
|
for(int i = 0; i < loopers.size(); i++)
|
||||||
|
@ -121,18 +123,7 @@ int Jack::process (jack_nframes_t nframes)
|
||||||
for(uint i = 0; i < loopers.size(); i++)
|
for(uint i = 0; i < loopers.size(); i++)
|
||||||
loopers.at(i)->process( nframes, &buffers );
|
loopers.at(i)->process( nframes, &buffers );
|
||||||
|
|
||||||
if (true)
|
metronome.process( nframes, &buffers );
|
||||||
metronome.process( nframes, &buffers );
|
|
||||||
|
|
||||||
/*
|
|
||||||
float* input = buffers.audio[Buffers::MASTER_INPUT];
|
|
||||||
float* output = buffers.audio[Buffers::MASTER_OUTPUT];
|
|
||||||
|
|
||||||
for(uint i = 0; i < nframes; i++)
|
|
||||||
{
|
|
||||||
*output++ = *input++;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -152,9 +143,10 @@ void Jack::writeApcOutput( unsigned char* data )
|
||||||
void* apcOutput = buffers.midi[Buffers::APC_OUTPUT];
|
void* apcOutput = buffers.midi[Buffers::APC_OUTPUT];
|
||||||
|
|
||||||
unsigned char* buf = jack_midi_event_reserve( apcOutput, 0, 3);
|
unsigned char* buf = jack_midi_event_reserve( apcOutput, 0, 3);
|
||||||
if( buf )
|
if( buf != 0 )
|
||||||
{
|
{
|
||||||
memcpy( buf, data, sizeof( unsigned char ) * 3);
|
memcpy( buf, data, sizeof( unsigned char ) * 3);
|
||||||
|
cout << "writeApcOutput " << int(buf[0]) << ", " << int(buf[1]) << ", " << int(buf[2]) << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,8 @@ extern Jack* jack;
|
||||||
Looper::Looper(int t) :
|
Looper::Looper(int t) :
|
||||||
track(t),
|
track(t),
|
||||||
state(STATE_STOPPED),
|
state(STATE_STOPPED),
|
||||||
|
fpb(120),
|
||||||
|
gain(1.f),
|
||||||
numBeats (4),
|
numBeats (4),
|
||||||
playedBeats(0),
|
playedBeats(0),
|
||||||
stopRecordOnBar(false),
|
stopRecordOnBar(false),
|
||||||
|
@ -55,6 +57,13 @@ void Looper::midi(unsigned char* data)
|
||||||
case 48: setState( STATE_STOP_QUEUED );
|
case 48: setState( STATE_STOP_QUEUED );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( data[0] - 176 == track )
|
||||||
|
{
|
||||||
|
switch ( data[1] )
|
||||||
|
{
|
||||||
|
case 7: gain = int(data[2])/127.f; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,11 +81,10 @@ void Looper::setState(State s)
|
||||||
{
|
{
|
||||||
numBeats = 0;
|
numBeats = 0;
|
||||||
unsigned char data[3];
|
unsigned char data[3];
|
||||||
data[0] == 144 + track;
|
data[0] = 144 + track;
|
||||||
data[1] == 48; // record LED
|
data[1] = 48; // record LED
|
||||||
data[2] == 127;
|
data[2] = 127;
|
||||||
jack->writeApcOutput( &data[0] );
|
jack->writeApcOutput( &data[0] );
|
||||||
cout << "wrote to APC" << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,15 +115,14 @@ void Looper::process(int nframes, Buffers* buffers)
|
||||||
{
|
{
|
||||||
if ( playPoint < endPoint )
|
if ( playPoint < endPoint )
|
||||||
{
|
{
|
||||||
tmpBuffer[i] = sample[playPoint];
|
tmpBuffer[i] = sample[playPoint] * gain;
|
||||||
}
|
}
|
||||||
// always update playPoint, even when not playing sound.
|
// always update playPoint, even when not playing sound.
|
||||||
// it updates the UI of progress
|
// it updates the UI of progress
|
||||||
playPoint++;
|
playPoint++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now pitch-shift the audio in the buffer
|
||||||
// not pitch-shift the audio in the buffer
|
|
||||||
pitchShift( nframes, &tmpBuffer[0], out);
|
pitchShift( nframes, &tmpBuffer[0], out);
|
||||||
|
|
||||||
float prog = (float(playPoint) / (fpb*numBeats));
|
float prog = (float(playPoint) / (fpb*numBeats));
|
||||||
|
@ -228,12 +235,14 @@ void Looper::pitchShift(int count, float* input, float* output)
|
||||||
float fTemp3 = min((fSlow2 * fRec0[0]), 1.f );
|
float fTemp3 = min((fSlow2 * fRec0[0]), 1.f );
|
||||||
float fTemp4 = (fSlow0 + fRec0[0]);
|
float fTemp4 = (fSlow0 + fRec0[0]);
|
||||||
int iTemp5 = int(fTemp4);
|
int iTemp5 = int(fTemp4);
|
||||||
|
|
||||||
output0[i] += (float)(((1 - fTemp3) * (((fTemp4 - iTemp5) *
|
output0[i] += (float)(((1 - fTemp3) * (((fTemp4 - iTemp5) *
|
||||||
fVec0[(IOTA-int((int((1 + iTemp5)) & 65535)))&65535]) + ((0 - ((
|
fVec0[(IOTA-int((int((1 + iTemp5)) & 65535)))&65535]) + ((0 - ((
|
||||||
fRec0[0] + fSlow3) - iTemp5)) * fVec0[(IOTA-int((iTemp5 & 65535)))
|
fRec0[0] + fSlow3) - iTemp5)) * fVec0[(IOTA-int((iTemp5 & 65535)))
|
||||||
&65535]))) + (fTemp3 * (((fRec0[0] - iTemp1) * fVec0[(IOTA-int((int(
|
&65535]))) + (fTemp3 * (((fRec0[0] - iTemp1) * fVec0[(IOTA-int((int(
|
||||||
iTemp2) & 65535)))&65535]) + ((iTemp2 - fRec0[0]) * fVec0[(IOTA-int((
|
iTemp2) & 65535)))&65535]) + ((iTemp2 - fRec0[0]) * fVec0[(IOTA-int((
|
||||||
iTemp1 & 65535)))&65535]))));
|
iTemp1 & 65535)))&65535]))));
|
||||||
|
|
||||||
fRec0[1] = fRec0[0];
|
fRec0[1] = fRec0[0];
|
||||||
IOTA = IOTA+1;
|
IOTA = IOTA+1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ class Looper : public Observer // for notifications
|
||||||
State state;
|
State state;
|
||||||
|
|
||||||
int fpb;
|
int fpb;
|
||||||
|
float gain;
|
||||||
int numBeats;
|
int numBeats;
|
||||||
int playedBeats;
|
int playedBeats;
|
||||||
bool stopRecordOnBar;
|
bool stopRecordOnBar;
|
||||||
|
|
Loading…
Add table
Reference in a new issue