wavelength 1.0.0
Loading...
Searching...
No Matches
stdmidimuse.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "gs/muse.h"
6#include "os/command.h"
7#include "os/mem.h"
8#include "os/ptr.h"
9#include "os/scheduler.h"
10
18class StdMidiMuse : public Muse {
19public:
26 class StdMidiCommand : public Command {
27 public:
34 ~StdMidiCommand() override = default;
35
41 explicit StdMidiCommand(StdMidiMuse *pMuse) : mMuse(pMuse), mScheduler(nullptr) {
42 }
43
50 static void *operator new(size_t nSize) {
51 return PoolAlloc(static_cast<int>(nSize), sizeof(StdMidiCommand), "StdMidiMuse cmd", 0);
52 }
53
59 static void operator delete(void *pBlock) {
60 PoolFree(sizeof(StdMidiCommand), pBlock);
61 }
62
69 void Execute() override;
70
77 void Cancel();
78
81 return mScheduler;
82 }
83
85 void SetScheduler(Scheduler *pScheduler) {
86 mScheduler = pScheduler;
87 }
88
89 private:
90 StdMidiMuse *mMuse;
91 Scheduler *mScheduler;
92 };
93
103 StdMidiMuse(unsigned char nStatus, unsigned char nData1, unsigned char nData2);
104
111 static void *operator new(size_t nSize) {
112 return PoolAlloc(static_cast<int>(nSize), sizeof(StdMidiMuse), "StdMidiMuse", 0);
113 }
114
120 static void operator delete(void *pBlock) {
121 PoolFree(sizeof(StdMidiMuse), pBlock);
122 }
123
130 ~StdMidiMuse() override;
131
139 void Play(Scheduler *pScheduler) override;
140
149 void PlayFrom(Scheduler *pScheduler, int nOffset) override;
150
160 void PlayWindow(Scheduler *pScheduler, int nStart, int nEnd) override;
161
168 void Stop() override;
169
177 bool IsPlaying() override;
178
186 int GetLength() override {
187 return 0;
188 }
189
197 Muse *Clone() override;
198
206 void SetNoteCB(NoteCB *pNoteCB) override;
207
217 static StdMidiMuse *NewProgramChange(unsigned char nChannel, unsigned char nProgram);
218
228 static StdMidiMuse *NewChannelPressure(unsigned char nChannel, unsigned char nPressure);
229
240 static StdMidiMuse *
241 NewControlChange(unsigned char nChannel, unsigned char nController, unsigned char nValue);
242
244 unsigned char GetData2() const {
245 return mData2;
246 }
247
249 unsigned char GetData1() const {
250 return mData1;
251 }
252
253private:
254 unsigned char mStatus;
255 unsigned char mData1;
256 unsigned char mData2;
258};
Unit of work a Scheduler runs at a set time.
Definition command.h:13
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
StdMidiCommand(StdMidiMuse *pMuse)
Construct the command of a muse.
Definition stdmidimuse.h:41
~StdMidiCommand() override=default
Destroy the object.
void Cancel()
Withdraw the command from the scheduler that queued it.
void SetScheduler(Scheduler *pScheduler)
Definition stdmidimuse.h:85
void Execute() override
Send the message, timed within the pump of the scheduler, and forget the scheduler.
Scheduler * GetScheduler() const
Definition stdmidimuse.h:80
unsigned char GetData2() const
Definition stdmidimuse.h:244
void Stop() override
Withdraw the queued message.
bool IsPlaying() override
Report whether the message waits to be sent.
static StdMidiMuse * NewChannelPressure(unsigned char nChannel, unsigned char nPressure)
Allocate a channel pressure message.
static StdMidiMuse * NewProgramChange(unsigned char nChannel, unsigned char nProgram)
Allocate a program change message.
void PlayWindow(Scheduler *pScheduler, int nStart, int nEnd) override
Send the message like PlayFrom() when the window is not empty.
void Play(Scheduler *pScheduler) override
Send the message at once.
void SetNoteCB(NoteCB *pNoteCB) override
Ignore a receiver of notes.
~StdMidiMuse() override
Withdraw the message and release the command.
StdMidiMuse(unsigned char nStatus, unsigned char nData1, unsigned char nData2)
Construct a muse for a message.
static StdMidiMuse * NewControlChange(unsigned char nChannel, unsigned char nController, unsigned char nValue)
Allocate a control change message.
int GetLength() override
Report the length of the message.
Definition stdmidimuse.h:186
void PlayFrom(Scheduler *pScheduler, int nOffset) override
Send the message after the ticks a negative offset delays it, or at once.
Muse * Clone() override
Produce a copy of the muse on the heap.
unsigned char GetData1() const
Definition stdmidimuse.h:249
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.