wavelength 1.0.0
Loading...
Searching...
No Matches
mixtrack.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <memory>
5
6#include "gs/muse.h"
7#include "gs/muselooper.h"
8#include "os/command.h"
9#include "os/mem.h"
10#include "os/ptr.h"
11#include "os/ramp.h"
12
20class MixTrack : public MuseLooper {
21public:
27 class VolumeRamp : public Ramp {
28 public:
36 explicit VolumeRamp(MixTrack *pOwner);
37
44 ~VolumeRamp() override;
45
54 void Apply(float fValue, int nTick) override;
55
56 private:
57 MixTrack *mOwner;
58 };
59
68 void *operator new(size_t nSize) {
69 return PoolMemAlloc(static_cast<int>(nSize), "MixTrack", 0);
70 }
71
79 void operator delete(void *pBlock) {
80 PoolMemFree(pBlock);
81 }
82
95 MixTrack(Muse *pMuse, int nLength, unsigned char nChannel);
96
104
113 void FadeIn(int nFadeTicks, int nPosition);
114
122 void FadeOut(int nFadeTicks);
123
130 void StopNow();
131
139 bool IsPlaying() const;
140
148 void SetVolume(float fVolume);
149
158 void RampTo(float fTarget, int nTicks);
159
160private:
161 std::unique_ptr<VolumeRamp> mRamp;
162 unsigned char mChannel;
163 float mMaxVolume;
164 Ptr<Command> mStopCmd;
165};
VolumeRamp(MixTrack *pOwner)
Construct a ramp at 0 on the scheduler of the front end.
void Apply(float fValue, int nTick) override
Set the volume of the track.
~VolumeRamp() override
Stop the ramp.
void StopNow()
Stop the track and its fade at once and return its volume to full.
MixTrack(Muse *pMuse, int nLength, unsigned char nChannel)
Construct a silent, stopped track.
void SetVolume(float fVolume)
Send a volume, limited to the range from 0 to 1, as the expression of the track's channel.
void RampTo(float fTarget, int nTicks)
Start moving the volume to a target.
void FadeIn(int nFadeTicks, int nPosition)
Start the track at a position of its loop and fade its volume up to the maximum.
bool IsPlaying() const
Report whether the track plays.
void FadeOut(int nFadeTicks)
Fade a playing track's volume to 0 and stop the track once the fade has ended.
~MixTrack()
Stop the track and release its ramp.
MuseLooper(Muse *pMuse, int nLength)
Construct a stopped looper.
Piece of MIDI performance that a Scheduler plays.
Definition muse.h:12
Owner of one reference to an Attachment.
Definition ptr.h:16
Ramp(Scheduler *pScheduler, float fValue)
Construct a ramp that holds a value.
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.