-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhivelyhelper.cpp
87 lines (74 loc) · 1.69 KB
/
hivelyhelper.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 "hivelyhelper.h"
HivelyHelper::HivelyHelper(const QString &path)
: m_path(path)
{
}
HivelyHelper::~HivelyHelper()
{
deinit();
}
void HivelyHelper::deinit()
{
if(m_input)
{
hvl_FreeTune(m_input);
}
}
bool HivelyHelper::initialize()
{
QFile file(m_path);
if(!file.open(QIODevice::ReadOnly))
{
qWarning("HivelyHelper: open file failed");
return false;
}
const QByteArray &buffer = file.readAll();
file.close();
hvl_InitReplayer();
m_input = hvl_ParseTune((unsigned char *)buffer.constData(), buffer.length(), sampleRate(), 0);
if(!m_input)
{
qWarning("HivelyHelper: hvl_LoadTune error");
return false;
}
m_ahxHeader = (buffer[0] == 'H') && (buffer[1] == 'V') && (buffer[2] == 'L');
return true;
}
QString HivelyHelper::format() const
{
return m_ahxHeader ? "AHX Tracker" : "Hively Tracker";
}
QString HivelyHelper::instruments() const
{
QString value;
// instruments starts from 1 in hively so skip 0
for(int i = 1; i < instrumentCount(); ++i)
{
value += m_input->ht_Instruments[i].ins_Name;
value += "\n";
}
return value;
}
QString HivelyHelper::subSongs() const
{
QString value;
if(subSongCount() > 1)
{
for(int i = 0; i < subSongCount(); ++i)
{
value += m_input->ht_Name;
value += "\n";
}
}
return value;
}
qint64 HivelyHelper::read(unsigned char *data, qint64)
{
if(m_input->ht_SongEndReached)
{
return 0;
}
int8 *ptr = (int8*)data;
hvl_DecodeFrame(m_input, ptr, ptr + 2, 4);
return (m_input->ht_Frequency / 50 / m_input->ht_SpeedMultiplier) * 4;
}