wavelength 1.0.0
Loading...
Searching...
No Matches
levelmidibuilder.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "game/axetrackdata.h"
7#include "game/backmusic.h"
8#include "game/bankloader.h"
10#include "game/fxmgr.h"
11#include "game/lyric.h"
13#include "game/playmap.h"
17#include "game/slotgrid.h"
18#include "game/worldtrack.h"
19#include "gs/muse.h"
20#include "mid/midireader.h"
21#include "mid/midireceiver.h"
22#include "mid/trackbuilder.h"
23#include "os/file.h"
24#include "os/ptr.h"
25#include "os/string.h"
26
37public:
55
58 public:
64 explicit BuilderReceiver(LevelMidiBuilder *pOwner) : mOwner(pOwner) {
65 }
66
73 ~BuilderReceiver() override {
74 }
75
83 void OnNewTrack(unsigned char nTrack) override {
84 mOwner->OnNewTrack(nTrack);
85 }
86
93 void OnEndTrack() override {
94 mOwner->OnEndTrack();
95 }
96
103 void OnAllDone() override {
104 mOwner->OnAllDone();
105 }
106
117 void OnMidi(int nTick,
118 unsigned char nStatus,
119 unsigned char nData1,
120 unsigned char nData2) override {
121 mOwner->OnMidi(nTick, nStatus, nData1, nData2);
122 }
123
132 void OnTempo(int nTick, int nMicrosecondsPerBeat) override {
133 mOwner->OnTempo(nTick, nMicrosecondsPerBeat);
134 }
135
145 void OnText(int nTick, const char *pszText, unsigned char nType) override {
146 mOwner->OnText(nTick, pszText, nType);
147 }
148
158 void OnTimeSignature(int nTick, int nNumerator, int nDenominator) override {
159 mOwner->OnTimeSignature(nTick, nNumerator, nDenominator);
160 }
161
162 private:
163 LevelMidiBuilder *mOwner;
164 };
165
182 LevelMidiBuilder(const char *pszMidiFile,
183 int nDifficulty,
184 int nRuleSet,
185 int nNumBars,
186 int nIntroBars,
187 int nFreestyleEffectsBus,
188 int nRemixEffectsBus,
189 SectionBoundaries *pSections,
190 float *pMsPerTick,
191 SlotGrid *pSlotGrid);
192
200
209 void StartLoad();
210
221
231 void Poll();
232
242 int IsDone() const;
243
251 void OnNewTrack(unsigned char nTrack);
252
260
267 void OnAllDone();
268
279 void OnMidi(int nTick, unsigned char nStatus, unsigned char nData1, unsigned char nData2);
280
289 void OnTempo(int nTick, int nMicrosecondsPerBeat);
290
300 void OnTimeSignature(int nTick, int nNumerator, int nDenominator);
301
312 void OnText(int nTick, const char *pszText, unsigned char nType);
313
323 void LoadRemix();
324
332 int GetNumTracks() const;
333
342 int GetTrackType(int nTrack) const;
343
352 int GetTrackInstrument(int nTrack) const;
353
363
373
382 AxeTrackData *GetAxeData(int nTrack) const;
383
393
402 CatchTrackData *GetVoxData(int nTrack) const;
403
412 int GetTrackFlags(int nTrack) const;
413
421 int GetNumBackMusic() const;
422
431 BackMusic *GetBackMusic(int nIndex) const;
432
440 int GetNumIntroMuses() const;
441
450 Muse *GetIntroMuse(int nIndex) const;
451
462 ScriptTrackData *FindScriptTrack(const char *pszName) const;
463
475 static String FormatError(const String &prefix, int nTick, int nTrack, const String &message);
476
478 int GetTicksPerBar() const {
479 return mTicksPerBar;
480 }
481
484 return mPlayMap.get();
485 }
486
489 return mBankTrack.get();
490 }
491
494 return &mWorldTrack;
495 }
496
498 Lyric *GetLyric() const {
499 return mLyric.get();
500 }
501
503 FXMgr *GetFXMgr() const {
504 return mFXMgr.get();
505 }
506
508 float GetSpeed() const {
509 return mSpeed;
510 }
511
512private:
519 void OpenFile();
520
528 void ClassifyTrack(const char *pszName);
529
537 void ParseGameTrackName(const String &name);
538
545 void CreateTrackBuilder();
546
555 void Error(int nTick, const String &message);
556
562 class Tracks {
563 public:
574 Tracks(int nType, CatchTrackData *pGems, int nInstrument);
575
584 Tracks(ScratchTrackData *pScratch, int nInstrument);
585
594 Tracks(AxeTrackData *pAxe, int nInstrument);
595
604 Tracks(PitchTrackRiffData *pRiffs, int nInstrument);
605
615 ~Tracks() = default;
616
622 Tracks(Tracks &&other) = default;
623
624 std::unique_ptr<CatchTrackData> mCatch;
625 std::unique_ptr<ScratchTrackData> mScratch;
626 std::unique_ptr<AxeTrackData> mAxe;
627 std::unique_ptr<PitchTrackRiffData> mRiffs;
628 std::unique_ptr<CatchTrackData> mVox;
629 int mFlags;
630 int mInstrument;
631 };
632
633 std::vector<Tracks> mTracks;
634 std::vector<std::unique_ptr<BackMusic>> mBackMusic;
635 std::vector<Ptr<Muse>> mIntroMuses;
636 std::vector<std::unique_ptr<ScriptTrackData>> mScriptTracks;
637 std::unique_ptr<PlayMap> mPlayMap;
638 std::unique_ptr<BankLoader> mBankTrack;
639 WorldTrack mWorldTrack;
640 std::unique_ptr<Lyric> mLyric;
641 std::unique_ptr<FXMgr> mFXMgr;
642 float mSpeed;
643 char *mBuffer;
644 int mSize;
645 std::unique_ptr<File> mFile;
646 std::unique_ptr<MidiReader> mReader;
647 String mDirectory;
648 int mReadDone;
649 int mDone;
650 const char *mMidiFile;
651 int mDifficulty;
652 int mTicksPerBar;
653 int mNumBars;
654 int mIntroBars;
655 int mFreestyleEffectsBus;
656 int mRemixEffectsBus;
657 std::unique_ptr<BuilderReceiver> mReceiver;
658 int mValidate;
659 TrackBuilder::ErrorHandler mErrorHandler;
660 int mTrackIndex;
661 int mGameTrackCount;
662 String mTrackName;
663 String mTrackLabel;
664 int mInstrument;
665 int mTrackKind;
666 int mScratchIndex;
667 int mHasWorldTrack;
668 std::unique_ptr<TrackBuilder> mTrackBuilder;
669 int mRuleSet;
670 SectionBoundaries *mSections;
671 float *mMsPerTick;
672 SlotGrid *mSlotGrid;
673};
The notes and chords of a guitar track, one set of each for each span of the song.
Definition axetrackdata.h:17
Background music of a song, played alone or along with a catch track.
Definition backmusic.h:20
Loader of the sound banks of a song, from its track named "BANK".
Definition bankloader.h:19
The gems of one catch track, in the order of their ticks.
Definition catchtrackdata.h:14
The effect sets a song applies to the synthesiser channels at given bars.
Definition fxmgr.h:15
void OnEndTrack() override
Pass the end of a track to the builder.
Definition levelmidibuilder.h:93
void OnAllDone() override
Pass the end of the file to the builder.
Definition levelmidibuilder.h:103
void OnText(int nTick, const char *pszText, unsigned char nType) override
Pass a text event to the builder.
Definition levelmidibuilder.h:145
~BuilderReceiver() override
Release the receiver.
Definition levelmidibuilder.h:73
void OnNewTrack(unsigned char nTrack) override
Pass the start of a track to the builder.
Definition levelmidibuilder.h:83
void OnMidi(int nTick, unsigned char nStatus, unsigned char nData1, unsigned char nData2) override
Pass a channel message to the builder.
Definition levelmidibuilder.h:117
BuilderReceiver(LevelMidiBuilder *pOwner)
Construct a receiver for a builder.
Definition levelmidibuilder.h:64
void OnTempo(int nTick, int nMicrosecondsPerBeat) override
Pass a tempo change to the builder.
Definition levelmidibuilder.h:132
void OnTimeSignature(int nTick, int nNumerator, int nDenominator) override
Pass a time signature to the builder.
Definition levelmidibuilder.h:158
int GetNumIntroMuses() const
Report the number of performances of the tracks named "INTRO".
void StartLoad(TrackBuilder::ErrorHandler pfnError)
Start reading the MIDI file and check it for authoring errors.
LevelMidiBuilder(const char *pszMidiFile, int nDifficulty, int nRuleSet, int nNumBars, int nIntroBars, int nFreestyleEffectsBus, int nRemixEffectsBus, SectionBoundaries *pSections, float *pMsPerTick, SlotGrid *pSlotGrid)
Construct a builder for the MIDI file of a song.
int IsDone() const
Report whether the MIDI file is parsed.
void StartLoad()
Start reading the MIDI file without checking it for authoring errors.
~LevelMidiBuilder()
Release the builder, the file, and the data of every track.
CatchTrackData * GetVoxData(int nTrack) const
Report the gems of a vocal track.
void OnEndTrack()
Finish the track, and make the lyrics after the conductor track.
PitchTrackRiffData * GetTrackRiffData(int nTrack) const
Report the riffs of a pitch track.
void OnAllDone()
Report a song without a WORLD track or a BANK track.
int GetTrackInstrument(int nTrack) const
Report the instrument of a track.
ScratchTrackData * GetScratchData(int nTrack) const
Report the patterns of a turntable track.
PlayMap * GetPlayMap() const
Definition levelmidibuilder.h:483
WorldTrack * GetWorldTrack()
Definition levelmidibuilder.h:493
void OnText(int nTick, const char *pszText, unsigned char nType)
Take the name of a track that has none yet, and build its builder.
void OnTimeSignature(int nTick, int nNumerator, int nDenominator)
Pass a time signature to the builder of the track.
int GetTrackType(int nTrack) const
Report the type of an instrument track.
void OnTempo(int nTick, int nMicrosecondsPerBeat)
Pass a tempo change to the builder of the track.
int GetTicksPerBar() const
Definition levelmidibuilder.h:478
int GetNumTracks() const
Report the number of instrument tracks.
TrackKind
Kinds of a MIDI track, as its name identifies them.
Definition levelmidibuilder.h:39
@ kTrackKindNone
Definition levelmidibuilder.h:40
@ kTrackKindScratch
Definition levelmidibuilder.h:46
@ kTrackKindAxeHarmony
Definition levelmidibuilder.h:43
@ kTrackKindScript
Definition levelmidibuilder.h:51
@ kTrackKindBank
Definition levelmidibuilder.h:52
@ kTrackKindIgnore
Definition levelmidibuilder.h:53
@ kTrackKindPitch
Definition levelmidibuilder.h:44
@ kTrackKindVox
Definition levelmidibuilder.h:45
@ kTrackKindBackground
Definition levelmidibuilder.h:48
@ kTrackKindConductor
Definition levelmidibuilder.h:41
@ kTrackKindWorld
Definition levelmidibuilder.h:50
@ kTrackKindIntro
Definition levelmidibuilder.h:49
@ kTrackKindAxeContour
Definition levelmidibuilder.h:42
@ kTrackKindCatch
Definition levelmidibuilder.h:47
Muse * GetIntroMuse(int nIndex) const
Report the performance of one track named "INTRO".
ScriptTrackData * FindScriptTrack(const char *pszName) const
Find the commands of a track named "SCRIPT" by their name.
BankLoader * GetBankTrack() const
Definition levelmidibuilder.h:488
CatchTrackData * GetCatchTrackData(int nTrack) const
Report the gems of a catch track.
int GetTrackFlags(int nTrack) const
Report the flags of a track.
void LoadRemix()
Replace the data of the tracks with the saved remix of the game database.
void Poll()
Advance the read of the MIDI file, parsing it for up to 15 milliseconds once it is in memory,...
float GetSpeed() const
Definition levelmidibuilder.h:508
int GetNumBackMusic() const
Report the number of background music tracks.
AxeTrackData * GetAxeData(int nTrack) const
Report the notes of a guitar track.
Lyric * GetLyric() const
Definition levelmidibuilder.h:498
void OnNewTrack(unsigned char nTrack)
Start a track.
static String FormatError(const String &prefix, int nTick, int nTrack, const String &message)
Format an error message with the MIDI track and the position it concerns.
void OnMidi(int nTick, unsigned char nStatus, unsigned char nData1, unsigned char nData2)
Pass a channel message to the builder of the track.
FXMgr * GetFXMgr() const
Definition levelmidibuilder.h:503
BackMusic * GetBackMusic(int nIndex) const
Report one background music track.
Lyrics of a song loop, each shown when the song reaches its tick.
Definition lyric.h:18
Listener a MIDI file reader reports each track and event to.
Definition midireceiver.h:8
Piece of MIDI performance that a Scheduler plays.
Definition muse.h:12
The riffs a pitch track plays, one set of riffs for each tick that starts a set.
Definition pitchtrackriffdata.h:16
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
The scratchers of a scratch track, one set of three for each span of the song.
Definition scratchtrackdata.h:15
The script commands of a song's SCRIPT track, each at its tick.
Definition scripttrackdata.h:14
Ascending list of the measures at which the sections of a song end.
Definition sectionboundaries.h:12
The pattern each section of a remixed song repeats, as the section the pattern comes from.
Definition slotgrid.h:10
Growable text buffer that is also a PrnStream.
Definition string.h:19
void(* ErrorHandler)(String &message)
Routine that reports a build error.
Definition trackbuilder.h:19
The events of the track of a song named "WORLD", sorted by tick.
Definition worldtrack.h:11