Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
areaaudio.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 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
22#include "./areaaudio.h"
23#include "../../savefile.h"
26#include <pse-db/music.h>
28#include <pse-db/mapsdb.h>
29#include <pse-common/random.h>
30
32{
33 load(saveFile);
34}
35
37
39{
40 reset();
41 if(saveFile == nullptr)
42 return;
43
44 auto toolset = saveFile->toolset;
45
46 musicID = toolset->getByte(0x2607);
48
49 musicBank = toolset->getByte(0x2608);
51
52 noAudioFadeout = toolset->getBit(0x29D8, 1, 1);
54
55 preventMusicChange = toolset->getBit(0x29DF, 1, 1);
57}
58
60{
61 auto toolset = saveFile->toolset;
62
63 toolset->setByte(0x2607, musicID);
64 toolset->setByte(0x2608, musicBank);
65 toolset->setBit(0x29D8, 1, 1, noAudioFadeout);
66 toolset->setBit(0x29DF, 1, 1, preventMusicChange);
67}
68
70{
71 musicID = 0;
73
74 musicBank = 0;
76
77 noAudioFadeout = false;
79
80 preventMusicChange = false;
82}
83
85{
86 reset();
87
88 // Select a random song
89 auto musicEntry = MusicDB::inst()->getStore().at(Random::inst()->rangeExclusive(0, MusicDB::inst()->getStoreSize()));
90
91 // Load it into the map
92 musicID = musicEntry->id;
94
95 musicBank = musicEntry->bank;
97}
98
100{
101 reset();
102
103 // Select a random song
104 MusicDBEntry* musicEntry = map->getToMusic();
105
106 // Load it into the map
107 musicID = (musicEntry == nullptr)
108 ? 0
109 : musicEntry->id;
111
112 musicBank = musicID = (musicEntry == nullptr)
113 ? 0
114 : musicEntry->bank;
116}
AreaAudio(SaveFile *saveFile=nullptr)
< Playing track id.
Definition areaaudio.cpp:31
int musicBank
Definition areaaudio.h:63
void setTo(MapDBEntry *map)
Set music to map's default.
Definition areaaudio.cpp:99
virtual ~AreaAudio()
Definition areaaudio.cpp:36
void randomize()
Randomize the track.
Definition areaaudio.cpp:84
int musicID
Definition areaaudio.h:62
bool preventMusicChange
Definition areaaudio.h:65
void preventMusicChangeChanged()
protected::void musicIDChanged()
bool noAudioFadeout
Definition areaaudio.h:64
void save(SaveFile *saveFile)
Flatten audio settings to the save.
Definition areaaudio.cpp:59
void reset()
Blank audio settings.
Definition areaaudio.cpp:69
void noAudioFadeoutChanged()
void musicBankChanged()
void load(SaveFile *saveFile=nullptr)
Expand audio settings from the save.
Definition areaaudio.cpp:38
const QVector< MusicDBEntry * > getStore() const
All tracks.
Definition music.cpp:43
static MusicDB * inst()
< Number of tracks.
Definition music.cpp:37
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
void setByte(var16 addr, var8 val)
Simply sets a byte.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition savefile.h:117
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
MusicDBEntry * getToMusic() const
One music track: its name and bank/id, plus the maps that use it.
Definition music.h:38
var8 bank
Audio bank.
Definition music.h:43
var8 id
Track id within the bank.
Definition music.h:44