aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop/qmpinfowindow.cpp
blob: 654c8f4e5b2028037a97ca127636c679ea84b7a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <QTextCodec>
#include "qmpinfowindow.hpp"
#include "ui_qmpinfowindow.h"
#include "qmpmainwindow.hpp"
#include "qmpsettingswindow.hpp"

const char *minors = "abebbbf c g d a e b f#c#g#d#a#";
const char *majors = "CbGbDbAbEbBbF C G D A E B F#C#";
const char *standards = "?  GM GM2GS XG ";

qmpInfoWindow::qmpInfoWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::qmpInfoWindow)
{
    ui->setupUi(this);
    qmpMainWindow::getInstance()->registerFunctionality(
        infof = new qmpInfoFunc(this),
        std::string("FileInfo"),
        tr("File Information").toStdString(),
        getThemedIconc(":/img/info.svg"),
        0,
        true
    );
}

qmpInfoWindow::~qmpInfoWindow()
{
    qmpMainWindow::getInstance()->unregisterFunctionality("FileInfo");
    delete infof;
    delete ui;
}

void qmpInfoWindow::closeEvent(QCloseEvent *e)
{
    setVisible(false);
    qmpMainWindow::getInstance()->setFuncState("FileInfo", false);
    e->accept();
}
void qmpInfoWindow::hideEvent(QHideEvent *e)
{
    qmpMainWindow::getInstance()->setFuncState("FileInfo", false);
    e->accept();
}


void qmpInfoWindow::updateInfo()
{
    char str[256];
    CMidiPlayer *player = qmpMainWindow::getInstance()->getPlayer();
    std::string textencoding = qmpMainWindow::getInstance()->getSettings()->getOptionEnumIntOptName("Midi/TextEncoding");
    ui->lbFileName->setText(QString("File name: ") + qmpMainWindow::getInstance()->getFileName());
    if (player->getTitle())
    {
        if (textencoding != "Unicode")
            ui->lbTitle->setText(QString("Title: ") +
                QTextCodec::codecForName(textencoding.c_str())->toUnicode(player->getTitle()));
        else
            ui->lbTitle->setText(QString("Title: ") + player->getTitle());
    }
    else ui->lbTitle->setText(QString("Title: "));
    if (player->getCopyright())
    {
        if (textencoding != "Unicode")
            ui->lbCopyright->setText(QString("Copyright: ") +
                QTextCodec::codecForName(textencoding.c_str())->toUnicode(player->getCopyright()));
        else
            ui->lbCopyright->setText(QString("Copyright: ") + player->getCopyright());
    }
    else ui->lbCopyright->setText(QString("Copyright: "));
    ui->lbTempo->setText(QString("Tempo: ") + QString::number(player->getTempo(), 'g', 5));
    int t, r;
    t = player->getCurrentKeySignature();
    r = (int8_t)((t >> 8) & 0xFF) + 7;
    strncpy(str, t & 0xFF ? minors + 2 * r : majors + 2 * r, 2);
    str[2] = '\0';
    ui->lbKeySig->setText(QString("Key Sig.: ") + str);
    player->getCurrentTimeSignature(&t, &r);
    sprintf(str, "Time Sig.: %d/%d", t, r);
    ui->lbTimeSig->setText(str);
    sprintf(str, "Note count: %u", player->getFileNoteCount());
    ui->lbNoteCount->setText(str);
    strncpy(str, standards + player->getFileStandard() * 3, 3);
    str[3] = '\0';
    ui->lbFileStandard->setText(QString("File standard: ") + str);
}

qmpInfoFunc::qmpInfoFunc(qmpInfoWindow *par)
{
    p = par;
}
void qmpInfoFunc::show()
{
    p->show();
}
void qmpInfoFunc::close()
{
    p->close();
}