Skip to content

Commit

Permalink
added instrument::applyRelease(...)
Browse files Browse the repository at this point in the history
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@519 0778d3d1-df1d-0410-868b-ea421aaaa00d
  • Loading branch information
tobydox committed Aug 6, 2007
1 parent 83f3398 commit 0243338
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@


#include "plugin.h"
#include "mixer.h"


// forward-declarations
Expand Down Expand Up @@ -131,6 +132,11 @@ class instrument : public QWidget, public plugin
return( m_instrumentTrack );
}

// instruments may use this to apply a soft fade out at the end of
// notes - method does this only if really less or equal
// desiredReleaseFrames() frames are left
void applyRelease( sampleFrame * buf, const notePlayHandle * _n );


private:
instrumentTrack * m_instrumentTrack;
Expand Down
21 changes: 21 additions & 0 deletions src/core/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "instrument.h"
#include "instrument_track.h"
#include "dummy_instrument.h"
#include "note_play_handle.h"


instrument::instrument( instrumentTrack * _instrument_track,
Expand Down Expand Up @@ -105,5 +106,25 @@ bool instrument::isFromTrack( const track * _track ) const



void instrument::applyRelease( sampleFrame * buf, const notePlayHandle * _n )
{
const fpp_t frames = _n->framesLeftForCurrentPeriod();
const fpp_t fpp = engine::getMixer()->framesPerPeriod();
const f_cnt_t fl = _n->framesLeft();
if( fl <= desiredReleaseFrames()+fpp )
{
for( fpp_t f = fl > desiredReleaseFrames() ?
( tMax( fpp - desiredReleaseFrames(), 0 ) +
fl % fpp ) : 0; f < frames; ++f )
{
const float fac = (float)( fl-f-1 ) /
desiredReleaseFrames();
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
{
buf[f][ch] *= fac;
}
}
}
}

#endif

0 comments on commit 0243338

Please sign in to comment.