-
Notifications
You must be signed in to change notification settings - Fork 0
/
adlmidihelper.cpp
87 lines (74 loc) · 1.7 KB
/
adlmidihelper.cpp
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
#include "adlmidihelper.h"
#include <QSettings>
AdlMidiHelper::AdlMidiHelper(const QString &path)
: m_path(path)
{
}
AdlMidiHelper::~AdlMidiHelper()
{
deinit();
}
void AdlMidiHelper::deinit()
{
if(m_input)
{
adl_close(m_input);
}
}
bool AdlMidiHelper::initialize()
{
m_input = adl_init(sampleRate());
if(adl_openFile(m_input, qPrintable(m_path)) < 0)
{
qWarning("AdlMidiHelper: adl_openFile error");
return false;
}
readSettings();
adl_setLoopEnabled(m_input, 0);
return true;
}
void AdlMidiHelper::readSettings()
{
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
settings.beginGroup("Midi");
if(!settings.value("use_wopl", false).toBool())
{
const int index = settings.value("index", -1).toInt();
adl_setBank(m_input, index >= adl_getBanksCount() ? 0 : index);
}
else
{
adl_openBankFile(m_input, qPrintable(settings.value("conf_path").toString()));
}
settings.endGroup();
adl_reset(m_input);
}
qint64 AdlMidiHelper::read(unsigned char *data, qint64 maxSize)
{
const int samples = maxSize / channels();
return adl_play(m_input, samples, (short*)data) * 2;
}
QString AdlMidiHelper::trackTitle() const
{
QString value;
for(int i = 0; i < trackTitleCount(); ++i)
{
value += adl_metaTrackTitle(m_input, i);
value += "\n";
}
return value;
}
QString AdlMidiHelper::metaMarker() const
{
QString value;
for(int i = 0; i < metaMarkerCount(); ++i)
{
value += adl_metaMarker(m_input, i).label;
value += "\n";
}
return value;
}