wavelength 1.0.0
Loading...
Searching...
No Matches
bankloader.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "game/playmap.h"
7#include "os/command.h"
8#include "os/ptr.h"
9#include "os/string.h"
10
20public:
28
35 public:
44 PermBankLoader(unsigned short nSlot, const char *pszFile);
45
53
60 void Load();
61
69 bool IsLoaded() const;
70
72 unsigned short GetSlot() const {
73 return mSlot;
74 }
75
77 int GetBlockCount() const {
78 return mBlockCount;
79 }
80
81 private:
82 unsigned short mSlot;
83 String mFile;
84 int mBlockCount;
85 int mLoading;
86 };
87
96 public:
98 struct SwapBank {
100 int mSize;
101 };
102
109
121 SwapBankLoader(unsigned short nBaseSlot,
122 PlayMap *pPlayMap,
123 int nLeadBars,
124 int nNumBars,
125 int nTicksPerBar);
126
134
143 void AddBank(const char *pszFile, int nStartBar);
144
152 int GetMaxBankSize() const;
153
160 void Load();
161
169 bool PollLoad();
170
177 void Start();
178
185 void Unload();
186
193 void Restart();
194
196 unsigned short GetBaseSlot() const {
197 return mBaseSlot;
198 }
199
200 private:
209 int GetBank(int nBar) const {
210 return mBankOfBar[nBar + mLeadBars];
211 }
212
221 void SetBank(int nBar, int nBank) {
222 mBankOfBar[nBar + mLeadBars] = nBank;
223 }
224
232 void Advance();
233
241 unsigned short GetLoadSlot() const;
242
250 void LoadBank(int nBank);
251
253 static constexpr int kNumSlots = 2;
254
255 unsigned short mBaseSlot;
256 const char *mLoaded[kNumSlots];
257 int mLeadBars;
258 int mNumBars;
259 int mTicksPerBar;
260 PlayMap *mPlayMap;
261 std::vector<SwapBank> mBanks;
262 std::vector<int> mBankOfBar;
263 int mState;
264 int mLoadCount;
265 Ptr<Command> mAdvanceCmd;
266 };
267
279 BankLoader(unsigned short nFirstSlot,
280 PlayMap *pPlayMap,
281 int nIntroBars,
282 int nNumBars,
283 int nTicksPerBar);
284
292
300 void AddPermBank(const char *pszFile);
301
310 void AddSwapBank(const char *pszFile, int nBar);
311
321 void Load();
322
330 bool PollLoad();
331
338 void Start();
339
346 void Stop();
347
354 void Restart();
355
364
372 unsigned short GetEndBankSlot();
373
374private:
381 void PartitionSlots();
382
383 int mState;
384 unsigned short mFirstSlot;
385 int mIntroBars;
386 int mNumBars;
387 int mTicksPerBar;
388 PlayMap *mPlayMap;
389 std::vector<std::unique_ptr<PermBankLoader>> mPermBanks;
390 std::unique_ptr<SwapBankLoader> mSwapBanks;
391 int mLoadCount;
392};
bool IsLoaded() const
Report whether the bank finished loading.
~PermBankLoader()
Unload the bank when Load() was called.
int GetBlockCount() const
Definition bankloader.h:77
PermBankLoader(unsigned short nSlot, const char *pszFile)
Construct a loader and query the size of the bank from the synthesiser.
unsigned short GetSlot() const
Definition bankloader.h:72
void Load()
Start loading the bank into its slot.
~SwapBankLoader()
Unload the banks.
bool PollLoad()
Report whether the first bank is loaded.
void Load()
Start loading the first bank.
void AddBank(const char *pszFile, int nStartBar)
Add a bank that plays from a bar to the end of the song.
int GetMaxBankSize() const
Report the size of the largest bank.
void Unload()
Withdraw the scheduled load and unload the slots.
SwapBankLoader(unsigned short nBaseSlot, PlayMap *pPlayMap, int nLeadBars, int nNumBars, int nTicksPerBar)
Construct a loader with no banks.
void Restart()
Withdraw the scheduled load and load the bank the song needs next.
void Start()
Load the bank the song needs next.
unsigned short GetBaseSlot() const
Definition bankloader.h:196
State
Values of mState.
Definition bankloader.h:104
@ kStateLoading
Definition bankloader.h:106
@ kStateIdle
Definition bankloader.h:105
@ kStateLoaded
Definition bankloader.h:107
State
Values of mState.
Definition bankloader.h:22
@ kStateLoaded
Definition bankloader.h:25
@ kStateIdle
Definition bankloader.h:23
@ kStatePlaying
Definition bankloader.h:26
@ kStateLoading
Definition bankloader.h:24
void Stop()
Stop a load or the swapping that is under way.
BankLoader(unsigned short nFirstSlot, PlayMap *pPlayMap, int nIntroBars, int nNumBars, int nTicksPerBar)
Construct a loader with no bank.
unsigned short GetEndBankSlot()
Report the first synthesiser bank slot after the slots the banks fill.
void AddSwapBank(const char *pszFile, int nBar)
Add a swapped bank that plays from a bar on.
~BankLoader()
Stop a load and release the loaders.
void Start()
Enter the playing state and start swapping the banks.
void Load()
Start loading the sound banks.
void AddPermBank(const char *pszFile)
Add a permanent bank in the next free slot.
void Restart()
Swap the banks for the song position again.
bool PollLoad()
Advance the load and report whether it finished.
int GetNumSlots()
Report the number of slots the banks fill.
Map from the bars a song plays to the bars of the song as written, with the loops that repeat stretch...
Definition playmap.h:11
Growable text buffer that is also a PrnStream.
Definition string.h:19
One bank file and its size.
Definition bankloader.h:98
int mSize
Definition bankloader.h:100
String mFile
Definition bankloader.h:99