wavelength 1.0.0
Loading...
Searching...
No Matches
notemusebase.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 NoteMuseBase : public Muse {
19public:
26 class NoteCommand : public Command {
27 public:
33 explicit NoteCommand(NoteMuseBase *pMuse) : mMuse(pMuse), mScheduler(nullptr) {
34 }
35
42 static void *operator new(size_t nSize) {
43 return PoolAlloc(static_cast<int>(nSize), sizeof(NoteCommand), "NoteMuse cmd", 0);
44 }
45
51 static void operator delete(void *pBlock) {
52 PoolFree(sizeof(NoteCommand), pBlock);
53 }
54
61 ~NoteCommand() override = default;
62
69 void Execute() override;
70
77 void Cancel();
78
85 void NoteOff();
86
93 void NoteOn();
94
97 return mMuse;
98 }
99
102 return mScheduler;
103 }
104
106 void SetScheduler(Scheduler *pScheduler) {
107 mScheduler = pScheduler;
108 }
109
110 private:
111 NoteMuseBase *mMuse;
112 Scheduler *mScheduler;
113 };
114
125 NoteMuseBase(unsigned char nNote,
126 unsigned char nVelocity,
127 int nDuration,
128 unsigned char nChannel);
129
136 ~NoteMuseBase() override;
137
145 void Play(Scheduler *pScheduler) override;
146
155 void PlayFrom(Scheduler *pScheduler, int nOffset) override;
156
166 void PlayWindow(Scheduler *pScheduler, int nStart, int nEnd) override;
167
174 void Stop() override;
175
183 bool IsPlaying() override;
184
192 int GetLength() override {
193 return mDuration;
194 }
195
203 void SetNoteCB(NoteCB *pNoteCB) override;
204
205protected:
206 unsigned char mNote;
207 unsigned char mVelocity;
208 unsigned char mChannel;
209 unsigned char mSounding;
213};
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
void Execute() override
Send the note on, or the note off when the note sounds.
void Cancel()
Silence the note when it sounds and withdraw the command.
~NoteCommand() override=default
Release the command.
Scheduler * GetScheduler() const
Definition notemusebase.h:101
void SetScheduler(Scheduler *pScheduler)
Definition notemusebase.h:106
NoteMuseBase * GetMuse() const
Definition notemusebase.h:96
void NoteOff()
Send the note off.
NoteCommand(NoteMuseBase *pMuse)
Construct the command of a note.
Definition notemusebase.h:33
void NoteOn()
Send the note on and report it to the receiver of the note.
unsigned char mChannel
Definition notemusebase.h:208
int mDuration
Definition notemusebase.h:210
unsigned char mSounding
Definition notemusebase.h:209
void SetNoteCB(NoteCB *pNoteCB) override
Set the receiver of the note.
NoteMuseBase(unsigned char nNote, unsigned char nVelocity, int nDuration, unsigned char nChannel)
Construct a note.
unsigned char mNote
Definition notemusebase.h:206
Ptr< NoteCommand > mCmd
Definition notemusebase.h:211
void Stop() override
Withdraw the queued note and silence it.
void PlayWindow(Scheduler *pScheduler, int nStart, int nEnd) override
Play the note like PlayFrom() when the window is not empty.
void Play(Scheduler *pScheduler) override
Play the note at once.
~NoteMuseBase() override
Silence the note and release the command.
int GetLength() override
Report the length of the note.
Definition notemusebase.h:192
bool IsPlaying() override
Report whether the note waits to sound or sounds.
unsigned char mVelocity
Definition notemusebase.h:207
NoteCB * mNoteCB
Definition notemusebase.h:212
void PlayFrom(Scheduler *pScheduler, int nOffset) override
Play the note after the ticks a negative offset delays it.
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.