⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audio2ui.cpp

📁 Symbian OS C++ 程序开发事例
💻 CPP
字号:
/* Copyright (c) 2004, Symbian Software Ltd. All rights reserved */


#include "Audio2.pan"
#include "Audio2ui.h"
#include "Audio2view.h"
#include <gdi.h>
#include "Audio2.hrh"
#include <Audio2.rsg>
#include "Audio2eng.h"

#include <eikdialg.h>
#include <eiktxlbx.h>
#include <eiktxlbm.h>
//number editor
#include <eikmfne.h>
#include <eikmenup.h>

class CSelectItemDialog : public CEikDialog
    {
public:
    CSelectItemDialog(TInt aTitleId, TInt* aIndex, CDesCArrayFlat* aArray);
    void PreLayoutDynInitL();
    TBool OkToExitL(TInt aButtonId);
private:
    TInt iTitleId;
    TInt * iIndex;
    CDesCArrayFlat *iArray;
    };

CSelectItemDialog::CSelectItemDialog(TInt aTitleId, TInt* aIndex, CDesCArrayFlat* aArray)
    {
    iTitleId=aTitleId;
    iIndex=aIndex;
    iArray=aArray;
    }

void CSelectItemDialog::PreLayoutDynInitL()
    {
    SetTitleL(iTitleId);
    CEikTextListBox*listBox;
    listBox = static_cast<CEikTextListBox*>(Control(ECvtTypeField));
    CTextListBoxModel* lbModel = listBox->Model();
    lbModel->SetItemTextArray(iArray);
    lbModel->SetOwnershipType(ELbmDoesNotOwnItemArray);
    }

TBool CSelectItemDialog::OkToExitL(TInt /*aButtonId*/)
    {
    CEikTextListBox*listBox;
    listBox = static_cast<CEikTextListBox*>(Control(ECvtTypeField));
    *iIndex=listBox->CurrentItemIndex();
    return ETrue;
    }

_LIT(KNoFileLoaded, "No file loaded");

void CAudio2Ui::ConstructL()
    {
    BaseConstructL();
    iAppView = CAudio2View::NewL(ClientRect());  
    iAppView->UpdateLabelL(KNoFileLoaded);
    AddToStackL(iAppView);

    iEngine=CAudio2Engine::NewL(*this);
    iEngine->SetArrays(&iDataTypes, &iSampleRates, &iChannels);
    }

CAudio2Ui::CAudio2Ui()                              
    {
    }

CAudio2Ui::~CAudio2Ui()
    {
    if (iAppView)
        RemoveFromStack(iAppView);

    delete iAppView;
    iAppView = NULL;

    delete iEngine;
    iEngine=NULL;

    iSampleRates.Close();
    iChannels.Close();
    iDataTypes.Close();

    delete iFileTypeArray;
    iFileTypeArray=NULL;
    }

TKeyResponse CAudio2Ui::HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
    {
    return EKeyWasNotConsumed;
    }

_LIT(KFileName,"test.wav");

void CAudio2Ui::HandleCommandL(TInt aCommand)
    {
    switch(aCommand)
        {
    case ECmdRecord:
        iEngine->StartRecordingL();
        break;

    case ECmdPlay:
        {
        iEngine->PlayL();
        break;
        }
    case ECmdConversionFormats:
        FormatsDialogL();
        break;

    case ECmdConversionTypes:
        TypesDialogL();
        break;

    case ECmdConvert:
        iEngine->ConvertL(iFileTypeArray->MdcaPoint(iFormatIndex), iCodecIndex, iSampleRatesIndex, iChannelsIndex);
        break;

    case ECmdStop:
        iEngine->StopL();
        break;

    case EEikCmdExit:
        Exit();
        break;

    default:
        User::Invariant();
        break;
        }
    }

void CAudio2Ui::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
    {
    if (aMenuId == R_AUDIO2_MENU)
        iEngine->UpdateMenu(aMenuPane);
    }

void CAudio2Ui::UpdateViewL()
    {
    iAppView->UpdateLabelL(KFileName);
    iAppView->DrawNow();
    }

void CAudio2Ui::FormatsDialogL()
    {
    TInt index = 0;
    
    delete iFileTypeArray;
    iFileTypeArray=NULL;
    iFileTypeArray = new (ELeave) CDesCArrayFlat(4);
    iEngine->RecordTypesL(*iFileTypeArray);
    CSelectItemDialog* dialog =new(ELeave) CSelectItemDialog(R_AUDIO2_SELECT_FORMAT, &index,iFileTypeArray);
    dialog->ExecuteLD(R_AUDIO2_SELECT_RECORD_TYPE_DIALOG);
    iEngine->GetFormatsL(iFileTypeArray->MdcaPoint(index));
    iFormatIndex=index;
    iCodecIndex=-1; //flag that we haven't set any data types yet
    }

void CAudio2Ui::TypesDialogL()
    {
// Codecs
    CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(4);
    CleanupStack::PushL(array);
    HBufC8* buf8 = HBufC8::NewLC(10);
    TPtr8 ptr = buf8->Des();
    TBuf<5> buf;
    for (TInt i=0; i<iDataTypes.Count(); i++)
        {
        iDataTypes[i].FourCC(&ptr);
        buf.Copy(ptr);
        array->AppendL(buf);
        }
    TInt index = 0;
    CSelectItemDialog* dialog =new(ELeave) CSelectItemDialog(R_AUDIO2_SELECT_CODEC, &index,array);
    dialog->ExecuteLD(R_AUDIO2_SELECT_RECORD_TYPE_DIALOG);

    CleanupStack::PopAndDestroy(); //buf8
    CleanupStack::PopAndDestroy(); //array
    iCodecIndex=index;

    //sample rates
    array = new (ELeave) CDesCArrayFlat(4);
    CleanupStack::PushL(array);

    for (TInt j=0;j<iSampleRates.Count();j++)
        {
        TBuf<12> number;
        number.Num(iSampleRates[j]);
        array->AppendL(number);
        }

    dialog =new(ELeave) CSelectItemDialog(R_AUDIO2_SELECT_SAMPLE_RATE, &index,array);
    dialog->ExecuteLD(R_AUDIO2_SELECT_RECORD_TYPE_DIALOG);
    CleanupStack::PopAndDestroy(); //array
    iSampleRatesIndex=index;

    //channels
    array = new (ELeave) CDesCArrayFlat(4);
    CleanupStack::PushL(array);

    for (TInt k=0;k<iChannels.Count();k++)
        {
        TBuf<12> number;
        number.Num(iChannels[k]);
        array->AppendL(number);
        }

    dialog =new(ELeave) CSelectItemDialog(R_AUDIO2_SELECT_CHANNELS, &index,array);
    dialog->ExecuteLD(R_AUDIO2_SELECT_RECORD_TYPE_DIALOG);
    CleanupStack::PopAndDestroy(); //array
    iChannelsIndex=index;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -