<commit_before>#include "musicsongringtonemakerwidget.h"
#include "ui_musicsongringtonemakerwidget.h"
#include "musicbackgroundmanager.h"
#include "musiccutsliderwidget.h"
#include "musicuiobject.h"
#include "musicsongtag.h"
#include "musiccoremplayer.h"
#include "musictime.h"

#include <QFileDialog>
#include <QStyledItemDelegate>

MusicSongRingtoneMaker::MusicSongRingtoneMaker(QWidget *parent)
    : MusicAbstractMoveDialog(parent),
      ui(new Ui::MusicSongRingtoneMaker)
{
    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->addSongButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->playSongButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->playRingButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->saveSongButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->formatCombo->setItemDelegate(new QStyledItemDelegate(ui->formatCombo));
    ui->formatCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->formatCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    ui->kbpsCombo->setItemDelegate(new QStyledItemDelegate(ui->kbpsCombo));
    ui->kbpsCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->kbpsCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    ui->hzCombo->setItemDelegate(new QStyledItemDelegate(ui->hzCombo));
    ui->hzCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->hzCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    ui->msCombo->setItemDelegate(new QStyledItemDelegate(ui->msCombo));
    ui->msCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->msCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    initControlParameter();

    m_startPos = 0;
    m_stopPos = 9999;
    m_playRingtone = false;

    ui->playSongButton->setEnabled(false);
    ui->playRingButton->setEnabled(false);
    ui->saveSongButton->setEnabled(false);
    ui->cutSliderWidget->resizeWindow(435, 55);
    m_player = new MusicCoreMPlayer(this);

    connect(ui->addSongButton, SIGNAL(clicked()), SLOT(initInputPath()));
    connect(ui->playSongButton, SIGNAL(clicked()), SLOT(playInputSong()));
    connect(ui->playRingButton, SIGNAL(clicked()), SLOT(playRingtone()));
    connect(ui->saveSongButton, SIGNAL(clicked()), SLOT(initOutputPath()));
    connect(ui->cutSliderWidget, SIGNAL(posChanged(qint64,qint64)), SLOT(posChanged(qint64,qint64)));
    connect(m_player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
    connect(m_player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
}

MusicSongRingtoneMaker::~MusicSongRingtoneMaker()
{
    delete m_player;
    delete ui;
}

void MusicSongRingtoneMaker::initInputPath()
{
    QStringList supportedFormat;
    supportedFormat << "mp3" <<"wav" <<"wma" << "ogg" << "flac" << "ac3" << "aac";

    QString filter = "Files (";
    for(int i=0; i<supportedFormat.count(); ++i)
    {
        filter += QString("*.%1 ").arg(supportedFormat[i]);
    }
    filter = filter.trimmed() + ")";

    QString path = QFileDialog::getOpenFileName(this, QString(), "./", filter);
    if(path.isEmpty())
    {
        return;
    }

    m_inputFilePath = path;
    MusicSongTag tag;
    if(tag.readFile(m_inputFilePath))
    {
        QString name = m_inputFilePath.split("/").last();
        ui->songLabelValue->setText(tr("SongName: %1 ( %2, %3, %4)").arg(name)
                .arg(tag.getLengthString()).arg(tag.getSamplingRate()).arg(tag.getBitrate()));
    }
    else
    {
        ui->songLabelValue->setText(tr("Open File Error!"));
        return;
    }

    ui->playSongButton->setEnabled(true);
    ui->playRingButton->setEnabled(true);
    ui->saveSongButton->setEnabled(true);

    m_player->setMedia(MusicCoreMPlayer::MusicCategory, m_inputFilePath);
    playInputSong();

}

void MusicSongRingtoneMaker::initOutputPath()
{

}

void MusicSongRingtoneMaker::playInputSong()
{
    m_playRingtone = false;
    if(m_player->state() == MusicCoreMPlayer::StoppedState ||
       m_player->state() == MusicCoreMPlayer::PausedState)
    {
        ui->playSongButton->setText(tr("Stop"));
    }
    else
    {
        ui->playSongButton->setText(tr("Play"));
    }
    m_player->play();
}

void MusicSongRingtoneMaker::playRingtone()
{
    m_playRingtone = true;
    m_player->setPosition(m_startPos);
}

void MusicSongRingtoneMaker::positionChanged(qint64 position)
{
    if(m_playRingtone && m_stopPos < position)
    {
        m_player->play();
        ui->playSongButton->setText(tr("Play"));
        return;
    }
    ui->cutSliderWidget->setPosition(position);
}

void MusicSongRingtoneMaker::durationChanged(qint64 duration)
{
    ui->cutSliderWidget->setDuration(duration);
}

void MusicSongRingtoneMaker::posChanged(qint64 start, qint64 end)
{
    m_startPos = start;
    m_stopPos = end;
    ui->startTimeLabel->setText( MusicTime::toString(start, MusicTime::All_Sec, "mm:ss:zzz") );
    ui->stopTimeLabel->setText( MusicTime::toString(end, MusicTime::All_Sec, "mm:ss:zzz") );
}

int MusicSongRingtoneMaker::exec()
{
    QPixmap pix(M_BACKGROUND_PTR->getMBackground());
    ui->background->setPixmap(pix.scaled( size() ));
    return MusicAbstractMoveDialog::exec();
}<commit_msg>#35 add save ringtone song to local file[031284]<commit_after>#include "musicsongringtonemakerwidget.h"
#include "ui_musicsongringtonemakerwidget.h"
#include "musicbackgroundmanager.h"
#include "musiccutsliderwidget.h"
#include "musiccoremplayer.h"
#include "musicmessagebox.h"
#include "musicuiobject.h"
#include "musicsongtag.h"
#include "musictime.h"

#include <QProcess>
#include <QFileDialog>
#include <QStyledItemDelegate>
#include <QDebug>
MusicSongRingtoneMaker::MusicSongRingtoneMaker(QWidget *parent)
    : MusicAbstractMoveDialog(parent),
      ui(new Ui::MusicSongRingtoneMaker)
{
    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->addSongButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->playSongButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->playRingButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->saveSongButton->setStyleSheet(MusicUIObject::MPushButtonStyle08);
    ui->formatCombo->setItemDelegate(new QStyledItemDelegate(ui->formatCombo));
    ui->formatCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->formatCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    ui->kbpsCombo->setItemDelegate(new QStyledItemDelegate(ui->kbpsCombo));
    ui->kbpsCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->kbpsCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    ui->hzCombo->setItemDelegate(new QStyledItemDelegate(ui->hzCombo));
    ui->hzCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->hzCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    ui->msCombo->setItemDelegate(new QStyledItemDelegate(ui->msCombo));
    ui->msCombo->setStyleSheet(MusicUIObject::MComboBoxStyle01 + MusicUIObject::MItemView01);
    ui->msCombo->view()->setStyleSheet(MusicUIObject::MScrollBarStyle01);
    initControlParameter();

    m_startPos = 0;
    m_stopPos = 9999;
    m_playRingtone = false;

    ui->playSongButton->setEnabled(false);
    ui->playRingButton->setEnabled(false);
    ui->saveSongButton->setEnabled(false);
    ui->cutSliderWidget->resizeWindow(435, 55);
    m_player = new MusicCoreMPlayer(this);

    connect(ui->addSongButton, SIGNAL(clicked()), SLOT(initInputPath()));
    connect(ui->playSongButton, SIGNAL(clicked()), SLOT(playInputSong()));
    connect(ui->playRingButton, SIGNAL(clicked()), SLOT(playRingtone()));
    connect(ui->saveSongButton, SIGNAL(clicked()), SLOT(initOutputPath()));
    connect(ui->cutSliderWidget, SIGNAL(posChanged(qint64,qint64)), SLOT(posChanged(qint64,qint64)));
    connect(m_player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
    connect(m_player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
}

MusicSongRingtoneMaker::~MusicSongRingtoneMaker()
{
    delete m_player;
    delete ui;
}

void MusicSongRingtoneMaker::initInputPath()
{
    QStringList supportedFormat;
    supportedFormat << "mp3" <<"wav" <<"wma" << "ogg" << "flac" << "ac3" << "aac";

    QString filter = "Files (";
    for(int i=0; i<supportedFormat.count(); ++i)
    {
        filter += QString("*.%1 ").arg(supportedFormat[i]);
    }
    filter = filter.trimmed() + ")";

    QString path = QFileDialog::getOpenFileName(this, QString(), "./", filter);
    if(path.isEmpty())
    {
        return;
    }

    m_inputFilePath = path;
    MusicSongTag tag;
    if(tag.readFile(m_inputFilePath))
    {
        QString name = m_inputFilePath.split("/").last();
        ui->songLabelValue->setText(tr("SongName: %1 ( %2, %3, %4)").arg(name)
                .arg(tag.getLengthString()).arg(tag.getSamplingRate()).arg(tag.getBitrate()));
    }
    else
    {
        ui->songLabelValue->setText(tr("Open File Error!"));
        return;
    }

    ui->playSongButton->setEnabled(true);
    ui->playRingButton->setEnabled(true);
    ui->saveSongButton->setEnabled(true);

    m_player->setMedia(MusicCoreMPlayer::MusicCategory, m_inputFilePath);
    playInputSong();

}

void MusicSongRingtoneMaker::initOutputPath()
{
    QString value = QString("Files (*.%1 )").arg(ui->formatCombo->currentText().toLower());
    value = QFileDialog::getSaveFileName(this, QString(), "./", value);
    if(value.isEmpty())
    {
        return;
    }

    QProcess::execute(MAKE_TRANSFORM_FULL, QStringList()
        << "-i" << m_inputFilePath << "-ss" << QString::number(m_startPos)
        << "-t" << QString::number(m_stopPos) << "-acodec" << "copy"
        << "-ab" << ui->kbpsCombo->currentText() + "k"
        << "-ar" << ui->hzCombo->currentText()
        << "-ac" << QString::number(ui->msCombo->currentIndex() + 1) << value );
    qDebug() << QStringList()
             << "-i" << m_inputFilePath << "-ss" << QString::number(m_startPos)
             << "-t" << QString::number(m_stopPos) << "-acodec" << "copy"
             << "-ab" << ui->kbpsCombo->currentText() + "k"
             << "-ar" << ui->hzCombo->currentText()
             << "-ac" << QString::number(ui->msCombo->currentIndex() + 1) << value;
}

void MusicSongRingtoneMaker::playInputSong()
{
    m_playRingtone = false;
    if(m_player->state() == MusicCoreMPlayer::StoppedState ||
       m_player->state() == MusicCoreMPlayer::PausedState)
    {
        ui->playSongButton->setText(tr("Stop"));
    }
    else
    {
        ui->playSongButton->setText(tr("Play"));
    }
    m_player->play();
}

void MusicSongRingtoneMaker::playRingtone()
{
    m_playRingtone = true;
    m_player->setPosition(m_startPos);
}

void MusicSongRingtoneMaker::positionChanged(qint64 position)
{
    if(m_playRingtone && m_stopPos < position)
    {
        m_player->play();
        ui->playSongButton->setText(tr("Play"));
        return;
    }
    ui->cutSliderWidget->setPosition(position);
}

void MusicSongRingtoneMaker::durationChanged(qint64 duration)
{
    ui->cutSliderWidget->setDuration(duration);
}

void MusicSongRingtoneMaker::posChanged(qint64 start, qint64 end)
{
    m_startPos = start;
    m_stopPos = end;
    ui->startTimeLabel->setText( MusicTime::toString(start, MusicTime::All_Sec, "mm:ss:zzz") );
    ui->stopTimeLabel->setText( MusicTime::toString(end, MusicTime::All_Sec, "mm:ss:zzz") );
    ui->ringLabelValue->setText( tr("Ring Info.\tCut Length: %1")
                        .arg(MusicTime::toString(end - start, MusicTime::All_Sec, "mm:ss")));
}

int MusicSongRingtoneMaker::exec()
{
    if(!QFile::exists(MAKE_TRANSFORM_FULL))
    {
        MusicMessageBox message;
        message.setText(tr("Lack of plugin file!"));
        message.exec();
        return -1;
    }

    QPixmap pix(M_BACKGROUND_PTR->getMBackground());
    ui->background->setPixmap(pix.scaled( size() ));
    return MusicAbstractMoveDialog::exec();
}
{'fraction_non_alphanumeric': 0.16036036036036036, 'fraction_numerical': 0.012925969447708578, 'mean_word_length': 4.874827427519558, 'pattern_counts': {'":': 2, '<': 103, '<?xml version=': 0, '>': 217, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140712', 'n_tokens_mistral': 4465, 'n_tokens_neox': 4219, 'n_words': 505}