From 08bdc1ff09293085a8a77f668e7ec4e579d4a424 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Mon, 27 Mar 2017 21:04:30 +0100 Subject: [PATCH] restyled code after stereo added --- src/audiobuffer.cxx | 8 +-- src/audiobuffer.hxx | 2 +- src/diskreader.cxx | 38 ++++++------- src/diskwriter.cxx | 35 ++++++------ src/gaudioeditor.cxx | 124 +++++++++++++++++++++---------------------- src/jack.cxx | 54 +++++++++---------- 6 files changed, 128 insertions(+), 133 deletions(-) diff --git a/src/audiobuffer.cxx b/src/audiobuffer.cxx index 0086d33..c7612df 100644 --- a/src/audiobuffer.cxx +++ b/src/audiobuffer.cxx @@ -102,10 +102,10 @@ long AudioBuffer::getAudioFrames() long AudioBuffer::getSize() { - if(bufferL.size() != bufferR.size()) { - LUPPP_WARN("left and right channels of audio buffer have different size: %i vs %i", bufferL.size(), bufferR.size() ); - } - return std::min(bufferL.size(), bufferR.size()); + if(bufferL.size() != bufferR.size()) { + LUPPP_WARN("left and right channels of audio buffer have different size: %i vs %i", bufferL.size(), bufferR.size() ); + } + return std::min(bufferL.size(), bufferR.size()); } std::vector& AudioBuffer::getDataL() diff --git a/src/audiobuffer.hxx b/src/audiobuffer.hxx index 37024a6..0c9e4d4 100644 --- a/src/audiobuffer.hxx +++ b/src/audiobuffer.hxx @@ -52,7 +52,7 @@ public: long getAudioFrames(); - long getSize(); + long getSize(); std::vector& getDataL(); std::vector& getDataR(); diff --git a/src/diskreader.cxx b/src/diskreader.cxx index c34f957..974b622 100644 --- a/src/diskreader.cxx +++ b/src/diskreader.cxx @@ -167,7 +167,7 @@ int DiskReader::loadSample( int track, int scene, string path ) int chnls = infile.channels(); std::vector bufL( infile.frames() ); std::vector bufR( infile.frames() ); - float frameBuf[ sizeof(float) * chnls ]; + float frameBuf[ sizeof(float) * chnls ]; if ( infile.error() ) { LUPPP_ERROR("File %s, Error %s", path.c_str(), infile.strError() ); @@ -177,22 +177,22 @@ int DiskReader::loadSample( int track, int scene, string path ) LUPPP_NOTE("Loading file with %i chnls, frames %i, bufferL size %i bufferR size %i", infile.channels(), infile.frames(), bufL.size(), bufR.size() ); // Read data - for(int f=0; f 0) { - bufL[f] = frameBuf[0]; - bufR[f] = frameBuf[0]; - } - // Second sample - // used for right channel when file is stereo - if(chnls > 1) { - bufR[f] = frameBuf[1]; - } - } + // Frist sapmle + // used for both channels when file is mono + // used for left channel when file is stereo + if(chnls > 0) { + bufL[f] = frameBuf[0]; + bufR[f] = frameBuf[0]; + } + // Second sample + // used for right channel when file is stereo + if(chnls > 1) { + bufR[f] = frameBuf[1]; + } + } /// resample? if ( infile.samplerate() != gui->samplerate ) { @@ -632,10 +632,10 @@ int DiskReader::readTracks() LUPPP_WARN("Track %i has no send data saved.", t); } else { EventTrackSendActive e1( t, SEND_POSTFADER, sendActive->valueint ); - EventTrackSendActive e2( t, SEND_KEY , keyActive ->valueint ); + EventTrackSendActive e2( t, SEND_KEY, keyActive ->valueint ); - EventTrackSend e3( t, SEND_XSIDE , xside->valuedouble ); - EventTrackSend e4( t, SEND_POSTFADER , send->valuedouble ); + EventTrackSend e3( t, SEND_XSIDE, xside->valuedouble ); + EventTrackSend e4( t, SEND_POSTFADER, send->valuedouble ); writeToDspRingbuffer( &e1 ); diff --git a/src/diskwriter.cxx b/src/diskwriter.cxx index e7d036f..59c2ea5 100644 --- a/src/diskwriter.cxx +++ b/src/diskwriter.cxx @@ -97,7 +97,7 @@ void DiskWriter::initialize(std::string path, std::string name ) /* If project dir doesn't exist yet, create it */ int projectDir = mkdir( path.c_str(), - S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ); + S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ); if ( errno == EEXIST ) { //LUPPP_NOTE("project dir %s exists, this is good", path.c_str()); } else if ( projectDir ) { @@ -193,15 +193,15 @@ int DiskWriter::writeControllerFile( Controller* c ) cJSON_AddItemToObject( binding, "action", cJSON_CreateString( actionName ) ); cJSON_AddNumberToObject( binding, "status", b.at(i)->status ); - cJSON_AddNumberToObject( binding, "data" , b.at(i)->data ); + cJSON_AddNumberToObject( binding, "data", b.at(i)->data ); // only add JSON elements if they're not the "invalid" defaults if ( b.at(i)->track != -2 ) - cJSON_AddNumberToObject( binding, "track" , b.at(i)->track ); + cJSON_AddNumberToObject( binding, "track", b.at(i)->track ); if ( b.at(i)->scene != -1 ) - cJSON_AddNumberToObject( binding, "scene" , b.at(i)->scene ); + cJSON_AddNumberToObject( binding, "scene", b.at(i)->scene ); if ( b.at(i)->send != -1 ) - cJSON_AddNumberToObject( binding, "send" , b.at(i)->send ); + cJSON_AddNumberToObject( binding, "send", b.at(i)->send ); if ( b.at(i)->active!= -1 ) cJSON_AddNumberToObject( binding, "active", b.at(i)->active ); @@ -321,14 +321,13 @@ int DiskWriter::writeAudioBuffer(int track, int scene, AudioBuffer* ab, // FIXME: the size of the buffer is bigger than the audio contained in it: // calculate the length that needs saving using getBeats() * framesPerBeat if ( ab->getAudioFrames() > 0 ) { - float frameBuf[ sizeof(float) * 2 ]; - for(int i=0; igetAudioFrames(); i++) { - frameBuf[0] = ab->getDataL()[i]; - frameBuf[1] = ab->getDataR()[i]; - outfile.writef( frameBuf, 1); - } - } - else { + float frameBuf[ sizeof(float) * 2 ]; + for(int i=0; igetAudioFrames(); i++) { + frameBuf[0] = ab->getDataL()[i]; + frameBuf[1] = ab->getDataR()[i]; + outfile.writef( frameBuf, 1); + } + } else { LUPPP_WARN("%s","Sample has zero samples"); } @@ -402,14 +401,14 @@ int DiskWriter::writeSession() cJSON_AddNumberToObject( track, "fader", gui->getTrack(t)->getVolume()->value() ); cJSON_AddNumberToObject( track, "pan", gui->getTrack(t)->getPan()); - cJSON_AddNumberToObject( track, "sendAmount" , gui->getTrack(t)->getSend() ); - cJSON_AddNumberToObject( track, "sendActive" , gui->getTrack(t)->getSendActive() ); + cJSON_AddNumberToObject( track, "sendAmount", gui->getTrack(t)->getSend() ); + cJSON_AddNumberToObject( track, "sendActive", gui->getTrack(t)->getSendActive() ); - cJSON_AddNumberToObject( track, "jacksendAmount" , gui->getTrack(t)->getJackSend() ); - cJSON_AddNumberToObject( track, "jacksendActive" , gui->getTrack(t)->getJackSendActivate() ); + cJSON_AddNumberToObject( track, "jacksendAmount", gui->getTrack(t)->getJackSend() ); + cJSON_AddNumberToObject( track, "jacksendActive", gui->getTrack(t)->getJackSendActivate() ); cJSON_AddNumberToObject( track, "xsideAmount", gui->getTrack(t)->getXSide() ); - cJSON_AddNumberToObject( track, "keyActive" , gui->getTrack(t)->getKeyActive() ); + cJSON_AddNumberToObject( track, "keyActive", gui->getTrack(t)->getKeyActive() ); // write clipData vector into clip placeholder cJSON* clips = cJSON_CreateArray(); diff --git a/src/gaudioeditor.cxx b/src/gaudioeditor.cxx index f2c1b58..4b80275 100644 --- a/src/gaudioeditor.cxx +++ b/src/gaudioeditor.cxx @@ -84,11 +84,11 @@ AudioEditor::AudioEditor() } window->end(); - beatButtons[0]->callback( oneCB , this); - beatButtons[1]->callback( twoCB , this); - beatButtons[2]->callback( fourCB , this); - beatButtons[3]->callback( eightCB , this); - beatButtons[4]->callback( sixteenCB , this); + beatButtons[0]->callback( oneCB, this); + beatButtons[1]->callback( twoCB, this); + beatButtons[2]->callback( fourCB, this); + beatButtons[3]->callback( eightCB, this); + beatButtons[4]->callback( sixteenCB, this); beatButtons[5]->callback( thirtyTwoCB, this); beatButtons[6]->callback( sixtyfourCB, this); @@ -101,72 +101,68 @@ void AudioEditor::show( AudioBuffer* buf, bool modal ) if ( !ab ) { LUPPP_WARN("called with ab == 0"); - } else { - // TODO right (stereo) - std::vector& tmp = ab->getDataL(); - int size = tmp.size(); - waveform->setData( &tmp[0], size ); + return; + } - const int beats[]= {1,2,4,8,16,32,64}; + std::vector& tmp = ab->getDataL(); + int size = tmp.size(); + waveform->setData( &tmp[0], size ); - int iBeatOne = -1; - int iBeatTwo = -1; + const int beats[]= {1,2,4,8,16,32,64}; - // figure out BPM values from size - for( int i = 0; i < 7; i++ ) { - int beat = beats[i]; + int iBeatOne = -1; + int iBeatTwo = -1; - int fpb = size / beat; + // figure out BPM values from size + for( int i = 0; i < 7; i++ ) { + int beat = beats[i]; + int fpb = size / beat; + int bpm = (gui->samplerate / fpb) * 60; - int bpm = (gui->samplerate / fpb) * 60; - - - if ( bpm < 60 || bpm > 220 ) { - // disable option: not valid - beatButtons[i]->setGreyOut( true ); - beatButtons[i]->setColor( 0.4, 0.4, 0.4 ); - } else { - //printf("%i, fpb = %i, bpm= = %i\n", beat, fpb, bpm ); - // enable option ( may be disabled previously! ) - beatButtons[i]->setGreyOut( false ); - - // remember this beat was a valid one, to check for best match - if ( iBeatOne == -1 ) - iBeatOne = i; - else - iBeatTwo = i; - } - } - - // both valid: compare, and adjust color - if ( iBeatOne != -1 && iBeatTwo != -1 ) { - int masterFpb = (gui->samplerate * 60) / gui->getMasterTrack()->getBpm(); - int oneFpb = size / beats[iBeatOne]; - int twoFpb = size / beats[iBeatTwo]; - - int oneDelta = masterFpb - oneFpb; - int twoDelta = masterFpb - twoFpb; - - if ( oneDelta < 0 ) oneDelta = -oneDelta; - if ( twoDelta < 0 ) twoDelta = -twoDelta; - - if ( oneDelta == twoDelta ) { - beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 ); - beatButtons[iBeatTwo]->setColor( 0.0, 1.0, 0.0 ); - } else if ( oneDelta <= twoDelta ) { - // one is the better match - beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 ); - beatButtons[iBeatTwo]->setColor( 1.0, 0.0, 0.0 ); - } else { - beatButtons[iBeatTwo]->setColor( 0.0, 1.0, 0.0 ); - beatButtons[iBeatOne]->setColor( 1.0, 0.0, 0.0 ); - } - } else if( iBeatOne != -1 && iBeatTwo == -1) { // only one valid - beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 ); + if ( bpm < 60 || bpm > 220 ) { + // disable option: not valid + beatButtons[i]->setGreyOut( true ); + beatButtons[i]->setColor( 0.4, 0.4, 0.4 ); } else { - // no valid BPM range..? - } + //printf("%i, fpb = %i, bpm= = %i\n", beat, fpb, bpm ); + // enable option ( may be disabled previously! ) + beatButtons[i]->setGreyOut( false ); + // remember this beat was a valid one, to check for best match + if ( iBeatOne == -1 ) + iBeatOne = i; + else + iBeatTwo = i; + } + } + + // both valid: compare, and adjust color + if ( iBeatOne != -1 && iBeatTwo != -1 ) { + int masterFpb = (gui->samplerate * 60) / gui->getMasterTrack()->getBpm(); + int oneFpb = size / beats[iBeatOne]; + int twoFpb = size / beats[iBeatTwo]; + + int oneDelta = masterFpb - oneFpb; + int twoDelta = masterFpb - twoFpb; + + if ( oneDelta < 0 ) oneDelta = -oneDelta; + if ( twoDelta < 0 ) twoDelta = -twoDelta; + + if ( oneDelta == twoDelta ) { + beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 ); + beatButtons[iBeatTwo]->setColor( 0.0, 1.0, 0.0 ); + } else if ( oneDelta <= twoDelta ) { + // one is the better match + beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 ); + beatButtons[iBeatTwo]->setColor( 1.0, 0.0, 0.0 ); + } else { + beatButtons[iBeatTwo]->setColor( 0.0, 1.0, 0.0 ); + beatButtons[iBeatOne]->setColor( 1.0, 0.0, 0.0 ); + } + } else if( iBeatOne != -1 && iBeatTwo == -1) { // only one valid + beatButtons[iBeatOne]->setColor( 0.0, 1.0, 0.0 ); + } else { + // no valid BPM range..? } window->set_modal(); diff --git a/src/jack.cxx b/src/jack.cxx index 23892d5..081ccba 100644 --- a/src/jack.cxx +++ b/src/jack.cxx @@ -75,7 +75,7 @@ void Jack::resetMidiBindingState() } Jack::Jack( std::string name ) : - client( jack_client_open ( name.c_str(), JackNullOption , 0 , 0 ) ), + client( jack_client_open ( name.c_str(), JackNullOption, 0, 0 ) ), state( new State() ), controllerUpdater( new ControllerUpdater() ), clientActive(false) @@ -170,16 +170,16 @@ Jack::Jack( std::string name ) : 0 ); sidechainKeyOutputL = jack_port_register( client, - "sidechain_key_l", - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsOutput, - 0 ); + "sidechain_key_l", + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsOutput, + 0 ); sidechainKeyOutputR = jack_port_register( client, - "sidechain_key_r", - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsOutput, - 0 ); + "sidechain_key_r", + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsOutput, + 0 ); sidechainSignalOutputL = jack_port_register( client, "sidechain_signal_l", @@ -234,7 +234,7 @@ Jack::Jack( std::string name ) : tracksendreturns.push_back(new JackSendReturn(i,loopers.back(),client)); trackOutputs.push_back( new TrackOutput(i, tracksendreturns.back() ) ); - int o = i*2; + int o = i*2; buffers.audio[Buffers::TRACK_0_L + o] = new float[ buffers.nframes ]; buffers.audio[Buffers::TRACK_0_R + o] = new float[ buffers.nframes ]; buffers.audio[Buffers::SEND_TRACK_0_L+o]=new float[buffers.nframes]; @@ -315,7 +315,7 @@ Jack::~Jack() delete inputMeter; delete masterMeter; for(int i = 0; i < NTRACKS; i++) { - int o = i*2; + int o = i*2; delete [] buffers.audio[Buffers::TRACK_0_L+o]; delete [] buffers.audio[Buffers::TRACK_0_R+o]; delete [] buffers.audio[Buffers::SEND_TRACK_0_L+o]; @@ -431,32 +431,32 @@ int Jack::process (jack_nframes_t nframes) buffers.audio[Buffers::JACK_SIDECHAIN_SIGNAL_R]= (float*)jack_port_get_buffer( sidechainSignalOutputR,nframes ); if(gui->enablePerTrackOutput) { for(int t=0; tenablePerTrackOutput) { for(int t=0; tenablePerTrackOutput) { for(int t=0; t