SomE WHITESPACE

This commit is contained in:
Valentin Boettcher 2018-04-10 08:36:37 +02:00
parent bbaa7554cd
commit 69db656239
3 changed files with 175 additions and 182 deletions

View file

@ -104,7 +104,7 @@ double getCairoTextWith(cairo_t * cr, const char * str)
return ex.width; return ex.width;
} }
void trimToFit(cairo_t * cr, std::string * str, double maxWidth) void trimStringToFit(cairo_t * cr, std::string * str, double maxWidth)
{ {
double ellWidth = getCairoTextWith(cr, ""); double ellWidth = getCairoTextWith(cr, "");
double textWidth = getCairoTextWith(cr, str->c_str()); double textWidth = getCairoTextWith(cr, str->c_str());
@ -253,7 +253,7 @@ void ClipSelector::draw()
cairo_set_font_size( cr, 11 ); cairo_set_font_size( cr, 11 );
std::string tmp = clips[i].getName(); std::string tmp = clips[i].getName();
trimToFit(cr, &tmp, clipWidth - (clipHeight + 15 + beatLen)); trimStringToFit(cr, &tmp, clipWidth - (clipHeight + 15 + beatLen));
cairo_show_text( cr, tmp.c_str() ); cairo_show_text( cr, tmp.c_str() );
// special indicator // special indicator
@ -285,24 +285,24 @@ void ClipSelector::resize(int X, int Y, int W, int H)
void setRecordBarsCb(Fl_Widget *w, void* data) void setRecordBarsCb(Fl_Widget *w, void* data)
{ {
if(!w || !data) if(!w || !data)
return; return;
ClipSelector *track = (ClipSelector*)w; ClipSelector *track = (ClipSelector*)w;
long bars = (long)data; long bars = (long)data;
if(bars == -2) { if(bars == -2) {
const char* answer = fl_input("Enter a custom number: "); const char* answer = fl_input("Enter a custom number: ");
if(!answer) { if(!answer) {
bars = -1; bars = -1;
fl_message("Please enter value between 1 and %i.", MAX_BARS); fl_message("Please enter value between 1 and %i.", MAX_BARS);
} else } else
bars = atoi(answer); bars = atoi(answer);
} }
if(bars > MAX_BARS) { if(bars > MAX_BARS) {
bars = -1; bars = -1;
fl_message("Please enter value between 1 and %i.", MAX_BARS); fl_message("Please enter value between 1 and %i.", MAX_BARS);
} }
EventLooperBarsToRecord e(track->ID, track->getLastClipNum(), bars); EventLooperBarsToRecord e(track->ID, track->getLastClipNum(), bars);
writeToDspRingbuffer( &e ); writeToDspRingbuffer( &e );
@ -316,16 +316,6 @@ void setLengthCb(Fl_Widget *w, void* data)
writeToDspRingbuffer( &e ); writeToDspRingbuffer( &e );
} }
int ClipSelector::findClipNum() {
// calculate the clicked clip number
int clipHeight = (h / numClips);
clipNum = ( (Fl::event_y() ) - y ) / clipHeight;
if (clipNum >= numClips)
clipNum = numClips -1; // fix for clicking the lowest pixel
return clipNum;
}
int ClipSelector::getLastClipNum() int ClipSelector::getLastClipNum()
{ {
return clipNum; return clipNum;
@ -342,7 +332,13 @@ int ClipSelector::handle(int event)
case FL_PUSH: case FL_PUSH:
highlight = 1; highlight = 1;
{ {
findClipNum(); // calculate the clicked clip number
int clipHeight = (h / numClips);
clipNum = ( (Fl::event_y() ) - y ) / clipHeight;
if (clipNum >= numClips)
clipNum = numClips -1; // fix for clicking the lowest pixel
return clipNum;
// handle right clicks: popup menu // handle right clicks: popup menu
if ( Fl::event_state(FL_BUTTON3) ) { if ( Fl::event_state(FL_BUTTON3) ) {
@ -362,7 +358,7 @@ int ClipSelector::handle(int event)
{ "Load" }, { "Load" },
{ "Save" }, { "Save" },
{ "Special"}, { "Special"},
{ "Beats", 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER }, { "Beats", 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER },
RECORD_LENGTH_MENU_ITEM(1), RECORD_LENGTH_MENU_ITEM(1),
RECORD_LENGTH_MENU_ITEM(2), RECORD_LENGTH_MENU_ITEM(2),
RECORD_LENGTH_MENU_ITEM(4), RECORD_LENGTH_MENU_ITEM(4),
@ -371,15 +367,15 @@ int ClipSelector::handle(int event)
RECORD_LENGTH_MENU_ITEM(32), RECORD_LENGTH_MENU_ITEM(32),
RECORD_LENGTH_MENU_ITEM(64), RECORD_LENGTH_MENU_ITEM(64),
{0}, {0},
{ "Bars to record", 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER}, { "Bars to record", 0, 0, 0, FL_SUBMENU | FL_MENU_DIVIDER},
RECORD_BARS_MENU_ITEM(1), RECORD_BARS_MENU_ITEM(1),
RECORD_BARS_MENU_ITEM(2), RECORD_BARS_MENU_ITEM(2),
RECORD_BARS_MENU_ITEM(4), RECORD_BARS_MENU_ITEM(4),
RECORD_BARS_MENU_ITEM(6), RECORD_BARS_MENU_ITEM(6),
RECORD_BARS_MENU_ITEM(8), RECORD_BARS_MENU_ITEM(8),
{"Endless", 0, setRecordBarsCb, (void*)-1, FL_MENU_DIVIDER | FL_MENU_RADIO | ((clips[clipNum].getBeatsToRecord() <= 0) ? FL_MENU_VALUE : 0) | (empty ? 0 : FL_MENU_INACTIVE)}, {"Endless", 0, setRecordBarsCb, (void*)-1, FL_MENU_DIVIDER | FL_MENU_RADIO | ((clips[clipNum].getBeatsToRecord() <= 0) ? FL_MENU_VALUE : 0) | (empty ? 0 : FL_MENU_INACTIVE)},
{"Custom", 0, setRecordBarsCb, (void*)-2, empty ? 0 : FL_MENU_INACTIVE}, {"Custom", 0, setRecordBarsCb, (void*)-2, empty ? 0 : FL_MENU_INACTIVE},
{0}, {0},
//{ "Record" }, //{ "Record" },
{ "Use as tempo" }, { "Use as tempo" },
{ "Rename", 0, 0, 0, FL_MENU_DIVIDER}, { "Rename", 0, 0, 0, FL_MENU_DIVIDER},
@ -472,18 +468,18 @@ int ClipSelector::handle(int event)
void ClipState::setBeats(int numBeats, bool isBeatsToRecord) void ClipState::setBeats(int numBeats, bool isBeatsToRecord)
{ {
if(numBeats > 0) { if(numBeats > 0) {
beatsText = std::to_string(numBeats); beatsText = std::to_string(numBeats);
barsText = std::to_string(numBeats/4); barsText = std::to_string(numBeats/4);
if(isBeatsToRecord){ if(isBeatsToRecord){
beatsToRecord = numBeats; beatsToRecord = numBeats;
beats = 0; beats = 0;
} else { } else {
beats = numBeats; beats = numBeats;
if(numBeats <= 0) if(numBeats <= 0)
beatsToRecord = -1; beatsToRecord = -1;
} }
} }
else else
barsText = beatsText = std::string(""); barsText = beatsText = std::string("");
} }
} // Avtk } // Avtk

View file

@ -69,28 +69,28 @@ public:
return beatsToRecord; return beatsToRecord;
} }
int getBeats(){ int getBeats(){
return beats; return beats;
} }
void setBeats(int numBeats, bool isBeatsToRecord); void setBeats(int numBeats, bool isBeatsToRecord);
const char *getBeatsText() { const char *getBeatsText() {
return beatsText.c_str(); return beatsText.c_str();
} }
const char *getBarsText() { const char *getBarsText() {
return barsText.c_str(); return barsText.c_str();
} }
private: private:
GridLogic::State state; GridLogic::State state;
std::string name; std::string name;
std::string beatsText; std::string beatsText;
std::string barsText; std::string barsText;
int beatsToRecord = -1; int beatsToRecord = -1;
int beats = 0; int beats = 0;
}; };
class ClipSelector : public Fl_Button class ClipSelector : public Fl_Button
@ -129,13 +129,11 @@ public:
int handle(int event); int handle(int event);
void resize(int X, int Y, int W, int H); void resize(int X, int Y, int W, int H);
int findClipNum();
int getLastClipNum(); int getLastClipNum();
private: private:
int clipNum; int clipNum;
}; };
} // Avtk } // Avtk
#endif // AVTK_CLIP_SELECTOR_H #endif // AVTK_CLIP_SELECTOR_H

View file

@ -31,181 +31,180 @@
extern Jack* jack; extern Jack* jack;
Looper::Looper(int t) : Looper::Looper(int t) :
AudioProcessor(), AudioProcessor(),
TimeObserver(), TimeObserver(),
track(t) track(t)
{ {
uiUpdateConstant= jack->getSamplerate() / 30.f; uiUpdateConstant= jack->getSamplerate() / 30.f;
uiUpdateCounter = jack->getSamplerate() / 30.f; uiUpdateCounter = jack->getSamplerate() / 30.f;
// pre-zero the internal sample // pre-zero the internal sample
//tmpRecordBuffer = (float*)malloc( sizeof(float) * MAX_BUFFER_SIZE ); //tmpRecordBuffer = (float*)malloc( sizeof(float) * MAX_BUFFER_SIZE );
//memset( tmpRecordBuffer, 0, sizeof(float) * MAX_BUFFER_SIZE ); //memset( tmpRecordBuffer, 0, sizeof(float) * MAX_BUFFER_SIZE );
for(int i = 0; i < NSCENES; i++ ) { for(int i = 0; i < NSCENES; i++ ) {
clips[i] = new LooperClip(track, i); clips[i] = new LooperClip(track, i);
} }
tmpBuffer.resize( MAX_BUFFER_SIZE ); tmpBuffer.resize( MAX_BUFFER_SIZE );
fpb = 22050; fpb = 22050;
// init faust pitch shift variables // init faust pitch shift variables
fSamplingFreq = jack->getSamplerate(); fSamplingFreq = jack->getSamplerate();
IOTA = 0; IOTA = 0;
//tmpRecordBuffer.resize(MAX_BUFFER_SIZE); //tmpRecordBuffer.resize(MAX_BUFFER_SIZE);
for (int i=0; i<65536; i++) for (int i=0; i<65536; i++)
fVec0[i] = 0; fVec0[i] = 0;
for (int i=0; i<2; i++) for (int i=0; i<2; i++)
fRec0[i] = 0; fRec0[i] = 0;
semitoneShift = 0.0f; semitoneShift = 0.0f;
windowSize = 1000; windowSize = 1000;
crossfadeSize = 1000; crossfadeSize = 1000;
} }
LooperClip* Looper::getClip(int scene) LooperClip* Looper::getClip(int scene)
{ {
return clips[scene]; return clips[scene];
} }
void Looper::beat() void Looper::beat()
{ {
//TODO needed? //TODO needed?
//FIXME: Need to keep looperClips in sync when there exists no int N //FIXME: Need to keep looperClips in sync when there exists no int N
// such that playSpeed*N==1 // such that playSpeed*N==1
// for(int i=0;i<NSCENES;i++) // for(int i=0;i<NSCENES;i++)
// { // {
// int iph=clips[i]->getPlayhead()+1.0; // int iph=clips[i]->getPlayhead()+1.0;
// long targetFrames = clips[i]->getBeats() * fpb; // long targetFrames = clips[i]->getBeats() * fpb;
// long actualFrames = clips[i]->getActualAudioLength();//getBufferLenght(); // long actualFrames = clips[i]->getActualAudioLength();//getBufferLenght();
// float playSpeed = 1.0; // float playSpeed = 1.0;
// if ( targetFrames != 0 && actualFrames != 0 ) // if ( targetFrames != 0 && actualFrames != 0 )
// { // {
// playSpeed = float(actualFrames) / targetFrames; // playSpeed = float(actualFrames) / targetFrames;
// } // }
// clips[i]->setPlayHead(iph-(iph%fpb)*playSpeed); // clips[i]->setPlayHead(iph-(iph%fpb)*playSpeed);
// } // }
} }
void Looper::setRequestedBuffer(int s, AudioBuffer* ab) void Looper::setRequestedBuffer(int s, AudioBuffer* ab)
{ {
clips[s]->setRequestedBuffer( ab ); clips[s]->setRequestedBuffer( ab );
} }
void Looper::setFpb(int f) void Looper::setFpb(int f)
{ {
fpb = f; fpb = f;
} }
void Looper::process(unsigned int nframes, Buffers* buffers) void Looper::process(unsigned int nframes, Buffers* buffers)
{ {
// process each clip individually: this allows for playback of one clip, // process each clip individually: this allows for playback of one clip,
// while another clip records. // while another clip records.
for ( int clip = 0; clip < NSCENES; clip++ ) { for ( int clip = 0; clip < NSCENES; clip++ ) {
// handle state of clip, and do what needs doing: // handle state of clip, and do what needs doing:
// record into buffer, play from buffer, etc // record into buffer, play from buffer, etc
if ( clips[clip]->recording() ) { if ( clips[clip]->recording() ) {
if(clips[clip]->getBeatsToRecord() > 0 && clips[clip]->getBeats() >= clips[clip]->getBeatsToRecord() - 4) if(clips[clip]->getBeatsToRecord() > 0 && clips[clip]->getBeats() >= clips[clip]->getBeatsToRecord() - 4)
clips[clip]->queuePlay(true); clips[clip]->queuePlay(true);
if ( clips[clip]->recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST && if ( clips[clip]->recordSpaceAvailable() < LOOPER_SAMPLES_BEFORE_REQUEST &&
!clips[clip]->newBufferInTransit() ) { !clips[clip]->newBufferInTransit() ) {
EventLooperClipRequestBuffer e( track, clip, clips[clip]->audioBufferSize() + LOOPER_SAMPLES_UPDATE_SIZE); EventLooperClipRequestBuffer e( track, clip, clips[clip]->audioBufferSize() + LOOPER_SAMPLES_UPDATE_SIZE);
writeToGuiRingbuffer( &e ); writeToGuiRingbuffer( &e );
clips[clip]->newBufferInTransit(true); clips[clip]->newBufferInTransit(true);
} }
// copy data from input buffer to recording buffer // copy data from input buffer to recording buffer
float* inputL = buffers->audio[Buffers::MASTER_INPUT_L]; float* inputL = buffers->audio[Buffers::MASTER_INPUT_L];
float* inputR = buffers->audio[Buffers::MASTER_INPUT_R]; float* inputR = buffers->audio[Buffers::MASTER_INPUT_R];
clips[clip]->record( nframes, inputL, inputR); clips[clip]->record( nframes, inputL, inputR);
} else if ( clips[clip]->playing() ) { } else if ( clips[clip]->playing() ) {
// copy data into tmpBuffer, then pitch-stretch into track buffer // copy data into tmpBuffer, then pitch-stretch into track buffer
long targetFrames = clips[clip]->getBeats() * fpb; long targetFrames = clips[clip]->getBeats() * fpb;
long actualFrames = clips[clip]->getActualAudioLength();//getBufferLenght(); long actualFrames = clips[clip]->getActualAudioLength();//getBufferLenght();
float playSpeed = 1.0; float playSpeed = 1.0;
if ( targetFrames != 0 && actualFrames != 0 ) { if ( targetFrames != 0 && actualFrames != 0 ) {
playSpeed = float(actualFrames) / targetFrames; playSpeed = float(actualFrames) / targetFrames;
} }
float* outL = buffers->audio[Buffers::SEND_TRACK_0_L + track]; float* outL = buffers->audio[Buffers::SEND_TRACK_0_L + track];
float* outR = buffers->audio[Buffers::SEND_TRACK_0_R + track]; float* outR = buffers->audio[Buffers::SEND_TRACK_0_R + track];
for(unsigned int i = 0; i < nframes; i++ ) { for(unsigned int i = 0; i < nframes; i++ ) {
// REFACTOR into system that is better than per sample function calls // REFACTOR into system that is better than per sample function calls
float tmpL = 0; float tmpL = 0;
float tmpR = 0; float tmpR = 0;
clips[clip]->getSample(playSpeed, &tmpL, &tmpR); clips[clip]->getSample(playSpeed, &tmpL, &tmpR);
float deltaPitch = 12 * log ( playSpeed ) / log (2); float deltaPitch = 12 * log ( playSpeed ) / log (2);
semitoneShift = -deltaPitch; semitoneShift = -deltaPitch;
// write the pitch-shifted signal to the track buffer // write the pitch-shifted signal to the track buffer
//FIXME: pitchShift adds delay even for playSpeed = 1.0!! //FIXME: pitchShift adds delay even for playSpeed = 1.0!!
//we should use something better (e.g librubberband) //we should use something better (e.g librubberband)
if(0) { //playSpeed!=1.0f) { if(0) { //playSpeed!=1.0f) {
pitchShift( 1, &tmpL, &outL[i] ); pitchShift( 1, &tmpL, &outL[i] );
pitchShift( 1, &tmpR, &outR[i] ); pitchShift( 1, &tmpR, &outR[i] );
} else { } else {
outL[i]+=tmpL; outL[i]+=tmpL;
outR[i]+=tmpR; outR[i]+=tmpR;
} }
} }
//printf("Looper %i playing(), speed = %f\n", track, playSpeed ); //printf("Looper %i playing(), speed = %f\n", track, playSpeed );
if ( uiUpdateCounter > uiUpdateConstant ) { if ( uiUpdateCounter > uiUpdateConstant ) {
jack->getControllerUpdater()->setTrackSceneProgress(track, clip, clips[clip]->getProgress() ); jack->getControllerUpdater()->setTrackSceneProgress(track, clip, clips[clip]->getProgress() );
uiUpdateCounter = 0; uiUpdateCounter = 0;
} }
uiUpdateCounter += nframes; uiUpdateCounter += nframes;
} }
} }
} }
void Looper::resetTimeState() void Looper::resetTimeState()
{ {
for(int i=0; i<NSCENES; i++) for(int i=0; i<NSCENES; i++)
clips[i]->setPlayHead(0.0); clips[i]->setPlayHead(0.0);
} }
void Looper::pitchShift(int count, float* input, float* output) void Looper::pitchShift(int count, float* input, float* output)
{ {
float fSlow0 = windowSize; float fSlow0 = windowSize;
float fSlow1 = ((1 + fSlow0) - powf(2,(0.08333333333333333f * semitoneShift))); float fSlow1 = ((1 + fSlow0) - powf(2,(0.08333333333333333f * semitoneShift)));
float fSlow2 = (1.0f / crossfadeSize); float fSlow2 = (1.0f / crossfadeSize);
float fSlow3 = (fSlow0 - 1); float fSlow3 = (fSlow0 - 1);
float* input0 = &input[0]; float* input0 = &input[0];
//float* output0 = &output[0]; //float* output0 = &output[0];
for (int i=0; i<count; i++) { for (int i=0; i<count; i++) {
float fTemp0 = (float)input0[i]; float fTemp0 = (float)input0[i];
fVec0[IOTA&65535] = fTemp0; fVec0[IOTA&65535] = fTemp0;
fRec0[0] = fmodf((fRec0[1] + fSlow1),fSlow0); fRec0[0] = fmodf((fRec0[1] + fSlow1),fSlow0);
int iTemp1 = int(fRec0[0]); int iTemp1 = int(fRec0[0]);
int iTemp2 = (1 + iTemp1); int iTemp2 = (1 + iTemp1);
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);
float out=output[0]; float out=output[0];
out += (float)(((1 - fTemp3) * (((fTemp4 - iTemp5) * out += (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]))));
output[0]=out;
output[0]=out; fRec0[1] = fRec0[0];
fRec0[1] = fRec0[0]; IOTA = IOTA+1;
IOTA = IOTA+1; }
}
} }