wavelength 1.0.0
Loading...
Searching...
No Matches
mixer.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "os/command.h"
7#include "os/ptr.h"
8#include "os/ramp.h"
9#include "script/dataarray.h"
10
23class Mixer {
24public:
32
39
41 static constexpr int kChannelCount = 16;
42
44 static constexpr int kFxChannel = kChannelCount - 1;
45
47 struct TrackData {
48 int mPlayers = 0;
49 int mHeld = 0;
51 };
52
58 class VolumeRamp : public Ramp {
59 public:
66 ~VolumeRamp() override = default;
67
77 VolumeRamp(Scheduler *pScheduler, float fValue, unsigned char nChannel)
78 : Ramp(pScheduler, fValue), mChannel(nChannel) {
79 }
80
89 void Apply(float fValue, int nTick) override;
90
91 private:
92 unsigned char mChannel;
93 };
94
102
110
118 static Mixer *shared();
119
132 void Init(int nTracks, int nInstrument);
133
142 bool IsInstrumentTrack(int nTrack) const;
143
152 void SetVolumes(int nChannel, const std::vector<unsigned char> &volumes);
153
161 void SetInstrumentVolumes(const std::vector<unsigned char> &volumes);
162
170 void AddPlayer(int nTrack);
171
179 void RemovePlayer(int nTrack);
180
191 void HoldTrack(int nTrack, int nUntilTick);
192
200 void ReleaseTrack(int nTrack);
201
209
218
227 void Activate();
228
238
246 void FadeOut(int nTicks);
247
257 void SetVolume(int nChannel, unsigned char nVolume, int nTicks);
258
267 unsigned char GetVolume(int nChannel);
268
276 void RefreshAll(int nTicks);
277
286 static void ToggleMuteUnoccupied(DataArray *pCommand, void *pUserData);
287
288private:
298 static void
299 ReadVolumes(const DataArray *pConfig, const char *pszKey, std::vector<unsigned char> &volumes);
300
310 static int ReadInt(const char *pszKey, const DataArray *pConfig);
311
321 static unsigned char ReadByte(const char *pszKey, const DataArray *pConfig);
322
335 void ApplyVolume(int nChannel, const std::vector<unsigned char> &volumes, int nTicks);
336
345 void RefreshTrack(int nChannel, int nTicks);
346
347 int mRampTicks;
348 std::vector<TrackData> mTracks;
349 unsigned char mHighVolume;
350 std::vector<unsigned char> mVolumes[kChannelCount];
351 std::vector<unsigned char> mInstrumentVolumes;
352 unsigned char mVictoryLapVolume;
353 int mHeldCount;
354 int mMode;
355 int mHasInstrumentTrack;
356 int mMuteUnoccupied;
357 std::unique_ptr<VolumeRamp> mRamps[kChannelCount];
358};
359
365extern Mixer *TheMixer;
Reference-counted array of script data nodes.
Definition dataarray.h:20
~VolumeRamp() override=default
Destroy the object.
void Apply(float fValue, int nTick) override
Send a volume to the channel as MIDI controller 17.
VolumeRamp(Scheduler *pScheduler, float fValue, unsigned char nChannel)
Construct a ramp at full volume for a channel.
Definition mixer.h:77
Volume control of the song's tracks.
Definition mixer.h:23
void RefreshAll(int nTicks)
Move every channel to the volume its track's state selects.
static constexpr int kFxChannel
The channel of the effects.
Definition mixer.h:44
void Init(int nTracks, int nInstrument)
Set the mixer up for a song and read the "mixer" section of the configuration.
void FadeOut(int nTicks)
Fade every track but the effects to silence.
static constexpr int kChannelCount
The number of synthesiser channels the mixer controls.
Definition mixer.h:41
void Deactivate()
Stop following the players, unregister the cheat, and return every track to full volume.
void Activate()
Start following the players and register the track_solo cheat.
static void ToggleMuteUnoccupied(DataArray *pCommand, void *pUserData)
Toggle muting the tracks nobody is on, the track_solo script command.
Instrument
The instrument tracks Init() configures the mixer for.
Definition mixer.h:34
@ kInstrumentAxe
Definition mixer.h:36
@ kInstrumentNone
Definition mixer.h:35
@ kInstrumentScratch
Definition mixer.h:37
unsigned char GetVolume(int nChannel)
Report a channel's volume.
static Mixer * shared()
Report the single instance, constructing it on first use.
void SetVolumes(int nChannel, const std::vector< unsigned char > &volumes)
Replace a channel's volume list.
~Mixer()
Destroy the ramps.
void RemovePlayer(int nTrack)
Count one player fewer on a track and refresh the track's volume.
void HoldTrack(int nTrack, int nUntilTick)
Hold a track until the tick before a song tick, and refresh every other channel.
void SetVolume(int nChannel, unsigned char nVolume, int nTicks)
Move a channel to a volume.
void SetInstrumentVolumes(const std::vector< unsigned char > &volumes)
Replace the volume list the other tracks use while the instrument track is occupied.
bool IsInstrumentTrack(int nTrack) const
Report whether a track is the instrument track.
void PlayFullMix()
Play every track but the effects at mHighVolume.
void StartVictoryLap()
Move every channel to the victory lap volume, and an occupied instrument track to mHighVolume,...
Mode
What the mixer is doing, the values of mMode.
Definition mixer.h:26
@ kModePlaying
Definition mixer.h:28
@ kModeOff
Definition mixer.h:27
@ kModeVictoryLap
Definition mixer.h:30
@ kModeFullMix
Definition mixer.h:29
void ReleaseTrack(int nTrack)
End the hold on a track and refresh every channel.
Mixer()
Construct a mixer with no tracks and one ramp per channel.
void AddPlayer(int nTrack)
Count one more player on a track and refresh the track's volume.
Owner of one reference to an Attachment.
Definition ptr.h:16
Ramp(Scheduler *pScheduler, float fValue)
Construct a ramp that holds a value.
Queue of commands that run when the song clock reaches their tick.
Definition scheduler.h:20
Mixer * TheMixer
The track mixer, Mixer::shared() as the unit's static initialiser stored it.
The state of one of the song's tracks.
Definition mixer.h:47
int mHeld
Definition mixer.h:49
Ptr< Command > mReleaseCommand
Definition mixer.h:50
int mPlayers
Definition mixer.h:48