MusicAudioRecorderWidget::MusicAudioRecorderWidget(QWidget *parent)
    : MusicAbstractMoveDialog(parent),
      ui(new Ui::MusicAudioRecorderWidget), m_mBuffer(BufferSize, 0)
{
    ui->setupUi(this);

    ui->topTitleCloseButton->setIcon(QIcon(":/share/searchclosed"));
    ui->topTitleCloseButton->setStyleSheet(MusicUIObject::MToolButtonStyle03);
    ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->topTitleCloseButton->setToolTip(tr("Close"));

    connect(ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
    ui->startButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->startButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->startButton->setToolTip(tr("startAudio"));
    ui->stopButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->stopButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->stopButton->setToolTip(tr("stopAudio"));
    ui->playButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->playButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->playButton->setToolTip(tr("playAudio"));
    ui->saveButton->setStyleSheet(MusicUIObject::MPushButtonStyle05);
    ui->saveButton->setCursor(QCursor(Qt::PointingHandCursor));
    ui->saveButton->setToolTip(tr("saveButton"));

    connect(ui->startButton, SIGNAL(clicked()), SLOT(onRecordStart()));
    connect(ui->stopButton, SIGNAL(clicked()), SLOT(onRecordStop()));
    connect(ui->playButton, SIGNAL(clicked()), SLOT(onRecordPlay()));
    connect(ui->saveButton, SIGNAL(clicked()), SLOT(onRecordSave()));

    ui->checkBox->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_2->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_3->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_4->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox_5->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    ui->checkBox->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_2->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_3->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_4->setCursor(QCursor(Qt::PointingHandCursor));
    ui->checkBox_5->setCursor(QCursor(Qt::PointingHandCursor));

    connect(&m_timer, SIGNAL(timeout()), SLOT(onTimerout()));
    ui->stopButton->setEnabled(false);
    ui->playButton->setEnabled(false);
    ui->saveButton->setEnabled(false);
    m_movie = nullptr;
    m_time = 0;

    m_miMaxValue = 0;
    ui->horizontalSlider->setValue(100);
    m_miVolume = 100;
    m_mpOutputFile = nullptr;
    m_mpAudioInputFile = nullptr;
    m_mpAudioOutputFile = nullptr;

    m_mpAudioInputSound = nullptr;
    m_mpAudioOutputSound = nullptr;

    m_mpInputDevSound = nullptr;
    m_mpInputDevSound = nullptr;

    m_mpOutputFile = new QFile(this);
    m_mpOutputFile->setFileName("record.raw");

    m_mFormatFile.setSampleSize(16);
    m_mFormatFile.setSampleType(QAudioFormat::SignedInt);
    m_mFormatFile.setByteOrder(QAudioFormat::LittleEndian);
    m_mFormatFile.setCodec("audio/pcm");

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
    if(!info.isFormatSupported(m_mFormatFile))
    {
        M_LOGGERS("input default mFormatFile not supported try to use nearest");
        m_mFormatFile = info.nearestFormat(m_mFormatFile);
    }
    QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
    if(!info1.isFormatSupported(m_mFormatFile))
    {
        M_LOGGERS("output default mFormatFile not supported - trying to use nearest");
        //           mFormatFile = info.nearestFormat(mFormatSound);
        M_LOGGERS("output no support input mFormatFile.");
        return;
    }
    if(m_mFormatFile.sampleSize() != 16)
    {
        M_LOGGER << "audio device doesn't support 16 bit support %d bit samples, example cannot run"
                 << m_mFormatFile.sampleSize() << LOG_END;
        m_mpAudioInputFile = 0;
        return;
    }

    m_mpAudioInputFile = nullptr;
    m_mpAudioOutputFile = nullptr;

    initMonitor();
}
MusicAudioRecorderWidget::MusicAudioRecorderWidget(QWidget *parent)
    : MusicAbstractMoveWidget(parent),
      m_ui(new Ui::MusicAudioRecorderWidget), m_mBuffer(BufferSize, 0)
{
    m_ui->setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose, true);
    setAttribute(Qt::WA_QuitOnClose, true);

    m_ui->topTitleCloseButton->setIcon(QIcon(":/functions/btn_close_hover"));
    m_ui->topTitleCloseButton->setStyleSheet(MusicUIObject::MToolButtonStyle04);
    m_ui->topTitleCloseButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->topTitleCloseButton->setToolTip(tr("Close"));

    connect(m_ui->topTitleCloseButton, SIGNAL(clicked()), SLOT(close()));
    m_ui->startButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->startButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->startButton->setToolTip(tr("startAudio"));
    m_ui->stopButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->stopButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->stopButton->setToolTip(tr("stopAudio"));
    m_ui->playButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->playButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->playButton->setToolTip(tr("playAudio"));
    m_ui->saveButton->setStyleSheet(MusicUIObject::MPushButtonStyle04);
    m_ui->saveButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->saveButton->setToolTip(tr("saveButton"));

    connect(m_ui->startButton, SIGNAL(clicked()), SLOT(onRecordStart()));
    connect(m_ui->stopButton, SIGNAL(clicked()), SLOT(onRecordStop()));
    connect(m_ui->playButton, SIGNAL(clicked()), SLOT(onRecordPlay()));
    connect(m_ui->saveButton, SIGNAL(clicked()), SLOT(onRecordSave()));

    m_ui->checkBox->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_2->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_3->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_4->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox_5->setStyleSheet(MusicUIObject::MCheckBoxStyle01);
    m_ui->checkBox->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_2->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_3->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_4->setCursor(QCursor(Qt::PointingHandCursor));
    m_ui->checkBox_5->setCursor(QCursor(Qt::PointingHandCursor));

#ifdef Q_OS_UNIX
    m_ui->startButton->setFocusPolicy(Qt::NoFocus);
    m_ui->stopButton->setFocusPolicy(Qt::NoFocus);
    m_ui->playButton->setFocusPolicy(Qt::NoFocus);
    m_ui->saveButton->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_2->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_3->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_4->setFocusPolicy(Qt::NoFocus);
    m_ui->checkBox_5->setFocusPolicy(Qt::NoFocus);
#endif

    m_ui->progress->setStyleSheet(MusicUIObject::MProgressBar02);
    m_ui->horizontalSlider->setStyleSheet(MusicUIObject::MSliderStyle01);

    connect(&m_timer, SIGNAL(timeout()), SLOT(onTimerout()));
    m_ui->stopButton->setEnabled(false);
    m_ui->playButton->setEnabled(false);
    m_ui->saveButton->setEnabled(false);
    m_movie = nullptr;
    m_time = 0;

    m_miMaxValue = 0;
    m_ui->horizontalSlider->setValue(100);
    m_miVolume = 100;

    m_mpAudioInputSound = nullptr;
    m_mpAudioOutputSound = nullptr;

    m_mpInputDevSound = nullptr;
    m_mpOutputDevSound = nullptr;

    m_recordCore = new MusicAudioRecorderCore(this);

    initMonitor();
}