Loopp/src/trackoutput.cxx

160 lines
3.8 KiB
C++
Raw Normal View History

2013-12-08 22:44:43 +01:00
/*
* Author: Harry van Haaren 2013
* harryhaaren@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2013-08-15 18:17:16 +02:00
#include "trackoutput.hxx"
2013-09-17 14:11:11 +02:00
#include "jack.hxx"
extern Jack* jack;
2013-08-15 18:17:16 +02:00
TrackOutput::TrackOutput(int t, AudioProcessor* ap) :
AudioProcessor(),
track(t),
_recordArm(false),
2013-09-17 14:11:11 +02:00
previousInChain(ap)
2013-08-15 18:17:16 +02:00
{
// UI update
2013-09-17 14:11:11 +02:00
uiUpdateConstant = jack->getSamplerate() / 30;
uiUpdateCounter = jack->getSamplerate() / 30;
dbMeter = new DBMeter( jack->getSamplerate() );
2013-08-15 18:17:16 +02:00
_toMaster = 0.8;
2013-09-23 16:23:48 +02:00
_toReverb = 0.0;
2013-08-15 18:17:16 +02:00
_toSidechain = 0.0;
2013-09-11 02:50:47 +02:00
_toPostSidechain = 0.0;
2013-09-23 16:23:48 +02:00
_toPostfaderActive = 0;
_toKeyActive = 0;
2013-10-07 00:26:06 +02:00
_toXSideActive = true;
2013-08-15 18:17:16 +02:00
}
void TrackOutput::setMaster(float value)
{
_toMaster = value;
}
float TrackOutput::getMaster()
{
return _toMaster;
}
bool TrackOutput::recordArm()
{
return _recordArm;
}
void TrackOutput::recordArm(bool r)
{
_recordArm = r;
}
2013-09-23 16:23:48 +02:00
void TrackOutput::setSendActive( int send, bool a )
{
switch( send )
{
2013-10-03 02:18:06 +02:00
case SEND_POSTFADER:
_toPostfaderActive = a;
2013-09-23 16:23:48 +02:00
break;
2013-10-03 02:18:06 +02:00
case SEND_KEY:
_toKeyActive = a;
2013-09-23 16:23:48 +02:00
break;
2013-10-07 00:26:06 +02:00
//case SEND_XSIDE:
// _toXSideActive = a;
default:
2013-09-23 16:23:48 +02:00
break;
}
}
2013-08-15 18:17:16 +02:00
void TrackOutput::setSend( int send, float value )
{
switch( send )
{
2013-10-03 02:18:06 +02:00
case SEND_POSTFADER:
2013-08-15 18:17:16 +02:00
_toReverb = value;
break;
2013-10-03 02:18:06 +02:00
case SEND_KEY:
2013-09-23 16:23:48 +02:00
// setSendActive() handles on/off for this send
//_toSidechain = value;
2013-08-15 18:17:16 +02:00
break;
2013-10-03 02:18:06 +02:00
case SEND_XSIDE:
2013-08-15 18:17:16 +02:00
_toPostSidechain = value;
break;
}
}
void TrackOutput::process(unsigned int nframes, Buffers* buffers)
2013-08-15 18:17:16 +02:00
{
// get & zero track buffer
float* trackBuffer = buffers->audio[Buffers::TRACK_0 + track];
memset( trackBuffer, 0, sizeof(float)*nframes );
2013-08-15 18:17:16 +02:00
// call process() up the chain
2013-08-15 18:17:16 +02:00
previousInChain->process( nframes, buffers );
// run the meter
2013-09-17 14:11:11 +02:00
dbMeter->process( nframes, trackBuffer, trackBuffer );
2013-08-15 18:17:16 +02:00
if (uiUpdateCounter > uiUpdateConstant )
{
float l = dbMeter->getLeftDB() * _toMaster;
float r = dbMeter->getRightDB() * _toMaster;
EventTrackSignalLevel e( track, l, r );
2013-08-15 18:17:16 +02:00
writeToGuiRingbuffer( &e );
uiUpdateCounter = 0;
}
uiUpdateCounter += nframes;
// copy audio data into reverb / sidechain / master buffers
float* reverb = buffers->audio[Buffers::SEND];
float* sidechain = buffers->audio[Buffers::SIDECHAIN_KEY];
float* postSidechain = buffers->audio[Buffers::SIDECHAIN_SIGNAL];
2013-08-15 18:17:16 +02:00
float* masterL = buffers->audio[Buffers::MASTER_OUT_L];
float* masterR = buffers->audio[Buffers::MASTER_OUT_R];
for(unsigned int i = 0; i < nframes; i++)
2013-08-15 18:17:16 +02:00
{
// * master for "post-fader" sends
float tmp = trackBuffer[i];
2013-08-15 18:17:16 +02:00
// post-sidechain *moves* signal between "before/after" ducking, not add!
masterL[i] += tmp * _toMaster * (1-_toPostSidechain);
masterR[i] += tmp * _toMaster * (1-_toPostSidechain);
2013-08-15 18:17:16 +02:00
if ( _toPostfaderActive )
2013-09-23 16:23:48 +02:00
reverb[i] += tmp * _toReverb * _toMaster;
if ( _toXSideActive )
2013-09-23 16:23:48 +02:00
postSidechain[i] += tmp * _toPostSidechain * _toMaster;
// turning down an element in the mix should *NOT* influence sidechaining
if ( _toKeyActive )
2013-09-23 16:23:48 +02:00
sidechain[i] += tmp;
2013-08-15 18:17:16 +02:00
}
}
TrackOutput::~TrackOutput()
{
2013-09-23 16:23:48 +02:00
delete dbMeter;
2013-08-15 18:17:16 +02:00
}