- became a QObject

- create handle from sampleTCO
- fill audio buffer from the requested base frame
- made automation-awared


git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@314 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Javier Serrano Polo
2006-08-13 14:03:35 +00:00
parent 69663a5890
commit 85e336b48b
2 changed files with 84 additions and 12 deletions

View File

@@ -26,22 +26,29 @@
#ifndef _SAMPLE_PLAY_HANDLE_H
#define _SAMPLE_PLAY_HANDLE_H
#include <qobject.h>
#include "play_handle.h"
#include "types.h"
#include "engine.h"
class sampleBuffer;
class sampleTCO;
class track;
class audioPort;
class samplePlayHandle : public playHandle, public engineObject
class samplePlayHandle : public QObject, public playHandle, public engineObject
{
Q_OBJECT
public:
samplePlayHandle( const QString & _sample_file, engine * _engine );
samplePlayHandle( sampleBuffer * _sample_buffer );
samplePlayHandle( sampleTCO * _tco );
virtual ~samplePlayHandle();
virtual void play( void );
void play( const fpab_t _frame_base );
virtual bool done( void ) const;
f_cnt_t totalFrames( void ) const;
@@ -55,6 +62,10 @@ public:
}
public slots:
void setVolume( float _new_volume );
private:
sampleBuffer * m_sampleBuffer;
const bool m_ownSampleBuffer;
@@ -63,6 +74,10 @@ private:
f_cnt_t m_frame;
audioPort * m_audioPort;
const bool m_ownAudioPort;
float m_volume;
track * m_track;
} ;

View File

@@ -27,6 +27,7 @@
#include "sample_play_handle.h"
#include "sample_buffer.h"
#include "sample_track.h"
#include "buffer_allocator.h"
#include "audio_port.h"
@@ -40,7 +41,10 @@ samplePlayHandle::samplePlayHandle( const QString & _sample_file,
m_ownSampleBuffer( TRUE ),
m_doneMayReturnTrue( TRUE ),
m_frame( 0 ),
m_audioPort( new audioPort( "samplePlayHandle", eng() ) )
m_audioPort( new audioPort( "samplePlayHandle", eng() ) ),
m_ownAudioPort( TRUE ),
m_volume( 1.0f ),
m_track( NULL )
{
}
@@ -54,7 +58,27 @@ samplePlayHandle::samplePlayHandle( sampleBuffer * _sample_buffer ) :
m_ownSampleBuffer( FALSE ),
m_doneMayReturnTrue( TRUE ),
m_frame( 0 ),
m_audioPort( new audioPort( "samplePlayHandle", eng() ) )
m_audioPort( new audioPort( "samplePlayHandle", eng() ) ),
m_ownAudioPort( TRUE ),
m_volume( 1.0f ),
m_track( NULL )
{
}
samplePlayHandle::samplePlayHandle( sampleTCO * _tco ) :
playHandle( SAMPLE_PLAY_HANDLE ),
engineObject( _tco->eng() ),
m_sampleBuffer( _tco->getSampleBuffer() ),
m_ownSampleBuffer( FALSE ),
m_doneMayReturnTrue( TRUE ),
m_frame( 0 ),
m_audioPort( ( (sampleTrack *)_tco->getTrack() )->getAudioPort() ),
m_ownAudioPort( FALSE ),
m_volume( 1.0f ),
m_track( _tco->getTrack() )
{
}
@@ -67,30 +91,47 @@ samplePlayHandle::~samplePlayHandle()
{
delete m_sampleBuffer;
}
delete m_audioPort;
if( m_ownAudioPort )
{
delete m_audioPort;
}
}
void samplePlayHandle::play( void )
{
play( 0 );
}
void samplePlayHandle::play( const fpab_t _frame_base )
{
if( framesDone() >= totalFrames() )
{
return;
}
const fpab_t frames = eng()->getMixer()->framesPerAudioBuffer();
sampleFrame * buf = bufferAllocator::alloc<sampleFrame>( frames );
volumeVector v = { 1.0f, 1.0f
const fpab_t frames = eng()->getMixer()->framesPerAudioBuffer()
- _frame_base;
if( !( m_track && m_track->muted() ) )
{
sampleFrame * buf = bufferAllocator::alloc<sampleFrame>(
frames );
volumeVector v = { { m_volume, m_volume
#ifndef DISABLE_SURROUND
, 1.0f, 1.0f
, m_volume, m_volume
#endif
} ;
m_sampleBuffer->play( buf, m_frame, frames );
eng()->getMixer()->bufferToPort( buf, frames, 0, v, m_audioPort );
} } ;
m_sampleBuffer->play( buf, m_frame, frames );
eng()->getMixer()->bufferToPort( buf, frames, _frame_base, v,
m_audioPort );
bufferAllocator::free( buf );
bufferAllocator::free( buf );
}
m_frame += frames;
}
@@ -112,4 +153,20 @@ f_cnt_t samplePlayHandle::totalFrames( void ) const
}
void samplePlayHandle::setVolume( float _new_volume )
{
if( _new_volume <= MAX_VOLUME )
{
m_volume = _new_volume / 100.0f;
}
}
#include "sample_play_handle.moc"
#endif