📄 stkcontainer.cpp
字号:
/*
* ============================================================================
* Name : CSTKContainer from STKContainer.h
* Part of : STK
* Created : 07.02.2006 by Georg Essl
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright: Deutsche Telekom Laboratories & TU-Berlin
* ============================================================================
*/
// INCLUDE FILES
#include "STKContainer.h"
#include "Stk.h"
#include "Debug.h"
#undef DEBUG
#include <eiklabel.h> // for example label control
// ================= MEMBER FUNCTIONS =======================
CSTKContainer::CSTKContainer()
:iStatus(ENotReady), time(0), aData1(0), aData2(0), iDescBuf(0,0), dBuffer(0), iAudioStream(0), excitation(1)
{
}
// ---------------------------------------------------------
// CSTKContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSTKContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
/*
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
// iLabel->SetTextL( _L("Example View") );
// iToDoLabel = new (ELeave) CEikLabel;
// iToDoLabel->SetContainerWindowL( *this );
// iToDoLabel->SetTextL( _L("Add Your controls\n here") );
*/
iAudioStream = CMdaAudioOutputStream::NewL( *this );
iStatus = ENotReady;
aData1 = new (ELeave) TUint8[KBufferSize];
aData2 = new (ELeave) TUint8[KBufferSize];
plucked = new (ELeave) Plucked(110.0);
blowbotl = new (ELeave) BlowBotl();
sax = new (ELeave) Saxofony(220.0);
bwg = new (ELeave) BandedWG();
flt = new (ELeave) Flute(220.0);
beethree = new (ELeave) BeeThree();
moog = new (ELeave) Moog();
instrument_nr = 0;
sinewave.setFrequency(440.0);
#ifdef DEBUG
CStaticDebug::WriteIntN( delay->getDelay());
#endif
iDescBuf.Set(aData1,KBufferSize,KBufferSize);
iAudioStream->Open(&iSettings);
SetRect(aRect);
ActivateL();
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::CSTKContainer -> Finished") );
#endif
}
// Destructor
CSTKContainer::~CSTKContainer()
{
delete iAudioStream;
delete aData1;
delete aData2;
delete delay;
delete blowbotl;
delete plucked;
delete sax;
delete flt;
delete beethree;
delete moog;
delete bwg;
// delete iLabel;
// delete iToDoLabel;
}
void CSTKContainer::Excite()
{
int j;
switch(instrument_nr)
{
case 0:
plucked->pluck(1.0);
break;
case 1:
flt->noteOn(220.0,1.0);
break;
case 2:
sax->noteOn(220.0,1.0);
break;
case 3:
bwg->noteOn(220.0,1.0);
break;
case 4:
blowbotl->noteOn(220,1.0);
break;
case 5:
beethree->noteOn(220,1.0);
break;
case 6:
moog->noteOn(220,1.0);
break;
default:
plucked->pluck(1.0);
}
}
int CSTKContainer::setInstrument(int instr)
{
return instrument_nr = instr % MAX_INST;
}
TUint8 *CSTKContainer::FillBuffer()
{
int i=0,j=0;
TReal in,out;
TUint8 *aData;
if(dBuffer==0)
{
aData = aData1;
dBuffer = 1;
}
else
{
aData = aData2;
dBuffer = 0;
}
for(i=0;i<KBufferSize; i++)
{
in = 2.0*3.1415926*time*440.0/SRATE;
if(excitation==1 /*&& iStatus == EPlaying*/)
{
Excite();
excitation = 0;
}
switch(instrument_nr)
{
case 0:
aData[i]= 127*plucked->tick();
break;
case 1:
aData[i]= 127*flt->tick();
break;
case 2:
aData[i]= 127* sax->tick();
break;
case 3:
aData[i]= 127*bwg->tick();
break;
case 4:
aData[i]= 127*blowbotl->tick();
break;
case 5:
aData[i]= 127*beethree->tick();
//aData[i]=32*wl->tick();
break;
case 6:
aData[i]= 127*moog->tick();
break;
case 7:
aData[i]= 127*sinewave.tick();
break;
default:
aData[i]= 32*sinewave.tick()+32*plucked->tick();
break;
}
#ifdef DEBUG
if(aData[i]!=0 && i<6)
{
CStaticDebug::WriteInt(i); CStaticDebug::WriteInt(delay->getDelay()); CStaticDebug::WriteIntN(aData[i]); }
#endif
time ++;
}
return aData;
}
void CSTKContainer::MaoscOpenComplete(TInt aError)
{
if(aError==KErrNone)
{ //set stream properties
iAudioStream -> SetAudioPropertiesL ( TMdaAudioDataSettings::ESampleRate8000Hz, TMdaAudioDataSettings::EChannelsMono );
//Set the appropriate volume. Note that the
//MaxVolume () differs from the emulator to
//the target device
iAudioStream -> SetVolume(iAudioStream -> MaxVolume()/2);
iAudioStream -> SetPriority( EPriorityNormal, EMdaPriorityPreferenceNone); //Fill first buffer
iDescBuf.Set(FillBuffer(),KBufferSize,KBufferSize);
iStatus = EReadyToPlay;
// PlayL();
}
else
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscOpenComplete -> ERROR") );
#endif
// Error handling here
}
}
void CSTKContainer::PlayL()
{
if(iStatus==EReadyToPlay)
{
iAudioStream -> WriteL(iDescBuf);
iStatus = EPlaying;
}
}
void CSTKContainer::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
{
if(aError == KErrNone)
{
iDescBuf.Set(FillBuffer(),KBufferSize,KBufferSize);
iAudioStream -> WriteL(iDescBuf);
}
else if(aError == KErrAbort)
{
//StopL();
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscBufferCopied -> KErrAbort") );
#endif
// Stop playback
}
else
{
// Error handling
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscBufferCopied -> ERROR") );
#endif
}
}
void CSTKContainer::StopL()
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::StopL -> Entered") );
#endif
if(iStatus == EPlaying)
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::StopL -> Stopping") );
#endif
iAudioStream -> Stop();
excitation = 1;
}
}
void CSTKContainer::MaoscPlayComplete(TInt aError)
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscPlayComplete -> Entered") );
#endif
if(aError == KErrNone)
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscPlayComplete -> No error") );
#endif
iStatus = EReadyToPlay;
// close succeeded
}
else if(aError == KErrUnderflow)
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscPlayComplete -> Underflow") );
#endif
// FillBuffer();
// iAudioStream -> WriteL(iDescBuf);
}
else if(aError == KErrDied)
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscPlayComplete -> KErrDied") );
#endif
//. . . Actions required for KErrDied. . .
iStatus = EReadyToPlay;
}
else
{
#ifdef DEBUG
CStaticDebug::WriteInfoN( _L("CSTKContainer::MaoscPlayComplete -> ERROR") );
#endif
//. . . Actions required for a general error . . .
iStatus = EReadyToPlay;
}
}
// ---------------------------------------------------------
// CSTKContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSTKContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
// iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
// iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}
// ---------------------------------------------------------
// CSTKContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSTKContainer::CountComponentControls() const
{
return 0; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CSTKContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSTKContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
// case 0:
// return iLabel;
// case 1:
// return iToDoLabel;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CSTKContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSTKContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CSTKContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSTKContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -