Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
music.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2019 Twilight
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
21
22
#include <QJsonArray>
23
#include <QQmlEngine>
24
#include <
pse-common/utility.h
>
25
26
#include "
./music.h
"
27
#include "
./util/gamedata.h
"
28
29
MusicDBEntry::MusicDBEntry
() {}
30
MusicDBEntry::MusicDBEntry
(QJsonValue& data)
31
{
32
name
= data[
"name"
].toString();
33
bank
=
static_cast<
var8
>
(data[
"bank"
].toDouble());
34
id
=
static_cast<
var8
>
(data[
"id"
].toDouble());
35
}
36
37
MusicDB*
MusicDB::inst
()
38
{
39
static
MusicDB* _inst =
new
MusicDB;
40
return
_inst;
41
}
42
43
const
QVector<MusicDBEntry*>
MusicDB::getStore
()
const
{
return
store; }
44
const
QHash<QString, MusicDBEntry*>
MusicDB::getInd
()
const
{
return
ind; }
45
int
MusicDB::getStoreSize
()
const
{
return
store.size(); }
46
47
MusicDBEntry
*
MusicDB::getStoreAt
(
int
idx)
const
48
{
49
if
(idx < 0 || idx >= store.size())
return
nullptr
;
50
return
store.at(idx);
51
}
52
53
MusicDBEntry
*
MusicDB::getIndAt
(
const
QString& key)
const
54
{
55
return
ind.value(key,
nullptr
);
56
}
57
58
void
MusicDB::load
()
59
{
60
static
bool
once =
false
;
61
if
(once)
return
;
62
auto
jsonData =
GameData::inst
()->
json
(
"music"
);
63
for
(QJsonValue entry : jsonData.array())
64
store.append(
new
MusicDBEntry
(entry));
65
once =
true
;
66
}
67
68
void
MusicDB::index
()
69
{
70
static
bool
once =
false
;
71
if
(once)
return
;
72
for
(
auto
* entry : store) {
73
ind.insert(entry->name, entry);
74
ind.insert(QString::number(entry->bank) +
"_"
+ QString::number(entry->id), entry);
75
}
76
once =
true
;
77
}
78
79
void
MusicDB::qmlProtect
(
const
QQmlEngine*
const
engine)
const
80
{
81
Utility::qmlProtectUtil
(
this
, engine);
82
}
83
84
void
MusicDB::qmlRegister()
const
85
{
86
static
bool
once =
false
;
87
if
(once)
return
;
88
qmlRegisterUncreatableType<MusicDB>(
"PSE.DB.MusicDB"
, 1, 0,
"MusicDB"
,
"Can't instantiate in QML"
);
89
once =
true
;
90
}
91
92
MusicDB::MusicDB()
93
{
94
qmlRegister();
95
}
GameData::json
const QJsonDocument json(const QString filename) const
Parsed document for filename.
Definition
gamedata.cpp:45
GameData::inst
static GameData * inst()
The process-wide GameData singleton.
Definition
gamedata.cpp:71
MusicDB::getStore
const QVector< MusicDBEntry * > getStore() const
All tracks.
Definition
music.cpp:43
MusicDB::getStoreAt
MusicDBEntry * getStoreAt(int idx) const
Track by store index (for QML).
Definition
music.cpp:47
MusicDB::getInd
const QHash< QString, MusicDBEntry * > getInd() const
Name->entry index.
Definition
music.cpp:44
MusicDB::load
void load()
Load tracks from JSON.
Definition
music.cpp:58
MusicDB::getStoreSize
int getStoreSize() const
Track count.
Definition
music.cpp:45
MusicDB::index
void index()
Build the name->entry index.
Definition
music.cpp:68
MusicDB::getIndAt
MusicDBEntry * getIndAt(const QString &key) const
Track by name key (for QML).
Definition
music.cpp:53
MusicDB::inst
static MusicDB * inst()
< Number of tracks.
Definition
music.cpp:37
MusicDB::qmlProtect
void qmlProtect(const QQmlEngine *const engine) const
Pin to C++ ownership.
Definition
music.cpp:79
Utility::qmlProtectUtil
static void qmlProtectUtil(const QObject *const obj, const QQmlEngine *const engine)
Pin obj to C++ ownership so the QML engine never garbage-collects it.
Definition
utility.cpp:63
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
gamedata.h
music.h
MusicDBEntry
One music track: its name and bank/id, plus the maps that use it.
Definition
music.h:38
MusicDBEntry::bank
var8 bank
Audio bank.
Definition
music.h:43
MusicDBEntry::MusicDBEntry
MusicDBEntry()
Empty entry.
Definition
music.cpp:29
MusicDBEntry::name
QString name
Track name (key).
Definition
music.h:42
utility.h
projects
db
src
pse-db
music.cpp
Generated by
1.17.0