wavelength 1.0.0
Loading...
Searching...
No Matches
multimuse.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <list>
5
6#include "gs/muse.h"
7#include "os/command.h"
8#include "os/mem.h"
9#include "os/ptr.h"
10#include "os/scheduler.h"
11
20class MultiMuse : public Muse {
21public:
23 struct TimedMuse {
25 int mTick;
26 };
27
34 class MultiMuseCmd : public Command {
35 public:
42 ~MultiMuseCmd() override = default;
43
49 explicit MultiMuseCmd(MultiMuse *pMulti) : mMulti(pMulti) {
50 }
51
58 static void *operator new(size_t nSize) {
59 return PoolAlloc(static_cast<int>(nSize), sizeof(MultiMuseCmd), "MultiMuse cmd", 0);
60 }
61
67 static void operator delete(void *pBlock) {
68 PoolFree(sizeof(MultiMuseCmd), pBlock);
69 }
70
77 void Execute() override;
78
79 private:
80 MultiMuse *mMulti;
81 };
82
90 explicit MultiMuse(int nStopPrevious);
91
98 static void *operator new(size_t nSize) {
99 return PoolAlloc(static_cast<int>(nSize), sizeof(MultiMuse), "MultiMuse", 0);
100 }
101
107 static void operator delete(void *pBlock) {
108 PoolFree(sizeof(MultiMuse), pBlock);
109 }
110
117 ~MultiMuse() override;
118
126 void Play(Scheduler *pScheduler) override;
127
136 void PlayFrom(Scheduler *pScheduler, int nOffset) override;
137
149 void PlayWindow(Scheduler *pScheduler, int nStart, int nEnd) override;
150
158 bool IsPlaying() override;
159
167 int GetLength() override;
168
175 void Stop() override;
176
184 Muse *Clone() override;
185
193 void SetNoteCB(NoteCB *pNoteCB) override;
194
205 void Add(Muse *pMuse, int nTick);
206
207private:
214 void Advance();
215
216 std::list<TimedMuse> mMuses;
217 std::list<TimedMuse>::iterator mNext;
218 std::list<TimedMuse>::iterator mFirstActive;
219 int mStopPrevious;
220 Scheduler *mScheduler;
221 Ptr<Command> mCmd;
222 int mLength;
223 int mOffset;
224 int mEnd;
225};
Unit of work a Scheduler runs at a set time.
Definition command.h:13
MultiMuseCmd(MultiMuse *pMulti)
Construct the command of a sequence.
Definition multimuse.h:49
void Execute() override
Start the muses of the next tick.
~MultiMuseCmd() override=default
Destroy the object.
void PlayWindow(Scheduler *pScheduler, int nStart, int nEnd) override
Play the part of the sequence in a window of ticks.
void Play(Scheduler *pScheduler) override
Play from the start.
void Stop() override
Withdraw the queued command and stop every muse.
void Add(Muse *pMuse, int nTick)
Insert a muse at a tick, after the muses of the same tick.
void SetNoteCB(NoteCB *pNoteCB) override
Set the receiver of the notes of every muse of the sequence.
int GetLength() override
Report the length of the sequence.
Muse * Clone() override
Produce a copy of the sequence and of each muse on the heap.
bool IsPlaying() override
Report whether the sequence plays.
~MultiMuse() override
Stop the sequence and release the muses.
MultiMuse(int nStopPrevious)
Construct an empty sequence.
void PlayFrom(Scheduler *pScheduler, int nOffset) override
Play from a tick of the sequence to its end.
Receiver of each note a muse starts.
Definition muse.h:20
Piece of MIDI performance that a Scheduler plays.
Definition muse.h:12
Owner of one reference to an Attachment.
Definition ptr.h:16
Queue of commands that run when the song clock reaches their tick.
Definition scheduler.h:20
void * PoolAlloc(int nSize, int nBlockSize, const char *pszTag, int nUnused)
Allocate a block from the small-block pool and bill it to a tag.
void PoolFree(int nSize, void *pBlock)
Return a block to the small-block pool.
One muse of the sequence and its tick.
Definition multimuse.h:23
int mTick
Definition multimuse.h:25
Ptr< Muse > mMuse
Definition multimuse.h:24